Merge "Update floating-ip pollster to use cache"
This commit is contained in:
commit
8122de74c8
@ -35,9 +35,17 @@ class FloatingIPPollster(plugin.CentralPollster):
|
|||||||
def get_counter_names():
|
def get_counter_names():
|
||||||
return ['ip.floating']
|
return ['ip.floating']
|
||||||
|
|
||||||
def get_counters(self, manager, cache):
|
def _get_floating_ips(self):
|
||||||
nv = nova_client.Client()
|
nv = nova_client.Client()
|
||||||
for ip in nv.floating_ip_get_all():
|
return nv.floating_ip_get_all()
|
||||||
|
|
||||||
|
def _iter_floating_ips(self, cache):
|
||||||
|
if 'floating_ips' not in cache:
|
||||||
|
cache['floating_ips'] = list(self._get_floating_ips())
|
||||||
|
return iter(cache['floating_ips'])
|
||||||
|
|
||||||
|
def get_counters(self, manager, cache):
|
||||||
|
for ip in self._iter_floating_ips(cache):
|
||||||
self.LOG.info("FLOATING IP USAGE: %s" % ip.ip)
|
self.LOG.info("FLOATING IP USAGE: %s" % ip.ip)
|
||||||
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those
|
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those
|
||||||
# attributes were used by Ceilometer, such as project id, host.
|
# attributes were used by Ceilometer, such as project id, host.
|
||||||
|
@ -85,3 +85,9 @@ class TestFloatingIPPollster(base.TestCase):
|
|||||||
counters = list(self.pollster.get_counters(self.manager, {}))
|
counters = list(self.pollster.get_counters(self.manager, {}))
|
||||||
self.assertEqual(set([c.name for c in counters]),
|
self.assertEqual(set([c.name for c in counters]),
|
||||||
set(self.pollster.get_counter_names()))
|
set(self.pollster.get_counter_names()))
|
||||||
|
|
||||||
|
def test_get_counters_cached(self):
|
||||||
|
cache = {}
|
||||||
|
cache['floating_ips'] = self.faux_get_ips(None)[:2]
|
||||||
|
counters = list(self.pollster.get_counters(self.manager, cache))
|
||||||
|
self.assertEqual(len(counters), 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user