summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsongminglong <songminglong@cmss.chinamobile.com>2016-11-13 10:11:03 +0800
committersongminglong <songminglong@cmss.chinamobile.com>2016-11-13 10:11:03 +0800
commit839c5f7a84b48cecbc80606e894b7906fa01d66b (patch)
treed33b72d4c839af8a8dbe00b299350273a8790a7f
parent95c26cebaa6bf7419a54d632b07ea5303ad0d134 (diff)
downloadpython-openstackclient-839c5f7a84b48cecbc80606e894b7906fa01d66b.tar.gz
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
-rw-r--r--doc/source/command-objects/floating-ip.rst21
-rw-r--r--openstackclient/network/v2/floating_ip.py36
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip.py61
-rw-r--r--releasenotes/notes/bug-1614379-da92ded6d19f5ad5.yaml6
4 files changed, 123 insertions, 1 deletions
diff --git a/doc/source/command-objects/floating-ip.rst b/doc/source/command-objects/floating-ip.rst
index 2ab21f36..b2cc8af0 100644
--- a/doc/source/command-objects/floating-ip.rst
+++ b/doc/source/command-objects/floating-ip.rst
@@ -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
----------------
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py
index 7ae5d448..2aac8e7b 100644
--- a/openstackclient/network/v2/floating_ip.py
+++ b/openstackclient/network/v2/floating_ip.py
@@ -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,
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip.py b/openstackclient/tests/unit/network/v2/test_floating_ip.py
index 0454733b..10f3067d 100644
--- a/openstackclient/tests/unit/network/v2/test_floating_ip.py
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip.py
@@ -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))
diff --git a/releasenotes/notes/bug-1614379-da92ded6d19f5ad5.yaml b/releasenotes/notes/bug-1614379-da92ded6d19f5ad5.yaml
new file mode 100644
index 00000000..a5ac74f1
--- /dev/null
+++ b/releasenotes/notes/bug-1614379-da92ded6d19f5ad5.yaml
@@ -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>`_] \ No newline at end of file