Skip to content

Commit 48ebc49

Browse files
committed
Add new share and default parms to subnet pool cmds
Add the "share" and "default" parms to subnet pool create command. Add the "default" and "no-default" parms to subnet pool set command. Note that "share" can not be modified once subnet pool has been created, so do not add this to the set command. Change-Id: I1eecad69527a1cde7fb234669f4aff2be2db491e Partial-Bug: #1544591 Partial-Bug: #1544586
1 parent 3f2ed7d commit 48ebc49

4 files changed

Lines changed: 161 additions & 0 deletions

File tree

doc/source/command-objects/subnet-pool.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Create subnet pool
1919
[--max-prefix-length <max-prefix-length>]
2020
[--project <project> [--project-domain <project-domain>]]
2121
[--address-scope <address-scope>]
22+
[--default | --no-default]
23+
[--share | --no-share]
2224
<name>
2325
2426
.. option:: --pool-prefix <pool-prefix>
@@ -52,6 +54,22 @@ Create subnet pool
5254
Set address scope associated with the subnet pool (name or ID),
5355
prefixes must be unique across address scopes
5456
57+
.. option:: --default
58+
59+
Set this as a default subnet pool
60+
61+
.. option:: --no-default
62+
63+
Set this as a non-default subnet pool
64+
65+
.. option:: --share
66+
67+
Set this subnet pool as shared
68+
69+
.. option:: --no-share
70+
71+
Set this subnet pool as not shared
72+
5573
.. _subnet_pool_create-name:
5674
.. describe:: <name>
5775
@@ -103,6 +121,7 @@ Set subnet pool properties
103121
[--min-prefix-length <min-prefix-length>]
104122
[--max-prefix-length <max-prefix-length>]
105123
[--address-scope <address-scope> | --no-address-scope]
124+
[--default | --no-default]
106125
<subnet-pool>
107126
108127
.. option:: --name <name>
@@ -135,6 +154,14 @@ Set subnet pool properties
135154
136155
Remove address scope associated with the subnet pool
137156
157+
.. option:: --default
158+
159+
Set this as a default subnet pool
160+
161+
.. option:: --no-default
162+
163+
Set this as a non-default subnet pool
164+
138165
.. _subnet_pool_set-subnet-pool:
139166
.. describe:: <subnet-pool>
140167

openstackclient/network/v2/subnet_pool.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ def _get_attrs(client_manager, parsed_args):
5555
if 'no_address_scope' in parsed_args and parsed_args.no_address_scope:
5656
attrs['address_scope_id'] = None
5757

58+
if parsed_args.default:
59+
attrs['is_default'] = True
60+
if parsed_args.no_default:
61+
attrs['is_default'] = False
62+
63+
if 'share' in parsed_args and parsed_args.share:
64+
attrs['shared'] = True
65+
if 'no_share' in parsed_args and parsed_args.no_share:
66+
attrs['shared'] = False
67+
5868
# "subnet pool set" command doesn't support setting project.
5969
if 'project' in parsed_args and parsed_args.project is not None:
6070
identity_client = client_manager.identity
@@ -97,6 +107,20 @@ def _add_prefix_options(parser):
97107
)
98108

99109

110+
def _add_default_options(parser):
111+
default_group = parser.add_mutually_exclusive_group()
112+
default_group.add_argument(
113+
'--default',
114+
action='store_true',
115+
help=_("Set this as a default subnet pool"),
116+
)
117+
default_group.add_argument(
118+
'--no-default',
119+
action='store_true',
120+
help=_("Set this as a non-default subnet pool"),
121+
)
122+
123+
100124
class CreateSubnetPool(command.ShowOne):
101125
"""Create subnet pool"""
102126

@@ -121,6 +145,18 @@ def get_parser(self, prog_name):
121145
"(name or ID), prefixes must be unique across address "
122146
"scopes")
123147
)
148+
_add_default_options(parser)
149+
shared_group = parser.add_mutually_exclusive_group()
150+
shared_group.add_argument(
151+
'--share',
152+
action='store_true',
153+
help=_("Set this subnet pool as shared"),
154+
)
155+
shared_group.add_argument(
156+
'--no-share',
157+
action='store_true',
158+
help=_("Set this subnet pool as not shared"),
159+
)
124160
return parser
125161

126162
def take_action(self, parsed_args):
@@ -176,13 +212,17 @@ def take_action(self, parsed_args):
176212
'Prefixes',
177213
'Default Prefix Length',
178214
'Address Scope',
215+
'Default Subnet Pool',
216+
'Shared',
179217
)
180218
columns = (
181219
'id',
182220
'name',
183221
'prefixes',
184222
'default_prefixlen',
185223
'address_scope_id',
224+
'is_default',
225+
'shared',
186226
)
187227
else:
188228
headers = (
@@ -232,6 +272,8 @@ def get_parser(self, prog_name):
232272
action='store_true',
233273
help=_("Remove address scope associated with the subnet pool")
234274
)
275+
_add_default_options(parser)
276+
235277
return parser
236278

237279
def take_action(self, parsed_args):

openstackclient/tests/network/v2/test_subnet_pool.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,32 @@ def test_create_address_scope_option(self):
221221
self.assertEqual(self.columns, columns)
222222
self.assertEqual(self.data, data)
223223

224+
def test_create_default_and_shared_options(self):
225+
arglist = [
226+
'--pool-prefix', '10.0.10.0/24',
227+
'--default',
228+
'--share',
229+
self._subnet_pool.name,
230+
]
231+
verifylist = [
232+
('prefixes', ['10.0.10.0/24']),
233+
('default', True),
234+
('share', True),
235+
('name', self._subnet_pool.name),
236+
]
237+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
238+
239+
columns, data = (self.cmd.take_action(parsed_args))
240+
241+
self.network.create_subnet_pool.assert_called_once_with(**{
242+
'is_default': True,
243+
'name': self._subnet_pool.name,
244+
'prefixes': ['10.0.10.0/24'],
245+
'shared': True,
246+
})
247+
self.assertEqual(self.columns, columns)
248+
self.assertEqual(self.data, data)
249+
224250

225251
class TestDeleteSubnetPool(TestSubnetPool):
226252

@@ -267,6 +293,8 @@ class TestListSubnetPool(TestSubnetPool):
267293
columns_long = columns + (
268294
'Default Prefix Length',
269295
'Address Scope',
296+
'Default Subnet Pool',
297+
'Shared',
270298
)
271299

272300
data = []
@@ -285,6 +313,8 @@ class TestListSubnetPool(TestSubnetPool):
285313
utils.format_list(pool.prefixes),
286314
pool.default_prefixlen,
287315
pool.address_scope_id,
316+
pool.is_default,
317+
pool.shared,
288318
))
289319

290320
def setUp(self):
@@ -474,6 +504,62 @@ def test_set_no_address_scope_conflict(self):
474504
self.assertRaises(tests_utils.ParserException, self.check_parser,
475505
self.cmd, arglist, verifylist)
476506

507+
def test_set_default(self):
508+
arglist = [
509+
'--default',
510+
self._subnet_pool.name,
511+
]
512+
verifylist = [
513+
('default', True),
514+
('subnet_pool', self._subnet_pool.name),
515+
]
516+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
517+
518+
result = self.cmd.take_action(parsed_args)
519+
520+
attrs = {
521+
'is_default': True
522+
}
523+
self.network.update_subnet_pool.assert_called_once_with(
524+
self._subnet_pool, **attrs)
525+
self.assertIsNone(result)
526+
527+
def test_set_no_default(self):
528+
arglist = [
529+
'--no-default',
530+
self._subnet_pool.name,
531+
]
532+
verifylist = [
533+
('no_default', True),
534+
('subnet_pool', self._subnet_pool.name),
535+
]
536+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
537+
538+
result = self.cmd.take_action(parsed_args)
539+
540+
attrs = {
541+
'is_default': False,
542+
}
543+
self.network.update_subnet_pool.assert_called_once_with(
544+
self._subnet_pool, **attrs)
545+
self.assertIsNone(result)
546+
547+
def test_set_no_default_conflict(self):
548+
arglist = [
549+
'--default',
550+
'--no-default',
551+
self._subnet_pool.name,
552+
]
553+
verifylist = [
554+
('default', True),
555+
('no_default', True),
556+
('subnet_pool', self._subnet_pool.name),
557+
]
558+
559+
# Exclusive arguments will conflict here.
560+
self.assertRaises(tests_utils.ParserException, self.check_parser,
561+
self.cmd, arglist, verifylist)
562+
477563

478564
class TestShowSubnetPool(TestSubnetPool):
479565

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- Add ``--share`` and ``--default`` options to ``subnet pool create``
4+
and ``--default`` option to ``subnet pool set``
5+
[Bug `1544586 <https://bugs.launchpad.net/python-openstackclient/+bug/1544586>`_]
6+
[Bug `1544591 <https://bugs.launchpad.net/python-openstackclient/+bug/1544591>`_]

0 commit comments

Comments
 (0)