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
|
os port list
|
||||||
[--device-owner <device-owner>]
|
[--device-owner <device-owner>]
|
||||||
[--router <router> | --server <server>]
|
[--router <router> | --server <server>]
|
||||||
|
[--network <network>]
|
||||||
|
|
||||||
.. option:: --device-owner <device-owner>
|
.. option:: --device-owner <device-owner>
|
||||||
|
|
||||||
@ -130,6 +131,10 @@ List ports
|
|||||||
|
|
||||||
List only ports attached to this server (name or ID)
|
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
|
port set
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -345,6 +345,10 @@ class ListPort(command.Lister):
|
|||||||
"This is the entity that uses the port (for example, "
|
"This is the entity that uses the port (for example, "
|
||||||
"network:dhcp).")
|
"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 = parser.add_mutually_exclusive_group()
|
||||||
device_group.add_argument(
|
device_group.add_argument(
|
||||||
'--router',
|
'--router',
|
||||||
@ -387,6 +391,10 @@ class ListPort(command.Lister):
|
|||||||
server = utils.find_resource(compute_client.servers,
|
server = utils.find_resource(compute_client.servers,
|
||||||
parsed_args.server)
|
parsed_args.server)
|
||||||
filters['device_id'] = server.id
|
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)
|
data = network_client.ports(**filters)
|
||||||
|
|
||||||
|
@ -337,7 +337,11 @@ class TestListPort(TestPort):
|
|||||||
fake_router = network_fakes.FakeRouter.create_one_router({
|
fake_router = network_fakes.FakeRouter.create_one_router({
|
||||||
'id': 'fake-router-id',
|
'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_router = mock.Mock(return_value=fake_router)
|
||||||
|
self.network.find_network = mock.Mock(return_value=fake_network)
|
||||||
self.app.client_manager.compute = mock.Mock()
|
self.app.client_manager.compute = mock.Mock()
|
||||||
|
|
||||||
def test_port_list_no_options(self):
|
def test_port_list_no_options(self):
|
||||||
@ -414,11 +418,13 @@ class TestListPort(TestPort):
|
|||||||
arglist = [
|
arglist = [
|
||||||
'--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',
|
||||||
]
|
]
|
||||||
|
|
||||||
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')
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -427,7 +433,8 @@ 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'
|
||||||
})
|
})
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, list(data))
|
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