Skip to content

Commit 0a887a4

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add --security-group to port list"
2 parents f533dca + c8c4f76 commit 0a887a4

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@ def get_parser(self, prog_name):
615615
metavar='<name>',
616616
help=_("List ports according to their name")
617617
)
618+
parser.add_argument(
619+
'--security-group',
620+
action='append',
621+
dest='security_groups',
622+
metavar='<security-group>',
623+
help=_("List only ports associated with this security group")
624+
)
618625
identity_common.add_project_domain_option_to_parser(parser)
619626
parser.add_argument(
620627
'--fixed-ip',
@@ -687,6 +694,8 @@ def take_action(self, parsed_args):
687694
if parsed_args.fixed_ip:
688695
filters['fixed_ips'] = _prepare_filter_fixed_ips(
689696
self.app.client_manager, parsed_args)
697+
if parsed_args.security_groups:
698+
filters['security_groups'] = parsed_args.security_groups
690699

691700
_tag.get_tag_filtering_args(parsed_args, filters)
692701

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,26 @@ def test_list_with_tag_options(self):
12961296
self.assertEqual(self.columns, columns)
12971297
self.assertCountEqual(self.data, list(data))
12981298

1299+
def test_port_list_security_group(self):
1300+
arglist = [
1301+
'--security-group', 'sg-id1',
1302+
'--security-group', 'sg-id2',
1303+
]
1304+
verifylist = [
1305+
('security_groups', ['sg-id1', 'sg-id2']),
1306+
]
1307+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1308+
1309+
columns, data = self.cmd.take_action(parsed_args)
1310+
filters = {
1311+
'security_groups': ['sg-id1', 'sg-id2'],
1312+
'fields': LIST_FIELDS_TO_RETRIEVE,
1313+
}
1314+
1315+
self.network.ports.assert_called_once_with(**filters)
1316+
self.assertEqual(self.columns, columns)
1317+
self.assertCountEqual(self.data, list(data))
1318+
12991319

13001320
class TestSetPort(TestPort):
13011321

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Added ``--security-group`` option to the ``os port list`` command. This
5+
option is appendable and multiple security group IDs can be provided.

0 commit comments

Comments
 (0)