Skip to content

Commit 5fdd073

Browse files
Hongbin Luhongbin
authored andcommitted
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
1 parent b13a323 commit 5fdd073

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

doc/source/cli/command-objects/port.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ List ports
170170
171171
openstack port list
172172
[--device-owner <device-owner>]
173-
[--router <router> | --server <server>]
173+
[--router <router> | --server <server> | --device-id <device-id>]
174174
[--network <network>]
175175
[--mac-address <mac-address>]
176176
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
@@ -192,6 +192,10 @@ List ports
192192
193193
List only ports attached to this server (name or ID)
194194
195+
.. option:: --device-id <device-id>
196+
197+
List only ports with the specified device ID
198+
195199
.. option:: --network <network>
196200
197201
List only ports attached to this network (name or ID)

openstackclient/network/v2/port.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ def get_parser(self, prog_name):
499499
metavar='<server>',
500500
help=_("List only ports attached to this server (name or ID)"),
501501
)
502+
device_group.add_argument(
503+
'--device-id',
504+
metavar='<device-id>',
505+
help=_("List only ports with the specified device ID")
506+
)
502507
parser.add_argument(
503508
'--mac-address',
504509
metavar='<mac-address>',
@@ -553,6 +558,8 @@ def take_action(self, parsed_args):
553558
column_headers += ('Security Groups', 'Device Owner', 'Tags')
554559
if parsed_args.device_owner is not None:
555560
filters['device_owner'] = parsed_args.device_owner
561+
if parsed_args.device_id is not None:
562+
filters['device_id'] = parsed_args.device_id
556563
if parsed_args.router:
557564
_router = network_client.find_router(parsed_args.router,
558565
ignore_missing=False)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,25 @@ def test_port_list_with_server_option(self, mock_find):
759759
self.assertEqual(self.columns, columns)
760760
self.assertEqual(self.data, list(data))
761761

762+
def test_port_list_device_id_opt(self):
763+
arglist = [
764+
'--device-id', self._ports[0].device_id,
765+
]
766+
767+
verifylist = [
768+
('device_id', self._ports[0].device_id)
769+
]
770+
771+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
772+
773+
columns, data = self.cmd.take_action(parsed_args)
774+
775+
self.network.ports.assert_called_once_with(**{
776+
'device_id': self._ports[0].device_id
777+
})
778+
self.assertEqual(self.columns, columns)
779+
self.assertEqual(self.data, list(data))
780+
762781
def test_port_list_device_owner_opt(self):
763782
arglist = [
764783
'--device-owner', self._ports[0].device_owner,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
Add ``--device-id`` option to the ``port list`` command.

0 commit comments

Comments
 (0)