Skip to content

Commit 9c22369

Browse files
MIBcstephenfin
authored andcommitted
Add status filtering options to port list
The patch adds "--status" options to list command. Change-Id: I710437f67e9432b2b6389986bc922eac4a60c934 Partial-bug: #1672680
1 parent 067261e commit 9c22369

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,19 @@ def get_parser(self, prog_name):
792792
metavar='<security-group>',
793793
help=_("List only ports associated with this security group"),
794794
)
795+
# the API sadly reports these in upper case and while it would be
796+
# wonderful to plaster over this ugliness client-side, there are
797+
# already users in the wild doing this in upper case that we need to
798+
# support
799+
parser.add_argument(
800+
'--status',
801+
metavar='<status>',
802+
choices=('ACTIVE', 'BUILD', 'DOWN', 'ERROR'),
803+
help=_(
804+
"List ports according to their status "
805+
"('ACTIVE', 'BUILD', 'DOWN', 'ERROR')"
806+
),
807+
)
795808
identity_common.add_project_domain_option_to_parser(parser)
796809
parser.add_argument(
797810
'--fixed-ip',
@@ -859,6 +872,8 @@ def take_action(self, parsed_args):
859872
filters['network_id'] = network.id
860873
if parsed_args.mac_address:
861874
filters['mac_address'] = parsed_args.mac_address
875+
if parsed_args.status:
876+
filters['status'] = parsed_args.status
862877
if parsed_args.project:
863878
project_id = identity_common.find_project(
864879
identity_client,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,29 @@ def test_port_list_security_group(self):
17121712
self.assertEqual(self.columns, columns)
17131713
self.assertCountEqual(self.data, list(data))
17141714

1715+
def test_port_list_status(self):
1716+
arglist = [
1717+
'--status',
1718+
'ACTIVE',
1719+
]
1720+
verifylist = [
1721+
('status', 'ACTIVE'),
1722+
]
1723+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1724+
1725+
columns, data = self.cmd.take_action(parsed_args)
1726+
filters = {
1727+
'status': 'ACTIVE',
1728+
'fields': LIST_FIELDS_TO_RETRIEVE,
1729+
}
1730+
1731+
self.network_client.ports.assert_called_once_with(**filters)
1732+
self.assertEqual(self.columns, columns)
1733+
self.assertEqual(
1734+
self.data,
1735+
list(data),
1736+
)
1737+
17151738

17161739
class TestSetPort(TestPort):
17171740
_port = network_fakes.create_one_port({'tags': ['green', 'red']})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--status`` option to ``port list`` command.
5+
[Bug `1672680 <https://bugs.launchpad.net/python-openstackclient/+bug/1672680>`_]

0 commit comments

Comments
 (0)