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:
parent
e1c53250bc
commit
668bc028d1
@ -147,6 +147,10 @@ List subnets
|
|||||||
|
|
||||||
List additional fields in output
|
List additional fields in output
|
||||||
|
|
||||||
|
.. option:: --ip-version {4, 6}
|
||||||
|
|
||||||
|
List only subnets of given IP version in output
|
||||||
|
|
||||||
subnet set
|
subnet set
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -296,10 +296,22 @@ class ListSubnet(command.Lister):
|
|||||||
default=False,
|
default=False,
|
||||||
help=_("List additional fields in output")
|
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
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
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')
|
headers = ('ID', 'Name', 'Network', 'Subnet')
|
||||||
columns = ('id', 'name', 'network_id', 'cidr')
|
columns = ('id', 'name', 'network_id', 'cidr')
|
||||||
|
@ -469,6 +469,22 @@ class TestListSubnet(TestSubnet):
|
|||||||
self.assertEqual(self.columns_long, columns)
|
self.assertEqual(self.columns_long, columns)
|
||||||
self.assertEqual(self.data_long, list(data))
|
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):
|
class TestSetSubnet(TestSubnet):
|
||||||
|
|
||||||
|
6
releasenotes/notes/bug-1581179-4d15dc504777f9e7.yaml
Normal file
6
releasenotes/notes/bug-1581179-4d15dc504777f9e7.yaml
Normal 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>`_]
|
Loading…
x
Reference in New Issue
Block a user