Skip to content

Commit 59f8e32

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add network support for "quota set""
2 parents 2686584 + b92cf77 commit 59f8e32

6 files changed

Lines changed: 175 additions & 14 deletions

File tree

doc/source/command-objects/quota.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ Set quotas for project
3232
[--volumes <new-volumes>]
3333
[--volume-type <volume-type>]
3434
35+
# Network settings
36+
[--floating-ips <num-floatingips>]
37+
[--secgroup-rules <num-security-group-rules>]
38+
[--secgroups <num-security-groups>]
39+
[--networks <num-networks>]
40+
[--subnets <num-subnets>]
41+
[--ports <num-ports>]
42+
[--routers <num-routers>]
43+
[--rbac-policies <num-rbac-policies>]
44+
[--vips <num-vips>]
45+
[--subnetpools <num-subnetpools>]
46+
[--members <num-members>]
47+
[--health-monitors <num-health-monitors>]
48+
3549
<project>
3650
3751
Set quotas for class
@@ -126,6 +140,42 @@ Set quotas for class
126140

127141
Set quotas for a specific <volume-type>
128142

143+
.. option:: --networks <num-networks>
144+
145+
New value for the networks quota
146+
147+
.. option:: --subnets <num-subnets>
148+
149+
New value for the subnets quota
150+
151+
.. option:: --ports <num-ports>
152+
153+
New value for the ports quota
154+
155+
.. option:: --routers <num-routers>
156+
157+
New value for the routers quota
158+
159+
.. option:: --rbac-policies <num-rbac-policies>
160+
161+
New value for the rbac-policies quota
162+
163+
.. option:: --vips <num-vips>
164+
165+
New value for the vips quota
166+
167+
.. option:: --subnetpools <num-subnetpools>
168+
169+
New value for the subnetpools quota
170+
171+
.. option:: --members <num-members>
172+
173+
New value for the members quota
174+
175+
.. option:: --health-monitors <num-health-monitors>
176+
177+
New value for the health-monitors quota
178+
129179
quota show
130180
----------
131181

functional/tests/common/test_quota.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class QuotaTests(test.TestCase):
1717
"""Functional tests for quota. """
1818
# Test quota information for compute, network and volume.
19-
EXPECTED_FIELDS = ['instances', 'network', 'volumes']
19+
EXPECTED_FIELDS = ['instances', 'networks', 'volumes']
2020
PROJECT_NAME = None
2121

2222
@classmethod
@@ -25,12 +25,11 @@ def setUpClass(cls):
2525
cls.get_openstack_configuration_value('auth.project_name')
2626

2727
def test_quota_set(self):
28-
# TODO(rtheis): Add --network option once supported on set.
29-
self.openstack('quota set --instances 11 --volumes 11 ' +
30-
self.PROJECT_NAME)
28+
self.openstack('quota set --instances 11 --volumes 11 --networks 11 '
29+
+ self.PROJECT_NAME)
3130
opts = self.get_show_opts(self.EXPECTED_FIELDS)
3231
raw_output = self.openstack('quota show ' + self.PROJECT_NAME + opts)
33-
self.assertEqual("11\n10\n11\n", raw_output)
32+
self.assertEqual("11\n11\n11\n", raw_output)
3433

3534
def test_quota_show(self):
3635
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)

openstackclient/common/quota.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@
2929
COMPUTE_QUOTAS = {
3030
'cores': 'cores',
3131
'fixed_ips': 'fixed-ips',
32-
'floating_ips': 'floating-ips',
3332
'injected_file_content_bytes': 'injected-file-size',
3433
'injected_file_path_bytes': 'injected-path-size',
3534
'injected_files': 'injected-files',
3635
'instances': 'instances',
3736
'key_pairs': 'key-pairs',
3837
'metadata_items': 'properties',
3938
'ram': 'ram',
40-
'security_group_rules': 'secgroup-rules',
41-
'security_groups': 'secgroups',
4239
}
4340

4441
VOLUME_QUOTAS = {
@@ -47,16 +44,41 @@
4744
'volumes': 'volumes',
4845
}
4946

47+
NOVA_NETWORK_QUOTAS = {
48+
'floating_ips': 'floating-ips',
49+
'security_group_rules': 'secgroup-rules',
50+
'security_groups': 'secgroups',
51+
}
52+
5053
NETWORK_QUOTAS = {
5154
'floatingip': 'floating-ips',
5255
'security_group_rule': 'secgroup-rules',
5356
'security_group': 'secgroups',
57+
'network': 'networks',
58+
'subnet': 'subnets',
59+
'port': 'ports',
60+
'router': 'routers',
61+
'rbac_policy': 'rbac-policies',
62+
'vip': 'vips',
63+
'subnetpool': 'subnetpools',
64+
'member': 'members',
65+
'health_monitor': 'health-monitors',
5466
}
5567

5668

5769
class SetQuota(command.Command):
5870
"""Set quotas for project or class"""
5971

72+
def _build_options_list(self):
73+
if self.app.client_manager.is_network_endpoint_enabled():
74+
return itertools.chain(COMPUTE_QUOTAS.items(),
75+
VOLUME_QUOTAS.items(),
76+
NETWORK_QUOTAS.items())
77+
else:
78+
return itertools.chain(COMPUTE_QUOTAS.items(),
79+
VOLUME_QUOTAS.items(),
80+
NOVA_NETWORK_QUOTAS.items())
81+
6082
def get_parser(self, prog_name):
6183
parser = super(SetQuota, self).get_parser(prog_name)
6284
parser.add_argument(
@@ -71,8 +93,7 @@ def get_parser(self, prog_name):
7193
default=False,
7294
help='Set quotas for <class>',
7395
)
74-
for k, v in itertools.chain(
75-
COMPUTE_QUOTAS.items(), VOLUME_QUOTAS.items()):
96+
for k, v in self._build_options_list():
7697
parser.add_argument(
7798
'--%s' % v,
7899
metavar='<%s>' % v,
@@ -92,7 +113,7 @@ def take_action(self, parsed_args):
92113
identity_client = self.app.client_manager.identity
93114
compute_client = self.app.client_manager.compute
94115
volume_client = self.app.client_manager.volume
95-
116+
network_client = self.app.client_manager.network
96117
compute_kwargs = {}
97118
for k, v in COMPUTE_QUOTAS.items():
98119
value = getattr(parsed_args, k, None)
@@ -107,7 +128,20 @@ def take_action(self, parsed_args):
107128
k = k + '_%s' % parsed_args.volume_type
108129
volume_kwargs[k] = value
109130

110-
if compute_kwargs == {} and volume_kwargs == {}:
131+
network_kwargs = {}
132+
if self.app.client_manager.is_network_endpoint_enabled():
133+
for k, v in NETWORK_QUOTAS.items():
134+
value = getattr(parsed_args, k, None)
135+
if value is not None:
136+
network_kwargs[k] = value
137+
else:
138+
for k, v in NOVA_NETWORK_QUOTAS.items():
139+
value = getattr(parsed_args, k, None)
140+
if value is not None:
141+
compute_kwargs[k] = value
142+
143+
if (compute_kwargs == {} and volume_kwargs == {}
144+
and network_kwargs == {}):
111145
sys.stderr.write("No quotas updated")
112146
return
113147

@@ -126,6 +160,9 @@ def take_action(self, parsed_args):
126160
volume_client.quota_classes.update(
127161
project.id,
128162
**volume_kwargs)
163+
if network_kwargs:
164+
sys.stderr.write("Network quotas are ignored since quota class"
165+
"is not supported.")
129166
else:
130167
if compute_kwargs:
131168
compute_client.quotas.update(
@@ -135,6 +172,10 @@ def take_action(self, parsed_args):
135172
volume_client.quotas.update(
136173
project.id,
137174
**volume_kwargs)
175+
if network_kwargs:
176+
network_client.update_quota(
177+
project.id,
178+
**network_kwargs)
138179

139180

140181
class ShowQuota(command.ShowOne):
@@ -232,8 +273,8 @@ def take_action(self, parsed_args):
232273
# neutron is enabled, quotas of these three resources
233274
# in nova will be replaced by neutron's.
234275
for k, v in itertools.chain(
235-
COMPUTE_QUOTAS.items(), VOLUME_QUOTAS.items(),
236-
NETWORK_QUOTAS.items()):
276+
COMPUTE_QUOTAS.items(), NOVA_NETWORK_QUOTAS.items(),
277+
VOLUME_QUOTAS.items(), NETWORK_QUOTAS.items()):
237278
if not k == v and info.get(k):
238279
info[v] = info[k]
239280
info.pop(k)

openstackclient/tests/common/test_quota.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def setUp(self):
9797
loaded=True,
9898
)
9999

100+
self.network_mock = self.app.client_manager.network
101+
self.network_mock.update_quota = mock.Mock()
102+
100103
self.cmd = quota.SetQuota(self.app, None)
101104

102105
def test_quota_set(self):
@@ -132,6 +135,7 @@ def test_quota_set(self):
132135
('project', identity_fakes.project_name),
133136
]
134137

138+
self.app.client_manager.network_endpoint_enabled = False
135139
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
136140

137141
self.cmd.take_action(parsed_args)
@@ -185,6 +189,61 @@ def test_quota_set_volume(self):
185189
**kwargs
186190
)
187191

192+
def test_quota_set_network(self):
193+
arglist = [
194+
'--subnets', str(network_fakes.QUOTA['subnet']),
195+
'--networks', str(network_fakes.QUOTA['network']),
196+
'--floating-ips', str(network_fakes.QUOTA['floatingip']),
197+
'--subnetpools', str(network_fakes.QUOTA['subnetpool']),
198+
'--secgroup-rules',
199+
str(network_fakes.QUOTA['security_group_rule']),
200+
'--secgroups', str(network_fakes.QUOTA['security_group']),
201+
'--routers', str(network_fakes.QUOTA['router']),
202+
'--rbac-policies', str(network_fakes.QUOTA['rbac_policy']),
203+
'--ports', str(network_fakes.QUOTA['port']),
204+
'--vips', str(network_fakes.QUOTA['vip']),
205+
'--members', str(network_fakes.QUOTA['member']),
206+
'--health-monitors', str(network_fakes.QUOTA['health_monitor']),
207+
identity_fakes.project_name,
208+
]
209+
verifylist = [
210+
('subnet', network_fakes.QUOTA['subnet']),
211+
('network', network_fakes.QUOTA['network']),
212+
('floatingip', network_fakes.QUOTA['floatingip']),
213+
('subnetpool', network_fakes.QUOTA['subnetpool']),
214+
('security_group_rule',
215+
network_fakes.QUOTA['security_group_rule']),
216+
('security_group', network_fakes.QUOTA['security_group']),
217+
('router', network_fakes.QUOTA['router']),
218+
('rbac_policy', network_fakes.QUOTA['rbac_policy']),
219+
('port', network_fakes.QUOTA['port']),
220+
('vip', network_fakes.QUOTA['vip']),
221+
('member', network_fakes.QUOTA['member']),
222+
('health_monitor', network_fakes.QUOTA['health_monitor']),
223+
]
224+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
225+
226+
self.cmd.take_action(parsed_args)
227+
kwargs = {
228+
'subnet': network_fakes.QUOTA['subnet'],
229+
'network': network_fakes.QUOTA['network'],
230+
'floatingip': network_fakes.QUOTA['floatingip'],
231+
'subnetpool': network_fakes.QUOTA['subnetpool'],
232+
'security_group_rule':
233+
network_fakes.QUOTA['security_group_rule'],
234+
'security_group': network_fakes.QUOTA['security_group'],
235+
'router': network_fakes.QUOTA['router'],
236+
'rbac_policy': network_fakes.QUOTA['rbac_policy'],
237+
'port': network_fakes.QUOTA['port'],
238+
'vip': network_fakes.QUOTA['vip'],
239+
'member': network_fakes.QUOTA['member'],
240+
'health_monitor': network_fakes.QUOTA['health_monitor'],
241+
}
242+
self.network_mock.update_quota.assert_called_with(
243+
identity_fakes.project_id,
244+
**kwargs
245+
)
246+
188247

189248
class TestQuotaShow(TestQuota):
190249

openstackclient/tests/network/v2/fakes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"router": 10,
3737
"rbac_policy": -1,
3838
"port": 50,
39+
"vip": 10,
40+
"member": 10,
41+
"health_monitor": 10,
3942
}
4043

4144

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Add network support for ``quota set`` command. Options added includes
5+
``--networks --subnets --subnetpools --ports --routers --rbac-policies``
6+
``--vips --members --health-monitors``.
7+
Options ``--floating-ips --secgroup-rules --secgroups`` now support
8+
both network and compute API.
9+
[Bug `1489441 <https://bugs.launchpad.net/bugs/1489441>`_]

0 commit comments

Comments
 (0)