Add '--network' and other options to floating ip list
The patch adds filtering '--network', '--port', '--fixed-ip-address' options to floating ip list command Partial-Bug: #1614379 Change-Id: I82319d0985d9e864431097c90264a20bf88167cc
This commit is contained in:
parent
95c26cebaa
commit
839c5f7a84
@ -72,6 +72,27 @@ List floating IP(s)
|
||||
.. code:: bash
|
||||
|
||||
os floating ip list
|
||||
[--network <network>]
|
||||
[--port <port>]
|
||||
[--fixed-ip-address <fixed-ip-address>]
|
||||
|
||||
.. option:: --network <network>
|
||||
|
||||
List floating IP(s) according to given network (name or ID)
|
||||
|
||||
*Network version 2 only*
|
||||
|
||||
.. option:: --port <port>
|
||||
|
||||
List floating IP(s) according to given port (name or ID)
|
||||
|
||||
*Network version 2 only*
|
||||
|
||||
.. option:: --fixed-ip-address <fixed-ip-address>
|
||||
|
||||
List floating IP(s) according to given fixed IP address
|
||||
|
||||
*Network version 2 only*
|
||||
|
||||
floating ip show
|
||||
----------------
|
||||
|
@ -205,7 +205,31 @@ class DeleteIPFloating(DeleteFloatingIP):
|
||||
class ListFloatingIP(common.NetworkAndComputeLister):
|
||||
"""List floating IP(s)"""
|
||||
|
||||
def update_parser_network(self, parser):
|
||||
parser.add_argument(
|
||||
'--network',
|
||||
metavar='<network>',
|
||||
help=_("List floating IP(s) according to "
|
||||
"given network (name or ID)")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--port',
|
||||
metavar='<port>',
|
||||
help=_("List floating IP(s) according to "
|
||||
"given port (name or ID)")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--fixed-ip-address',
|
||||
metavar='<fixed-ip-address>',
|
||||
help=_("List floating IP(s) according to "
|
||||
"given fixed IP address")
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action_network(self, client, parsed_args):
|
||||
network_client = self.app.client_manager.network
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
'floating_ip_address',
|
||||
@ -224,6 +248,18 @@ class ListFloatingIP(common.NetworkAndComputeLister):
|
||||
)
|
||||
|
||||
query = {}
|
||||
|
||||
if parsed_args.network is not None:
|
||||
network = network_client.find_network(parsed_args.network,
|
||||
ignore_missing=False)
|
||||
query['floating_network_id'] = network.id
|
||||
if parsed_args.port is not None:
|
||||
port = network_client.find_port(parsed_args.port,
|
||||
ignore_missing=False)
|
||||
query['port_id'] = port.id
|
||||
if parsed_args.fixed_ip_address is not None:
|
||||
query['fixed_ip_address'] = parsed_args.fixed_ip_address
|
||||
|
||||
data = client.ips(**query)
|
||||
|
||||
return (headers,
|
||||
|
@ -231,6 +231,12 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
|
||||
|
||||
# The floating ips to list up
|
||||
floating_ips = network_fakes.FakeFloatingIP.create_floating_ips(count=3)
|
||||
fake_network = network_fakes.FakeNetwork.create_one_network({
|
||||
'id': 'fake_network_id',
|
||||
})
|
||||
fake_port = network_fakes.FakePort.create_one_port({
|
||||
'id': 'fake_port_id',
|
||||
})
|
||||
|
||||
columns = (
|
||||
'ID',
|
||||
@ -256,6 +262,8 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
|
||||
super(TestListFloatingIPNetwork, self).setUp()
|
||||
|
||||
self.network.ips = mock.Mock(return_value=self.floating_ips)
|
||||
self.network.find_network = mock.Mock(return_value=self.fake_network)
|
||||
self.network.find_port = mock.Mock(return_value=self.fake_port)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = floating_ip.ListFloatingIP(self.app, self.namespace)
|
||||
@ -267,7 +275,58 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.ips.assert_called_once_with(**{})
|
||||
self.network.ips.assert_called_once_with()
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_floating_ip_list_network(self):
|
||||
arglist = [
|
||||
'--network', 'fake_network_id',
|
||||
]
|
||||
verifylist = [
|
||||
('network', 'fake_network_id'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.ips.assert_called_once_with(**{
|
||||
'floating_network_id': 'fake_network_id',
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_floating_ip_list_port(self):
|
||||
arglist = [
|
||||
'--port', 'fake_port_id',
|
||||
]
|
||||
verifylist = [
|
||||
('port', 'fake_port_id'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.ips.assert_called_once_with(**{
|
||||
'port_id': 'fake_port_id',
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_floating_ip_list_fixed_ip_address(self):
|
||||
arglist = [
|
||||
'--fixed-ip-address', self.floating_ips[0].fixed_ip_address,
|
||||
]
|
||||
verifylist = [
|
||||
('fixed_ip_address', self.floating_ips[0].fixed_ip_address),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.ips.assert_called_once_with(**{
|
||||
'fixed_ip_address': self.floating_ips[0].fixed_ip_address,
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
6
releasenotes/notes/bug-1614379-da92ded6d19f5ad5.yaml
Normal file
6
releasenotes/notes/bug-1614379-da92ded6d19f5ad5.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--port``, ``--fixed-ip-address``, ``--network``,
|
||||
options to ``floating ip list`` command
|
||||
[Bug `1614379 <https://bugs.launchpad.net/bugs/1614379>`_]
|
Loading…
Reference in New Issue
Block a user