Add option to allow filtering by mac-address on port list
Added support to allow filtering ports via --mac-address option to the port list command. Change-Id: I903e443f2f9057571d46520c4cafb88d1972c0cb Partial-bug: #1634333 Partially-Implements: blueprint network-commands-options
This commit is contained in:
parent
5e3ec1b42f
commit
a1e3056414
@ -127,6 +127,7 @@ List ports
|
|||||||
[--device-owner <device-owner>]
|
[--device-owner <device-owner>]
|
||||||
[--router <router> | --server <server>]
|
[--router <router> | --server <server>]
|
||||||
[--network <network>]
|
[--network <network>]
|
||||||
|
[--mac-address <mac-address>]
|
||||||
[--long]
|
[--long]
|
||||||
|
|
||||||
.. option:: --device-owner <device-owner>
|
.. option:: --device-owner <device-owner>
|
||||||
@ -146,6 +147,10 @@ List ports
|
|||||||
|
|
||||||
List only ports attached to this network (name or ID)
|
List only ports attached to this network (name or ID)
|
||||||
|
|
||||||
|
.. option:: --mac-address <mac-address>
|
||||||
|
|
||||||
|
List only ports with this MAC address
|
||||||
|
|
||||||
.. option:: --long
|
.. option:: --long
|
||||||
|
|
||||||
List additional fields in output
|
List additional fields in output
|
||||||
|
@ -384,6 +384,11 @@ class ListPort(command.Lister):
|
|||||||
metavar='<server>',
|
metavar='<server>',
|
||||||
help=_("List only ports attached to this server (name or ID)"),
|
help=_("List only ports attached to this server (name or ID)"),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--mac-address',
|
||||||
|
metavar='<mac-address>',
|
||||||
|
help=_("List only ports with this MAC address")
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--long',
|
'--long',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -429,6 +434,8 @@ class ListPort(command.Lister):
|
|||||||
network = network_client.find_network(parsed_args.network,
|
network = network_client.find_network(parsed_args.network,
|
||||||
ignore_missing=False)
|
ignore_missing=False)
|
||||||
filters['network_id'] = network.id
|
filters['network_id'] = network.id
|
||||||
|
if parsed_args.mac_address:
|
||||||
|
filters['mac_address'] = parsed_args.mac_address
|
||||||
|
|
||||||
data = network_client.ports(**filters)
|
data = network_client.ports(**filters)
|
||||||
|
|
||||||
|
@ -530,12 +530,14 @@ class TestListPort(TestPort):
|
|||||||
'--device-owner', self._ports[0].device_owner,
|
'--device-owner', self._ports[0].device_owner,
|
||||||
'--router', 'fake-router-name',
|
'--router', 'fake-router-name',
|
||||||
'--network', 'fake-network-name',
|
'--network', 'fake-network-name',
|
||||||
|
'--mac-address', self._ports[0].mac_address,
|
||||||
]
|
]
|
||||||
|
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('device_owner', self._ports[0].device_owner),
|
('device_owner', self._ports[0].device_owner),
|
||||||
('router', 'fake-router-name'),
|
('router', 'fake-router-name'),
|
||||||
('network', 'fake-network-name')
|
('network', 'fake-network-name'),
|
||||||
|
('mac_address', self._ports[0].mac_address)
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -545,7 +547,27 @@ class TestListPort(TestPort):
|
|||||||
self.network.ports.assert_called_once_with(**{
|
self.network.ports.assert_called_once_with(**{
|
||||||
'device_owner': self._ports[0].device_owner,
|
'device_owner': self._ports[0].device_owner,
|
||||||
'device_id': 'fake-router-id',
|
'device_id': 'fake-router-id',
|
||||||
'network_id': 'fake-network-id'
|
'network_id': 'fake-network-id',
|
||||||
|
'mac_address': self._ports[0].mac_address
|
||||||
|
})
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
def test_port_list_mac_address_opt(self):
|
||||||
|
arglist = [
|
||||||
|
'--mac-address', self._ports[0].mac_address,
|
||||||
|
]
|
||||||
|
|
||||||
|
verifylist = [
|
||||||
|
('mac_address', self._ports[0].mac_address)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.network.ports.assert_called_once_with(**{
|
||||||
|
'mac_address': self._ports[0].mac_address
|
||||||
})
|
})
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, list(data))
|
self.assertEqual(self.data, list(data))
|
||||||
|
6
releasenotes/notes/bug-1634333-a2b04d33ca39440e.yaml
Normal file
6
releasenotes/notes/bug-1634333-a2b04d33ca39440e.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add support to allow filtering ports via ``--mac-address``
|
||||||
|
option to the ``port list`` command.
|
||||||
|
[Bug `1634333 <https://bugs.launchpad.net/bugs/1634333>`_]
|
Loading…
Reference in New Issue
Block a user