diff options
| author | Zuul <zuul@review.opendev.org> | 2022-01-13 20:13:30 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2022-01-13 20:13:30 +0000 |
| commit | 0a887a4786eef67bb88d191c66217f82cf7b8127 (patch) | |
| tree | 10e776808be4adb197eab2f4c48ad2495b5251bc /openstackclient | |
| parent | f533dca520127446f2769b88f239799336954833 (diff) | |
| parent | c8c4f76498de3380c7cbf80c5dc800a588bed649 (diff) | |
| download | python-openstackclient-0a887a4786eef67bb88d191c66217f82cf7b8127.tar.gz | |
Merge "Add --security-group to port list"
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/network/v2/port.py | 9 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_port.py | 20 |
2 files changed, 29 insertions, 0 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 7cafd08b..85a32545 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -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) diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index c8540ba0..6da6deaa 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -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): |
