summaryrefslogtreecommitdiff
path: root/ceilometer/network
diff options
context:
space:
mode:
authorPradeep Kilambi <pkilambi@redhat.com>2016-01-18 18:38:00 -0500
committerPradeep Kilambi <pkilambi@redhat.com>2016-01-21 17:37:22 -0500
commit1f9f4e1072a5e5037b93734bafcc65e4211eb19f (patch)
tree1c30207e78ac07aec95274eca7fbf2c1895fe26e /ceilometer/network
parent62928318f84a0431b1b9e4dea83205835408c02c (diff)
downloadceilometer-1f9f4e1072a5e5037b93734bafcc65e4211eb19f.tar.gz
Fix ceilometer floatingip pollster
The existing floatingip pollster talks to nova api to get the floatingip data. There are limitations in nova api wrt returning this info for all the tenants as stated in the bug#1402514. This patch changes the pollster to use the neutron api to get this data instead. Considering this is a network related pollster and in most cases network networking manages the floating ips now, it makes sense to get this data from neutron. Closes-Bug: #1536338 Change-Id: I372e3a85b34f90ff9aba842d9598b468f90fe94f
Diffstat (limited to 'ceilometer/network')
-rw-r--r--ceilometer/network/floatingip.py85
1 files changed, 46 insertions, 39 deletions
diff --git a/ceilometer/network/floatingip.py b/ceilometer/network/floatingip.py
index 7258cf59..ebbc13a9 100644
--- a/ceilometer/network/floatingip.py
+++ b/ceilometer/network/floatingip.py
@@ -1,6 +1,6 @@
-#
+# Copyright 2016 Sungard Availability Services
+# Copyright 2016 Red Hat
# Copyright 2012 eNovance <licensing@enovance.com>
-#
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -21,53 +21,60 @@ from oslo_log import log
from oslo_utils import timeutils
from ceilometer.agent import plugin_base
-from ceilometer.i18n import _LI
-from ceilometer import nova_client
+from ceilometer.i18n import _LW
+from ceilometer import neutron_client
from ceilometer import sample
-
LOG = log.getLogger(__name__)
+cfg.CONF.import_group('service_types', 'ceilometer.neutron_client')
+
class FloatingIPPollster(plugin_base.PollsterBase):
- @staticmethod
- def _get_floating_ips(ksclient, endpoint):
- nv = nova_client.Client(
- auth=ksclient.session.auth,
- endpoint_override=endpoint)
- return nv.floating_ip_get_all()
+ STATUS = {
+ 'inactive': 0,
+ 'active': 1,
+ 'pending_create': 2,
+ }
- def _iter_floating_ips(self, ksclient, cache, endpoint):
- key = '%s-floating_ips' % endpoint
- if key not in cache:
- cache[key] = list(self._get_floating_ips(ksclient, endpoint))
- return iter(cache[key])
+ def __init__(self):
+ self.neutron_cli = neutron_client.Client()
@property
def default_discovery(self):
- return 'endpoint:%s' % cfg.CONF.service_types.nova
+ return 'endpoint:%s' % cfg.CONF.service_types.neutron
+
+ @staticmethod
+ def _form_metadata_for_fip(fip):
+ """Return a metadata dictionary for the fip usage data."""
+ metadata = {
+ 'router_id': fip.get("router_id"),
+ 'status': fip.get("status"),
+ 'floating_network_id': fip.get("floating_network_id"),
+ 'fixed_ip_address': fip.get("fixed_ip_address"),
+ 'port_id': fip.get("port_id"),
+ 'floating_ip_address': fip.get("floating_ip_address")
+ }
+ return metadata
def get_samples(self, manager, cache, resources):
- for endpoint in resources:
- for ip in self._iter_floating_ips(manager.keystone, cache,
- endpoint):
- LOG.info(_LI("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. In this fix, those attributes usage will be
- # removed temporarily. And they will be back after fix the
- # Nova bug 1174802.
- yield sample.Sample(
- name='ip.floating',
- type=sample.TYPE_GAUGE,
- unit='ip',
- volume=1,
- user_id=None,
- project_id=None,
- resource_id=ip.id,
- timestamp=timeutils.utcnow().isoformat(),
- resource_metadata={
- 'address': ip.ip,
- 'pool': ip.pool
- })
+
+ for fip in self.neutron_cli.fip_get_all():
+ status = self.STATUS.get(fip['status'].lower())
+ if status is None:
+ LOG.warn(_LW("Invalid status, skipping IP address %s") %
+ fip['floating_ip_address'])
+ continue
+ res_metadata = self._form_metadata_for_fip(fip)
+ yield sample.Sample(
+ name='ip.floating',
+ type=sample.TYPE_GAUGE,
+ unit='ip',
+ volume=status,
+ user_id=fip.get('user_id'),
+ project_id=fip['tenant_id'],
+ resource_id=fip['id'],
+ timestamp=timeutils.utcnow().isoformat(),
+ resource_metadata=res_metadata
+ )