Add --subnet-pool to subnet list
The neutron API supports filtering subnets by subnet pool id, but the CLI was missing support for it. Change-Id: Ic230c2c5cda8255d8f2c422880aeac81670b2df3
This commit is contained in:
parent
1c84b44ac2
commit
e4e9fb594d
@ -488,6 +488,12 @@ class ListSubnet(command.Lister):
|
||||
"(in CIDR notation) in output "
|
||||
"e.g.: --subnet-range 10.10.0.0/16")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--subnet-pool',
|
||||
metavar='<subnet-pool>',
|
||||
help=_("List only subnets which belong to a given subnet pool "
|
||||
"in output (Name or ID)")
|
||||
)
|
||||
_tag.add_tag_filtering_option_to_parser(parser, _('subnets'))
|
||||
return parser
|
||||
|
||||
@ -523,6 +529,10 @@ class ListSubnet(command.Lister):
|
||||
filters['name'] = parsed_args.name
|
||||
if parsed_args.subnet_range:
|
||||
filters['cidr'] = parsed_args.subnet_range
|
||||
if parsed_args.subnet_pool:
|
||||
subnetpool_id = network_client.find_subnet_pool(
|
||||
parsed_args.subnet_pool, ignore_missing=False).id
|
||||
filters['subnetpool_id'] = subnetpool_id
|
||||
_tag.get_tag_filtering_args(parsed_args, filters)
|
||||
data = network_client.subnets(**filters)
|
||||
|
||||
|
@ -899,6 +899,48 @@ class TestListSubnet(TestSubnet):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertItemsEqual(self.data, list(data))
|
||||
|
||||
def test_subnet_list_subnetpool_by_name(self):
|
||||
subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
|
||||
subnet = network_fakes.FakeSubnet.create_one_subnet(
|
||||
{'subnetpool_id': subnet_pool.id})
|
||||
self.network.find_network = mock.Mock(return_value=subnet)
|
||||
self.network.find_subnet_pool = mock.Mock(return_value=subnet_pool)
|
||||
arglist = [
|
||||
'--subnet-pool', subnet_pool.name,
|
||||
]
|
||||
verifylist = [
|
||||
('subnet_pool', subnet_pool.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
filters = {'subnetpool_id': subnet_pool.id}
|
||||
|
||||
self.network.subnets.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertItemsEqual(self.data, list(data))
|
||||
|
||||
def test_subnet_list_subnetpool_by_id(self):
|
||||
subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
|
||||
subnet = network_fakes.FakeSubnet.create_one_subnet(
|
||||
{'subnetpool_id': subnet_pool.id})
|
||||
self.network.find_network = mock.Mock(return_value=subnet)
|
||||
self.network.find_subnet_pool = mock.Mock(return_value=subnet_pool)
|
||||
arglist = [
|
||||
'--subnet-pool', subnet_pool.id,
|
||||
]
|
||||
verifylist = [
|
||||
('subnet_pool', subnet_pool.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
filters = {'subnetpool_id': subnet_pool.id}
|
||||
|
||||
self.network.subnets.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertItemsEqual(self.data, list(data))
|
||||
|
||||
def test_list_with_tag_options(self):
|
||||
arglist = [
|
||||
'--tags', 'red,blue',
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--subnet-pool`` option to ``subnet list`` to filter
|
||||
by subnets by subnet pool.
|
Loading…
x
Reference in New Issue
Block a user