Merge "Add --security-group to port list"

This commit is contained in:
Zuul 2022-01-13 20:13:30 +00:00 committed by Gerrit Code Review
commit 0a887a4786
3 changed files with 34 additions and 0 deletions

View File

@ -615,6 +615,13 @@ class ListPort(command.Lister):
metavar='<name>',
help=_("List ports according to their name")
)
parser.add_argument(
'--security-group',
action='append',
dest='security_groups',
metavar='<security-group>',
help=_("List only ports associated with this security group")
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--fixed-ip',
@ -687,6 +694,8 @@ class ListPort(command.Lister):
if parsed_args.fixed_ip:
filters['fixed_ips'] = _prepare_filter_fixed_ips(
self.app.client_manager, parsed_args)
if parsed_args.security_groups:
filters['security_groups'] = parsed_args.security_groups
_tag.get_tag_filtering_args(parsed_args, filters)

View File

@ -1296,6 +1296,26 @@ class TestListPort(TestPort):
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.data, list(data))
def test_port_list_security_group(self):
arglist = [
'--security-group', 'sg-id1',
'--security-group', 'sg-id2',
]
verifylist = [
('security_groups', ['sg-id1', 'sg-id2']),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {
'security_groups': ['sg-id1', 'sg-id2'],
'fields': LIST_FIELDS_TO_RETRIEVE,
}
self.network.ports.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.data, list(data))
class TestSetPort(TestPort):

View File

@ -0,0 +1,5 @@
---
features:
- |
Added ``--security-group`` option to the ``os port list`` command. This
option is appendable and multiple security group IDs can be provided.