Update floating-ip pollster to use cache
Use the pollster cache to store the list of floating IPs. blueprint one-meter-per-plugin Change-Id: I05da484a3336a59f1ceab335028aa8149f636019 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
parent
4437fb5f0b
commit
df62b92191
@ -35,9 +35,17 @@ class FloatingIPPollster(plugin.CentralPollster):
|
||||
def get_counter_names():
|
||||
return ['ip.floating']
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def _get_floating_ips(self):
|
||||
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)
|
||||
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those
|
||||
# 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, {}))
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
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