Add '--dhcp' and '--no-dhcp' options to os subnet list cmd
This patch adds '--dhcp' and '--no-dhcp' options to filter subnets resulted by os subnet list command. Change-Id: Ib574cc54594845bc5c5afc38bf44e3b224d33b17 Partial-Bug: #1610883
This commit is contained in:
parent
0b91368164
commit
831546fb9e
@ -152,6 +152,7 @@ List subnets
|
||||
os subnet list
|
||||
[--long]
|
||||
[--ip-version {4,6}]
|
||||
[--dhcp | --no-dhcp]
|
||||
|
||||
.. option:: --long
|
||||
|
||||
@ -162,6 +163,14 @@ List subnets
|
||||
List only subnets of given IP version in output.
|
||||
Allowed values for IP version are 4 and 6.
|
||||
|
||||
.. option:: --dhcp
|
||||
|
||||
List subnets which have DHCP enabled
|
||||
|
||||
.. option:: --no-dhcp
|
||||
|
||||
List subnets which have DHCP disabled
|
||||
|
||||
subnet set
|
||||
----------
|
||||
|
||||
|
@ -341,12 +341,27 @@ class ListSubnet(command.Lister):
|
||||
help=_("List only subnets of given IP version in output."
|
||||
"Allowed values for IP version are 4 and 6."),
|
||||
)
|
||||
dhcp_enable_group = parser.add_mutually_exclusive_group()
|
||||
dhcp_enable_group.add_argument(
|
||||
'--dhcp',
|
||||
action='store_true',
|
||||
help=_("List subnets which have DHCP enabled")
|
||||
)
|
||||
dhcp_enable_group.add_argument(
|
||||
'--no-dhcp',
|
||||
action='store_true',
|
||||
help=_("List subnets which have DHCP disabled")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
filters = {}
|
||||
if parsed_args.ip_version:
|
||||
filters['ip_version'] = parsed_args.ip_version
|
||||
if parsed_args.dhcp:
|
||||
filters['enable_dhcp'] = True
|
||||
elif parsed_args.no_dhcp:
|
||||
filters['enable_dhcp'] = False
|
||||
data = self.app.client_manager.network.subnets(**filters)
|
||||
|
||||
headers = ('ID', 'Name', 'Network', 'Subnet')
|
||||
|
@ -584,6 +584,38 @@ class TestListSubnet(TestSubnet):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_subnet_list_dhcp(self):
|
||||
arglist = [
|
||||
'--dhcp',
|
||||
]
|
||||
verifylist = [
|
||||
('dhcp', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
filters = {'enable_dhcp': True}
|
||||
|
||||
self.network.subnets.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_subnet_list_no_dhcp(self):
|
||||
arglist = [
|
||||
'--no-dhcp',
|
||||
]
|
||||
verifylist = [
|
||||
('no_dhcp', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
filters = {'enable_dhcp': False}
|
||||
|
||||
self.network.subnets.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
class TestSetSubnet(TestSubnet):
|
||||
|
||||
|
7
releasenotes/notes/bug-1610883-e6345c32a35cc290.yaml
Normal file
7
releasenotes/notes/bug-1610883-e6345c32a35cc290.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Make ``subnet list`` command supports listing up subnets with
|
||||
dhcp enabled/disabled by adding ``--dhcp`` and ``--no-dhcp``
|
||||
options to the command.
|
||||
[Bug `1610883 <https://bugs.launchpad.net/bugs/1610883>`_]
|
Loading…
Reference in New Issue
Block a user