2013-03-13 18:09:17 -04:00
|
|
|
# Copyright 2011 OpenStack Foundation
|
2011-08-09 13:12:09 -07:00
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2011-08-08 14:48:07 -07:00
|
|
|
from novaclient import base
|
|
|
|
|
|
|
|
|
|
|
|
class QuotaSet(base.Resource):
|
2011-08-15 13:38:40 -07:00
|
|
|
|
2012-01-03 17:00:29 +01:00
|
|
|
@property
|
|
|
|
def id(self):
|
|
|
|
"""QuotaSet does not have a 'id' attribute but base.Resource needs it
|
2013-12-12 03:55:50 +00:00
|
|
|
to self-refresh and QuotaSet is indexed by tenant_id.
|
|
|
|
"""
|
2012-01-03 17:00:29 +01:00
|
|
|
return self.tenant_id
|
2011-08-08 14:48:07 -07:00
|
|
|
|
|
|
|
def update(self, *args, **kwargs):
|
2012-12-22 20:12:20 +04:00
|
|
|
return self.manager.update(self.tenant_id, *args, **kwargs)
|
2011-08-08 14:48:07 -07:00
|
|
|
|
|
|
|
|
2013-05-15 16:45:01 +03:00
|
|
|
class QuotaSetManager(base.Manager):
|
2011-08-08 14:48:07 -07:00
|
|
|
resource_class = QuotaSet
|
|
|
|
|
2013-07-30 10:18:59 +08:00
|
|
|
def get(self, tenant_id, user_id=None):
|
2011-08-08 14:48:07 -07:00
|
|
|
if hasattr(tenant_id, 'tenant_id'):
|
2011-08-15 13:38:40 -07:00
|
|
|
tenant_id = tenant_id.tenant_id
|
2013-07-30 10:18:59 +08:00
|
|
|
if user_id:
|
|
|
|
url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
|
|
|
|
else:
|
|
|
|
url = '/os-quota-sets/%s' % tenant_id
|
|
|
|
return self._get(url, "quota_set")
|
2011-08-08 14:48:07 -07:00
|
|
|
|
2013-12-11 17:49:25 +10:30
|
|
|
def _update_body(self, tenant_id, **kwargs):
|
|
|
|
kwargs['tenant_id'] = tenant_id
|
|
|
|
return {'quota_set': kwargs}
|
2011-08-08 14:48:07 -07:00
|
|
|
|
2013-12-11 17:49:25 +10:30
|
|
|
def update(self, tenant_id, **kwargs):
|
|
|
|
|
|
|
|
user_id = kwargs.pop('user_id', None)
|
|
|
|
body = self._update_body(tenant_id, **kwargs)
|
2011-08-08 14:48:07 -07:00
|
|
|
|
2013-09-22 09:04:20 -07:00
|
|
|
for key in list(body['quota_set']):
|
2012-01-04 09:54:39 +08:00
|
|
|
if body['quota_set'][key] is None:
|
2011-08-08 14:48:07 -07:00
|
|
|
body['quota_set'].pop(key)
|
|
|
|
|
2013-07-30 10:18:59 +08:00
|
|
|
if user_id:
|
|
|
|
url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
|
|
|
|
else:
|
|
|
|
url = '/os-quota-sets/%s' % tenant_id
|
|
|
|
return self._update(url, body, 'quota_set')
|
2011-08-08 14:48:07 -07:00
|
|
|
|
2011-08-15 13:38:40 -07:00
|
|
|
def defaults(self, tenant_id):
|
|
|
|
return self._get('/os-quota-sets/%s/defaults' % tenant_id,
|
2011-08-16 13:36:45 -07:00
|
|
|
'quota_set')
|
2013-06-03 17:33:17 +05:30
|
|
|
|
2013-07-30 10:18:59 +08:00
|
|
|
def delete(self, tenant_id, user_id=None):
|
|
|
|
if user_id:
|
|
|
|
url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
|
|
|
|
else:
|
|
|
|
url = '/os-quota-sets/%s' % tenant_id
|
|
|
|
self._delete(url)
|