Merge "quota: Use neutron quota_details API to retrieve usage"
This commit is contained in:
commit
135a279246
@ -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)
|
||||
|
@ -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)) \
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user