Merge "Add '--dhcp' and '--no-dhcp' options to os subnet list cmd"

This commit is contained in:
Jenkins 2016-08-11 07:27:35 +00:00 committed by Gerrit Code Review
commit fc7a69e410
4 changed files with 63 additions and 0 deletions

View File

@ -152,6 +152,7 @@ List subnets
os subnet list os subnet list
[--long] [--long]
[--ip-version {4,6}] [--ip-version {4,6}]
[--dhcp | --no-dhcp]
.. option:: --long .. option:: --long
@ -162,6 +163,14 @@ List subnets
List only subnets of given IP version in output. List only subnets of given IP version in output.
Allowed values for IP version are 4 and 6. 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 subnet set
---------- ----------

View File

@ -341,12 +341,27 @@ class ListSubnet(command.Lister):
help=_("List only subnets of given IP version in output." help=_("List only subnets of given IP version in output."
"Allowed values for IP version are 4 and 6."), "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 return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
filters = {} filters = {}
if parsed_args.ip_version: if parsed_args.ip_version:
filters['ip_version'] = 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) data = self.app.client_manager.network.subnets(**filters)
headers = ('ID', 'Name', 'Network', 'Subnet') headers = ('ID', 'Name', 'Network', 'Subnet')

View File

@ -584,6 +584,38 @@ class TestListSubnet(TestSubnet):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data)) 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): class TestSetSubnet(TestSubnet):

View 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>`_]