diff --git a/openstack_dashboard/api/neutron.py b/openstack_dashboard/api/neutron.py index 8962179936..7a19605345 100644 --- a/openstack_dashboard/api/neutron.py +++ b/openstack_dashboard/api/neutron.py @@ -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) diff --git a/openstack_dashboard/dashboards/project/floating_ips/tests.py b/openstack_dashboard/dashboards/project/floating_ips/tests.py index e7fc4bd276..51f2d0bfef 100644 --- a/openstack_dashboard/dashboards/project/floating_ips/tests.py +++ b/openstack_dashboard/dashboards/project/floating_ips/tests.py @@ -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)) \ diff --git a/openstack_dashboard/test/unit/usage/test_quotas.py b/openstack_dashboard/test/unit/usage/test_quotas.py index 5cd907723a..6af3bd0618 100644 --- a/openstack_dashboard/test/unit/usage/test_quotas.py +++ b/openstack_dashboard/test/unit/usage/test_quotas.py @@ -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: diff --git a/openstack_dashboard/usage/quotas.py b/openstack_dashboard/usage/quotas.py index 54aaf4711f..ce3925d5b3 100644 --- a/openstack_dashboard/usage/quotas.py +++ b/openstack_dashboard/usage/quotas.py @@ -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: