diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index dfdb604d55..6885e147e0 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -600,6 +600,11 @@ class ListPort(command.Lister): metavar='', help=_("List ports according to their project (name or ID)") ) + parser.add_argument( + '--name', + metavar='', + 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) diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index c8bced71c3..8c5158d7c8 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -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',