2013-03-13 18:09:17 -04:00
|
|
|
# Copyright 2012 OpenStack Foundation
|
2012-03-14 16:14:56 -05: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 novaclient import base
|
|
|
|
|
|
|
|
|
|
|
|
class QuotaClassSet(base.Resource):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self):
|
|
|
|
"""QuotaClassSet does not have a 'id' attribute but base.Resource
|
2013-12-12 03:55:50 +00:00
|
|
|
needs it to self-refresh and QuotaSet is indexed by class_name.
|
|
|
|
"""
|
2012-03-14 16:14:56 -05:00
|
|
|
return self.class_name
|
|
|
|
|
|
|
|
def update(self, *args, **kwargs):
|
2012-12-22 20:12:20 +04:00
|
|
|
return self.manager.update(self.class_name, *args, **kwargs)
|
2012-03-14 16:14:56 -05:00
|
|
|
|
|
|
|
|
2013-05-15 16:45:01 +03:00
|
|
|
class QuotaClassSetManager(base.Manager):
|
2012-03-14 16:14:56 -05:00
|
|
|
resource_class = QuotaClassSet
|
|
|
|
|
|
|
|
def get(self, class_name):
|
|
|
|
return self._get("/os-quota-class-sets/%s" % (class_name),
|
|
|
|
"quota_class_set")
|
|
|
|
|
2013-12-11 20:51:01 +10:30
|
|
|
def _update_body(self, **kwargs):
|
|
|
|
return {'quota_class_set': kwargs}
|
2012-03-14 16:14:56 -05:00
|
|
|
|
2013-12-11 20:51:01 +10:30
|
|
|
def update(self, class_name, **kwargs):
|
|
|
|
kwargs['class_name'] = class_name
|
|
|
|
body = self._update_body(**kwargs)
|
2012-03-14 16:14:56 -05:00
|
|
|
|
2013-09-22 09:04:20 -07:00
|
|
|
for key in list(body['quota_class_set']):
|
2012-03-14 16:14:56 -05:00
|
|
|
if body['quota_class_set'][key] is None:
|
|
|
|
body['quota_class_set'].pop(key)
|
|
|
|
|
2012-12-22 20:12:20 +04:00
|
|
|
return self._update('/os-quota-class-sets/%s' % (class_name),
|
|
|
|
body,
|
|
|
|
'quota_class_set')
|