Skip to content

Commit 4b61efe

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "--device-owner" option to "port list""
2 parents 4b38753 + c7fb3b3 commit 4b61efe

4 files changed

Lines changed: 66 additions & 4 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Create new port
4545
4646
.. option:: --device-owner <device-owner>
4747
48-
Device owner of this port
48+
Device owner of this port. This is the entity that uses
49+
the port (for example, network:dhcp).
4950
5051
.. option:: --vnic-type <vnic-type>
5152
@@ -113,8 +114,14 @@ List ports
113114
.. code:: bash
114115
115116
os port list
117+
[--device-owner <device-owner>]
116118
[--router <router>]
117119
120+
.. option:: --device-owner <device-owner>
121+
122+
List only ports with the specified device owner. This is
123+
the entity that uses the port (for example, network:dhcp).
124+
118125
.. option:: --router <router>
119126
120127
List only ports attached to this router (name or ID)
@@ -154,7 +161,8 @@ Set port properties
154161
155162
.. option:: --device-owner <device-owner>
156163
157-
Device owner of this port
164+
Device owner of this port. This is the entity that uses
165+
the port (for example, network:dhcp).
158166
159167
.. option:: --vnic-type <vnic-type>
160168

openstackclient/network/v2/port.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def _add_updatable_args(parser):
196196
parser.add_argument(
197197
'--device-owner',
198198
metavar='<device-owner>',
199-
help=_("Device owner of this port")
199+
help=_("Device owner of this port. This is the entity that uses "
200+
"the port (for example, network:dhcp).")
200201
)
201202
parser.add_argument(
202203
'--vnic-type',
@@ -336,6 +337,13 @@ class ListPort(command.Lister):
336337

337338
def get_parser(self, prog_name):
338339
parser = super(ListPort, self).get_parser(prog_name)
340+
parser.add_argument(
341+
'--device-owner',
342+
metavar='<device-owner>',
343+
help=_("List only ports with the specified device owner. "
344+
"This is the entity that uses the port (for example, "
345+
"network:dhcp).")
346+
)
339347
parser.add_argument(
340348
'--router',
341349
metavar='<router>',
@@ -361,10 +369,12 @@ def take_action(self, parsed_args):
361369
)
362370

363371
filters = {}
372+
if parsed_args.device_owner is not None:
373+
filters['device_owner'] = parsed_args.device_owner
364374
if parsed_args.router:
365375
_router = client.find_router(parsed_args.router,
366376
ignore_missing=False)
367-
filters = {'device_id': _router.id}
377+
filters['device_id'] = _router.id
368378

369379
data = client.ports(**filters)
370380

openstackclient/tests/network/v2/test_port.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,47 @@ def test_port_list_router_opt(self):
369369
self.assertEqual(self.columns, columns)
370370
self.assertEqual(self.data, list(data))
371371

372+
def test_port_list_device_owner_opt(self):
373+
arglist = [
374+
'--device-owner', self._ports[0].device_owner,
375+
]
376+
377+
verifylist = [
378+
('device_owner', self._ports[0].device_owner)
379+
]
380+
381+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
382+
383+
columns, data = self.cmd.take_action(parsed_args)
384+
385+
self.network.ports.assert_called_once_with(**{
386+
'device_owner': self._ports[0].device_owner
387+
})
388+
self.assertEqual(self.columns, columns)
389+
self.assertEqual(self.data, list(data))
390+
391+
def test_port_list_all_opt(self):
392+
arglist = [
393+
'--device-owner', self._ports[0].device_owner,
394+
'--router', 'fake-router-name',
395+
]
396+
397+
verifylist = [
398+
('device_owner', self._ports[0].device_owner),
399+
('router', 'fake-router-name')
400+
]
401+
402+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
403+
404+
columns, data = self.cmd.take_action(parsed_args)
405+
406+
self.network.ports.assert_called_once_with(**{
407+
'device_owner': self._ports[0].device_owner,
408+
'device_id': 'fake-router-id'
409+
})
410+
self.assertEqual(self.columns, columns)
411+
self.assertEqual(self.data, list(data))
412+
372413

373414
class TestSetPort(TestPort):
374415

releasenotes/notes/bp-neutron-client-a0552f8ca909b665.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ features:
77
- Add ``geneve`` choice to the ``network create`` command
88
``--provider-network-type`` option.
99
[Blueprint :oscbp:`neutron-client`]
10+
- Add ``--device-owner`` option to the ``port list`` command
11+
to enable listing ports based on device owner.
12+
[Blueprint :oscbp:`neutron-client`]

0 commit comments

Comments
 (0)