Allow ports filtering with device_id

Right now, if a neutron port is owned by a container powered by
Kuryr, there is no way to list and filter those ports because
OSC assumed a neutron port is owned by either a server or router.
This patch adds support for that by introducing an option '--device-id'
to the 'port list' command.

Change-Id: Ib1fd27e8d843a99fb02ccabd8a12a24ac27cec9c
This commit is contained in:
Hongbin Lu 2017-12-08 22:52:59 +00:00 committed by Hongbin Lu
parent b13a323128
commit 5fdd0730c8
4 changed files with 35 additions and 1 deletions

View File

@ -170,7 +170,7 @@ List ports
openstack port list
[--device-owner <device-owner>]
[--router <router> | --server <server>]
[--router <router> | --server <server> | --device-id <device-id>]
[--network <network>]
[--mac-address <mac-address>]
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
@ -192,6 +192,10 @@ List ports
List only ports attached to this server (name or ID)
.. option:: --device-id <device-id>
List only ports with the specified device ID
.. option:: --network <network>
List only ports attached to this network (name or ID)

View File

@ -499,6 +499,11 @@ class ListPort(command.Lister):
metavar='<server>',
help=_("List only ports attached to this server (name or ID)"),
)
device_group.add_argument(
'--device-id',
metavar='<device-id>',
help=_("List only ports with the specified device ID")
)
parser.add_argument(
'--mac-address',
metavar='<mac-address>',
@ -553,6 +558,8 @@ class ListPort(command.Lister):
column_headers += ('Security Groups', 'Device Owner', 'Tags')
if parsed_args.device_owner is not None:
filters['device_owner'] = parsed_args.device_owner
if parsed_args.device_id is not None:
filters['device_id'] = parsed_args.device_id
if parsed_args.router:
_router = network_client.find_router(parsed_args.router,
ignore_missing=False)

View File

@ -759,6 +759,25 @@ class TestListPort(TestPort):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_port_list_device_id_opt(self):
arglist = [
'--device-id', self._ports[0].device_id,
]
verifylist = [
('device_id', self._ports[0].device_id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.ports.assert_called_once_with(**{
'device_id': self._ports[0].device_id
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_port_list_device_owner_opt(self):
arglist = [
'--device-owner', self._ports[0].device_owner,

View File

@ -0,0 +1,4 @@
---
features:
- |
Add ``--device-id`` option to the ``port list`` command.