Skip to content

Commit fc7a69e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add '--dhcp' and '--no-dhcp' options to os subnet list cmd"
2 parents c9cf6c4 + 831546f commit fc7a69e

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

doc/source/command-objects/subnet.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ List subnets
152152
os subnet list
153153
[--long]
154154
[--ip-version {4,6}]
155+
[--dhcp | --no-dhcp]
155156
156157
.. option:: --long
157158
@@ -162,6 +163,14 @@ List subnets
162163
List only subnets of given IP version in output.
163164
Allowed values for IP version are 4 and 6.
164165
166+
.. option:: --dhcp
167+
168+
List subnets which have DHCP enabled
169+
170+
.. option:: --no-dhcp
171+
172+
List subnets which have DHCP disabled
173+
165174
subnet set
166175
----------
167176

openstackclient/network/v2/subnet.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,27 @@ def get_parser(self, prog_name):
341341
help=_("List only subnets of given IP version in output."
342342
"Allowed values for IP version are 4 and 6."),
343343
)
344+
dhcp_enable_group = parser.add_mutually_exclusive_group()
345+
dhcp_enable_group.add_argument(
346+
'--dhcp',
347+
action='store_true',
348+
help=_("List subnets which have DHCP enabled")
349+
)
350+
dhcp_enable_group.add_argument(
351+
'--no-dhcp',
352+
action='store_true',
353+
help=_("List subnets which have DHCP disabled")
354+
)
344355
return parser
345356

346357
def take_action(self, parsed_args):
347358
filters = {}
348359
if parsed_args.ip_version:
349360
filters['ip_version'] = parsed_args.ip_version
361+
if parsed_args.dhcp:
362+
filters['enable_dhcp'] = True
363+
elif parsed_args.no_dhcp:
364+
filters['enable_dhcp'] = False
350365
data = self.app.client_manager.network.subnets(**filters)
351366

352367
headers = ('ID', 'Name', 'Network', 'Subnet')

openstackclient/tests/network/v2/test_subnet.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,38 @@ def test_subnet_list_ip_version(self):
584584
self.assertEqual(self.columns, columns)
585585
self.assertEqual(self.data, list(data))
586586

587+
def test_subnet_list_dhcp(self):
588+
arglist = [
589+
'--dhcp',
590+
]
591+
verifylist = [
592+
('dhcp', True),
593+
]
594+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
595+
596+
columns, data = self.cmd.take_action(parsed_args)
597+
filters = {'enable_dhcp': True}
598+
599+
self.network.subnets.assert_called_once_with(**filters)
600+
self.assertEqual(self.columns, columns)
601+
self.assertEqual(self.data, list(data))
602+
603+
def test_subnet_list_no_dhcp(self):
604+
arglist = [
605+
'--no-dhcp',
606+
]
607+
verifylist = [
608+
('no_dhcp', True),
609+
]
610+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
611+
612+
columns, data = self.cmd.take_action(parsed_args)
613+
filters = {'enable_dhcp': False}
614+
615+
self.network.subnets.assert_called_once_with(**filters)
616+
self.assertEqual(self.columns, columns)
617+
self.assertEqual(self.data, list(data))
618+
587619

588620
class TestSetSubnet(TestSubnet):
589621

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Make ``subnet list`` command supports listing up subnets with
5+
dhcp enabled/disabled by adding ``--dhcp`` and ``--no-dhcp``
6+
options to the command.
7+
[Bug `1610883 <https://bugs.launchpad.net/bugs/1610883>`_]

0 commit comments

Comments
 (0)