Merge "Add --security-group to port list"
This commit is contained in:
commit
0a887a4786
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user