From 02328d33373479b33f4fee8112d47c1ae29e8bd4 Mon Sep 17 00:00:00 2001 From: liu-sheng Date: Fri, 28 Mar 2014 11:32:39 +0800 Subject: [PATCH] Allow admin user to get all tenant's floating IPs When getting floatingips with Nova API, the results will be filtered with the 'tenant_id'. So, we can only get the floatingips belonging to the tenant of the current context. When ceilometer invokes novaclient to list floatingips, it will get an empty list because the tenant is 'service'. we should allow an admin user to index all tenants's floatingip by adding a parameter 'all_tenants'. This patch provides CLI support Change-Id: I35a2155401247d49017bf3c03341b082cb87750d Closes-bug: #1262124 --- novaclient/tests/v1_1/test_floating_ips.py | 11 +++++++++-- novaclient/tests/v1_1/test_shell.py | 4 ++++ novaclient/v1_1/floating_ips.py | 9 ++++++--- novaclient/v1_1/shell.py | 10 +++++++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/novaclient/tests/v1_1/test_floating_ips.py b/novaclient/tests/v1_1/test_floating_ips.py index 0b2313f51..5a9147fa0 100644 --- a/novaclient/tests/v1_1/test_floating_ips.py +++ b/novaclient/tests/v1_1/test_floating_ips.py @@ -25,9 +25,16 @@ cs = fakes.FakeClient() class FloatingIPsTest(utils.TestCase): def test_list_floating_ips(self): - fl = cs.floating_ips.list() + fips = cs.floating_ips.list() cs.assert_called('GET', '/os-floating-ips') - [self.assertIsInstance(f, floating_ips.FloatingIP) for f in fl] + for fip in fips: + self.assertIsInstance(fip, floating_ips.FloatingIP) + + def test_list_floating_ips_all_tenants(self): + fips = cs.floating_ips.list(all_tenants=True) + cs.assert_called('GET', '/os-floating-ips?all_tenants=1') + for fip in fips: + self.assertIsInstance(fip, floating_ips.FloatingIP) def test_delete_floating_ip(self): fl = cs.floating_ips.list()[0] diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index 58c50b64d..bfff2e34e 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -1039,6 +1039,10 @@ class ShellTest(utils.TestCase): self.run_command('floating-ip-list') self.assert_called('GET', '/os-floating-ips') + def test_floating_ip_list_all_tenants(self): + self.run_command('floating-ip-list --all-tenants') + self.assert_called('GET', '/os-floating-ips?all_tenants=1') + def test_floating_ip_create(self): self.run_command('floating-ip-create') self.assert_called('GET', '/os-floating-ips/1') diff --git a/novaclient/v1_1/floating_ips.py b/novaclient/v1_1/floating_ips.py index 25f5a7437..54979371f 100644 --- a/novaclient/v1_1/floating_ips.py +++ b/novaclient/v1_1/floating_ips.py @@ -28,11 +28,14 @@ class FloatingIP(base.Resource): class FloatingIPManager(base.ManagerWithFind): resource_class = FloatingIP - def list(self): + def list(self, all_tenants=False): """ - List floating ips for a tenant + List floating ips """ - return self._list("/os-floating-ips", "floating_ips") + url = '/os-floating-ips' + if all_tenants: + url += '?all_tenants=1' + return self._list(url, "floating_ips") def create(self, pool=None): """ diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index a2a50bbab..7b99f1ecf 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -2031,9 +2031,13 @@ def do_floating_ip_delete(cs, args): args.address) -def do_floating_ip_list(cs, _args): - """List floating ips for this tenant.""" - _print_floating_ip_list(cs.floating_ips.list()) +@utils.arg('--all-tenants', + action='store_true', + default=False, + help=_('Display floatingips from all tenants (Admin only).')) +def do_floating_ip_list(cs, args): + """List floating ips.""" + _print_floating_ip_list(cs.floating_ips.list(args.all_tenants)) def do_floating_ip_pool_list(cs, _args):