Merge "quota: Use neutron quota_details API to retrieve usage"

This commit is contained in:
Zuul 2017-12-26 21:20:18 +00:00 committed by Gerrit Code Review
commit 135a279246
4 changed files with 34 additions and 0 deletions

View File

@ -1447,6 +1447,13 @@ def tenant_quota_update(request, tenant_id, **kwargs):
return neutronclient(request).update_quota(tenant_id, quotas)
@profiler.trace
def tenant_quota_detail_get(request, tenant_id=None):
tenant_id = tenant_id or request.user.tenant_id
response = neutronclient(request).get('/quotas/%s/details' % tenant_id)
return response['quota']
@profiler.trace
def agent_list(request, **params):
agents = neutronclient(request).list_agents(**params)

View File

@ -333,6 +333,8 @@ class FloatingIpViewTests(test.TestCase):
.AndReturn(True)
api.neutron.is_router_enabled(IsA(http.HttpRequest)) \
.AndReturn(True)
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'quota_details').AndReturn(False)
api.neutron.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \
.AndReturn(self.neutron_quotas.first())
api.neutron.floating_ip_supported(IsA(http.HttpRequest)) \

View File

@ -472,6 +472,8 @@ class QuotaTests(test.APITestCase):
api.base.is_service_enabled(IsA(http.HttpRequest), 'compute') \
.MultipleTimes().AndReturn(True)
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'quota_details').AndReturn(False)
api.neutron.tenant_quota_get(IsA(http.HttpRequest), '1') \
.AndReturn(self.neutron_quotas.first())
if 'networks' in targets:

View File

@ -355,6 +355,29 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
if not enabled_quotas:
return
if neutron.is_extension_supported(request, 'quota_details'):
details = neutron.tenant_quota_detail_get(request, tenant_id)
for name, neutron_name in (
('floating_ips', 'floatingip'),
('security_groups', 'security_group'),
('security_group_rules', 'security_group_rule'),
('networks', 'network'),
('subnets', 'subnet'),
('ports', 'port'),
('routers', 'router')):
if neutron_name in disabled_quotas:
continue
detail = details[neutron_name]
usages.add_quota(base.Quota(name, detail['limit']))
usages.tally(name, detail['used'] + detail['reserved'])
else:
_get_tenant_network_usages_legacy(
request, usages, disabled_quotas, tenant_id)
def _get_tenant_network_usages_legacy(request, usages, disabled_quotas,
tenant_id):
enabled_quotas = NEUTRON_QUOTA_FIELDS - disabled_quotas
qs = base.QuotaSet()
_get_neutron_quota_data(request, qs, disabled_quotas, tenant_id)
for quota in qs: