summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHongbin Lu <hongbin.lu@huawei.com>2017-12-08 22:52:59 +0000
committerHongbin Lu <hongbin034@gmail.com>2018-01-03 21:11:02 +0000
commit5fdd0730c88b7a3f65b728c0ea87bb34cbc1d9c4 (patch)
treeaca35b2cc9cb7afb1dcb217bed2f676427d34453
parentb13a323128072f6f56619a816f5be165796171a4 (diff)
downloadpython-openstackclient-5fdd0730c88b7a3f65b728c0ea87bb34cbc1d9c4.tar.gz
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
-rw-r--r--doc/source/cli/command-objects/port.rst6
-rw-r--r--openstackclient/network/v2/port.py7
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py19
-rw-r--r--releasenotes/notes/add-device_id-to-port-list-0c658db51ce43c9e.yaml4
4 files changed, 35 insertions, 1 deletions
diff --git a/doc/source/cli/command-objects/port.rst b/doc/source/cli/command-objects/port.rst
index cf29bb2c..f8e88230 100644
--- a/doc/source/cli/command-objects/port.rst
+++ b/doc/source/cli/command-objects/port.rst
@@ -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)
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 21f30c41..032e1787 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -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)
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index 3f751818..908177ce 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -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,
diff --git a/releasenotes/notes/add-device_id-to-port-list-0c658db51ce43c9e.yaml b/releasenotes/notes/add-device_id-to-port-list-0c658db51ce43c9e.yaml
new file mode 100644
index 00000000..05dae9e9
--- /dev/null
+++ b/releasenotes/notes/add-device_id-to-port-list-0c658db51ce43c9e.yaml
@@ -0,0 +1,4 @@
+---
+features:
+ - |
+ Add ``--device-id`` option to the ``port list`` command.