Skip to content

Commit 01c1b1e

Browse files
committed
network: Allow multiple FIP filter opts
This is allowed by the neutron API. Allow it in OSC. Change-Id: I7642ecd686d11c5af9e11cc80896243e853e33f3 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 5e1fc3d commit 01c1b1e

File tree

3 files changed

+69
-35
lines changed

3 files changed

+69
-35
lines changed

openstackclient/network/v2/floating_ip.py

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -243,18 +243,26 @@ def update_parser_network(self, parser):
243243
parser.add_argument(
244244
'--network',
245245
metavar='<network>',
246+
dest='networks',
247+
action='append',
246248
help=self.enhance_help_neutron(
247249
_(
248-
"List floating IP(s) according to "
249-
"given network (name or ID)"
250+
"List floating IP(s) according to given network "
251+
"(name or ID) "
252+
"(repeat option to fiter on multiple networks)"
250253
)
251254
),
252255
)
253256
parser.add_argument(
254257
'--port',
255258
metavar='<port>',
259+
dest='ports',
260+
action='append',
256261
help=self.enhance_help_neutron(
257-
_("List floating IP(s) according to given port (name or ID)")
262+
_(
263+
"List floating IP(s) according to given port (name or ID) "
264+
"(repeat option to fiter on multiple ports)"
265+
)
258266
),
259267
)
260268
parser.add_argument(
@@ -271,14 +279,6 @@ def update_parser_network(self, parser):
271279
_("List floating IP(s) according to given floating IP address")
272280
),
273281
)
274-
parser.add_argument(
275-
'--long',
276-
action='store_true',
277-
default=False,
278-
help=self.enhance_help_neutron(
279-
_("List additional fields in output")
280-
),
281-
)
282282
parser.add_argument(
283283
'--status',
284284
metavar='<status>',
@@ -295,22 +295,36 @@ def update_parser_network(self, parser):
295295
metavar='<project>',
296296
help=self.enhance_help_neutron(
297297
_(
298-
"List floating IP(s) according to given project (name or "
299-
"ID)"
298+
"List floating IP(s) according to given project "
299+
"(name or ID) "
300300
)
301301
),
302302
)
303303
identity_common.add_project_domain_option_to_parser(parser)
304304
parser.add_argument(
305305
'--router',
306306
metavar='<router>',
307+
dest='routers',
308+
action='append',
307309
help=self.enhance_help_neutron(
308-
_("List floating IP(s) according to given router (name or ID)")
310+
_(
311+
"List floating IP(s) according to given router "
312+
"(name or ID) "
313+
"(repeat option to fiter on multiple routers)"
314+
)
309315
),
310316
)
311317
_tag.add_tag_filtering_option_to_parser(
312318
parser, _('floating IP'), enhance_help=self.enhance_help_neutron
313319
)
320+
parser.add_argument(
321+
'--long',
322+
action='store_true',
323+
default=False,
324+
help=self.enhance_help_neutron(
325+
_("List additional fields in output")
326+
),
327+
)
314328

315329
return parser
316330

@@ -354,34 +368,49 @@ def take_action_network(self, client, parsed_args):
354368

355369
query = {}
356370

357-
if parsed_args.network is not None:
358-
network = network_client.find_network(
359-
parsed_args.network, ignore_missing=False
360-
)
361-
query['floating_network_id'] = network.id
362-
if parsed_args.port is not None:
363-
port = network_client.find_port(
364-
parsed_args.port, ignore_missing=False
365-
)
366-
query['port_id'] = port.id
371+
if parsed_args.networks is not None:
372+
network_ids = []
373+
for network in parsed_args.networks:
374+
network_id = network_client.find_network(
375+
network, ignore_missing=False
376+
).id
377+
network_ids.append(network_id)
378+
query['floating_network_id'] = network_ids
379+
380+
if parsed_args.ports is not None:
381+
port_ids = []
382+
for port in parsed_args.ports:
383+
port_id = network_client.find_port(
384+
port, ignore_missing=False
385+
).id
386+
port_ids.append(port_id)
387+
query['port_id'] = port_ids
388+
367389
if parsed_args.fixed_ip_address is not None:
368390
query['fixed_ip_address'] = parsed_args.fixed_ip_address
391+
369392
if parsed_args.floating_ip_address is not None:
370393
query['floating_ip_address'] = parsed_args.floating_ip_address
394+
371395
if parsed_args.status:
372396
query['status'] = parsed_args.status
397+
373398
if parsed_args.project is not None:
374399
project = identity_common.find_project(
375400
identity_client,
376401
parsed_args.project,
377402
parsed_args.project_domain,
378403
)
379404
query['project_id'] = project.id
380-
if parsed_args.router is not None:
381-
router = network_client.find_router(
382-
parsed_args.router, ignore_missing=False
383-
)
384-
query['router_id'] = router.id
405+
406+
if parsed_args.routers is not None:
407+
router_ids = []
408+
for router in parsed_args.routers:
409+
router_id = network_client.find_router(
410+
router, ignore_missing=False
411+
).id
412+
router_ids.append(router_id)
413+
query['router_id'] = router_ids
385414

386415
_tag.get_tag_filtering_args(parsed_args, query)
387416

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,15 @@ def test_floating_ip_list_network(self):
499499
'fake_network_id',
500500
]
501501
verifylist = [
502-
('network', 'fake_network_id'),
502+
('networks', ['fake_network_id']),
503503
]
504504
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
505505

506506
columns, data = self.cmd.take_action(parsed_args)
507507

508508
self.network_client.ips.assert_called_once_with(
509509
**{
510-
'floating_network_id': 'fake_network_id',
510+
'floating_network_id': ['fake_network_id'],
511511
}
512512
)
513513
self.assertEqual(self.columns, columns)
@@ -519,15 +519,15 @@ def test_floating_ip_list_port(self):
519519
'fake_port_id',
520520
]
521521
verifylist = [
522-
('port', 'fake_port_id'),
522+
('ports', ['fake_port_id']),
523523
]
524524
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
525525

526526
columns, data = self.cmd.take_action(parsed_args)
527527

528528
self.network_client.ips.assert_called_once_with(
529529
**{
530-
'port_id': 'fake_port_id',
530+
'port_id': ['fake_port_id'],
531531
}
532532
)
533533
self.assertEqual(self.columns, columns)
@@ -660,15 +660,15 @@ def test_floating_ip_list_router(self):
660660
'--long',
661661
]
662662
verifylist = [
663-
('router', 'fake_router_id'),
663+
('routers', ['fake_router_id']),
664664
]
665665
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
666666

667667
columns, data = self.cmd.take_action(parsed_args)
668668

669669
self.network_client.ips.assert_called_once_with(
670670
**{
671-
'router_id': 'fake_router_id',
671+
'router_id': ['fake_router_id'],
672672
}
673673
)
674674
self.assertEqual(self.columns_long, columns)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
The ``--network``, ``--port``, and ``--router`` options of the ``floating
5+
ip list`` command can now be specified multiple times.

0 commit comments

Comments
 (0)