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
This commit is contained in:
liu-sheng 2014-03-28 11:32:39 +08:00
parent 0586260407
commit 02328d3337
4 changed files with 26 additions and 8 deletions

View File

@ -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]

View File

@ -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')

View File

@ -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):
"""

View File

@ -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):