Merge "Add status filtering options to port list"
This commit is contained in:
commit
ac59673b5d
@ -792,6 +792,19 @@ class ListPort(command.Lister):
|
||||
metavar='<security-group>',
|
||||
help=_("List only ports associated with this security group"),
|
||||
)
|
||||
# the API sadly reports these in upper case and while it would be
|
||||
# wonderful to plaster over this ugliness client-side, there are
|
||||
# already users in the wild doing this in upper case that we need to
|
||||
# support
|
||||
parser.add_argument(
|
||||
'--status',
|
||||
metavar='<status>',
|
||||
choices=('ACTIVE', 'BUILD', 'DOWN', 'ERROR'),
|
||||
help=_(
|
||||
"List ports according to their status "
|
||||
"('ACTIVE', 'BUILD', 'DOWN', 'ERROR')"
|
||||
),
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
parser.add_argument(
|
||||
'--fixed-ip',
|
||||
@ -859,6 +872,8 @@ class ListPort(command.Lister):
|
||||
filters['network_id'] = network.id
|
||||
if parsed_args.mac_address:
|
||||
filters['mac_address'] = parsed_args.mac_address
|
||||
if parsed_args.status:
|
||||
filters['status'] = parsed_args.status
|
||||
if parsed_args.project:
|
||||
project_id = identity_common.find_project(
|
||||
identity_client,
|
||||
|
@ -1712,6 +1712,29 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, list(data))
|
||||
|
||||
def test_port_list_status(self):
|
||||
arglist = [
|
||||
'--status',
|
||||
'ACTIVE',
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'ACTIVE'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
filters = {
|
||||
'status': 'ACTIVE',
|
||||
'fields': LIST_FIELDS_TO_RETRIEVE,
|
||||
}
|
||||
|
||||
self.network_client.ports.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(
|
||||
self.data,
|
||||
list(data),
|
||||
)
|
||||
|
||||
|
||||
class TestSetPort(TestPort):
|
||||
_port = network_fakes.create_one_port({'tags': ['green', 'red']})
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--status`` option to ``port list`` command.
|
||||
[Bug `1672680 <https://bugs.launchpad.net/python-openstackclient/+bug/1672680>`_]
|
Loading…
x
Reference in New Issue
Block a user