From 54ab9fb230e70042a244ba7b0e2aac8fed2bf201 Mon Sep 17 00:00:00 2001 From: zhiyuan_cai Date: Thu, 15 Jan 2015 18:58:39 +0800 Subject: [PATCH] Add network support to quota show Currently quota show only lists quotas of Nova and Cinder, we should make it also support Neutron resources. Also, Nova and Neutron may have conflicts in the quotas of the following resources: floating ip, security group and security group rule. When Neutron is enabled, we should display the quotas of the above resouces in Neutron, not Nova. Change-Id: I6e508d2077b6cda41ca93d81a82f39aee0ebfb4c Closes-Bug: #1411160 --- openstackclient/common/quota.py | 36 +++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 6d04b5c99d..dde4a9acb6 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -48,6 +48,12 @@ VOLUME_QUOTAS = { 'volumes': 'volumes', } +NETWORK_QUOTAS = { + 'floatingip': 'floating-ips', + 'security_group_rule': 'secgroup-rules', + 'security_group': 'secgroups', +} + class SetQuota(command.Command): """Set quotas for project or class""" @@ -147,7 +153,7 @@ class ShowQuota(show.ShowOne): ) return parser - def get_quota(self, client, parsed_args): + def get_compute_volume_quota(self, client, parsed_args): try: if parsed_args.quota_class: quota = client.quota_classes.get(parsed_args.project) @@ -162,29 +168,47 @@ class ShowQuota(show.ShowOne): raise e return quota._info + def get_network_quota(self, parsed_args): + if parsed_args.quota_class or parsed_args.default: + return {} + service_catalog = self.app.client_manager.auth_ref.service_catalog + if 'network' in service_catalog.get_endpoints(): + network_client = self.app.client_manager.network + return network_client.show_quota(parsed_args.project)['quota'] + else: + return {} + def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) compute_client = self.app.client_manager.compute volume_client = self.app.client_manager.volume - # NOTE(dtroyer): These quota API calls do not validate the project # or class arguments and return what appears to be # the default quota values if the project or class # does not exist. If this is determined to be the # intended behaviour of the API we will validate # the argument with Identity ourselves later. - compute_quota_info = self.get_quota(compute_client, parsed_args) - volume_quota_info = self.get_quota(volume_client, parsed_args) + compute_quota_info = self.get_compute_volume_quota(compute_client, + parsed_args) + volume_quota_info = self.get_compute_volume_quota(volume_client, + parsed_args) + network_quota_info = self.get_network_quota(parsed_args) info = {} info.update(compute_quota_info) info.update(volume_quota_info) + info.update(network_quota_info) # Map the internal quota names to the external ones + # COMPUTE_QUOTAS and NETWORK_QUOTAS share floating-ips, + # secgroup-rules and secgroups as dict value, so when + # neutron is enabled, quotas of these three resources + # in nova will be replaced by neutron's. for k, v in itertools.chain( - COMPUTE_QUOTAS.items(), VOLUME_QUOTAS.items()): - if not k == v and info[k]: + COMPUTE_QUOTAS.items(), VOLUME_QUOTAS.items(), + NETWORK_QUOTAS.items()): + if not k == v and info.get(k): info[v] = info[k] info.pop(k)