diff --git a/cinderclient/v1/quota_classes.py b/cinderclient/v1/quota_classes.py index df637eaa7..c6a85f4ac 100644 --- a/cinderclient/v1/quota_classes.py +++ b/cinderclient/v1/quota_classes.py @@ -36,20 +36,10 @@ class QuotaClassSetManager(base.Manager): return self._get("/os-quota-class-sets/%s" % (class_name), "quota_class_set") - def update(self, - class_name, - volumes=None, - snapshots=None, - gigabytes=None): + def update(self, class_name, **updates): + body = {'quota_class_set': {'class_name': class_name}} - body = {'quota_class_set': { - 'class_name': class_name, - 'volumes': volumes, - 'snapshots': snapshots, - 'gigabytes': gigabytes}} - - for key in list(body['quota_class_set'].keys()): - if body['quota_class_set'][key] is None: - body['quota_class_set'].pop(key) + for update in updates.keys(): + body['quota_class_set'][update] = updates[update] self._update('/os-quota-class-sets/%s' % (class_name), body) diff --git a/cinderclient/v1/quotas.py b/cinderclient/v1/quotas.py index ce7a91283..bf37462b8 100644 --- a/cinderclient/v1/quotas.py +++ b/cinderclient/v1/quotas.py @@ -37,17 +37,11 @@ class QuotaSetManager(base.Manager): tenant_id = tenant_id.tenant_id return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set") - def update(self, tenant_id, volumes=None, snapshots=None, gigabytes=None): + def update(self, tenant_id, **updates): + body = {'quota_set': {'tenant_id': tenant_id}} - body = {'quota_set': { - 'tenant_id': tenant_id, - 'volumes': volumes, - 'snapshots': snapshots, - 'gigabytes': gigabytes}} - - for key in list(body['quota_set'].keys()): - if body['quota_set'][key] is None: - body['quota_set'].pop(key) + for update in updates.keys(): + body['quota_set'][update] = updates[update] self._update('/os-quota-sets/%s' % (tenant_id), body) diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index eeb30ba11..f1b06dead 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -539,12 +539,19 @@ def do_credentials(cs, args): utils.print_dict(catalog['access']['user'], "User Credentials") utils.print_dict(catalog['access']['token'], "Token") + _quota_resources = ['volumes', 'snapshots', 'gigabytes'] def _quota_show(quotas): quota_dict = {} - for resource in _quota_resources: + for resource in quotas._info.keys(): + good_name = False + for name in _quota_resources: + if resource.startswith(name): + good_name = True + if not good_name: + continue quota_dict[resource] = getattr(quotas, resource, None) utils.print_dict(quota_dict) @@ -554,6 +561,8 @@ def _quota_update(manager, identifier, args): for resource in _quota_resources: val = getattr(args, resource, None) if val is not None: + if args.volume_type: + resource = resource + '_%s' % args.volume_type updates[resource] = val if updates: @@ -592,6 +601,10 @@ def do_quota_defaults(cs, args): metavar='<gigabytes>', type=int, default=None, help='New value for the "gigabytes" quota.') +@utils.arg('--volume-type', + metavar='<volume_type_name>', + default=None, + help='Volume type (Optional, Default=None)') @utils.service_type('volume') def do_quota_update(cs, args): """Update the quotas for a tenant.""" @@ -622,6 +635,10 @@ def do_quota_class_show(cs, args): metavar='<gigabytes>', type=int, default=None, help='New value for the "gigabytes" quota.') +@utils.arg('--volume-type', + metavar='<volume_type_name>', + default=None, + help='Volume type (Optional, Default=None)') @utils.service_type('volume') def do_quota_class_update(cs, args): """Update the quotas for a quota class.""" diff --git a/cinderclient/v2/quota_classes.py b/cinderclient/v2/quota_classes.py index a4e2043d1..2d46a6d83 100644 --- a/cinderclient/v2/quota_classes.py +++ b/cinderclient/v2/quota_classes.py @@ -34,20 +34,10 @@ class QuotaClassSetManager(base.Manager): return self._get("/os-quota-class-sets/%s" % (class_name), "quota_class_set") - def update(self, - class_name, - volumes=None, - snapshots=None, - gigabytes=None): + def update(self, class_name, **updates): + body = {'quota_class_set': {'class_name': class_name}} - body = {'quota_class_set': { - 'class_name': class_name, - 'volumes': volumes, - 'snapshots': snapshots, - 'gigabytes': gigabytes}} - - for key in list(body['quota_class_set'].keys()): - if body['quota_class_set'][key] is None: - body['quota_class_set'].pop(key) + for update in updates.keys(): + body['quota_class_set'][update] = updates[update] self._update('/os-quota-class-sets/%s' % (class_name), body) diff --git a/cinderclient/v2/quotas.py b/cinderclient/v2/quotas.py index 30c4186d5..5b19b079e 100644 --- a/cinderclient/v2/quotas.py +++ b/cinderclient/v2/quotas.py @@ -35,17 +35,11 @@ class QuotaSetManager(base.Manager): tenant_id = tenant_id.tenant_id return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set") - def update(self, tenant_id, volumes=None, snapshots=None, gigabytes=None): + def update(self, tenant_id, **updates): + body = {'quota_set': {'tenant_id': tenant_id}} - body = {'quota_set': { - 'tenant_id': tenant_id, - 'volumes': volumes, - 'snapshots': snapshots, - 'gigabytes': gigabytes}} - - for key in list(body['quota_set'].keys()): - if body['quota_set'][key] is None: - body['quota_set'].pop(key) + for update in updates.keys(): + body['quota_set'][update] = updates[update] self._update('/os-quota-sets/%s' % (tenant_id), body) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 98883d6ba..fbba8ae8a 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -604,12 +604,19 @@ def do_credentials(cs, args): utils.print_dict(catalog['access']['user'], "User Credentials") utils.print_dict(catalog['access']['token'], "Token") + _quota_resources = ['volumes', 'snapshots', 'gigabytes'] def _quota_show(quotas): quota_dict = {} - for resource in _quota_resources: + for resource in quotas._info.keys(): + good_name = False + for name in _quota_resources: + if resource.startswith(name): + good_name = True + if not good_name: + continue quota_dict[resource] = getattr(quotas, resource, None) utils.print_dict(quota_dict) @@ -619,6 +626,8 @@ def _quota_update(manager, identifier, args): for resource in _quota_resources: val = getattr(args, resource, None) if val is not None: + if args.volume_type: + resource = resource + '_%s' % args.volume_type updates[resource] = val if updates: @@ -660,6 +669,10 @@ def do_quota_defaults(cs, args): metavar='<gigabytes>', type=int, default=None, help='New value for the "gigabytes" quota.') +@utils.arg('--volume-type', + metavar='<volume_type_name>', + default=None, + help='Volume type (Optional, Default=None)') @utils.service_type('volume') def do_quota_update(cs, args): """Update the quotas for a tenant.""" @@ -692,6 +705,10 @@ def do_quota_class_show(cs, args): metavar='<gigabytes>', type=int, default=None, help='New value for the "gigabytes" quota.') +@utils.arg('--volume-type', + metavar='<volume_type_name>', + default=None, + help='Volume type (Optional, Default=None)') @utils.service_type('volume') def do_quota_class_update(cs, args): """Update the quotas for a quota class."""