Skip to content

Commit 04d0368

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add network support to quota show"
2 parents 0935700 + 54ab9fb commit 04d0368

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

‎openstackclient/common/quota.py‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
'volumes': 'volumes',
4949
}
5050

51+
NETWORK_QUOTAS = {
52+
'floatingip': 'floating-ips',
53+
'security_group_rule': 'secgroup-rules',
54+
'security_group': 'secgroups',
55+
}
56+
5157

5258
class SetQuota(command.Command):
5359
"""Set quotas for project or class"""
@@ -147,7 +153,7 @@ def get_parser(self, prog_name):
147153
)
148154
return parser
149155

150-
def get_quota(self, client, parsed_args):
156+
def get_compute_volume_quota(self, client, parsed_args):
151157
try:
152158
if parsed_args.quota_class:
153159
quota = client.quota_classes.get(parsed_args.project)
@@ -162,29 +168,47 @@ def get_quota(self, client, parsed_args):
162168
raise e
163169
return quota._info
164170

171+
def get_network_quota(self, parsed_args):
172+
if parsed_args.quota_class or parsed_args.default:
173+
return {}
174+
service_catalog = self.app.client_manager.auth_ref.service_catalog
175+
if 'network' in service_catalog.get_endpoints():
176+
network_client = self.app.client_manager.network
177+
return network_client.show_quota(parsed_args.project)['quota']
178+
else:
179+
return {}
180+
165181
def take_action(self, parsed_args):
166182
self.log.debug('take_action(%s)', parsed_args)
167183

168184
compute_client = self.app.client_manager.compute
169185
volume_client = self.app.client_manager.volume
170-
171186
# NOTE(dtroyer): These quota API calls do not validate the project
172187
# or class arguments and return what appears to be
173188
# the default quota values if the project or class
174189
# does not exist. If this is determined to be the
175190
# intended behaviour of the API we will validate
176191
# the argument with Identity ourselves later.
177-
compute_quota_info = self.get_quota(compute_client, parsed_args)
178-
volume_quota_info = self.get_quota(volume_client, parsed_args)
192+
compute_quota_info = self.get_compute_volume_quota(compute_client,
193+
parsed_args)
194+
volume_quota_info = self.get_compute_volume_quota(volume_client,
195+
parsed_args)
196+
network_quota_info = self.get_network_quota(parsed_args)
179197

180198
info = {}
181199
info.update(compute_quota_info)
182200
info.update(volume_quota_info)
201+
info.update(network_quota_info)
183202

184203
# Map the internal quota names to the external ones
204+
# COMPUTE_QUOTAS and NETWORK_QUOTAS share floating-ips,
205+
# secgroup-rules and secgroups as dict value, so when
206+
# neutron is enabled, quotas of these three resources
207+
# in nova will be replaced by neutron's.
185208
for k, v in itertools.chain(
186-
COMPUTE_QUOTAS.items(), VOLUME_QUOTAS.items()):
187-
if not k == v and info[k]:
209+
COMPUTE_QUOTAS.items(), VOLUME_QUOTAS.items(),
210+
NETWORK_QUOTAS.items()):
211+
if not k == v and info.get(k):
188212
info[v] = info[k]
189213
info.pop(k)
190214

0 commit comments

Comments
 (0)