Add --name to port list

The neutron API supports filtering ports by name, but
the CLI was missing support for it like it does for
other networking resources.

Change-Id: I4ff339e18656013218a26f045b205cb7a02dd2fb
Story: #2008654
This commit is contained in:
Brian Haley 2021-02-23 18:58:24 -05:00
parent 01a53fa96f
commit 16c72f8642
2 changed files with 27 additions and 0 deletions

View File

@ -600,6 +600,11 @@ class ListPort(command.Lister):
metavar='<project>',
help=_("List ports according to their project (name or ID)")
)
parser.add_argument(
'--name',
metavar='<name>',
help=_("List ports according to their name")
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--fixed-ip',
@ -667,6 +672,8 @@ class ListPort(command.Lister):
).id
filters['tenant_id'] = project_id
filters['project_id'] = project_id
if parsed_args.name:
filters['name'] = parsed_args.name
if parsed_args.fixed_ip:
filters['fixed_ips'] = _prepare_filter_fixed_ips(
self.app.client_manager, parsed_args)

View File

@ -1250,6 +1250,26 @@ class TestListPort(TestPort):
self.assertEqual(self.columns, columns)
self.assertItemsEqual(self.data, list(data))
def test_port_list_name(self):
test_name = "fakename"
arglist = [
'--name', test_name,
]
verifylist = [
('name', test_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {
'name': test_name,
'fields': LIST_FIELDS_TO_RETRIEVE,
}
self.network.ports.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',