Add ip version filter to subnet list

This patch will add argument ip-version to command
subnet list

Change-Id: If7458d4979e53aec7e2633c4f1779c3810f9a3f1
Closes-Bug: #1581179
This commit is contained in:
Manjeet Singh Bhatia 2016-05-12 18:59:58 +00:00
parent e1c53250bc
commit 668bc028d1
4 changed files with 39 additions and 1 deletions

View File

@ -147,6 +147,10 @@ List subnets
List additional fields in output
.. option:: --ip-version {4, 6}
List only subnets of given IP version in output
subnet set
----------

View File

@ -296,10 +296,22 @@ class ListSubnet(command.Lister):
default=False,
help=_("List additional fields in output")
)
parser.add_argument(
'--ip-version',
type=int,
choices=[4, 6],
metavar='<ip-version>',
dest='ip_version',
help=_("List only subnets of given IP version in output"
"Allowed values for IP version are 4 and 6."),
)
return parser
def take_action(self, parsed_args):
data = self.app.client_manager.network.subnets()
filters = {}
if parsed_args.ip_version:
filters['ip_version'] = parsed_args.ip_version
data = self.app.client_manager.network.subnets(**filters)
headers = ('ID', 'Name', 'Network', 'Subnet')
columns = ('id', 'name', 'network_id', 'cidr')

View File

@ -469,6 +469,22 @@ class TestListSubnet(TestSubnet):
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
def test_subnet_list_ip_version(self):
arglist = [
'--ip-version', str(4),
]
verifylist = [
('ip_version', 4),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'ip_version': 4}
self.network.subnets.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
class TestSetSubnet(TestSubnet):

View File

@ -0,0 +1,6 @@
---
features:
-
Add the ``--ip-version`` option to the ``subnet list`` command. This
will output subnets based on IP version filter.
[`Bug 1581179 <https://bugs.launchpad.net/python-openstackclient/+bug/1581179>`_]