Provide support to list ports by network
The new --network option provides a list of ports connected with the current network. Change-Id: I6a45184887b3e65f792391cb7e91f4ad85f29e03 Partial-Bug:#1562067 Partially-Implements: blueprint network-commands-options
This commit is contained in:
parent
7e990ba1e2
commit
554607eb3d
@ -116,6 +116,7 @@ List ports
|
||||
os port list
|
||||
[--device-owner <device-owner>]
|
||||
[--router <router> | --server <server>]
|
||||
[--network <network>]
|
||||
|
||||
.. option:: --device-owner <device-owner>
|
||||
|
||||
@ -130,6 +131,10 @@ List ports
|
||||
|
||||
List only ports attached to this server (name or ID)
|
||||
|
||||
.. option:: --network <network>
|
||||
|
||||
List only ports attached to this network (name or ID)
|
||||
|
||||
port set
|
||||
--------
|
||||
|
||||
|
@ -345,6 +345,10 @@ class ListPort(command.Lister):
|
||||
"This is the entity that uses the port (for example, "
|
||||
"network:dhcp).")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--network',
|
||||
metavar='<network>',
|
||||
help=_("List only ports connected to this network (name or ID)"))
|
||||
device_group = parser.add_mutually_exclusive_group()
|
||||
device_group.add_argument(
|
||||
'--router',
|
||||
@ -387,6 +391,10 @@ class ListPort(command.Lister):
|
||||
server = utils.find_resource(compute_client.servers,
|
||||
parsed_args.server)
|
||||
filters['device_id'] = server.id
|
||||
if parsed_args.network:
|
||||
network = network_client.find_network(parsed_args.network,
|
||||
ignore_missing=False)
|
||||
filters['network_id'] = network.id
|
||||
|
||||
data = network_client.ports(**filters)
|
||||
|
||||
|
@ -337,7 +337,11 @@ class TestListPort(TestPort):
|
||||
fake_router = network_fakes.FakeRouter.create_one_router({
|
||||
'id': 'fake-router-id',
|
||||
})
|
||||
fake_network = network_fakes.FakeNetwork.create_one_network({
|
||||
'id': 'fake-network-id',
|
||||
})
|
||||
self.network.find_router = mock.Mock(return_value=fake_router)
|
||||
self.network.find_network = mock.Mock(return_value=fake_network)
|
||||
self.app.client_manager.compute = mock.Mock()
|
||||
|
||||
def test_port_list_no_options(self):
|
||||
@ -414,11 +418,13 @@ class TestListPort(TestPort):
|
||||
arglist = [
|
||||
'--device-owner', self._ports[0].device_owner,
|
||||
'--router', 'fake-router-name',
|
||||
'--network', 'fake-network-name',
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('device_owner', self._ports[0].device_owner),
|
||||
('router', 'fake-router-name')
|
||||
('router', 'fake-router-name'),
|
||||
('network', 'fake-network-name')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -427,7 +433,8 @@ class TestListPort(TestPort):
|
||||
|
||||
self.network.ports.assert_called_once_with(**{
|
||||
'device_owner': self._ports[0].device_owner,
|
||||
'device_id': 'fake-router-id'
|
||||
'device_id': 'fake-router-id',
|
||||
'network_id': 'fake-network-id'
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Ports can now be listed as per the networks they are
|
||||
connected to by using the ``--network`` option with
|
||||
the ``port list`` CLI.
|
||||
[ Blueprint `network-commands-options <https://blueprints.launchpad.net/python-openstackclient/+spec/network-commands-options>`_]
|
Loading…
Reference in New Issue
Block a user