2013-09-20 03:31:42 +08:00
|
|
|
# Copyright (c) 2011 OpenStack Foundation
|
2012-08-16 15:48:55 -06: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.
|
|
|
|
|
|
|
|
from cinderclient import base
|
|
|
|
|
|
|
|
|
|
|
|
class QuotaSet(base.Resource):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self):
|
2013-06-09 11:18:02 +02:00
|
|
|
"""QuotaSet does not have a 'id' attribute but base. Resource needs it
|
|
|
|
to self-refresh and QuotaSet is indexed by tenant_id.
|
|
|
|
"""
|
2012-08-16 15:48:55 -06:00
|
|
|
return self.tenant_id
|
|
|
|
|
|
|
|
def update(self, *args, **kwargs):
|
2014-05-14 11:11:08 -03:00
|
|
|
return self.manager.update(self.tenant_id, *args, **kwargs)
|
2012-08-16 15:48:55 -06:00
|
|
|
|
|
|
|
|
2013-05-19 18:24:14 +03:00
|
|
|
class QuotaSetManager(base.Manager):
|
2012-08-16 15:48:55 -06:00
|
|
|
resource_class = QuotaSet
|
|
|
|
|
2013-09-26 21:48:17 +00:00
|
|
|
def get(self, tenant_id, usage=False):
|
2012-08-16 15:48:55 -06:00
|
|
|
if hasattr(tenant_id, 'tenant_id'):
|
|
|
|
tenant_id = tenant_id.tenant_id
|
2013-09-26 21:48:17 +00:00
|
|
|
return self._get("/os-quota-sets/%s?usage=%s" % (tenant_id, usage),
|
|
|
|
"quota_set")
|
2012-08-16 15:48:55 -06:00
|
|
|
|
2013-03-21 16:53:43 -05:00
|
|
|
def update(self, tenant_id, **updates):
|
|
|
|
body = {'quota_set': {'tenant_id': tenant_id}}
|
2012-08-16 15:48:55 -06:00
|
|
|
|
2013-10-06 22:39:41 -04:00
|
|
|
for update in updates:
|
2013-03-21 16:53:43 -05:00
|
|
|
body['quota_set'][update] = updates[update]
|
2012-08-16 15:48:55 -06:00
|
|
|
|
2014-05-14 11:11:08 -03:00
|
|
|
result = self._update('/os-quota-sets/%s' % (tenant_id), body)
|
|
|
|
return self.resource_class(self, result['quota_set'], loaded=True)
|
2012-08-16 15:48:55 -06:00
|
|
|
|
|
|
|
def defaults(self, tenant_id):
|
|
|
|
return self._get('/os-quota-sets/%s/defaults' % tenant_id,
|
|
|
|
'quota_set')
|
2014-02-19 15:37:25 -03:00
|
|
|
|
|
|
|
def delete(self, tenant_id):
|
|
|
|
if hasattr(tenant_id, 'tenant_id'):
|
|
|
|
tenant_id = tenant_id.tenant_id
|
|
|
|
return self._delete("/os-quota-sets/%s" % tenant_id)
|