Skip to content

Commit f4536e7

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add '--network' and other options to floating ip list"
2 parents 5787d3c + 839c5f7 commit f4536e7

4 files changed

Lines changed: 123 additions & 1 deletion

File tree

doc/source/command-objects/floating-ip.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ List floating IP(s)
7272
.. code:: bash
7373
7474
os floating ip list
75+
[--network <network>]
76+
[--port <port>]
77+
[--fixed-ip-address <fixed-ip-address>]
78+
79+
.. option:: --network <network>
80+
81+
List floating IP(s) according to given network (name or ID)
82+
83+
*Network version 2 only*
84+
85+
.. option:: --port <port>
86+
87+
List floating IP(s) according to given port (name or ID)
88+
89+
*Network version 2 only*
90+
91+
.. option:: --fixed-ip-address <fixed-ip-address>
92+
93+
List floating IP(s) according to given fixed IP address
94+
95+
*Network version 2 only*
7596

7697
floating ip show
7798
----------------

openstackclient/network/v2/floating_ip.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,31 @@ def take_action_compute(self, client, parsed_args):
205205
class ListFloatingIP(common.NetworkAndComputeLister):
206206
_description = _("List floating IP(s)")
207207

208+
def update_parser_network(self, parser):
209+
parser.add_argument(
210+
'--network',
211+
metavar='<network>',
212+
help=_("List floating IP(s) according to "
213+
"given network (name or ID)")
214+
)
215+
parser.add_argument(
216+
'--port',
217+
metavar='<port>',
218+
help=_("List floating IP(s) according to "
219+
"given port (name or ID)")
220+
)
221+
parser.add_argument(
222+
'--fixed-ip-address',
223+
metavar='<fixed-ip-address>',
224+
help=_("List floating IP(s) according to "
225+
"given fixed IP address")
226+
)
227+
228+
return parser
229+
208230
def take_action_network(self, client, parsed_args):
231+
network_client = self.app.client_manager.network
232+
209233
columns = (
210234
'id',
211235
'floating_ip_address',
@@ -224,6 +248,18 @@ def take_action_network(self, client, parsed_args):
224248
)
225249

226250
query = {}
251+
252+
if parsed_args.network is not None:
253+
network = network_client.find_network(parsed_args.network,
254+
ignore_missing=False)
255+
query['floating_network_id'] = network.id
256+
if parsed_args.port is not None:
257+
port = network_client.find_port(parsed_args.port,
258+
ignore_missing=False)
259+
query['port_id'] = port.id
260+
if parsed_args.fixed_ip_address is not None:
261+
query['fixed_ip_address'] = parsed_args.fixed_ip_address
262+
227263
data = client.ips(**query)
228264

229265
return (headers,

openstackclient/tests/unit/network/v2/test_floating_ip.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
231231

232232
# The floating ips to list up
233233
floating_ips = network_fakes.FakeFloatingIP.create_floating_ips(count=3)
234+
fake_network = network_fakes.FakeNetwork.create_one_network({
235+
'id': 'fake_network_id',
236+
})
237+
fake_port = network_fakes.FakePort.create_one_port({
238+
'id': 'fake_port_id',
239+
})
234240

235241
columns = (
236242
'ID',
@@ -256,6 +262,8 @@ def setUp(self):
256262
super(TestListFloatingIPNetwork, self).setUp()
257263

258264
self.network.ips = mock.Mock(return_value=self.floating_ips)
265+
self.network.find_network = mock.Mock(return_value=self.fake_network)
266+
self.network.find_port = mock.Mock(return_value=self.fake_port)
259267

260268
# Get the command object to test
261269
self.cmd = floating_ip.ListFloatingIP(self.app, self.namespace)
@@ -267,7 +275,58 @@ def test_floating_ip_list(self):
267275

268276
columns, data = self.cmd.take_action(parsed_args)
269277

270-
self.network.ips.assert_called_once_with(**{})
278+
self.network.ips.assert_called_once_with()
279+
self.assertEqual(self.columns, columns)
280+
self.assertEqual(self.data, list(data))
281+
282+
def test_floating_ip_list_network(self):
283+
arglist = [
284+
'--network', 'fake_network_id',
285+
]
286+
verifylist = [
287+
('network', 'fake_network_id'),
288+
]
289+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
290+
291+
columns, data = self.cmd.take_action(parsed_args)
292+
293+
self.network.ips.assert_called_once_with(**{
294+
'floating_network_id': 'fake_network_id',
295+
})
296+
self.assertEqual(self.columns, columns)
297+
self.assertEqual(self.data, list(data))
298+
299+
def test_floating_ip_list_port(self):
300+
arglist = [
301+
'--port', 'fake_port_id',
302+
]
303+
verifylist = [
304+
('port', 'fake_port_id'),
305+
]
306+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
307+
308+
columns, data = self.cmd.take_action(parsed_args)
309+
310+
self.network.ips.assert_called_once_with(**{
311+
'port_id': 'fake_port_id',
312+
})
313+
self.assertEqual(self.columns, columns)
314+
self.assertEqual(self.data, list(data))
315+
316+
def test_floating_ip_list_fixed_ip_address(self):
317+
arglist = [
318+
'--fixed-ip-address', self.floating_ips[0].fixed_ip_address,
319+
]
320+
verifylist = [
321+
('fixed_ip_address', self.floating_ips[0].fixed_ip_address),
322+
]
323+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
324+
325+
columns, data = self.cmd.take_action(parsed_args)
326+
327+
self.network.ips.assert_called_once_with(**{
328+
'fixed_ip_address': self.floating_ips[0].fixed_ip_address,
329+
})
271330
self.assertEqual(self.columns, columns)
272331
self.assertEqual(self.data, list(data))
273332

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add ``--port``, ``--fixed-ip-address``, ``--network``,
5+
options to ``floating ip list`` command
6+
[Bug `1614379 <https://bugs.launchpad.net/bugs/1614379>`_]

0 commit comments

Comments
 (0)