summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2017-12-03 19:52:01 +0900
committerAkihiro Motoki <amotoki@gmail.com>2017-12-13 20:27:02 +0900
commit1340904d47a256979cca3a651d4de4a1a4717dde (patch)
tree80738a78d27bd45c68c085039b67e933583cb932
parentcd3f3e51275a29a7c30c711370c8257c3d07aaea (diff)
quota: Use network quota field names consistently
Previously neutron quota names and nova-network quota names are mixly used and this makes the readability terrible. We no longer supports nova-network, so it looks simple to use neutron quota names consistently. Neutron quota names use singular form and it is different from nova and cinder (which adopt plural form as quota names). Although it might be confusing, the mixed usage is much worse. Some wrapper layer may address singular vs plural form issue, but it can be solved later. Let's use neutron quota names directly now to simplify the code. blueprint make-quotas-great-again Change-Id: Ie31414ada34cbdbd046063b512d3cef0a6e68acf
Notes
Notes (review): Code-Review+2: Ivan Kolodyazhny <e0ne@e0ne.info> Workflow+1: Ivan Kolodyazhny <e0ne@e0ne.info> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 26 Dec 2017 21:40:34 +0000 Reviewed-on: https://review.openstack.org/526700 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--openstack_dashboard/dashboards/admin/networks/ports/tables.py4
-rw-r--r--openstack_dashboard/dashboards/admin/networks/subnets/tables.py6
-rw-r--r--openstack_dashboard/dashboards/admin/networks/subnets/tests.py2
-rw-r--r--openstack_dashboard/dashboards/admin/networks/tables.py6
-rw-r--r--openstack_dashboard/dashboards/admin/networks/tests.py16
-rw-r--r--openstack_dashboard/dashboards/project/floating_ips/forms.py4
-rw-r--r--openstack_dashboard/dashboards/project/floating_ips/tables.py4
-rw-r--r--openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html10
-rw-r--r--openstack_dashboard/dashboards/project/floating_ips/tests.py15
-rw-r--r--openstack_dashboard/dashboards/project/floating_ips/views.py2
-rw-r--r--openstack_dashboard/dashboards/project/network_topology/tests.py8
-rw-r--r--openstack_dashboard/dashboards/project/network_topology/utils.py4
-rw-r--r--openstack_dashboard/dashboards/project/networks/ports/tables.py6
-rw-r--r--openstack_dashboard/dashboards/project/networks/subnets/tables.py6
-rw-r--r--openstack_dashboard/dashboards/project/networks/tables.py12
-rw-r--r--openstack_dashboard/dashboards/project/networks/tests.py54
-rw-r--r--openstack_dashboard/dashboards/project/routers/tables.py6
-rw-r--r--openstack_dashboard/dashboards/project/routers/tests.py22
-rw-r--r--openstack_dashboard/dashboards/project/security_groups/tables.py4
-rw-r--r--openstack_dashboard/dashboards/project/security_groups/tests.py18
-rw-r--r--openstack_dashboard/test/test_data/neutron_data.py12
-rw-r--r--openstack_dashboard/test/unit/usage/test_quotas.py38
-rw-r--r--openstack_dashboard/usage/quotas.py132
23 files changed, 160 insertions, 231 deletions
diff --git a/openstack_dashboard/dashboards/admin/networks/ports/tables.py b/openstack_dashboard/dashboards/admin/networks/ports/tables.py
index 20fa3c1..580afec 100644
--- a/openstack_dashboard/dashboards/admin/networks/ports/tables.py
+++ b/openstack_dashboard/dashboards/admin/networks/ports/tables.py
@@ -38,8 +38,8 @@ class CreatePort(project_tables.CreatePort):
38 network = self.table._get_network() 38 network = self.table._get_network()
39 tenant_id = network.tenant_id 39 tenant_id = network.tenant_id
40 usages = quotas.tenant_quota_usages( 40 usages = quotas.tenant_quota_usages(
41 request, tenant_id=tenant_id, targets=('ports', )) 41 request, tenant_id=tenant_id, targets=('port', ))
42 if usages.get('ports', {}).get('available', 1) <= 0: 42 if usages.get('port', {}).get('available', 1) <= 0:
43 if "disabled" not in self.classes: 43 if "disabled" not in self.classes:
44 self.classes = [c for c in self.classes] + ["disabled"] 44 self.classes = [c for c in self.classes] + ["disabled"]
45 self.verbose_name = _("Create Port (Quota exceeded)") 45 self.verbose_name = _("Create Port (Quota exceeded)")
diff --git a/openstack_dashboard/dashboards/admin/networks/subnets/tables.py b/openstack_dashboard/dashboards/admin/networks/subnets/tables.py
index 75275c7..5c72803 100644
--- a/openstack_dashboard/dashboards/admin/networks/subnets/tables.py
+++ b/openstack_dashboard/dashboards/admin/networks/subnets/tables.py
@@ -80,11 +80,11 @@ class CreateSubnet(proj_tables.SubnetPolicyTargetMixin, tables.LinkAction):
80 def allowed(self, request, datum=None): 80 def allowed(self, request, datum=None):
81 network = self.table._get_network() 81 network = self.table._get_network()
82 usages = quotas.tenant_quota_usages( 82 usages = quotas.tenant_quota_usages(
83 request, tenant_id=network.tenant_id, targets=('subnets', )) 83 request, tenant_id=network.tenant_id, targets=('subnet', ))
84 84
85 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 85 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
86 # usages["subnets'] is empty 86 # usages["subnet'] is empty
87 if usages.get('subnets', {}).get('available', 1) <= 0: 87 if usages.get('subnet', {}).get('available', 1) <= 0:
88 if 'disabled' not in self.classes: 88 if 'disabled' not in self.classes:
89 self.classes = [c for c in self.classes] + ['disabled'] 89 self.classes = [c for c in self.classes] + ['disabled']
90 self.verbose_name = _('Create Subnet (Quota exceeded)') 90 self.verbose_name = _('Create Subnet (Quota exceeded)')
diff --git a/openstack_dashboard/dashboards/admin/networks/subnets/tests.py b/openstack_dashboard/dashboards/admin/networks/subnets/tests.py
index 14fc63f..d31a8ab 100644
--- a/openstack_dashboard/dashboards/admin/networks/subnets/tests.py
+++ b/openstack_dashboard/dashboards/admin/networks/subnets/tests.py
@@ -436,7 +436,7 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
436 .MultipleTimes().AndReturn(True) 436 .MultipleTimes().AndReturn(True)
437 quotas.tenant_quota_usages( 437 quotas.tenant_quota_usages(
438 IsA(http.HttpRequest), tenant_id=network.tenant_id, 438 IsA(http.HttpRequest), tenant_id=network.tenant_id,
439 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 439 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
440 self.mox.ReplayAll() 440 self.mox.ReplayAll()
441 from django.utils.http import urlunquote 441 from django.utils.http import urlunquote
442 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 442 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
diff --git a/openstack_dashboard/dashboards/admin/networks/tables.py b/openstack_dashboard/dashboards/admin/networks/tables.py
index d7c98ea..c359e8d 100644
--- a/openstack_dashboard/dashboards/admin/networks/tables.py
+++ b/openstack_dashboard/dashboards/admin/networks/tables.py
@@ -85,11 +85,11 @@ class CreateSubnet(project_tables.CreateSubnet):
85 85
86 def allowed(self, request, datum=None): 86 def allowed(self, request, datum=None):
87 usages = quotas.tenant_quota_usages( 87 usages = quotas.tenant_quota_usages(
88 request, tenant_id=datum.tenant_id, targets=('subnets', )) 88 request, tenant_id=datum.tenant_id, targets=('subnet', ))
89 89
90 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 90 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
91 # usages["subnets'] is empty 91 # usages["subnet'] is empty
92 if usages.get('subnets', {}).get('available', 1) <= 0: 92 if usages.get('subnet', {}).get('available', 1) <= 0:
93 if 'disabled' not in self.classes: 93 if 'disabled' not in self.classes:
94 self.classes = [c for c in self.classes] + ['disabled'] 94 self.classes = [c for c in self.classes] + ['disabled']
95 self.verbose_name = _('Create Subnet (Quota exceeded)') 95 self.verbose_name = _('Create Subnet (Quota exceeded)')
diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py
index 34f64af..4e4aa2d 100644
--- a/openstack_dashboard/dashboards/admin/networks/tests.py
+++ b/openstack_dashboard/dashboards/admin/networks/tests.py
@@ -49,7 +49,7 @@ class NetworkTests(test.BaseAdminViewTests):
49 for network in self.networks.list(): 49 for network in self.networks.list():
50 usage.quotas.tenant_quota_usages( 50 usage.quotas.tenant_quota_usages(
51 IsA(http.HttpRequest), tenant_id=network.tenant_id, 51 IsA(http.HttpRequest), tenant_id=network.tenant_id,
52 targets=('subnets', )).AndReturn(quota_data) 52 targets=('subnet', )).AndReturn(quota_data)
53 api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest), 53 api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest),
54 network.id)\ 54 network.id)\
55 .AndReturn(self.agents.list()) 55 .AndReturn(self.agents.list())
@@ -131,7 +131,7 @@ class NetworkTests(test.BaseAdminViewTests):
131 'dhcp_agent_scheduler').AndReturn(True) 131 'dhcp_agent_scheduler').AndReturn(True)
132 usage.quotas.tenant_quota_usages( 132 usage.quotas.tenant_quota_usages(
133 IsA(http.HttpRequest), tenant_id=network.tenant_id, 133 IsA(http.HttpRequest), tenant_id=network.tenant_id,
134 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 134 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
135 self.mox.ReplayAll() 135 self.mox.ReplayAll()
136 url = urlunquote(reverse('horizon:admin:networks:detail', 136 url = urlunquote(reverse('horizon:admin:networks:detail',
137 args=[network.id])) 137 args=[network.id]))
@@ -172,7 +172,7 @@ class NetworkTests(test.BaseAdminViewTests):
172 'dhcp_agent_scheduler').AndReturn(True) 172 'dhcp_agent_scheduler').AndReturn(True)
173 usage.quotas.tenant_quota_usages( 173 usage.quotas.tenant_quota_usages(
174 IsA(http.HttpRequest), tenant_id=network.tenant_id, 174 IsA(http.HttpRequest), tenant_id=network.tenant_id,
175 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 175 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
176 self.mox.ReplayAll() 176 self.mox.ReplayAll()
177 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 177 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
178 args=[network.id])) 178 args=[network.id]))
@@ -197,7 +197,7 @@ class NetworkTests(test.BaseAdminViewTests):
197 quota_data = self.neutron_quota_usages.first() 197 quota_data = self.neutron_quota_usages.first()
198 usage.quotas.tenant_quota_usages( 198 usage.quotas.tenant_quota_usages(
199 IsA(http.HttpRequest), tenant_id=network.tenant_id, 199 IsA(http.HttpRequest), tenant_id=network.tenant_id,
200 targets=('ports',)).MultipleTimes().AndReturn(quota_data) 200 targets=('port',)).MultipleTimes().AndReturn(quota_data)
201 api.neutron.is_extension_supported( 201 api.neutron.is_extension_supported(
202 IsA(http.HttpRequest), 202 IsA(http.HttpRequest),
203 'network-ip-availability').AndReturn(True) 203 'network-ip-availability').AndReturn(True)
@@ -212,7 +212,7 @@ class NetworkTests(test.BaseAdminViewTests):
212 'dhcp_agent_scheduler').AndReturn(True) 212 'dhcp_agent_scheduler').AndReturn(True)
213 usage.quotas.tenant_quota_usages( 213 usage.quotas.tenant_quota_usages(
214 IsA(http.HttpRequest), tenant_id=network.tenant_id, 214 IsA(http.HttpRequest), tenant_id=network.tenant_id,
215 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 215 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
216 216
217 self.mox.ReplayAll() 217 self.mox.ReplayAll()
218 url = reverse('horizon:admin:networks:ports_tab', 218 url = reverse('horizon:admin:networks:ports_tab',
@@ -255,7 +255,7 @@ class NetworkTests(test.BaseAdminViewTests):
255 'dhcp_agent_scheduler').AndReturn(True) 255 'dhcp_agent_scheduler').AndReturn(True)
256 usage.quotas.tenant_quota_usages( 256 usage.quotas.tenant_quota_usages(
257 IsA(http.HttpRequest), tenant_id=network.tenant_id, 257 IsA(http.HttpRequest), tenant_id=network.tenant_id,
258 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 258 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
259 self.mox.ReplayAll() 259 self.mox.ReplayAll()
260 url = reverse('horizon:admin:networks:agents_tab', args=[network.id]) 260 url = reverse('horizon:admin:networks:agents_tab', args=[network.id])
261 res = self.client.get(urlunquote(url)) 261 res = self.client.get(urlunquote(url))
@@ -359,7 +359,7 @@ class NetworkTests(test.BaseAdminViewTests):
359 'dhcp_agent_scheduler').AndReturn(True) 359 'dhcp_agent_scheduler').AndReturn(True)
360 usage.quotas.tenant_quota_usages( 360 usage.quotas.tenant_quota_usages(
361 IsA(http.HttpRequest), tenant_id=network.tenant_id, 361 IsA(http.HttpRequest), tenant_id=network.tenant_id,
362 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 362 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
363 self.mox.ReplayAll() 363 self.mox.ReplayAll()
364 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 364 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
365 args=[network.id])) 365 args=[network.id]))
@@ -418,7 +418,7 @@ class NetworkTests(test.BaseAdminViewTests):
418 .AndReturn(True) 418 .AndReturn(True)
419 usage.quotas.tenant_quota_usages( 419 usage.quotas.tenant_quota_usages(
420 IsA(http.HttpRequest), tenant_id=network.tenant_id, 420 IsA(http.HttpRequest), tenant_id=network.tenant_id,
421 targets=('subnets',)).MultipleTimes().AndReturn(quota_data) 421 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
422 self.mox.ReplayAll() 422 self.mox.ReplayAll()
423 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 423 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
424 args=[network.id])) 424 args=[network.id]))
diff --git a/openstack_dashboard/dashboards/project/floating_ips/forms.py b/openstack_dashboard/dashboards/project/floating_ips/forms.py
index d14de09..85f68b4 100644
--- a/openstack_dashboard/dashboards/project/floating_ips/forms.py
+++ b/openstack_dashboard/dashboards/project/floating_ips/forms.py
@@ -39,8 +39,8 @@ class FloatingIpAllocate(forms.SelfHandlingForm):
39 try: 39 try:
40 # Prevent allocating more IP than the quota allows 40 # Prevent allocating more IP than the quota allows
41 usages = quotas.tenant_quota_usages(request, 41 usages = quotas.tenant_quota_usages(request,
42 targets=('floating_ips', )) 42 targets=('floatingip', ))
43 if usages['floating_ips']['available'] <= 0: 43 if usages['floatingip']['available'] <= 0:
44 error_message = _('You are already using all of your available' 44 error_message = _('You are already using all of your available'
45 ' floating IPs.') 45 ' floating IPs.')
46 self.api_error(error_message) 46 self.api_error(error_message)
diff --git a/openstack_dashboard/dashboards/project/floating_ips/tables.py b/openstack_dashboard/dashboards/project/floating_ips/tables.py
index 3c5d9f3..5777130 100644
--- a/openstack_dashboard/dashboards/project/floating_ips/tables.py
+++ b/openstack_dashboard/dashboards/project/floating_ips/tables.py
@@ -48,8 +48,8 @@ class AllocateIP(tables.LinkAction):
48 48
49 def allowed(self, request, fip=None): 49 def allowed(self, request, fip=None):
50 usages = quotas.tenant_quota_usages(request, 50 usages = quotas.tenant_quota_usages(request,
51 targets=('floating_ips', )) 51 targets=('floatingip', ))
52 if usages['floating_ips']['available'] <= 0: 52 if usages['floatingip']['available'] <= 0:
53 if "disabled" not in self.classes: 53 if "disabled" not in self.classes:
54 self.classes = [c for c in self.classes] + ['disabled'] 54 self.classes = [c for c in self.classes] + ['disabled']
55 self.verbose_name = string_concat(self.verbose_name, ' ', 55 self.verbose_name = string_concat(self.verbose_name, ' ',
diff --git a/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html b/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html
index 61d47ab..6bd9e48 100644
--- a/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html
+++ b/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html
@@ -12,15 +12,15 @@
12 <strong>{% trans "Floating IP" %}</strong> 12 <strong>{% trans "Floating IP" %}</strong>
13 </div> 13 </div>
14 <span class="pull-right"> 14 <span class="pull-right">
15 {% blocktrans with used=usages.floating_ips.used quota=usages.floating_ips.quota|quotainf %}{{ used }} of {{ quota }} Used{% endblocktrans %} 15 {% blocktrans with used=usages.floatingip.used quota=usages.floatingip.quota|quotainf %}{{ used }} of {{ quota }} Used{% endblocktrans %}
16 </span> 16 </span>
17 </div> 17 </div>
18 <div id="floating_ip_progress" 18 <div id="floating_ip_progress"
19 class="quota_bar" 19 class="quota_bar"
20 data-quota-used="{{ usages.floating_ips.used }}" 20 data-quota-used="{{ usages.floatingip.used }}"
21 data-quota-limit="{{ usages.floating_ips.quota }}"> 21 data-quota-limit="{{ usages.floatingip.quota }}">
22 {% widthratio usages.floating_ips.used usages.floating_ips.quota 100 as ip_percent %} 22 {% widthratio usages.floatingip.used usages.floatingip.quota 100 as ip_percent %}
23 {% widthratio 100 usages.floating_ips.quota 1 as single_step %} 23 {% widthratio 100 usages.floatingip.quota 1 as single_step %}
24 {% bs_progress_bar ip_percent single_step %} 24 {% bs_progress_bar ip_percent single_step %}
25 </div> 25 </div>
26</div> 26</div>
diff --git a/openstack_dashboard/dashboards/project/floating_ips/tests.py b/openstack_dashboard/dashboards/project/floating_ips/tests.py
index 51f2d0b..521740c 100644
--- a/openstack_dashboard/dashboards/project/floating_ips/tests.py
+++ b/openstack_dashboard/dashboards/project/floating_ips/tests.py
@@ -246,8 +246,7 @@ class FloatingIpViewTests(test.TestCase):
246 def test_allocate_button_attributes(self): 246 def test_allocate_button_attributes(self):
247 floating_ips = self.floating_ips.list() 247 floating_ips = self.floating_ips.list()
248 floating_pools = self.pools.list() 248 floating_pools = self.pools.list()
249 quota_data = self.quota_usages.first() 249 quota_data = self.neutron_quota_usages.first()
250 quota_data['floating_ips']['available'] = 10
251 250
252 api.neutron.tenant_floating_ip_list( 251 api.neutron.tenant_floating_ip_list(
253 IsA(http.HttpRequest)) \ 252 IsA(http.HttpRequest)) \
@@ -259,7 +258,7 @@ class FloatingIpViewTests(test.TestCase):
259 IsA(http.HttpRequest), detailed=False) \ 258 IsA(http.HttpRequest), detailed=False) \
260 .AndReturn([self.servers.list(), False]) 259 .AndReturn([self.servers.list(), False])
261 quotas.tenant_quota_usages( 260 quotas.tenant_quota_usages(
262 IsA(http.HttpRequest), targets=('floating_ips', )).MultipleTimes() \ 261 IsA(http.HttpRequest), targets=('floatingip', )).MultipleTimes() \
263 .AndReturn(quota_data) 262 .AndReturn(quota_data)
264 263
265 self.mox.ReplayAll() 264 self.mox.ReplayAll()
@@ -284,8 +283,8 @@ class FloatingIpViewTests(test.TestCase):
284 def test_allocate_button_disabled_when_quota_exceeded(self): 283 def test_allocate_button_disabled_when_quota_exceeded(self):
285 floating_ips = self.floating_ips.list() 284 floating_ips = self.floating_ips.list()
286 floating_pools = self.pools.list() 285 floating_pools = self.pools.list()
287 quota_data = self.quota_usages.first() 286 quota_data = self.neutron_quota_usages.first()
288 quota_data['floating_ips']['available'] = 0 287 quota_data['floatingip']['available'] = 0
289 288
290 api.neutron.tenant_floating_ip_list( 289 api.neutron.tenant_floating_ip_list(
291 IsA(http.HttpRequest)) \ 290 IsA(http.HttpRequest)) \
@@ -297,7 +296,7 @@ class FloatingIpViewTests(test.TestCase):
297 IsA(http.HttpRequest), detailed=False) \ 296 IsA(http.HttpRequest), detailed=False) \
298 .AndReturn([self.servers.list(), False]) 297 .AndReturn([self.servers.list(), False])
299 quotas.tenant_quota_usages( 298 quotas.tenant_quota_usages(
300 IsA(http.HttpRequest), targets=('floating_ips', )).MultipleTimes() \ 299 IsA(http.HttpRequest), targets=('floatingip', )).MultipleTimes() \
301 .AndReturn(quota_data) 300 .AndReturn(quota_data)
302 301
303 self.mox.ReplayAll() 302 self.mox.ReplayAll()
@@ -337,8 +336,6 @@ class FloatingIpViewTests(test.TestCase):
337 'quota_details').AndReturn(False) 336 'quota_details').AndReturn(False)
338 api.neutron.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \ 337 api.neutron.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \
339 .AndReturn(self.neutron_quotas.first()) 338 .AndReturn(self.neutron_quotas.first())
340 api.neutron.floating_ip_supported(IsA(http.HttpRequest)) \
341 .AndReturn(True)
342 api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \ 339 api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \
343 .MultipleTimes().AndReturn(self.floating_ips.list()) 340 .MultipleTimes().AndReturn(self.floating_ips.list())
344 api.neutron.floating_ip_pools_list(IsA(http.HttpRequest)) \ 341 api.neutron.floating_ip_pools_list(IsA(http.HttpRequest)) \
@@ -347,5 +344,5 @@ class FloatingIpViewTests(test.TestCase):
347 344
348 url = reverse('%s:allocate' % NAMESPACE) 345 url = reverse('%s:allocate' % NAMESPACE)
349 res = self.client.get(url) 346 res = self.client.get(url)
350 self.assertEqual(res.context['usages']['floating_ips']['quota'], 347 self.assertEqual(res.context['usages']['floatingip']['quota'],
351 self.neutron_quotas.first().get('floatingip').limit) 348 self.neutron_quotas.first().get('floatingip').limit)
diff --git a/openstack_dashboard/dashboards/project/floating_ips/views.py b/openstack_dashboard/dashboards/project/floating_ips/views.py
index f0a7071..fec4192 100644
--- a/openstack_dashboard/dashboards/project/floating_ips/views.py
+++ b/openstack_dashboard/dashboards/project/floating_ips/views.py
@@ -62,7 +62,7 @@ class AllocateView(forms.ModalFormView):
62 context = super(AllocateView, self).get_context_data(**kwargs) 62 context = super(AllocateView, self).get_context_data(**kwargs)
63 try: 63 try:
64 context['usages'] = quotas.tenant_quota_usages( 64 context['usages'] = quotas.tenant_quota_usages(
65 self.request, targets=('floating_ips', )) 65 self.request, targets=('floatingip', ))
66 except Exception: 66 except Exception:
67 exceptions.handle(self.request) 67 exceptions.handle(self.request)
68 return context 68 return context
diff --git a/openstack_dashboard/dashboards/project/network_topology/tests.py b/openstack_dashboard/dashboards/project/network_topology/tests.py
index df68a81..1231668 100644
--- a/openstack_dashboard/dashboards/project/network_topology/tests.py
+++ b/openstack_dashboard/dashboards/project/network_topology/tests.py
@@ -198,18 +198,18 @@ class NetworkTopologyCreateTests(test.TestCase):
198 self, expected_string, networks_quota=10, 198 self, expected_string, networks_quota=10,
199 routers_quota=10, instances_quota=10): 199 routers_quota=10, instances_quota=10):
200 quota_data = self.quota_usages.first() 200 quota_data = self.quota_usages.first()
201 quota_data['networks']['available'] = networks_quota 201 quota_data['network']['available'] = networks_quota
202 quota_data['routers']['available'] = routers_quota 202 quota_data['router']['available'] = routers_quota
203 quota_data['instances']['available'] = instances_quota 203 quota_data['instances']['available'] = instances_quota
204 204
205 quotas.tenant_quota_usages( 205 quotas.tenant_quota_usages(
206 IsA(http.HttpRequest), targets=('instances', ) 206 IsA(http.HttpRequest), targets=('instances', )
207 ).MultipleTimes().AndReturn(quota_data) 207 ).MultipleTimes().AndReturn(quota_data)
208 quotas.tenant_quota_usages( 208 quotas.tenant_quota_usages(
209 IsA(http.HttpRequest), targets=('networks', ) 209 IsA(http.HttpRequest), targets=('network', )
210 ).MultipleTimes().AndReturn(quota_data) 210 ).MultipleTimes().AndReturn(quota_data)
211 quotas.tenant_quota_usages( 211 quotas.tenant_quota_usages(
212 IsA(http.HttpRequest), targets=('routers', ) 212 IsA(http.HttpRequest), targets=('router', )
213 ).MultipleTimes().AndReturn(quota_data) 213 ).MultipleTimes().AndReturn(quota_data)
214 214
215 self.mox.ReplayAll() 215 self.mox.ReplayAll()
diff --git a/openstack_dashboard/dashboards/project/network_topology/utils.py b/openstack_dashboard/dashboards/project/network_topology/utils.py
index afa46cd..fbd670a 100644
--- a/openstack_dashboard/dashboards/project/network_topology/utils.py
+++ b/openstack_dashboard/dashboards/project/network_topology/utils.py
@@ -35,11 +35,11 @@ def get_context(request, context=None):
35 context['instance_quota_exceeded'] = _quota_exceeded(request, 'instances') 35 context['instance_quota_exceeded'] = _quota_exceeded(request, 'instances')
36 context['create_network_allowed'] = policy.check( 36 context['create_network_allowed'] = policy.check(
37 (("network", "create_network"),), request) 37 (("network", "create_network"),), request)
38 context['network_quota_exceeded'] = _quota_exceeded(request, 'networks') 38 context['network_quota_exceeded'] = _quota_exceeded(request, 'network')
39 context['create_router_allowed'] = ( 39 context['create_router_allowed'] = (
40 network_config.get('enable_router', True) and 40 network_config.get('enable_router', True) and
41 policy.check((("network", "create_router"),), request)) 41 policy.check((("network", "create_router"),), request))
42 context['router_quota_exceeded'] = _quota_exceeded(request, 'routers') 42 context['router_quota_exceeded'] = _quota_exceeded(request, 'router')
43 context['console_type'] = getattr(settings, 'CONSOLE_TYPE', 'AUTO') 43 context['console_type'] = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
44 context['show_ng_launch'] = ( 44 context['show_ng_launch'] = (
45 base.is_service_enabled(request, 'compute') and 45 base.is_service_enabled(request, 'compute') and
diff --git a/openstack_dashboard/dashboards/project/networks/ports/tables.py b/openstack_dashboard/dashboards/project/networks/ports/tables.py
index 7c6453e..3cb9f5e 100644
--- a/openstack_dashboard/dashboards/project/networks/ports/tables.py
+++ b/openstack_dashboard/dashboards/project/networks/ports/tables.py
@@ -88,10 +88,10 @@ class CreatePort(tables.LinkAction):
88 return reverse(self.url, args=(network_id,)) 88 return reverse(self.url, args=(network_id,))
89 89
90 def allowed(self, request, datum=None): 90 def allowed(self, request, datum=None):
91 usages = quotas.tenant_quota_usages(request, targets=('ports', )) 91 usages = quotas.tenant_quota_usages(request, targets=('port', ))
92 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 92 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
93 # usages["ports"] is empty 93 # usages["port"] is empty
94 if usages.get('ports', {}).get('available', 1) <= 0: 94 if usages.get('port', {}).get('available', 1) <= 0:
95 if "disabled" not in self.classes: 95 if "disabled" not in self.classes:
96 self.classes = [c for c in self.classes] + ["disabled"] 96 self.classes = [c for c in self.classes] + ["disabled"]
97 self.verbose_name = _("Create Port (Quota exceeded)") 97 self.verbose_name = _("Create Port (Quota exceeded)")
diff --git a/openstack_dashboard/dashboards/project/networks/subnets/tables.py b/openstack_dashboard/dashboards/project/networks/subnets/tables.py
index e975976..71f3440 100644
--- a/openstack_dashboard/dashboards/project/networks/subnets/tables.py
+++ b/openstack_dashboard/dashboards/project/networks/subnets/tables.py
@@ -99,11 +99,11 @@ class CreateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
99 return reverse(self.url, args=(network_id,)) 99 return reverse(self.url, args=(network_id,))
100 100
101 def allowed(self, request, datum=None): 101 def allowed(self, request, datum=None):
102 usages = quotas.tenant_quota_usages(request, targets=('subnets', )) 102 usages = quotas.tenant_quota_usages(request, targets=('subnet', ))
103 103
104 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 104 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
105 # usages["subnets'] is empty 105 # usages["subnet'] is empty
106 if usages.get('subnets', {}).get('available', 1) <= 0: 106 if usages.get('subnet', {}).get('available', 1) <= 0:
107 if 'disabled' not in self.classes: 107 if 'disabled' not in self.classes:
108 self.classes = [c for c in self.classes] + ['disabled'] 108 self.classes = [c for c in self.classes] + ['disabled']
109 self.verbose_name = _('Create Subnet (Quota exceeded)') 109 self.verbose_name = _('Create Subnet (Quota exceeded)')
diff --git a/openstack_dashboard/dashboards/project/networks/tables.py b/openstack_dashboard/dashboards/project/networks/tables.py
index 26c90ed..d995b23 100644
--- a/openstack_dashboard/dashboards/project/networks/tables.py
+++ b/openstack_dashboard/dashboards/project/networks/tables.py
@@ -92,10 +92,10 @@ class CreateNetwork(tables.LinkAction):
92 policy_rules = (("network", "create_network"),) 92 policy_rules = (("network", "create_network"),)
93 93
94 def allowed(self, request, datum=None): 94 def allowed(self, request, datum=None):
95 usages = quotas.tenant_quota_usages(request, targets=('networks', )) 95 usages = quotas.tenant_quota_usages(request, targets=('network', ))
96 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 96 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
97 # usages["networks"] is empty 97 # usages["network"] is empty
98 if usages.get('networks', {}).get('available', 1) <= 0: 98 if usages.get('network', {}).get('available', 1) <= 0:
99 if "disabled" not in self.classes: 99 if "disabled" not in self.classes:
100 self.classes = [c for c in self.classes] + ["disabled"] 100 self.classes = [c for c in self.classes] + ["disabled"]
101 self.verbose_name = _("Create Network (Quota exceeded)") 101 self.verbose_name = _("Create Network (Quota exceeded)")
@@ -127,10 +127,10 @@ class CreateSubnet(subnet_tables.SubnetPolicyTargetMixin, tables.LinkAction):
127 ("network:project_id", "tenant_id"),) 127 ("network:project_id", "tenant_id"),)
128 128
129 def allowed(self, request, datum=None): 129 def allowed(self, request, datum=None):
130 usages = quotas.tenant_quota_usages(request, targets=('subnets', )) 130 usages = quotas.tenant_quota_usages(request, targets=('subnet', ))
131 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 131 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
132 # usages["subnets'] is empty 132 # usages["subnet'] is empty
133 if usages.get('subnets', {}).get('available', 1) <= 0: 133 if usages.get('subnet', {}).get('available', 1) <= 0:
134 if 'disabled' not in self.classes: 134 if 'disabled' not in self.classes:
135 self.classes = [c for c in self.classes] + ['disabled'] 135 self.classes = [c for c in self.classes] + ['disabled']
136 self.verbose_name = _('Create Subnet (Quota exceeded)') 136 self.verbose_name = _('Create Subnet (Quota exceeded)')
diff --git a/openstack_dashboard/dashboards/project/networks/tests.py b/openstack_dashboard/dashboards/project/networks/tests.py
index bd2c860..fa70bfe 100644
--- a/openstack_dashboard/dashboards/project/networks/tests.py
+++ b/openstack_dashboard/dashboards/project/networks/tests.py
@@ -127,15 +127,15 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
127 'is_extension_supported'), 127 'is_extension_supported'),
128 quotas: ('tenant_quota_usages',)}) 128 quotas: ('tenant_quota_usages',)})
129 def test_index(self): 129 def test_index(self):
130 quota_data = self.quota_usages.first() 130 quota_data = self.neutron_quota_usages.first()
131 quota_data['networks']['available'] = 5 131 quota_data['network']['available'] = 5
132 quota_data['subnets']['available'] = 5 132 quota_data['subnet']['available'] = 5
133 self._stub_net_list() 133 self._stub_net_list()
134 quotas.tenant_quota_usages( 134 quotas.tenant_quota_usages(
135 IsA(http.HttpRequest), targets=('networks', )) \ 135 IsA(http.HttpRequest), targets=('network', )) \
136 .MultipleTimes().AndReturn(quota_data) 136 .MultipleTimes().AndReturn(quota_data)
137 quotas.tenant_quota_usages( 137 quotas.tenant_quota_usages(
138 IsA(http.HttpRequest), targets=('subnets', )) \ 138 IsA(http.HttpRequest), targets=('subnet', )) \
139 .MultipleTimes().AndReturn(quota_data) 139 .MultipleTimes().AndReturn(quota_data)
140 api.neutron.is_extension_supported( 140 api.neutron.is_extension_supported(
141 IsA(http.HttpRequest), 'network_availability_zone')\ 141 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -158,7 +158,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
158 tenant_id=self.tenant.id, 158 tenant_id=self.tenant.id,
159 shared=False).MultipleTimes().AndRaise(self.exceptions.neutron) 159 shared=False).MultipleTimes().AndRaise(self.exceptions.neutron)
160 quotas.tenant_quota_usages( 160 quotas.tenant_quota_usages(
161 IsA(http.HttpRequest), targets=('networks', )) \ 161 IsA(http.HttpRequest), targets=('network', )) \
162 .MultipleTimes().AndReturn(quota_data) 162 .MultipleTimes().AndReturn(quota_data)
163 api.neutron.is_extension_supported( 163 api.neutron.is_extension_supported(
164 IsA(http.HttpRequest), 'network_availability_zone')\ 164 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -200,7 +200,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
200 .AndReturn(mac_learning) 200 .AndReturn(mac_learning)
201 201
202 quotas.tenant_quota_usages( 202 quotas.tenant_quota_usages(
203 IsA(http.HttpRequest), targets=('subnets', )) \ 203 IsA(http.HttpRequest), targets=('subnet', )) \
204 .MultipleTimes().AndReturn(quota_data) 204 .MultipleTimes().AndReturn(quota_data)
205 api.neutron.is_extension_supported( 205 api.neutron.is_extension_supported(
206 IsA(http.HttpRequest), 'network_availability_zone')\ 206 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -228,7 +228,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
228 'mac-learning')\ 228 'mac-learning')\
229 .AndReturn(mac_learning) 229 .AndReturn(mac_learning)
230 quotas.tenant_quota_usages( 230 quotas.tenant_quota_usages(
231 IsA(http.HttpRequest), targets=('subnets', )) \ 231 IsA(http.HttpRequest), targets=('subnet', )) \
232 .MultipleTimes().AndReturn(quota_data) 232 .MultipleTimes().AndReturn(quota_data)
233 api.neutron.is_extension_supported( 233 api.neutron.is_extension_supported(
234 IsA(http.HttpRequest), 'network_availability_zone')\ 234 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -291,8 +291,8 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
291 def _test_subnets_tab_subnet_exception(self, mac_learning=False): 291 def _test_subnets_tab_subnet_exception(self, mac_learning=False):
292 network_id = self.networks.first().id 292 network_id = self.networks.first().id
293 quota_data = self.neutron_quota_usages.first() 293 quota_data = self.neutron_quota_usages.first()
294 quota_data['networks']['available'] = 5 294 quota_data['network']['available'] = 5
295 quota_data['subnets']['available'] = 5 295 quota_data['subnet']['available'] = 5
296 api.neutron.network_get(IsA(http.HttpRequest), network_id).\ 296 api.neutron.network_get(IsA(http.HttpRequest), network_id).\
297 MultipleTimes().AndReturn(self.networks.first()) 297 MultipleTimes().AndReturn(self.networks.first())
298 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\ 298 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
@@ -302,7 +302,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
302 'mac-learning')\ 302 'mac-learning')\
303 .AndReturn(mac_learning) 303 .AndReturn(mac_learning)
304 quotas.tenant_quota_usages( 304 quotas.tenant_quota_usages(
305 IsA(http.HttpRequest), targets=('subnets', )) \ 305 IsA(http.HttpRequest), targets=('subnet', )) \
306 .MultipleTimes().AndReturn(quota_data) 306 .MultipleTimes().AndReturn(quota_data)
307 api.neutron.is_extension_supported( 307 api.neutron.is_extension_supported(
308 IsA(http.HttpRequest), 'network_availability_zone')\ 308 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -336,7 +336,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
336 def _test_subnets_tab_port_exception(self, mac_learning=False): 336 def _test_subnets_tab_port_exception(self, mac_learning=False):
337 network_id = self.networks.first().id 337 network_id = self.networks.first().id
338 quota_data = self.neutron_quota_usages.first() 338 quota_data = self.neutron_quota_usages.first()
339 quota_data['subnets']['available'] = 5 339 quota_data['subnet']['available'] = 5
340 api.neutron.network_get(IsA(http.HttpRequest), network_id).\ 340 api.neutron.network_get(IsA(http.HttpRequest), network_id).\
341 AndReturn(self.networks.first()) 341 AndReturn(self.networks.first())
342 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\ 342 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
@@ -345,7 +345,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
345 'mac-learning')\ 345 'mac-learning')\
346 .AndReturn(mac_learning) 346 .AndReturn(mac_learning)
347 quotas.tenant_quota_usages( 347 quotas.tenant_quota_usages(
348 IsA(http.HttpRequest), targets=('subnets', )) \ 348 IsA(http.HttpRequest), targets=('subnet', )) \
349 .MultipleTimes().AndReturn(quota_data) 349 .MultipleTimes().AndReturn(quota_data)
350 api.neutron.is_extension_supported( 350 api.neutron.is_extension_supported(
351 IsA(http.HttpRequest), 'network_availability_zone')\ 351 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1096,15 +1096,15 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1096 # these keys are empty dicts, its disabled 1096 # these keys are empty dicts, its disabled
1097 quota_data = self.neutron_quota_usages.first() 1097 quota_data = self.neutron_quota_usages.first()
1098 1098
1099 quota_data['networks'].pop('available') 1099 quota_data['network'].pop('available')
1100 quota_data['subnets'].pop('available') 1100 quota_data['subnet'].pop('available')
1101 1101
1102 self._stub_net_list() 1102 self._stub_net_list()
1103 quotas.tenant_quota_usages( 1103 quotas.tenant_quota_usages(
1104 IsA(http.HttpRequest), targets=('networks', )) \ 1104 IsA(http.HttpRequest), targets=('network', )) \
1105 .MultipleTimes().AndReturn(quota_data) 1105 .MultipleTimes().AndReturn(quota_data)
1106 quotas.tenant_quota_usages( 1106 quotas.tenant_quota_usages(
1107 IsA(http.HttpRequest), targets=('subnets', )) \ 1107 IsA(http.HttpRequest), targets=('subnet', )) \
1108 .MultipleTimes().AndReturn(quota_data) 1108 .MultipleTimes().AndReturn(quota_data)
1109 api.neutron.is_extension_supported( 1109 api.neutron.is_extension_supported(
1110 IsA(http.HttpRequest), 'network_availability_zone')\ 1110 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1128,15 +1128,15 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1128 1128
1129 quota_data = self.neutron_quota_usages.first() 1129 quota_data = self.neutron_quota_usages.first()
1130 1130
1131 quota_data['networks']['available'] = network_quota 1131 quota_data['network']['available'] = network_quota
1132 quota_data['subnets']['available'] = subnet_quota 1132 quota_data['subnet']['available'] = subnet_quota
1133 1133
1134 self._stub_net_list() 1134 self._stub_net_list()
1135 quotas.tenant_quota_usages( 1135 quotas.tenant_quota_usages(
1136 IsA(http.HttpRequest), targets=('networks', )) \ 1136 IsA(http.HttpRequest), targets=('network', )) \
1137 .MultipleTimes().AndReturn(quota_data) 1137 .MultipleTimes().AndReturn(quota_data)
1138 quotas.tenant_quota_usages( 1138 quotas.tenant_quota_usages(
1139 IsA(http.HttpRequest), targets=('subnets', )) \ 1139 IsA(http.HttpRequest), targets=('subnet', )) \
1140 .MultipleTimes().AndReturn(quota_data) 1140 .MultipleTimes().AndReturn(quota_data)
1141 api.neutron.is_extension_supported( 1141 api.neutron.is_extension_supported(
1142 IsA(http.HttpRequest), 'network_availability_zone')\ 1142 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1221,7 +1221,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1221 IsA(http.HttpRequest), 'mac-learning')\ 1221 IsA(http.HttpRequest), 'mac-learning')\
1222 .AndReturn(False) 1222 .AndReturn(False)
1223 quotas.tenant_quota_usages( 1223 quotas.tenant_quota_usages(
1224 IsA(http.HttpRequest), targets=('subnets', )) \ 1224 IsA(http.HttpRequest), targets=('subnet', )) \
1225 .MultipleTimes().AndReturn(quota_data) 1225 .MultipleTimes().AndReturn(quota_data)
1226 api.neutron.is_extension_supported( 1226 api.neutron.is_extension_supported(
1227 IsA(http.HttpRequest), 'network_availability_zone')\ 1227 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1242,7 +1242,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1242 1242
1243 def test_subnet_create_button_disabled_when_quota_exceeded_detail(self): 1243 def test_subnet_create_button_disabled_when_quota_exceeded_detail(self):
1244 quota_data = self.neutron_quota_usages.first() 1244 quota_data = self.neutron_quota_usages.first()
1245 quota_data['subnets']['available'] = 0 1245 quota_data['subnet']['available'] = 0
1246 create_action = self._test_subnet_create_button(quota_data) 1246 create_action = self._test_subnet_create_button(quota_data)
1247 self.assertIn('disabled', create_action.classes, 1247 self.assertIn('disabled', create_action.classes,
1248 'The create button should be disabled') 1248 'The create button should be disabled')
@@ -1300,10 +1300,10 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1300 IsA(http.HttpRequest), 'mac-learning') \ 1300 IsA(http.HttpRequest), 'mac-learning') \
1301 .AndReturn(False) 1301 .AndReturn(False)
1302 quotas.tenant_quota_usages( 1302 quotas.tenant_quota_usages(
1303 IsA(http.HttpRequest), targets=('subnets', )) \ 1303 IsA(http.HttpRequest), targets=('subnet', )) \
1304 .MultipleTimes().AndReturn(quota_data) 1304 .MultipleTimes().AndReturn(quota_data)
1305 quotas.tenant_quota_usages( 1305 quotas.tenant_quota_usages(
1306 IsA(http.HttpRequest), targets=('ports',)) \ 1306 IsA(http.HttpRequest), targets=('port',)) \
1307 .MultipleTimes().AndReturn(quota_data) 1307 .MultipleTimes().AndReturn(quota_data)
1308 api.neutron.is_extension_supported( 1308 api.neutron.is_extension_supported(
1309 IsA(http.HttpRequest), 'network_availability_zone')\ 1309 IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1323,7 +1323,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1323 1323
1324 def test_port_create_button_disabled_when_quota_exceeded(self): 1324 def test_port_create_button_disabled_when_quota_exceeded(self):
1325 quota_data = self.neutron_quota_usages.first() 1325 quota_data = self.neutron_quota_usages.first()
1326 quota_data['ports']['available'] = 0 1326 quota_data['port']['available'] = 0
1327 create_action = self._test_port_create_button(quota_data) 1327 create_action = self._test_port_create_button(quota_data)
1328 self.assertIn('disabled', create_action.classes, 1328 self.assertIn('disabled', create_action.classes,
1329 'The create button should be disabled') 1329 'The create button should be disabled')
@@ -1338,7 +1338,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1338 1338
1339 def test_create_port_button_attributes(self): 1339 def test_create_port_button_attributes(self):
1340 quota_data = self.neutron_quota_usages.first() 1340 quota_data = self.neutron_quota_usages.first()
1341 quota_data['ports']['available'] = 1 1341 quota_data['port']['available'] = 1
1342 create_action = self._test_port_create_button(quota_data) 1342 create_action = self._test_port_create_button(quota_data)
1343 1343
1344 self.assertEqual(set(['ajax-modal']), set(create_action.classes)) 1344 self.assertEqual(set(['ajax-modal']), set(create_action.classes))
diff --git a/openstack_dashboard/dashboards/project/routers/tables.py b/openstack_dashboard/dashboards/project/routers/tables.py
index 0531049..b0cd5cb 100644
--- a/openstack_dashboard/dashboards/project/routers/tables.py
+++ b/openstack_dashboard/dashboards/project/routers/tables.py
@@ -96,10 +96,10 @@ class CreateRouter(tables.LinkAction):
96 policy_rules = (("network", "create_router"),) 96 policy_rules = (("network", "create_router"),)
97 97
98 def allowed(self, request, datum=None): 98 def allowed(self, request, datum=None):
99 usages = quotas.tenant_quota_usages(request, targets=('routers', )) 99 usages = quotas.tenant_quota_usages(request, targets=('router', ))
100 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False 100 # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
101 # usages['routers'] is empty 101 # usages['router'] is empty
102 if usages.get('routers', {}).get('available', 1) <= 0: 102 if usages.get('router', {}).get('available', 1) <= 0:
103 if "disabled" not in self.classes: 103 if "disabled" not in self.classes:
104 self.classes = [c for c in self.classes] + ["disabled"] 104 self.classes = [c for c in self.classes] + ["disabled"]
105 self.verbose_name = _("Create Router (Quota exceeded)") 105 self.verbose_name = _("Create Router (Quota exceeded)")
diff --git a/openstack_dashboard/dashboards/project/routers/tests.py b/openstack_dashboard/dashboards/project/routers/tests.py
index db3eb40..62153c5 100644
--- a/openstack_dashboard/dashboards/project/routers/tests.py
+++ b/openstack_dashboard/dashboards/project/routers/tests.py
@@ -102,7 +102,7 @@ class RouterTests(RouterMixin, test.TestCase):
102 IsA(http.HttpRequest), 102 IsA(http.HttpRequest),
103 tenant_id=self.tenant.id).AndReturn(self.routers.list()) 103 tenant_id=self.tenant.id).AndReturn(self.routers.list())
104 quotas.tenant_quota_usages( 104 quotas.tenant_quota_usages(
105 IsA(http.HttpRequest), targets=('routers', )) \ 105 IsA(http.HttpRequest), targets=('router', )) \
106 .MultipleTimes().AndReturn(quota_data) 106 .MultipleTimes().AndReturn(quota_data)
107 api.neutron.is_extension_supported(IsA(http.HttpRequest), 107 api.neutron.is_extension_supported(IsA(http.HttpRequest),
108 "router_availability_zone")\ 108 "router_availability_zone")\
@@ -126,7 +126,7 @@ class RouterTests(RouterMixin, test.TestCase):
126 tenant_id=self.tenant.id).MultipleTimes().AndRaise( 126 tenant_id=self.tenant.id).MultipleTimes().AndRaise(
127 self.exceptions.neutron) 127 self.exceptions.neutron)
128 quotas.tenant_quota_usages( 128 quotas.tenant_quota_usages(
129 IsA(http.HttpRequest), targets=('routers', )) \ 129 IsA(http.HttpRequest), targets=('router', )) \
130 .MultipleTimes().AndReturn(quota_data) 130 .MultipleTimes().AndReturn(quota_data)
131 api.neutron.is_extension_supported(IsA(http.HttpRequest), 131 api.neutron.is_extension_supported(IsA(http.HttpRequest),
132 "router_availability_zone")\ 132 "router_availability_zone")\
@@ -150,7 +150,7 @@ class RouterTests(RouterMixin, test.TestCase):
150 IsA(http.HttpRequest), 150 IsA(http.HttpRequest),
151 tenant_id=self.tenant.id).MultipleTimes().AndReturn([router]) 151 tenant_id=self.tenant.id).MultipleTimes().AndReturn([router])
152 quotas.tenant_quota_usages( 152 quotas.tenant_quota_usages(
153 IsA(http.HttpRequest), targets=('routers', )) \ 153 IsA(http.HttpRequest), targets=('router', )) \
154 .MultipleTimes().AndReturn(quota_data) 154 .MultipleTimes().AndReturn(quota_data)
155 api.neutron.is_extension_supported(IsA(http.HttpRequest), 155 api.neutron.is_extension_supported(IsA(http.HttpRequest),
156 "router_availability_zone")\ 156 "router_availability_zone")\
@@ -198,7 +198,7 @@ class RouterTests(RouterMixin, test.TestCase):
198 IsA(http.HttpRequest), 198 IsA(http.HttpRequest),
199 tenant_id=self.tenant.id).AndReturn(self.routers.list()) 199 tenant_id=self.tenant.id).AndReturn(self.routers.list())
200 quotas.tenant_quota_usages( 200 quotas.tenant_quota_usages(
201 IsA(http.HttpRequest), targets=('routers', )) \ 201 IsA(http.HttpRequest), targets=('router', )) \
202 .MultipleTimes().AndReturn(quota_data) 202 .MultipleTimes().AndReturn(quota_data)
203 api.neutron.is_extension_supported(IsA(http.HttpRequest), 203 api.neutron.is_extension_supported(IsA(http.HttpRequest),
204 "router_availability_zone")\ 204 "router_availability_zone")\
@@ -240,7 +240,7 @@ class RouterTests(RouterMixin, test.TestCase):
240 IsA(http.HttpRequest), 240 IsA(http.HttpRequest),
241 tenant_id=self.tenant.id).AndReturn(self.routers.list()) 241 tenant_id=self.tenant.id).AndReturn(self.routers.list())
242 quotas.tenant_quota_usages( 242 quotas.tenant_quota_usages(
243 IsA(http.HttpRequest), targets=('routers', )) \ 243 IsA(http.HttpRequest), targets=('router', )) \
244 .MultipleTimes().AndReturn(quota_data) 244 .MultipleTimes().AndReturn(quota_data)
245 api.neutron.is_extension_supported(IsA(http.HttpRequest), 245 api.neutron.is_extension_supported(IsA(http.HttpRequest),
246 "router_availability_zone")\ 246 "router_availability_zone")\
@@ -928,12 +928,12 @@ class RouterViewTests(RouterMixin, test.TestCase):
928 quotas: ('tenant_quota_usages',)}) 928 quotas: ('tenant_quota_usages',)})
929 def test_create_button_disabled_when_quota_exceeded(self): 929 def test_create_button_disabled_when_quota_exceeded(self):
930 quota_data = self.neutron_quota_usages.first() 930 quota_data = self.neutron_quota_usages.first()
931 quota_data['routers']['available'] = 0 931 quota_data['router']['available'] = 0
932 api.neutron.router_list( 932 api.neutron.router_list(
933 IsA(http.HttpRequest), 933 IsA(http.HttpRequest),
934 tenant_id=self.tenant.id).AndReturn(self.routers.list()) 934 tenant_id=self.tenant.id).AndReturn(self.routers.list())
935 quotas.tenant_quota_usages( 935 quotas.tenant_quota_usages(
936 IsA(http.HttpRequest), targets=('routers', )) \ 936 IsA(http.HttpRequest), targets=('router', )) \
937 .MultipleTimes().AndReturn(quota_data) 937 .MultipleTimes().AndReturn(quota_data)
938 api.neutron.is_extension_supported(IsA(http.HttpRequest), 938 api.neutron.is_extension_supported(IsA(http.HttpRequest),
939 "router_availability_zone")\ 939 "router_availability_zone")\
@@ -959,12 +959,12 @@ class RouterViewTests(RouterMixin, test.TestCase):
959 quotas: ('tenant_quota_usages',)}) 959 quotas: ('tenant_quota_usages',)})
960 def test_create_button_shown_when_quota_disabled(self): 960 def test_create_button_shown_when_quota_disabled(self):
961 quota_data = self.neutron_quota_usages.first() 961 quota_data = self.neutron_quota_usages.first()
962 quota_data['routers'].pop('available') 962 quota_data['router'].pop('available')
963 api.neutron.router_list( 963 api.neutron.router_list(
964 IsA(http.HttpRequest), 964 IsA(http.HttpRequest),
965 tenant_id=self.tenant.id).AndReturn(self.routers.list()) 965 tenant_id=self.tenant.id).AndReturn(self.routers.list())
966 quotas.tenant_quota_usages( 966 quotas.tenant_quota_usages(
967 IsA(http.HttpRequest), targets=('routers', )) \ 967 IsA(http.HttpRequest), targets=('router', )) \
968 .MultipleTimes().AndReturn(quota_data) 968 .MultipleTimes().AndReturn(quota_data)
969 api.neutron.is_extension_supported(IsA(http.HttpRequest), 969 api.neutron.is_extension_supported(IsA(http.HttpRequest),
970 "router_availability_zone")\ 970 "router_availability_zone")\
@@ -990,12 +990,12 @@ class RouterViewTests(RouterMixin, test.TestCase):
990 quotas: ('tenant_quota_usages',)}) 990 quotas: ('tenant_quota_usages',)})
991 def test_create_button_attributes(self): 991 def test_create_button_attributes(self):
992 quota_data = self.neutron_quota_usages.first() 992 quota_data = self.neutron_quota_usages.first()
993 quota_data['routers']['available'] = 10 993 quota_data['router']['available'] = 10
994 api.neutron.router_list( 994 api.neutron.router_list(
995 IsA(http.HttpRequest), 995 IsA(http.HttpRequest),
996 tenant_id=self.tenant.id).AndReturn(self.routers.list()) 996 tenant_id=self.tenant.id).AndReturn(self.routers.list())
997 quotas.tenant_quota_usages( 997 quotas.tenant_quota_usages(
998 IsA(http.HttpRequest), targets=('routers', )) \ 998 IsA(http.HttpRequest), targets=('router', )) \
999 .MultipleTimes().AndReturn(quota_data) 999 .MultipleTimes().AndReturn(quota_data)
1000 api.neutron.is_extension_supported(IsA(http.HttpRequest), 1000 api.neutron.is_extension_supported(IsA(http.HttpRequest),
1001 "router_availability_zone")\ 1001 "router_availability_zone")\
diff --git a/openstack_dashboard/dashboards/project/security_groups/tables.py b/openstack_dashboard/dashboards/project/security_groups/tables.py
index 1f8f0ec..e75fcbf 100644
--- a/openstack_dashboard/dashboards/project/security_groups/tables.py
+++ b/openstack_dashboard/dashboards/project/security_groups/tables.py
@@ -64,8 +64,8 @@ class CreateGroup(tables.LinkAction):
64 64
65 def allowed(self, request, security_group=None): 65 def allowed(self, request, security_group=None):
66 usages = quotas.tenant_quota_usages(request, 66 usages = quotas.tenant_quota_usages(request,
67 targets=('security_groups', )) 67 targets=('security_group', ))
68 if usages['security_groups'].get('available', 1) <= 0: 68 if usages['security_group'].get('available', 1) <= 0:
69 if "disabled" not in self.classes: 69 if "disabled" not in self.classes:
70 self.classes = [c for c in self.classes] + ["disabled"] 70 self.classes = [c for c in self.classes] + ["disabled"]
71 self.verbose_name = _("Create Security Group (Quota exceeded)") 71 self.verbose_name = _("Create Security Group (Quota exceeded)")
diff --git a/openstack_dashboard/dashboards/project/security_groups/tests.py b/openstack_dashboard/dashboards/project/security_groups/tests.py
index ccde979..520234c 100644
--- a/openstack_dashboard/dashboards/project/security_groups/tests.py
+++ b/openstack_dashboard/dashboards/project/security_groups/tests.py
@@ -68,14 +68,14 @@ class SecurityGroupsViewTests(test.TestCase):
68 quotas: ('tenant_quota_usages',)}) 68 quotas: ('tenant_quota_usages',)})
69 def test_index(self): 69 def test_index(self):
70 sec_groups = self.security_groups.list() 70 sec_groups = self.security_groups.list()
71 quota_data = self.quota_usages.first() 71 quota_data = self.neutron_quota_usages.first()
72 quota_data['security_groups']['available'] = 10 72 quota_data['security_group']['available'] = 10
73 73
74 api.neutron.security_group_list(IsA(http.HttpRequest)) \ 74 api.neutron.security_group_list(IsA(http.HttpRequest)) \
75 .AndReturn(sec_groups) 75 .AndReturn(sec_groups)
76 quotas.tenant_quota_usages( 76 quotas.tenant_quota_usages(
77 IsA(http.HttpRequest), 77 IsA(http.HttpRequest),
78 targets=('security_groups', )).MultipleTimes() \ 78 targets=('security_group', )).MultipleTimes() \
79 .AndReturn(quota_data) 79 .AndReturn(quota_data)
80 80
81 self.mox.ReplayAll() 81 self.mox.ReplayAll()
@@ -101,15 +101,15 @@ class SecurityGroupsViewTests(test.TestCase):
101 quotas: ('tenant_quota_usages',)}) 101 quotas: ('tenant_quota_usages',)})
102 def test_create_button_attributes(self): 102 def test_create_button_attributes(self):
103 sec_groups = self.security_groups.list() 103 sec_groups = self.security_groups.list()
104 quota_data = self.quota_usages.first() 104 quota_data = self.neutron_quota_usages.first()
105 quota_data['security_groups']['available'] = 10 105 quota_data['security_group']['available'] = 10
106 106
107 api.neutron.security_group_list( 107 api.neutron.security_group_list(
108 IsA(http.HttpRequest)) \ 108 IsA(http.HttpRequest)) \
109 .AndReturn(sec_groups) 109 .AndReturn(sec_groups)
110 quotas.tenant_quota_usages( 110 quotas.tenant_quota_usages(
111 IsA(http.HttpRequest), 111 IsA(http.HttpRequest),
112 targets=('security_groups', )).MultipleTimes() \ 112 targets=('security_group', )).MultipleTimes() \
113 .AndReturn(quota_data) 113 .AndReturn(quota_data)
114 114
115 self.mox.ReplayAll() 115 self.mox.ReplayAll()
@@ -135,15 +135,15 @@ class SecurityGroupsViewTests(test.TestCase):
135 def _test_create_button_disabled_when_quota_exceeded(self, 135 def _test_create_button_disabled_when_quota_exceeded(self,
136 network_enabled): 136 network_enabled):
137 sec_groups = self.security_groups.list() 137 sec_groups = self.security_groups.list()
138 quota_data = self.quota_usages.first() 138 quota_data = self.neutron_quota_usages.first()
139 quota_data['security_groups']['available'] = 0 139 quota_data['security_group']['available'] = 0
140 140
141 api.neutron.security_group_list( 141 api.neutron.security_group_list(
142 IsA(http.HttpRequest)) \ 142 IsA(http.HttpRequest)) \
143 .AndReturn(sec_groups) 143 .AndReturn(sec_groups)
144 quotas.tenant_quota_usages( 144 quotas.tenant_quota_usages(
145 IsA(http.HttpRequest), 145 IsA(http.HttpRequest),
146 targets=('security_groups', )).MultipleTimes() \ 146 targets=('security_group', )).MultipleTimes() \
147 .AndReturn(quota_data) 147 .AndReturn(quota_data)
148 148
149 self.mox.ReplayAll() 149 self.mox.ReplayAll()
diff --git a/openstack_dashboard/test/test_data/neutron_data.py b/openstack_dashboard/test/test_data/neutron_data.py
index 326ec81..7297716 100644
--- a/openstack_dashboard/test/test_data/neutron_data.py
+++ b/openstack_dashboard/test/test_data/neutron_data.py
@@ -618,11 +618,13 @@ def data(TEST):
618 TEST.neutron_quotas.add(base.QuotaSet(quota_data)) 618 TEST.neutron_quotas.add(base.QuotaSet(quota_data))
619 619
620 # Quota Usages 620 # Quota Usages
621 quota_usage_data = {'networks': {'used': 0, 'quota': 5}, 621 quota_usage_data = {
622 'subnets': {'used': 0, 'quota': 5}, 622 'network': {'used': 0, 'quota': 5},
623 'ports': {'used': 0, 'quota': 5}, 623 'subnet': {'used': 0, 'quota': 5},
624 'routers': {'used': 0, 'quota': 5}, 624 'port': {'used': 0, 'quota': 5},
625 } 625 'router': {'used': 0, 'quota': 5},
626 'floatingip': {'used': 0, 'quota': 10},
627 }
626 quota_usage = usage_quotas.QuotaUsage() 628 quota_usage = usage_quotas.QuotaUsage()
627 for k, v in quota_usage_data.items(): 629 for k, v in quota_usage_data.items():
628 quota_usage.add_quota(base.Quota(k, v['quota'])) 630 quota_usage.add_quota(base.Quota(k, v['quota']))
diff --git a/openstack_dashboard/test/unit/usage/test_quotas.py b/openstack_dashboard/test/unit/usage/test_quotas.py
index 6af3bd0..8eacf0a 100644
--- a/openstack_dashboard/test/unit/usage/test_quotas.py
+++ b/openstack_dashboard/test/unit/usage/test_quotas.py
@@ -437,15 +437,15 @@ class QuotaTests(test.APITestCase):
437 437
438 def test_tenant_quota_usages_neutron_with_target_network_resources(self): 438 def test_tenant_quota_usages_neutron_with_target_network_resources(self):
439 self._test_tenant_quota_usages_neutron_with_target( 439 self._test_tenant_quota_usages_neutron_with_target(
440 targets=('networks', 'subnets', 'routers', )) 440 targets=('network', 'subnet', 'router', ))
441 441
442 def test_tenant_quota_usages_neutron_with_target_security_groups(self): 442 def test_tenant_quota_usages_neutron_with_target_security_groups(self):
443 self._test_tenant_quota_usages_neutron_with_target( 443 self._test_tenant_quota_usages_neutron_with_target(
444 targets=('security_groups', )) 444 targets=('security_group', ))
445 445
446 def test_tenant_quota_usages_neutron_with_target_floating_ips(self): 446 def test_tenant_quota_usages_neutron_with_target_floating_ips(self):
447 self._test_tenant_quota_usages_neutron_with_target( 447 self._test_tenant_quota_usages_neutron_with_target(
448 targets=('floating_ips', )) 448 targets=('floatingip', ))
449 449
450 @test.create_stubs({api.base: ('is_service_enabled',), 450 @test.create_stubs({api.base: ('is_service_enabled',),
451 api.neutron: ('floating_ip_supported', 451 api.neutron: ('floating_ip_supported',
@@ -476,24 +476,22 @@ class QuotaTests(test.APITestCase):
476 'quota_details').AndReturn(False) 476 'quota_details').AndReturn(False)
477 api.neutron.tenant_quota_get(IsA(http.HttpRequest), '1') \ 477 api.neutron.tenant_quota_get(IsA(http.HttpRequest), '1') \
478 .AndReturn(self.neutron_quotas.first()) 478 .AndReturn(self.neutron_quotas.first())
479 if 'networks' in targets: 479 if 'network' in targets:
480 api.neutron.network_list(IsA(http.HttpRequest), 480 api.neutron.network_list(IsA(http.HttpRequest),
481 tenant_id=self.request.user.tenant_id) \ 481 tenant_id=self.request.user.tenant_id) \
482 .AndReturn(self.networks.list()) 482 .AndReturn(self.networks.list())
483 if 'subnets' in targets: 483 if 'subnet' in targets:
484 api.neutron.subnet_list(IsA(http.HttpRequest), 484 api.neutron.subnet_list(IsA(http.HttpRequest),
485 tenant_id=self.request.user.tenant_id) \ 485 tenant_id=self.request.user.tenant_id) \
486 .AndReturn(self.subnets.list()) 486 .AndReturn(self.subnets.list())
487 if 'routers' in targets: 487 if 'router' in targets:
488 api.neutron.router_list(IsA(http.HttpRequest), 488 api.neutron.router_list(IsA(http.HttpRequest),
489 tenant_id=self.request.user.tenant_id) \ 489 tenant_id=self.request.user.tenant_id) \
490 .AndReturn(self.routers.list()) 490 .AndReturn(self.routers.list())
491 if 'floating_ips' in targets: 491 if 'floatingip' in targets:
492 api.neutron.floating_ip_supported(IsA(http.HttpRequest)) \
493 .AndReturn(True)
494 api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \ 492 api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \
495 .AndReturn(self.floating_ips.list()) 493 .AndReturn(self.floating_ips.list())
496 if 'security_groups' in targets: 494 if 'security_group' in targets:
497 api.neutron.security_group_list(IsA(http.HttpRequest)) \ 495 api.neutron.security_group_list(IsA(http.HttpRequest)) \
498 .AndReturn(self.security_groups.list()) 496 .AndReturn(self.security_groups.list())
499 497
@@ -508,16 +506,16 @@ class QuotaTests(test.APITestCase):
508 fip_used = len(self.floating_ips.list()) 506 fip_used = len(self.floating_ips.list())
509 sg_used = len(self.security_groups.list()) 507 sg_used = len(self.security_groups.list())
510 expected = { 508 expected = {
511 'networks': {'used': network_used, 'quota': 10, 509 'network': {'used': network_used, 'quota': 10,
512 'available': 10 - network_used}, 510 'available': 10 - network_used},
513 'subnets': {'used': subnet_used, 'quota': 10, 511 'subnet': {'used': subnet_used, 'quota': 10,
514 'available': 10 - subnet_used}, 512 'available': 10 - subnet_used},
515 'routers': {'used': router_used, 'quota': 10, 513 'router': {'used': router_used, 'quota': 10,
516 'available': 10 - router_used}, 514 'available': 10 - router_used},
517 'security_groups': {'used': sg_used, 'quota': 20, 515 'security_group': {'used': sg_used, 'quota': 20,
518 'available': 20 - sg_used}, 516 'available': 20 - sg_used},
519 'floating_ips': {'used': fip_used, 'quota': 50, 517 'floatingip': {'used': fip_used, 'quota': 50,
520 'available': 50 - fip_used}, 518 'available': 50 - fip_used},
521 } 519 }
522 expected = dict((k, v) for k, v in expected.items() if k in targets) 520 expected = dict((k, v) for k, v in expected.items() if k in targets)
523 521
diff --git a/openstack_dashboard/usage/quotas.py b/openstack_dashboard/usage/quotas.py
index ce3925d..28f571d 100644
--- a/openstack_dashboard/usage/quotas.py
+++ b/openstack_dashboard/usage/quotas.py
@@ -235,33 +235,10 @@ def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id):
235 tenant_id = tenant_id or request.user.tenant_id 235 tenant_id = tenant_id or request.user.tenant_id
236 neutron_quotas = neutron.tenant_quota_get(request, tenant_id) 236 neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
237 237
238 if 'floatingip' not in disabled_quotas: 238 for quota_name in NEUTRON_QUOTA_FIELDS:
239 # Rename floatingip to floating_ips since that's how it's 239 if quota_name not in disabled_quotas:
240 # expected in some places (e.g. Security & Access' Floating IPs) 240 quota_data = neutron_quotas.get(quota_name).limit
241 fips_quota = neutron_quotas.get('floatingip').limit 241 qs.add(base.QuotaSet({quota_name: quota_data}))
242 qs.add(base.QuotaSet({'floating_ips': fips_quota}))
243
244 if 'security_group' not in disabled_quotas:
245 # Rename security_group to security_groups since that's how it's
246 # expected in some places (e.g. Security & Access' Security Groups)
247 sec_quota = neutron_quotas.get('security_group').limit
248 qs.add(base.QuotaSet({'security_groups': sec_quota}))
249
250 if 'network' not in disabled_quotas:
251 net_quota = neutron_quotas.get('network').limit
252 qs.add(base.QuotaSet({'networks': net_quota}))
253
254 if 'subnet' not in disabled_quotas:
255 net_quota = neutron_quotas.get('subnet').limit
256 qs.add(base.QuotaSet({'subnets': net_quota}))
257
258 if 'port' not in disabled_quotas:
259 net_quota = neutron_quotas.get('port').limit
260 qs.add(base.QuotaSet({'ports': net_quota}))
261
262 if 'router' not in disabled_quotas:
263 router_quota = neutron_quotas.get('router').limit
264 qs.add(base.QuotaSet({'routers': router_quota}))
265 242
266 return qs 243 return qs
267 244
@@ -357,19 +334,12 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
357 334
358 if neutron.is_extension_supported(request, 'quota_details'): 335 if neutron.is_extension_supported(request, 'quota_details'):
359 details = neutron.tenant_quota_detail_get(request, tenant_id) 336 details = neutron.tenant_quota_detail_get(request, tenant_id)
360 for name, neutron_name in ( 337 for quota_name in NEUTRON_QUOTA_FIELDS:
361 ('floating_ips', 'floatingip'), 338 if quota_name in disabled_quotas:
362 ('security_groups', 'security_group'),
363 ('security_group_rules', 'security_group_rule'),
364 ('networks', 'network'),
365 ('subnets', 'subnet'),
366 ('ports', 'port'),
367 ('routers', 'router')):
368 if neutron_name in disabled_quotas:
369 continue 339 continue
370 detail = details[neutron_name] 340 detail = details[quota_name]
371 usages.add_quota(base.Quota(name, detail['limit'])) 341 usages.add_quota(base.Quota(quota_name, detail['limit']))
372 usages.tally(name, detail['used'] + detail['reserved']) 342 usages.tally(quota_name, detail['used'] + detail['reserved'])
373 else: 343 else:
374 _get_tenant_network_usages_legacy( 344 _get_tenant_network_usages_legacy(
375 request, usages, disabled_quotas, tenant_id) 345 request, usages, disabled_quotas, tenant_id)
@@ -377,43 +347,30 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
377 347
378def _get_tenant_network_usages_legacy(request, usages, disabled_quotas, 348def _get_tenant_network_usages_legacy(request, usages, disabled_quotas,
379 tenant_id): 349 tenant_id):
380 enabled_quotas = NEUTRON_QUOTA_FIELDS - disabled_quotas
381 qs = base.QuotaSet() 350 qs = base.QuotaSet()
382 _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id) 351 _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id)
383 for quota in qs: 352 for quota in qs:
384 usages.add_quota(quota) 353 usages.add_quota(quota)
385 354
386 # NOTE(amotoki): floatingip is Neutron quota and floating_ips is 355 # TODO(amotoki): Add security_group_rule?
387 # Nova quota. We need to check both. 356 resource_lister = {
388 if {'floatingip', 'floating_ips'} & enabled_quotas: 357 'network': (neutron.network_list, {'tenant_id': tenant_id}),
389 floating_ips = [] 358 'subnet': (neutron.subnet_list, {'tenant_id': tenant_id}),
390 try: 359 'port': (neutron.port_list, {'tenant_id': tenant_id}),
391 if neutron.floating_ip_supported(request): 360 'router': (neutron.router_list, {'tenant_id': tenant_id}),
392 floating_ips = neutron.tenant_floating_ip_list(request) 361 'floatingip': (neutron.tenant_floating_ip_list, {}),
393 except Exception: 362 'security_group': (neutron.security_group_list, {}),
394 pass 363 }
395 usages.tally('floating_ips', len(floating_ips)) 364
396 365 for quota_name, lister_info in resource_lister.items():
397 if 'security_group' not in disabled_quotas: 366 if quota_name not in disabled_quotas:
398 security_groups = [] 367 lister = lister_info[0]
399 security_groups = neutron.security_group_list(request) 368 kwargs = lister_info[1]
400 usages.tally('security_groups', len(security_groups)) 369 try:
401 370 resources = lister(request, **kwargs)
402 if 'network' not in disabled_quotas: 371 except Exception:
403 networks = neutron.network_list(request, tenant_id=tenant_id) 372 resources = []
404 usages.tally('networks', len(networks)) 373 usages.tally(quota_name, len(resources))
405
406 if 'subnet' not in disabled_quotas:
407 subnets = neutron.subnet_list(request, tenant_id=tenant_id)
408 usages.tally('subnets', len(subnets))
409
410 if 'port' not in disabled_quotas:
411 ports = neutron.port_list(request, tenant_id=tenant_id)
412 usages.tally('ports', len(ports))
413
414 if 'router' not in disabled_quotas:
415 routers = neutron.router_list(request, tenant_id=tenant_id)
416 usages.tally('routers', len(routers))
417 374
418 375
419@profiler.trace 376@profiler.trace
@@ -435,34 +392,6 @@ def _get_tenant_volume_usages(request, usages, disabled_quotas, tenant_id):
435 disabled_quotas) 392 disabled_quotas)
436 393
437 394
438# Singular form key is used as quota field in the Neutron API.
439# We convert it explicitly here.
440# NOTE(amotoki): It is better to be converted in the horizon API wrapper
441# layer. Ideally the REST APIs of back-end services are consistent.
442NETWORK_QUOTA_API_KEY_MAP = {
443 'floating_ips': ['floatingip'],
444 'networks': ['network'],
445 'ports': ['port'],
446 'routers': ['router'],
447 'security_group_rules': ['security_group_rule'],
448 'security_groups': ['security_group'],
449 'subnets': ['subnet'],
450}
451
452
453def _convert_targets_to_quota_keys(targets):
454 quota_keys = set()
455 for target in targets:
456 if target in NETWORK_QUOTA_API_KEY_MAP:
457 quota_keys.update(NETWORK_QUOTA_API_KEY_MAP[target])
458 continue
459 if target in QUOTA_FIELDS:
460 quota_keys.add(target)
461 continue
462 raise ValueError('"%s" is not a valid quota field name.' % target)
463 return quota_keys
464
465
466# TODO(amotoki): Merge tenant_quota_usages and tenant_limit_usages. 395# TODO(amotoki): Merge tenant_quota_usages and tenant_limit_usages.
467# These two functions are similar. There seems no reason to have both. 396# These two functions are similar. There seems no reason to have both.
468 397
@@ -483,8 +412,11 @@ def tenant_quota_usages(request, tenant_id=None, targets=None):
483 usages = QuotaUsage() 412 usages = QuotaUsage()
484 413
485 if targets: 414 if targets:
415 if set(targets) - QUOTA_FIELDS:
416 raise ValueError('Unknown quota field names are included: %s'
417 % set(targets) - QUOTA_FIELDS)
486 enabled_quotas = set(QUOTA_FIELDS) - disabled_quotas 418 enabled_quotas = set(QUOTA_FIELDS) - disabled_quotas
487 enabled_quotas &= _convert_targets_to_quota_keys(targets) 419 enabled_quotas &= set(targets)
488 disabled_quotas = set(QUOTA_FIELDS) - enabled_quotas 420 disabled_quotas = set(QUOTA_FIELDS) - enabled_quotas
489 421
490 _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id) 422 _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id)