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
This commit is contained in:
Richard Theis 2016-06-15 08:53:00 -05:00
parent 40004b5d80
commit c7fb3b3655
4 changed files with 66 additions and 4 deletions

View File

@ -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>

View File

@ -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',
@ -309,6 +310,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>',
@ -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)

View File

@ -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):

View File

@ -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`]