Adds second part of quotas support for Nova V3 API

Adds support and tests for the os-quota-class-sets
extension for the Nova V3 API. Note that compared to
the V2 version this removes the ability to set quotas
which are not relevant to the V3 API (eg injected file
quotas are not relevant because the os-personalities
extension has been removed).

Partially implements blueprint v3-api

Change-Id: I3e7f36407f2f59737ecbce2c8ce014cef623ecdc
This commit is contained in:
Chris Yeoh 2013-12-11 20:51:01 +10:30
parent cfd38a7ef6
commit 6a9c81843f
5 changed files with 55 additions and 60 deletions

View File

@ -0,0 +1,25 @@
# Copyright IBM Corp. 2013
#
# 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.tests.v1_1 import test_quota_classes
from novaclient.tests.v3 import fakes
class QuotaClassSetsTest(test_quota_classes.QuotaClassSetsTest):
def setUp(self):
super(QuotaClassSetsTest, self).setUp()
self.cs = self._get_fake_client()
def _get_fake_client(self):
return fakes.FakeClient()

View File

@ -36,28 +36,12 @@ class QuotaClassSetManager(base.Manager):
return self._get("/os-quota-class-sets/%s" % (class_name),
"quota_class_set")
def update(self, class_name, metadata_items=None,
injected_file_content_bytes=None, injected_file_path_bytes=None,
volumes=None, gigabytes=None,
ram=None, floating_ips=None, instances=None,
injected_files=None, cores=None, key_pairs=None,
security_groups=None, security_group_rules=None):
def _update_body(self, **kwargs):
return {'quota_class_set': kwargs}
body = {'quota_class_set': {
'class_name': class_name,
'metadata_items': metadata_items,
'key_pairs': key_pairs,
'injected_file_content_bytes': injected_file_content_bytes,
'injected_file_path_bytes': injected_file_path_bytes,
'volumes': volumes,
'gigabytes': gigabytes,
'ram': ram,
'floating_ips': floating_ips,
'instances': instances,
'injected_files': injected_files,
'cores': cores,
'security_groups': security_groups,
'security_group_rules': security_group_rules}}
def update(self, class_name, **kwargs):
kwargs['class_name'] = class_name
body = self._update_body(**kwargs)
for key in list(body['quota_class_set']):
if body['quota_class_set'][key] is None:

View File

@ -21,6 +21,7 @@ from novaclient.v3 import flavor_access
from novaclient.v3 import flavors
from novaclient.v3 import hosts
from novaclient.v3 import images
from novaclient.v3 import quota_classes
from novaclient.v3 import quotas
from novaclient.v3 import servers
@ -65,6 +66,7 @@ class Client(object):
self.flavor_access = flavor_access.FlavorAccessManager(self)
self.images = images.ImageManager(self)
self.quotas = quotas.QuotaSetManager(self)
self.quota_classes = quota_classes.QuotaClassSetManager(self)
self.servers = servers.ServerManager(self)
# Add in any extensions...

View File

@ -0,0 +1,23 @@
# Copyright IBM Corp. 2013
#
# 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.v1_1 import quota_classes
class QuotaClassSet(quota_classes.QuotaClassSet):
pass
class QuotaClassSetManager(quota_classes.QuotaClassSetManager):
resource_class = QuotaClassSet

View File

@ -2974,14 +2974,6 @@ def do_quota_class_show(cs, args):
metavar='<gigabytes>',
type=int, default=None,
help='New value for the "gigabytes" quota.')
@utils.arg('--floating-ips',
metavar='<floating-ips>',
type=int,
default=None,
help='New value for the "floating-ips" quota.')
@utils.arg('--floating_ips',
type=int,
help=argparse.SUPPRESS)
@utils.arg('--metadata-items',
metavar='<metadata-items>',
type=int,
@ -2990,42 +2982,11 @@ def do_quota_class_show(cs, args):
@utils.arg('--metadata_items',
type=int,
help=argparse.SUPPRESS)
@utils.arg('--injected-files',
metavar='<injected-files>',
type=int,
default=None,
help='New value for the "injected-files" quota.')
@utils.arg('--injected_files',
type=int,
help=argparse.SUPPRESS)
@utils.arg('--injected-file-content-bytes',
metavar='<injected-file-content-bytes>',
type=int,
default=None,
help='New value for the "injected-file-content-bytes" quota.')
@utils.arg('--injected_file_content_bytes',
type=int,
help=argparse.SUPPRESS)
@utils.arg('--injected-file-path-bytes',
metavar='<injected-file-path-bytes>',
type=int,
default=None,
help='New value for the "injected-file-path-bytes" quota.')
@utils.arg('--key-pairs',
metavar='<key-pairs>',
type=int,
default=None,
help='New value for the "key-pairs" quota.')
@utils.arg('--security-groups',
metavar='<security-groups>',
type=int,
default=None,
help='New value for the "security-groups" quota.')
@utils.arg('--security-group-rules',
metavar='<security-group-rules>',
type=int,
default=None,
help='New value for the "security-group-rules" quota.')
def do_quota_class_update(cs, args):
"""Update the quotas for a quota class."""