diff --git a/doc/source/cli/command-objects/floating-ip.rst b/doc/source/cli/command-objects/floating-ip.rst index 14615749ca..749c32d6b8 100644 --- a/doc/source/cli/command-objects/floating-ip.rst +++ b/doc/source/cli/command-objects/floating-ip.rst @@ -144,6 +144,12 @@ List floating IP(s) *Network version 2 only* +.. option:: --floating-ip-address + + List floating IP(s) according to given floating IP address + + *Network version 2 only* + .. option:: --long List additional fields in output diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index e1ec82748f..8ac8e10703 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -236,6 +236,12 @@ class ListFloatingIP(common.NetworkAndComputeLister): help=_("List floating IP(s) according to " "given fixed IP address") ) + parser.add_argument( + '--floating-ip-address', + metavar='', + help=_("List floating IP(s) according to " + "given floating IP address") + ) parser.add_argument( '--long', action='store_true', @@ -316,6 +322,8 @@ class ListFloatingIP(common.NetworkAndComputeLister): query['port_id'] = port.id if parsed_args.fixed_ip_address is not None: query['fixed_ip_address'] = parsed_args.fixed_ip_address + if parsed_args.floating_ip_address is not None: + query['floating_ip_address'] = parsed_args.floating_ip_address if parsed_args.status: query['status'] = parsed_args.status if parsed_args.project is not None: diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py index 209c01cf1c..cbd4da38ca 100644 --- a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py +++ b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py @@ -504,6 +504,23 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork): self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + def test_floating_ip_list_floating_ip_address(self): + arglist = [ + '--floating-ip-address', self.floating_ips[0].floating_ip_address, + ] + verifylist = [ + ('floating_ip_address', self.floating_ips[0].floating_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(**{ + 'floating_ip_address': self.floating_ips[0].floating_ip_address, + }) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + def test_floating_ip_list_long(self): arglist = ['--long', ] verifylist = [('long', True), ]