summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2016-06-15 08:53:00 -0500
committerRichard Theis <rtheis@us.ibm.com>2016-06-20 16:32:20 -0500
commitc7fb3b36556a6e7622dd7b2bf2ddb5209e518773 (patch)
treea998c0cee73e4f0854d21b8686a7dd859b0a6ed5
parent40004b5d80689f9f9cd802b1487f8e78830e6d4f (diff)
downloadpython-openstackclient-c7fb3b36556a6e7622dd7b2bf2ddb5209e518773.tar.gz
Add "--device-owner" option to "port list"
Add "--device-owner" option to the "port list" command to enable listing ports based on device owner. Change-Id: I0a538ec41800b9f842e86dceb6ca4180ef239c95 Implements: blueprint neutron-client
-rw-r--r--doc/source/command-objects/port.rst12
-rw-r--r--openstackclient/network/v2/port.py14
-rw-r--r--openstackclient/tests/network/v2/test_port.py41
-rw-r--r--releasenotes/notes/bp-neutron-client-a0552f8ca909b665.yaml3
4 files changed, 66 insertions, 4 deletions
diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst
index e4cf2cd2..0a74f88c 100644
--- a/doc/source/command-objects/port.rst
+++ b/doc/source/command-objects/port.rst
@@ -45,7 +45,8 @@ Create new port
.. option:: --device-owner <device-owner>
- Device owner of this port
+ Device owner of this port. This is the entity that uses
+ the port (for example, network:dhcp).
.. option:: --vnic-type <vnic-type>
@@ -112,8 +113,14 @@ List ports
.. code:: bash
os port list
+ [--device-owner <device-owner>]
[--router <router>]
+.. option:: --device-owner <device-owner>
+
+ List only ports with the specified device owner. This is
+ the entity that uses the port (for example, network:dhcp).
+
.. option:: --router <router>
List only ports attached to this router (name or ID)
@@ -153,7 +160,8 @@ Set port properties
.. option:: --device-owner <device-owner>
- Device owner of this port
+ Device owner of this port. This is the entity that uses
+ the port (for example, network:dhcp).
.. option:: --vnic-type <vnic-type>
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 1c5db706..71dc1083 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -169,7 +169,8 @@ def _add_updatable_args(parser):
parser.add_argument(
'--device-owner',
metavar='<device-owner>',
- help=_("Device owner of this port")
+ help=_("Device owner of this port. This is the entity that uses "
+ "the port (for example, network:dhcp).")
)
parser.add_argument(
'--vnic-type',
@@ -310,6 +311,13 @@ class ListPort(command.Lister):
def get_parser(self, prog_name):
parser = super(ListPort, self).get_parser(prog_name)
parser.add_argument(
+ '--device-owner',
+ metavar='<device-owner>',
+ help=_("List only ports with the specified device owner. "
+ "This is the entity that uses the port (for example, "
+ "network:dhcp).")
+ )
+ parser.add_argument(
'--router',
metavar='<router>',
dest='router',
@@ -334,10 +342,12 @@ class ListPort(command.Lister):
)
filters = {}
+ if parsed_args.device_owner is not None:
+ filters['device_owner'] = parsed_args.device_owner
if parsed_args.router:
_router = client.find_router(parsed_args.router,
ignore_missing=False)
- filters = {'device_id': _router.id}
+ filters['device_id'] = _router.id
data = client.ports(**filters)
diff --git a/openstackclient/tests/network/v2/test_port.py b/openstackclient/tests/network/v2/test_port.py
index 779dca05..8da6ec10 100644
--- a/openstackclient/tests/network/v2/test_port.py
+++ b/openstackclient/tests/network/v2/test_port.py
@@ -316,6 +316,47 @@ class TestListPort(TestPort):
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,
+ ]
+
+ verifylist = [
+ ('device_owner', self._ports[0].device_owner)
+ ]
+
+ 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_owner': self._ports[0].device_owner
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_port_list_all_opt(self):
+ arglist = [
+ '--device-owner', self._ports[0].device_owner,
+ '--router', 'fake-router-name',
+ ]
+
+ verifylist = [
+ ('device_owner', self._ports[0].device_owner),
+ ('router', 'fake-router-name')
+ ]
+
+ 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_owner': self._ports[0].device_owner,
+ 'device_id': 'fake-router-id'
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
class TestSetPort(TestPort):
diff --git a/releasenotes/notes/bp-neutron-client-a0552f8ca909b665.yaml b/releasenotes/notes/bp-neutron-client-a0552f8ca909b665.yaml
index f8de4ee6..3665dd81 100644
--- a/releasenotes/notes/bp-neutron-client-a0552f8ca909b665.yaml
+++ b/releasenotes/notes/bp-neutron-client-a0552f8ca909b665.yaml
@@ -3,3 +3,6 @@ features:
- Add ``geneve`` choice to the ``network create`` command
``--provider-network-type`` option.
[Blueprint :oscbp:`neutron-client`]
+ - Add ``--device-owner`` option to the ``port list`` command
+ to enable listing ports based on device owner.
+ [Blueprint :oscbp:`neutron-client`]