Browse Source

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
tags/13.0.0.0b3
Akihiro Motoki 1 year ago
parent
commit
1340904d47
23 changed files with 160 additions and 231 deletions
  1. 2
    2
      openstack_dashboard/dashboards/admin/networks/ports/tables.py
  2. 3
    3
      openstack_dashboard/dashboards/admin/networks/subnets/tables.py
  3. 1
    1
      openstack_dashboard/dashboards/admin/networks/subnets/tests.py
  4. 3
    3
      openstack_dashboard/dashboards/admin/networks/tables.py
  5. 8
    8
      openstack_dashboard/dashboards/admin/networks/tests.py
  6. 2
    2
      openstack_dashboard/dashboards/project/floating_ips/forms.py
  7. 2
    2
      openstack_dashboard/dashboards/project/floating_ips/tables.py
  8. 5
    5
      openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html
  9. 6
    9
      openstack_dashboard/dashboards/project/floating_ips/tests.py
  10. 1
    1
      openstack_dashboard/dashboards/project/floating_ips/views.py
  11. 4
    4
      openstack_dashboard/dashboards/project/network_topology/tests.py
  12. 2
    2
      openstack_dashboard/dashboards/project/network_topology/utils.py
  13. 3
    3
      openstack_dashboard/dashboards/project/networks/ports/tables.py
  14. 3
    3
      openstack_dashboard/dashboards/project/networks/subnets/tables.py
  15. 6
    6
      openstack_dashboard/dashboards/project/networks/tables.py
  16. 27
    27
      openstack_dashboard/dashboards/project/networks/tests.py
  17. 3
    3
      openstack_dashboard/dashboards/project/routers/tables.py
  18. 11
    11
      openstack_dashboard/dashboards/project/routers/tests.py
  19. 2
    2
      openstack_dashboard/dashboards/project/security_groups/tables.py
  20. 9
    9
      openstack_dashboard/dashboards/project/security_groups/tests.py
  21. 7
    5
      openstack_dashboard/test/test_data/neutron_data.py
  22. 18
    20
      openstack_dashboard/test/unit/usage/test_quotas.py
  23. 32
    100
      openstack_dashboard/usage/quotas.py

+ 2
- 2
openstack_dashboard/dashboards/admin/networks/ports/tables.py View File

@@ -38,8 +38,8 @@ class CreatePort(project_tables.CreatePort):
38 38
         network = self.table._get_network()
39 39
         tenant_id = network.tenant_id
40 40
         usages = quotas.tenant_quota_usages(
41
-            request, tenant_id=tenant_id, targets=('ports', ))
42
-        if usages.get('ports', {}).get('available', 1) <= 0:
41
+            request, tenant_id=tenant_id, targets=('port', ))
42
+        if usages.get('port', {}).get('available', 1) <= 0:
43 43
             if "disabled" not in self.classes:
44 44
                 self.classes = [c for c in self.classes] + ["disabled"]
45 45
                 self.verbose_name = _("Create Port (Quota exceeded)")

+ 3
- 3
openstack_dashboard/dashboards/admin/networks/subnets/tables.py View File

@@ -80,11 +80,11 @@ class CreateSubnet(proj_tables.SubnetPolicyTargetMixin, tables.LinkAction):
80 80
     def allowed(self, request, datum=None):
81 81
         network = self.table._get_network()
82 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 85
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
86
-        # usages["subnets'] is empty
87
-        if usages.get('subnets', {}).get('available', 1) <= 0:
86
+        # usages["subnet'] is empty
87
+        if usages.get('subnet', {}).get('available', 1) <= 0:
88 88
             if 'disabled' not in self.classes:
89 89
                 self.classes = [c for c in self.classes] + ['disabled']
90 90
                 self.verbose_name = _('Create Subnet (Quota exceeded)')

+ 1
- 1
openstack_dashboard/dashboards/admin/networks/subnets/tests.py View File

@@ -436,7 +436,7 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
436 436
             .MultipleTimes().AndReturn(True)
437 437
         quotas.tenant_quota_usages(
438 438
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
439
-            targets=('subnets',)).MultipleTimes().AndReturn(quota_data)
439
+            targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
440 440
         self.mox.ReplayAll()
441 441
         from django.utils.http import urlunquote
442 442
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',

+ 3
- 3
openstack_dashboard/dashboards/admin/networks/tables.py View File

@@ -85,11 +85,11 @@ class CreateSubnet(project_tables.CreateSubnet):
85 85
 
86 86
     def allowed(self, request, datum=None):
87 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 90
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
91
-        # usages["subnets'] is empty
92
-        if usages.get('subnets', {}).get('available', 1) <= 0:
91
+        # usages["subnet'] is empty
92
+        if usages.get('subnet', {}).get('available', 1) <= 0:
93 93
             if 'disabled' not in self.classes:
94 94
                 self.classes = [c for c in self.classes] + ['disabled']
95 95
                 self.verbose_name = _('Create Subnet (Quota exceeded)')

+ 8
- 8
openstack_dashboard/dashboards/admin/networks/tests.py View File

@@ -49,7 +49,7 @@ class NetworkTests(test.BaseAdminViewTests):
49 49
         for network in self.networks.list():
50 50
             usage.quotas.tenant_quota_usages(
51 51
                 IsA(http.HttpRequest), tenant_id=network.tenant_id,
52
-                targets=('subnets', )).AndReturn(quota_data)
52
+                targets=('subnet', )).AndReturn(quota_data)
53 53
             api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest),
54 54
                                                          network.id)\
55 55
                 .AndReturn(self.agents.list())
@@ -131,7 +131,7 @@ class NetworkTests(test.BaseAdminViewTests):
131 131
             'dhcp_agent_scheduler').AndReturn(True)
132 132
         usage.quotas.tenant_quota_usages(
133 133
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
134
-            targets=('subnets',)).MultipleTimes().AndReturn(quota_data)
134
+            targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
135 135
         self.mox.ReplayAll()
136 136
         url = urlunquote(reverse('horizon:admin:networks:detail',
137 137
                                  args=[network.id]))
@@ -172,7 +172,7 @@ class NetworkTests(test.BaseAdminViewTests):
172 172
             'dhcp_agent_scheduler').AndReturn(True)
173 173
         usage.quotas.tenant_quota_usages(
174 174
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
175
-            targets=('subnets',)).MultipleTimes().AndReturn(quota_data)
175
+            targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
176 176
         self.mox.ReplayAll()
177 177
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
178 178
                          args=[network.id]))
@@ -197,7 +197,7 @@ class NetworkTests(test.BaseAdminViewTests):
197 197
         quota_data = self.neutron_quota_usages.first()
198 198
         usage.quotas.tenant_quota_usages(
199 199
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
200
-            targets=('ports',)).MultipleTimes().AndReturn(quota_data)
200
+            targets=('port',)).MultipleTimes().AndReturn(quota_data)
201 201
         api.neutron.is_extension_supported(
202 202
             IsA(http.HttpRequest),
203 203
             'network-ip-availability').AndReturn(True)
@@ -212,7 +212,7 @@ class NetworkTests(test.BaseAdminViewTests):
212 212
             'dhcp_agent_scheduler').AndReturn(True)
213 213
         usage.quotas.tenant_quota_usages(
214 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 217
         self.mox.ReplayAll()
218 218
         url = reverse('horizon:admin:networks:ports_tab',
@@ -255,7 +255,7 @@ class NetworkTests(test.BaseAdminViewTests):
255 255
             'dhcp_agent_scheduler').AndReturn(True)
256 256
         usage.quotas.tenant_quota_usages(
257 257
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
258
-            targets=('subnets',)).MultipleTimes().AndReturn(quota_data)
258
+            targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
259 259
         self.mox.ReplayAll()
260 260
         url = reverse('horizon:admin:networks:agents_tab', args=[network.id])
261 261
         res = self.client.get(urlunquote(url))
@@ -359,7 +359,7 @@ class NetworkTests(test.BaseAdminViewTests):
359 359
             'dhcp_agent_scheduler').AndReturn(True)
360 360
         usage.quotas.tenant_quota_usages(
361 361
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
362
-            targets=('subnets',)).MultipleTimes().AndReturn(quota_data)
362
+            targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
363 363
         self.mox.ReplayAll()
364 364
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
365 365
                          args=[network.id]))
@@ -418,7 +418,7 @@ class NetworkTests(test.BaseAdminViewTests):
418 418
             .AndReturn(True)
419 419
         usage.quotas.tenant_quota_usages(
420 420
             IsA(http.HttpRequest), tenant_id=network.tenant_id,
421
-            targets=('subnets',)).MultipleTimes().AndReturn(quota_data)
421
+            targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
422 422
         self.mox.ReplayAll()
423 423
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
424 424
                          args=[network.id]))

+ 2
- 2
openstack_dashboard/dashboards/project/floating_ips/forms.py View File

@@ -39,8 +39,8 @@ class FloatingIpAllocate(forms.SelfHandlingForm):
39 39
         try:
40 40
             # Prevent allocating more IP than the quota allows
41 41
             usages = quotas.tenant_quota_usages(request,
42
-                                                targets=('floating_ips', ))
43
-            if usages['floating_ips']['available'] <= 0:
42
+                                                targets=('floatingip', ))
43
+            if usages['floatingip']['available'] <= 0:
44 44
                 error_message = _('You are already using all of your available'
45 45
                                   ' floating IPs.')
46 46
                 self.api_error(error_message)

+ 2
- 2
openstack_dashboard/dashboards/project/floating_ips/tables.py View File

@@ -48,8 +48,8 @@ class AllocateIP(tables.LinkAction):
48 48
 
49 49
     def allowed(self, request, fip=None):
50 50
         usages = quotas.tenant_quota_usages(request,
51
-                                            targets=('floating_ips', ))
52
-        if usages['floating_ips']['available'] <= 0:
51
+                                            targets=('floatingip', ))
52
+        if usages['floatingip']['available'] <= 0:
53 53
             if "disabled" not in self.classes:
54 54
                 self.classes = [c for c in self.classes] + ['disabled']
55 55
                 self.verbose_name = string_concat(self.verbose_name, ' ',

+ 5
- 5
openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html View File

@@ -12,15 +12,15 @@
12 12
       <strong>{% trans "Floating IP" %}</strong>
13 13
     </div>
14 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 16
     </span>
17 17
   </div>
18 18
   <div id="floating_ip_progress"
19 19
        class="quota_bar"
20
-       data-quota-used="{{ usages.floating_ips.used }}"
21
-       data-quota-limit="{{ usages.floating_ips.quota }}">
22
-  {% widthratio usages.floating_ips.used usages.floating_ips.quota 100 as ip_percent %}
23
-  {% widthratio 100 usages.floating_ips.quota 1 as single_step %}
20
+       data-quota-used="{{ usages.floatingip.used }}"
21
+       data-quota-limit="{{ usages.floatingip.quota }}">
22
+  {% widthratio usages.floatingip.used usages.floatingip.quota 100 as ip_percent %}
23
+  {% widthratio 100 usages.floatingip.quota 1 as single_step %}
24 24
   {% bs_progress_bar ip_percent single_step %}
25 25
   </div>
26 26
 </div>

+ 6
- 9
openstack_dashboard/dashboards/project/floating_ips/tests.py View File

@@ -246,8 +246,7 @@ class FloatingIpViewTests(test.TestCase):
246 246
     def test_allocate_button_attributes(self):
247 247
         floating_ips = self.floating_ips.list()
248 248
         floating_pools = self.pools.list()
249
-        quota_data = self.quota_usages.first()
250
-        quota_data['floating_ips']['available'] = 10
249
+        quota_data = self.neutron_quota_usages.first()
251 250
 
252 251
         api.neutron.tenant_floating_ip_list(
253 252
             IsA(http.HttpRequest)) \
@@ -259,7 +258,7 @@ class FloatingIpViewTests(test.TestCase):
259 258
             IsA(http.HttpRequest), detailed=False) \
260 259
             .AndReturn([self.servers.list(), False])
261 260
         quotas.tenant_quota_usages(
262
-            IsA(http.HttpRequest), targets=('floating_ips', )).MultipleTimes() \
261
+            IsA(http.HttpRequest), targets=('floatingip', )).MultipleTimes() \
263 262
             .AndReturn(quota_data)
264 263
 
265 264
         self.mox.ReplayAll()
@@ -284,8 +283,8 @@ class FloatingIpViewTests(test.TestCase):
284 283
     def test_allocate_button_disabled_when_quota_exceeded(self):
285 284
         floating_ips = self.floating_ips.list()
286 285
         floating_pools = self.pools.list()
287
-        quota_data = self.quota_usages.first()
288
-        quota_data['floating_ips']['available'] = 0
286
+        quota_data = self.neutron_quota_usages.first()
287
+        quota_data['floatingip']['available'] = 0
289 288
 
290 289
         api.neutron.tenant_floating_ip_list(
291 290
             IsA(http.HttpRequest)) \
@@ -297,7 +296,7 @@ class FloatingIpViewTests(test.TestCase):
297 296
             IsA(http.HttpRequest), detailed=False) \
298 297
             .AndReturn([self.servers.list(), False])
299 298
         quotas.tenant_quota_usages(
300
-            IsA(http.HttpRequest), targets=('floating_ips', )).MultipleTimes() \
299
+            IsA(http.HttpRequest), targets=('floatingip', )).MultipleTimes() \
301 300
             .AndReturn(quota_data)
302 301
 
303 302
         self.mox.ReplayAll()
@@ -337,8 +336,6 @@ class FloatingIpViewTests(test.TestCase):
337 336
                                            'quota_details').AndReturn(False)
338 337
         api.neutron.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \
339 338
             .AndReturn(self.neutron_quotas.first())
340
-        api.neutron.floating_ip_supported(IsA(http.HttpRequest)) \
341
-            .AndReturn(True)
342 339
         api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \
343 340
             .MultipleTimes().AndReturn(self.floating_ips.list())
344 341
         api.neutron.floating_ip_pools_list(IsA(http.HttpRequest)) \
@@ -347,5 +344,5 @@ class FloatingIpViewTests(test.TestCase):
347 344
 
348 345
         url = reverse('%s:allocate' % NAMESPACE)
349 346
         res = self.client.get(url)
350
-        self.assertEqual(res.context['usages']['floating_ips']['quota'],
347
+        self.assertEqual(res.context['usages']['floatingip']['quota'],
351 348
                          self.neutron_quotas.first().get('floatingip').limit)

+ 1
- 1
openstack_dashboard/dashboards/project/floating_ips/views.py View File

@@ -62,7 +62,7 @@ class AllocateView(forms.ModalFormView):
62 62
         context = super(AllocateView, self).get_context_data(**kwargs)
63 63
         try:
64 64
             context['usages'] = quotas.tenant_quota_usages(
65
-                self.request, targets=('floating_ips', ))
65
+                self.request, targets=('floatingip', ))
66 66
         except Exception:
67 67
             exceptions.handle(self.request)
68 68
         return context

+ 4
- 4
openstack_dashboard/dashboards/project/network_topology/tests.py View File

@@ -198,18 +198,18 @@ class NetworkTopologyCreateTests(test.TestCase):
198 198
             self, expected_string, networks_quota=10,
199 199
             routers_quota=10, instances_quota=10):
200 200
         quota_data = self.quota_usages.first()
201
-        quota_data['networks']['available'] = networks_quota
202
-        quota_data['routers']['available'] = routers_quota
201
+        quota_data['network']['available'] = networks_quota
202
+        quota_data['router']['available'] = routers_quota
203 203
         quota_data['instances']['available'] = instances_quota
204 204
 
205 205
         quotas.tenant_quota_usages(
206 206
             IsA(http.HttpRequest), targets=('instances', )
207 207
         ).MultipleTimes().AndReturn(quota_data)
208 208
         quotas.tenant_quota_usages(
209
-            IsA(http.HttpRequest), targets=('networks', )
209
+            IsA(http.HttpRequest), targets=('network', )
210 210
         ).MultipleTimes().AndReturn(quota_data)
211 211
         quotas.tenant_quota_usages(
212
-            IsA(http.HttpRequest), targets=('routers', )
212
+            IsA(http.HttpRequest), targets=('router', )
213 213
         ).MultipleTimes().AndReturn(quota_data)
214 214
 
215 215
         self.mox.ReplayAll()

+ 2
- 2
openstack_dashboard/dashboards/project/network_topology/utils.py View File

@@ -35,11 +35,11 @@ def get_context(request, context=None):
35 35
     context['instance_quota_exceeded'] = _quota_exceeded(request, 'instances')
36 36
     context['create_network_allowed'] = policy.check(
37 37
         (("network", "create_network"),), request)
38
-    context['network_quota_exceeded'] = _quota_exceeded(request, 'networks')
38
+    context['network_quota_exceeded'] = _quota_exceeded(request, 'network')
39 39
     context['create_router_allowed'] = (
40 40
         network_config.get('enable_router', True) and
41 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 43
     context['console_type'] = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
44 44
     context['show_ng_launch'] = (
45 45
         base.is_service_enabled(request, 'compute') and

+ 3
- 3
openstack_dashboard/dashboards/project/networks/ports/tables.py View File

@@ -88,10 +88,10 @@ class CreatePort(tables.LinkAction):
88 88
         return reverse(self.url, args=(network_id,))
89 89
 
90 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 92
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
93
-        # usages["ports"] is empty
94
-        if usages.get('ports', {}).get('available', 1) <= 0:
93
+        # usages["port"] is empty
94
+        if usages.get('port', {}).get('available', 1) <= 0:
95 95
             if "disabled" not in self.classes:
96 96
                 self.classes = [c for c in self.classes] + ["disabled"]
97 97
                 self.verbose_name = _("Create Port (Quota exceeded)")

+ 3
- 3
openstack_dashboard/dashboards/project/networks/subnets/tables.py View File

@@ -99,11 +99,11 @@ class CreateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
99 99
         return reverse(self.url, args=(network_id,))
100 100
 
101 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 104
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
105
-        # usages["subnets'] is empty
106
-        if usages.get('subnets', {}).get('available', 1) <= 0:
105
+        # usages["subnet'] is empty
106
+        if usages.get('subnet', {}).get('available', 1) <= 0:
107 107
             if 'disabled' not in self.classes:
108 108
                 self.classes = [c for c in self.classes] + ['disabled']
109 109
                 self.verbose_name = _('Create Subnet (Quota exceeded)')

+ 6
- 6
openstack_dashboard/dashboards/project/networks/tables.py View File

@@ -92,10 +92,10 @@ class CreateNetwork(tables.LinkAction):
92 92
     policy_rules = (("network", "create_network"),)
93 93
 
94 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 96
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
97
-        # usages["networks"] is empty
98
-        if usages.get('networks', {}).get('available', 1) <= 0:
97
+        # usages["network"] is empty
98
+        if usages.get('network', {}).get('available', 1) <= 0:
99 99
             if "disabled" not in self.classes:
100 100
                 self.classes = [c for c in self.classes] + ["disabled"]
101 101
                 self.verbose_name = _("Create Network (Quota exceeded)")
@@ -127,10 +127,10 @@ class CreateSubnet(subnet_tables.SubnetPolicyTargetMixin, tables.LinkAction):
127 127
                            ("network:project_id", "tenant_id"),)
128 128
 
129 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 131
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
132
-        # usages["subnets'] is empty
133
-        if usages.get('subnets', {}).get('available', 1) <= 0:
132
+        # usages["subnet'] is empty
133
+        if usages.get('subnet', {}).get('available', 1) <= 0:
134 134
             if 'disabled' not in self.classes:
135 135
                 self.classes = [c for c in self.classes] + ['disabled']
136 136
                 self.verbose_name = _('Create Subnet (Quota exceeded)')

+ 27
- 27
openstack_dashboard/dashboards/project/networks/tests.py View File

@@ -127,15 +127,15 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
127 127
                                       'is_extension_supported'),
128 128
                         quotas: ('tenant_quota_usages',)})
129 129
     def test_index(self):
130
-        quota_data = self.quota_usages.first()
131
-        quota_data['networks']['available'] = 5
132
-        quota_data['subnets']['available'] = 5
130
+        quota_data = self.neutron_quota_usages.first()
131
+        quota_data['network']['available'] = 5
132
+        quota_data['subnet']['available'] = 5
133 133
         self._stub_net_list()
134 134
         quotas.tenant_quota_usages(
135
-            IsA(http.HttpRequest), targets=('networks', )) \
135
+            IsA(http.HttpRequest), targets=('network', )) \
136 136
             .MultipleTimes().AndReturn(quota_data)
137 137
         quotas.tenant_quota_usages(
138
-            IsA(http.HttpRequest), targets=('subnets', )) \
138
+            IsA(http.HttpRequest), targets=('subnet', )) \
139 139
             .MultipleTimes().AndReturn(quota_data)
140 140
         api.neutron.is_extension_supported(
141 141
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -158,7 +158,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
158 158
             tenant_id=self.tenant.id,
159 159
             shared=False).MultipleTimes().AndRaise(self.exceptions.neutron)
160 160
         quotas.tenant_quota_usages(
161
-            IsA(http.HttpRequest), targets=('networks', )) \
161
+            IsA(http.HttpRequest), targets=('network', )) \
162 162
             .MultipleTimes().AndReturn(quota_data)
163 163
         api.neutron.is_extension_supported(
164 164
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -200,7 +200,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
200 200
             .AndReturn(mac_learning)
201 201
 
202 202
         quotas.tenant_quota_usages(
203
-            IsA(http.HttpRequest), targets=('subnets', )) \
203
+            IsA(http.HttpRequest), targets=('subnet', )) \
204 204
             .MultipleTimes().AndReturn(quota_data)
205 205
         api.neutron.is_extension_supported(
206 206
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -228,7 +228,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
228 228
                                            'mac-learning')\
229 229
             .AndReturn(mac_learning)
230 230
         quotas.tenant_quota_usages(
231
-            IsA(http.HttpRequest), targets=('subnets', )) \
231
+            IsA(http.HttpRequest), targets=('subnet', )) \
232 232
             .MultipleTimes().AndReturn(quota_data)
233 233
         api.neutron.is_extension_supported(
234 234
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -291,8 +291,8 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
291 291
     def _test_subnets_tab_subnet_exception(self, mac_learning=False):
292 292
         network_id = self.networks.first().id
293 293
         quota_data = self.neutron_quota_usages.first()
294
-        quota_data['networks']['available'] = 5
295
-        quota_data['subnets']['available'] = 5
294
+        quota_data['network']['available'] = 5
295
+        quota_data['subnet']['available'] = 5
296 296
         api.neutron.network_get(IsA(http.HttpRequest), network_id).\
297 297
             MultipleTimes().AndReturn(self.networks.first())
298 298
         api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
@@ -302,7 +302,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
302 302
                                            'mac-learning')\
303 303
             .AndReturn(mac_learning)
304 304
         quotas.tenant_quota_usages(
305
-            IsA(http.HttpRequest), targets=('subnets', )) \
305
+            IsA(http.HttpRequest), targets=('subnet', )) \
306 306
             .MultipleTimes().AndReturn(quota_data)
307 307
         api.neutron.is_extension_supported(
308 308
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -336,7 +336,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
336 336
     def _test_subnets_tab_port_exception(self, mac_learning=False):
337 337
         network_id = self.networks.first().id
338 338
         quota_data = self.neutron_quota_usages.first()
339
-        quota_data['subnets']['available'] = 5
339
+        quota_data['subnet']['available'] = 5
340 340
         api.neutron.network_get(IsA(http.HttpRequest), network_id).\
341 341
             AndReturn(self.networks.first())
342 342
         api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
@@ -345,7 +345,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
345 345
                                            'mac-learning')\
346 346
             .AndReturn(mac_learning)
347 347
         quotas.tenant_quota_usages(
348
-            IsA(http.HttpRequest), targets=('subnets', )) \
348
+            IsA(http.HttpRequest), targets=('subnet', )) \
349 349
             .MultipleTimes().AndReturn(quota_data)
350 350
         api.neutron.is_extension_supported(
351 351
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1096,15 +1096,15 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1096 1096
         # these keys are empty dicts, its disabled
1097 1097
         quota_data = self.neutron_quota_usages.first()
1098 1098
 
1099
-        quota_data['networks'].pop('available')
1100
-        quota_data['subnets'].pop('available')
1099
+        quota_data['network'].pop('available')
1100
+        quota_data['subnet'].pop('available')
1101 1101
 
1102 1102
         self._stub_net_list()
1103 1103
         quotas.tenant_quota_usages(
1104
-            IsA(http.HttpRequest), targets=('networks', )) \
1104
+            IsA(http.HttpRequest), targets=('network', )) \
1105 1105
             .MultipleTimes().AndReturn(quota_data)
1106 1106
         quotas.tenant_quota_usages(
1107
-            IsA(http.HttpRequest), targets=('subnets', )) \
1107
+            IsA(http.HttpRequest), targets=('subnet', )) \
1108 1108
             .MultipleTimes().AndReturn(quota_data)
1109 1109
         api.neutron.is_extension_supported(
1110 1110
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1128,15 +1128,15 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1128 1128
 
1129 1129
         quota_data = self.neutron_quota_usages.first()
1130 1130
 
1131
-        quota_data['networks']['available'] = network_quota
1132
-        quota_data['subnets']['available'] = subnet_quota
1131
+        quota_data['network']['available'] = network_quota
1132
+        quota_data['subnet']['available'] = subnet_quota
1133 1133
 
1134 1134
         self._stub_net_list()
1135 1135
         quotas.tenant_quota_usages(
1136
-            IsA(http.HttpRequest), targets=('networks', )) \
1136
+            IsA(http.HttpRequest), targets=('network', )) \
1137 1137
             .MultipleTimes().AndReturn(quota_data)
1138 1138
         quotas.tenant_quota_usages(
1139
-            IsA(http.HttpRequest), targets=('subnets', )) \
1139
+            IsA(http.HttpRequest), targets=('subnet', )) \
1140 1140
             .MultipleTimes().AndReturn(quota_data)
1141 1141
         api.neutron.is_extension_supported(
1142 1142
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1221,7 +1221,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1221 1221
             IsA(http.HttpRequest), 'mac-learning')\
1222 1222
             .AndReturn(False)
1223 1223
         quotas.tenant_quota_usages(
1224
-            IsA(http.HttpRequest), targets=('subnets', )) \
1224
+            IsA(http.HttpRequest), targets=('subnet', )) \
1225 1225
             .MultipleTimes().AndReturn(quota_data)
1226 1226
         api.neutron.is_extension_supported(
1227 1227
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1242,7 +1242,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1242 1242
 
1243 1243
     def test_subnet_create_button_disabled_when_quota_exceeded_detail(self):
1244 1244
         quota_data = self.neutron_quota_usages.first()
1245
-        quota_data['subnets']['available'] = 0
1245
+        quota_data['subnet']['available'] = 0
1246 1246
         create_action = self._test_subnet_create_button(quota_data)
1247 1247
         self.assertIn('disabled', create_action.classes,
1248 1248
                       'The create button should be disabled')
@@ -1300,10 +1300,10 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1300 1300
             IsA(http.HttpRequest), 'mac-learning') \
1301 1301
             .AndReturn(False)
1302 1302
         quotas.tenant_quota_usages(
1303
-            IsA(http.HttpRequest), targets=('subnets', )) \
1303
+            IsA(http.HttpRequest), targets=('subnet', )) \
1304 1304
             .MultipleTimes().AndReturn(quota_data)
1305 1305
         quotas.tenant_quota_usages(
1306
-            IsA(http.HttpRequest), targets=('ports',)) \
1306
+            IsA(http.HttpRequest), targets=('port',)) \
1307 1307
             .MultipleTimes().AndReturn(quota_data)
1308 1308
         api.neutron.is_extension_supported(
1309 1309
             IsA(http.HttpRequest), 'network_availability_zone')\
@@ -1323,7 +1323,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1323 1323
 
1324 1324
     def test_port_create_button_disabled_when_quota_exceeded(self):
1325 1325
         quota_data = self.neutron_quota_usages.first()
1326
-        quota_data['ports']['available'] = 0
1326
+        quota_data['port']['available'] = 0
1327 1327
         create_action = self._test_port_create_button(quota_data)
1328 1328
         self.assertIn('disabled', create_action.classes,
1329 1329
                       'The create button should be disabled')
@@ -1338,7 +1338,7 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
1338 1338
 
1339 1339
     def test_create_port_button_attributes(self):
1340 1340
         quota_data = self.neutron_quota_usages.first()
1341
-        quota_data['ports']['available'] = 1
1341
+        quota_data['port']['available'] = 1
1342 1342
         create_action = self._test_port_create_button(quota_data)
1343 1343
 
1344 1344
         self.assertEqual(set(['ajax-modal']), set(create_action.classes))

+ 3
- 3
openstack_dashboard/dashboards/project/routers/tables.py View File

@@ -96,10 +96,10 @@ class CreateRouter(tables.LinkAction):
96 96
     policy_rules = (("network", "create_router"),)
97 97
 
98 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 100
         # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
101
-        # usages['routers'] is empty
102
-        if usages.get('routers', {}).get('available', 1) <= 0:
101
+        # usages['router'] is empty
102
+        if usages.get('router', {}).get('available', 1) <= 0:
103 103
             if "disabled" not in self.classes:
104 104
                 self.classes = [c for c in self.classes] + ["disabled"]
105 105
                 self.verbose_name = _("Create Router (Quota exceeded)")

+ 11
- 11
openstack_dashboard/dashboards/project/routers/tests.py View File

@@ -102,7 +102,7 @@ class RouterTests(RouterMixin, test.TestCase):
102 102
             IsA(http.HttpRequest),
103 103
             tenant_id=self.tenant.id).AndReturn(self.routers.list())
104 104
         quotas.tenant_quota_usages(
105
-            IsA(http.HttpRequest), targets=('routers', )) \
105
+            IsA(http.HttpRequest), targets=('router', )) \
106 106
             .MultipleTimes().AndReturn(quota_data)
107 107
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
108 108
                                            "router_availability_zone")\
@@ -126,7 +126,7 @@ class RouterTests(RouterMixin, test.TestCase):
126 126
             tenant_id=self.tenant.id).MultipleTimes().AndRaise(
127 127
             self.exceptions.neutron)
128 128
         quotas.tenant_quota_usages(
129
-            IsA(http.HttpRequest), targets=('routers', )) \
129
+            IsA(http.HttpRequest), targets=('router', )) \
130 130
             .MultipleTimes().AndReturn(quota_data)
131 131
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
132 132
                                            "router_availability_zone")\
@@ -150,7 +150,7 @@ class RouterTests(RouterMixin, test.TestCase):
150 150
             IsA(http.HttpRequest),
151 151
             tenant_id=self.tenant.id).MultipleTimes().AndReturn([router])
152 152
         quotas.tenant_quota_usages(
153
-            IsA(http.HttpRequest), targets=('routers', )) \
153
+            IsA(http.HttpRequest), targets=('router', )) \
154 154
             .MultipleTimes().AndReturn(quota_data)
155 155
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
156 156
                                            "router_availability_zone")\
@@ -198,7 +198,7 @@ class RouterTests(RouterMixin, test.TestCase):
198 198
             IsA(http.HttpRequest),
199 199
             tenant_id=self.tenant.id).AndReturn(self.routers.list())
200 200
         quotas.tenant_quota_usages(
201
-            IsA(http.HttpRequest), targets=('routers', )) \
201
+            IsA(http.HttpRequest), targets=('router', )) \
202 202
             .MultipleTimes().AndReturn(quota_data)
203 203
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
204 204
                                            "router_availability_zone")\
@@ -240,7 +240,7 @@ class RouterTests(RouterMixin, test.TestCase):
240 240
             IsA(http.HttpRequest),
241 241
             tenant_id=self.tenant.id).AndReturn(self.routers.list())
242 242
         quotas.tenant_quota_usages(
243
-            IsA(http.HttpRequest), targets=('routers', )) \
243
+            IsA(http.HttpRequest), targets=('router', )) \
244 244
             .MultipleTimes().AndReturn(quota_data)
245 245
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
246 246
                                            "router_availability_zone")\
@@ -928,12 +928,12 @@ class RouterViewTests(RouterMixin, test.TestCase):
928 928
                         quotas: ('tenant_quota_usages',)})
929 929
     def test_create_button_disabled_when_quota_exceeded(self):
930 930
         quota_data = self.neutron_quota_usages.first()
931
-        quota_data['routers']['available'] = 0
931
+        quota_data['router']['available'] = 0
932 932
         api.neutron.router_list(
933 933
             IsA(http.HttpRequest),
934 934
             tenant_id=self.tenant.id).AndReturn(self.routers.list())
935 935
         quotas.tenant_quota_usages(
936
-            IsA(http.HttpRequest), targets=('routers', )) \
936
+            IsA(http.HttpRequest), targets=('router', )) \
937 937
             .MultipleTimes().AndReturn(quota_data)
938 938
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
939 939
                                            "router_availability_zone")\
@@ -959,12 +959,12 @@ class RouterViewTests(RouterMixin, test.TestCase):
959 959
                         quotas: ('tenant_quota_usages',)})
960 960
     def test_create_button_shown_when_quota_disabled(self):
961 961
         quota_data = self.neutron_quota_usages.first()
962
-        quota_data['routers'].pop('available')
962
+        quota_data['router'].pop('available')
963 963
         api.neutron.router_list(
964 964
             IsA(http.HttpRequest),
965 965
             tenant_id=self.tenant.id).AndReturn(self.routers.list())
966 966
         quotas.tenant_quota_usages(
967
-            IsA(http.HttpRequest), targets=('routers', )) \
967
+            IsA(http.HttpRequest), targets=('router', )) \
968 968
             .MultipleTimes().AndReturn(quota_data)
969 969
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
970 970
                                            "router_availability_zone")\
@@ -990,12 +990,12 @@ class RouterViewTests(RouterMixin, test.TestCase):
990 990
                         quotas: ('tenant_quota_usages',)})
991 991
     def test_create_button_attributes(self):
992 992
         quota_data = self.neutron_quota_usages.first()
993
-        quota_data['routers']['available'] = 10
993
+        quota_data['router']['available'] = 10
994 994
         api.neutron.router_list(
995 995
             IsA(http.HttpRequest),
996 996
             tenant_id=self.tenant.id).AndReturn(self.routers.list())
997 997
         quotas.tenant_quota_usages(
998
-            IsA(http.HttpRequest), targets=('routers', )) \
998
+            IsA(http.HttpRequest), targets=('router', )) \
999 999
             .MultipleTimes().AndReturn(quota_data)
1000 1000
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
1001 1001
                                            "router_availability_zone")\

+ 2
- 2
openstack_dashboard/dashboards/project/security_groups/tables.py View File

@@ -64,8 +64,8 @@ class CreateGroup(tables.LinkAction):
64 64
 
65 65
     def allowed(self, request, security_group=None):
66 66
         usages = quotas.tenant_quota_usages(request,
67
-                                            targets=('security_groups', ))
68
-        if usages['security_groups'].get('available', 1) <= 0:
67
+                                            targets=('security_group', ))
68
+        if usages['security_group'].get('available', 1) <= 0:
69 69
             if "disabled" not in self.classes:
70 70
                 self.classes = [c for c in self.classes] + ["disabled"]
71 71
                 self.verbose_name = _("Create Security Group (Quota exceeded)")

+ 9
- 9
openstack_dashboard/dashboards/project/security_groups/tests.py View File

@@ -68,14 +68,14 @@ class SecurityGroupsViewTests(test.TestCase):
68 68
                         quotas: ('tenant_quota_usages',)})
69 69
     def test_index(self):
70 70
         sec_groups = self.security_groups.list()
71
-        quota_data = self.quota_usages.first()
72
-        quota_data['security_groups']['available'] = 10
71
+        quota_data = self.neutron_quota_usages.first()
72
+        quota_data['security_group']['available'] = 10
73 73
 
74 74
         api.neutron.security_group_list(IsA(http.HttpRequest)) \
75 75
             .AndReturn(sec_groups)
76 76
         quotas.tenant_quota_usages(
77 77
             IsA(http.HttpRequest),
78
-            targets=('security_groups', )).MultipleTimes() \
78
+            targets=('security_group', )).MultipleTimes() \
79 79
             .AndReturn(quota_data)
80 80
 
81 81
         self.mox.ReplayAll()
@@ -101,15 +101,15 @@ class SecurityGroupsViewTests(test.TestCase):
101 101
                         quotas: ('tenant_quota_usages',)})
102 102
     def test_create_button_attributes(self):
103 103
         sec_groups = self.security_groups.list()
104
-        quota_data = self.quota_usages.first()
105
-        quota_data['security_groups']['available'] = 10
104
+        quota_data = self.neutron_quota_usages.first()
105
+        quota_data['security_group']['available'] = 10
106 106
 
107 107
         api.neutron.security_group_list(
108 108
             IsA(http.HttpRequest)) \
109 109
             .AndReturn(sec_groups)
110 110
         quotas.tenant_quota_usages(
111 111
             IsA(http.HttpRequest),
112
-            targets=('security_groups', )).MultipleTimes() \
112
+            targets=('security_group', )).MultipleTimes() \
113 113
             .AndReturn(quota_data)
114 114
 
115 115
         self.mox.ReplayAll()
@@ -135,15 +135,15 @@ class SecurityGroupsViewTests(test.TestCase):
135 135
     def _test_create_button_disabled_when_quota_exceeded(self,
136 136
                                                          network_enabled):
137 137
         sec_groups = self.security_groups.list()
138
-        quota_data = self.quota_usages.first()
139
-        quota_data['security_groups']['available'] = 0
138
+        quota_data = self.neutron_quota_usages.first()
139
+        quota_data['security_group']['available'] = 0
140 140
 
141 141
         api.neutron.security_group_list(
142 142
             IsA(http.HttpRequest)) \
143 143
             .AndReturn(sec_groups)
144 144
         quotas.tenant_quota_usages(
145 145
             IsA(http.HttpRequest),
146
-            targets=('security_groups', )).MultipleTimes() \
146
+            targets=('security_group', )).MultipleTimes() \
147 147
             .AndReturn(quota_data)
148 148
 
149 149
         self.mox.ReplayAll()

+ 7
- 5
openstack_dashboard/test/test_data/neutron_data.py View File

@@ -618,11 +618,13 @@ def data(TEST):
618 618
     TEST.neutron_quotas.add(base.QuotaSet(quota_data))
619 619
 
620 620
     # Quota Usages
621
-    quota_usage_data = {'networks': {'used': 0, 'quota': 5},
622
-                        'subnets': {'used': 0, 'quota': 5},
623
-                        'ports': {'used': 0, 'quota': 5},
624
-                        'routers': {'used': 0, 'quota': 5},
625
-                        }
621
+    quota_usage_data = {
622
+        'network': {'used': 0, 'quota': 5},
623
+        'subnet': {'used': 0, 'quota': 5},
624
+        'port': {'used': 0, 'quota': 5},
625
+        'router': {'used': 0, 'quota': 5},
626
+        'floatingip': {'used': 0, 'quota': 10},
627
+    }
626 628
     quota_usage = usage_quotas.QuotaUsage()
627 629
     for k, v in quota_usage_data.items():
628 630
         quota_usage.add_quota(base.Quota(k, v['quota']))

+ 18
- 20
openstack_dashboard/test/unit/usage/test_quotas.py View File

@@ -437,15 +437,15 @@ class QuotaTests(test.APITestCase):
437 437
 
438 438
     def test_tenant_quota_usages_neutron_with_target_network_resources(self):
439 439
         self._test_tenant_quota_usages_neutron_with_target(
440
-            targets=('networks', 'subnets', 'routers', ))
440
+            targets=('network', 'subnet', 'router', ))
441 441
 
442 442
     def test_tenant_quota_usages_neutron_with_target_security_groups(self):
443 443
         self._test_tenant_quota_usages_neutron_with_target(
444
-            targets=('security_groups', ))
444
+            targets=('security_group', ))
445 445
 
446 446
     def test_tenant_quota_usages_neutron_with_target_floating_ips(self):
447 447
         self._test_tenant_quota_usages_neutron_with_target(
448
-            targets=('floating_ips', ))
448
+            targets=('floatingip', ))
449 449
 
450 450
     @test.create_stubs({api.base: ('is_service_enabled',),
451 451
                         api.neutron: ('floating_ip_supported',
@@ -476,24 +476,22 @@ class QuotaTests(test.APITestCase):
476 476
                                            'quota_details').AndReturn(False)
477 477
         api.neutron.tenant_quota_get(IsA(http.HttpRequest), '1') \
478 478
             .AndReturn(self.neutron_quotas.first())
479
-        if 'networks' in targets:
479
+        if 'network' in targets:
480 480
             api.neutron.network_list(IsA(http.HttpRequest),
481 481
                                      tenant_id=self.request.user.tenant_id) \
482 482
                 .AndReturn(self.networks.list())
483
-        if 'subnets' in targets:
483
+        if 'subnet' in targets:
484 484
             api.neutron.subnet_list(IsA(http.HttpRequest),
485 485
                                     tenant_id=self.request.user.tenant_id) \
486 486
                 .AndReturn(self.subnets.list())
487
-        if 'routers' in targets:
487
+        if 'router' in targets:
488 488
             api.neutron.router_list(IsA(http.HttpRequest),
489 489
                                     tenant_id=self.request.user.tenant_id) \
490 490
                 .AndReturn(self.routers.list())
491
-        if 'floating_ips' in targets:
492
-            api.neutron.floating_ip_supported(IsA(http.HttpRequest)) \
493
-                .AndReturn(True)
491
+        if 'floatingip' in targets:
494 492
             api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \
495 493
                 .AndReturn(self.floating_ips.list())
496
-        if 'security_groups' in targets:
494
+        if 'security_group' in targets:
497 495
             api.neutron.security_group_list(IsA(http.HttpRequest)) \
498 496
                 .AndReturn(self.security_groups.list())
499 497
 
@@ -508,16 +506,16 @@ class QuotaTests(test.APITestCase):
508 506
         fip_used = len(self.floating_ips.list())
509 507
         sg_used = len(self.security_groups.list())
510 508
         expected = {
511
-            'networks': {'used': network_used, 'quota': 10,
512
-                         'available': 10 - network_used},
513
-            'subnets': {'used': subnet_used, 'quota': 10,
514
-                        'available': 10 - subnet_used},
515
-            'routers': {'used': router_used, 'quota': 10,
516
-                        'available': 10 - router_used},
517
-            'security_groups': {'used': sg_used, 'quota': 20,
518
-                                'available': 20 - sg_used},
519
-            'floating_ips': {'used': fip_used, 'quota': 50,
520
-                             'available': 50 - fip_used},
509
+            'network': {'used': network_used, 'quota': 10,
510
+                        'available': 10 - network_used},
511
+            'subnet': {'used': subnet_used, 'quota': 10,
512
+                       'available': 10 - subnet_used},
513
+            'router': {'used': router_used, 'quota': 10,
514
+                       'available': 10 - router_used},
515
+            'security_group': {'used': sg_used, 'quota': 20,
516
+                               'available': 20 - sg_used},
517
+            'floatingip': {'used': fip_used, 'quota': 50,
518
+                           'available': 50 - fip_used},
521 519
         }
522 520
         expected = dict((k, v) for k, v in expected.items() if k in targets)
523 521
 

+ 32
- 100
openstack_dashboard/usage/quotas.py View File

@@ -235,33 +235,10 @@ def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id):
235 235
     tenant_id = tenant_id or request.user.tenant_id
236 236
     neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
237 237
 
238
-    if 'floatingip' not in disabled_quotas:
239
-        # Rename floatingip to floating_ips since that's how it's
240
-        # expected in some places (e.g. Security & Access' Floating IPs)
241
-        fips_quota = neutron_quotas.get('floatingip').limit
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}))
238
+    for quota_name in NEUTRON_QUOTA_FIELDS:
239
+        if quota_name not in disabled_quotas:
240
+            quota_data = neutron_quotas.get(quota_name).limit
241
+            qs.add(base.QuotaSet({quota_name: quota_data}))
265 242
 
266 243
     return qs
267 244
 
@@ -357,19 +334,12 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
357 334
 
358 335
     if neutron.is_extension_supported(request, 'quota_details'):
359 336
         details = neutron.tenant_quota_detail_get(request, tenant_id)
360
-        for name, neutron_name in (
361
-                ('floating_ips', 'floatingip'),
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:
337
+        for quota_name in NEUTRON_QUOTA_FIELDS:
338
+            if quota_name in disabled_quotas:
369 339
                 continue
370
-            detail = details[neutron_name]
371
-            usages.add_quota(base.Quota(name, detail['limit']))
372
-            usages.tally(name, detail['used'] + detail['reserved'])
340
+            detail = details[quota_name]
341
+            usages.add_quota(base.Quota(quota_name, detail['limit']))
342
+            usages.tally(quota_name, detail['used'] + detail['reserved'])
373 343
     else:
374 344
         _get_tenant_network_usages_legacy(
375 345
             request, usages, disabled_quotas, tenant_id)
@@ -377,43 +347,30 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
377 347
 
378 348
 def _get_tenant_network_usages_legacy(request, usages, disabled_quotas,
379 349
                                       tenant_id):
380
-    enabled_quotas = NEUTRON_QUOTA_FIELDS - disabled_quotas
381 350
     qs = base.QuotaSet()
382 351
     _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id)
383 352
     for quota in qs:
384 353
         usages.add_quota(quota)
385 354
 
386
-    # NOTE(amotoki): floatingip is Neutron quota and floating_ips is
387
-    # Nova quota. We need to check both.
388
-    if {'floatingip', 'floating_ips'} & enabled_quotas:
389
-        floating_ips = []
390
-        try:
391
-            if neutron.floating_ip_supported(request):
392
-                floating_ips = neutron.tenant_floating_ip_list(request)
393
-        except Exception:
394
-            pass
395
-        usages.tally('floating_ips', len(floating_ips))
396
-
397
-    if 'security_group' not in disabled_quotas:
398
-        security_groups = []
399
-        security_groups = neutron.security_group_list(request)
400
-        usages.tally('security_groups', len(security_groups))
401
-
402
-    if 'network' not in disabled_quotas:
403
-        networks = neutron.network_list(request, tenant_id=tenant_id)
404
-        usages.tally('networks', len(networks))
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))
355
+    # TODO(amotoki): Add security_group_rule?
356
+    resource_lister = {
357
+        'network': (neutron.network_list, {'tenant_id': tenant_id}),
358
+        'subnet': (neutron.subnet_list, {'tenant_id': tenant_id}),
359
+        'port': (neutron.port_list, {'tenant_id': tenant_id}),
360
+        'router': (neutron.router_list, {'tenant_id': tenant_id}),
361
+        'floatingip': (neutron.tenant_floating_ip_list, {}),
362
+        'security_group': (neutron.security_group_list, {}),
363
+    }
364
+
365
+    for quota_name, lister_info in resource_lister.items():
366
+        if quota_name not in disabled_quotas:
367
+            lister = lister_info[0]
368
+            kwargs = lister_info[1]
369
+            try:
370
+                resources = lister(request, **kwargs)
371
+            except Exception:
372
+                resources = []
373
+            usages.tally(quota_name, len(resources))
417 374
 
418 375
 
419 376
 @profiler.trace
@@ -435,34 +392,6 @@ def _get_tenant_volume_usages(request, usages, disabled_quotas, tenant_id):
435 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.
442
-NETWORK_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
-
453
-def _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 395
 # TODO(amotoki): Merge tenant_quota_usages and tenant_limit_usages.
467 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 412
     usages = QuotaUsage()
484 413
 
485 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 418
         enabled_quotas = set(QUOTA_FIELDS) - disabled_quotas
487
-        enabled_quotas &= _convert_targets_to_quota_keys(targets)
419
+        enabled_quotas &= set(targets)
488 420
         disabled_quotas = set(QUOTA_FIELDS) - enabled_quotas
489 421
 
490 422
     _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id)

Loading…
Cancel
Save