From 2630e7a7eb682e3f70195ae3f1a0f5d82412ea05 Mon Sep 17 00:00:00 2001 From: Pradeep Kilambi Date: Tue, 22 Jul 2014 09:30:39 -0700 Subject: [PATCH] Follow up fixes to network services pollsters This is a follow up commit addressing comments around minor clean up, fix resources variable to set to empty list instead of None and others. Change-Id: Ied9edd356d59f0cdccde45040897018228df2d20 --- ceilometer/network/services/base.py | 4 +--- ceilometer/network/services/discovery.py | 27 +----------------------- ceilometer/network/services/fwaas.py | 12 ++++++++--- ceilometer/network/services/lbaas.py | 21 ++++++++++++------ ceilometer/network/services/vpnaas.py | 12 ++++++++--- ceilometer/neutron_client.py | 1 - 6 files changed, 35 insertions(+), 42 deletions(-) diff --git a/ceilometer/network/services/base.py b/ceilometer/network/services/base.py index 64f330131..61ae542c8 100644 --- a/ceilometer/network/services/base.py +++ b/ceilometer/network/services/base.py @@ -46,6 +46,4 @@ class BaseServicesPollster(plugin.PollsterBase): @staticmethod def get_status_id(value): status = value.lower() - if status not in STATUS: - return -1 - return STATUS[status] + return STATUS.get(status, -1) diff --git a/ceilometer/network/services/discovery.py b/ceilometer/network/services/discovery.py index 2924b590f..87693cff7 100644 --- a/ceilometer/network/services/discovery.py +++ b/ceilometer/network/services/discovery.py @@ -1,6 +1,5 @@ -# -*- encoding: utf-8 -*- # -# Copyright © 2014 Cisco Systems, Inc +# Copyright (c) 2014 Cisco Systems, Inc # # Author:Pradeep Kilambi # @@ -29,9 +28,6 @@ class _BaseServicesDiscovery(plugin.DiscoveryBase): class LBPoolsDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(LBPoolsDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -42,9 +38,6 @@ class LBPoolsDiscovery(_BaseServicesDiscovery): class LBVipsDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(LBVipsDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -55,9 +48,6 @@ class LBVipsDiscovery(_BaseServicesDiscovery): class LBMembersDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(LBMembersDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -68,9 +58,6 @@ class LBMembersDiscovery(_BaseServicesDiscovery): class LBHealthMonitorsDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(LBHealthMonitorsDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -80,9 +67,6 @@ class LBHealthMonitorsDiscovery(_BaseServicesDiscovery): class VPNServicesDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(VPNServicesDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -93,9 +77,6 @@ class VPNServicesDiscovery(_BaseServicesDiscovery): class IPSecConnectionsDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(IPSecConnectionsDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -105,9 +86,6 @@ class IPSecConnectionsDiscovery(_BaseServicesDiscovery): class FirewallDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(FirewallDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" @@ -118,9 +96,6 @@ class FirewallDiscovery(_BaseServicesDiscovery): class FirewallPolicyDiscovery(_BaseServicesDiscovery): - def __init__(self): - super(FirewallPolicyDiscovery, self).__init__() - def discover(self, param=None): """Discover resources to monitor.""" diff --git a/ceilometer/network/services/fwaas.py b/ceilometer/network/services/fwaas.py index 27ed88e9a..74967b7a2 100644 --- a/ceilometer/network/services/fwaas.py +++ b/ceilometer/network/services/fwaas.py @@ -16,6 +16,7 @@ # under the License. from ceilometer.network.services import base +from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log from ceilometer.openstack.common import timeutils from ceilometer import sample @@ -34,13 +35,16 @@ class FirewallPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for fw in resources: LOG.debug("Firewall : %s" % fw) status = self.get_status_id(fw['status']) if status == -1: # unknown status, skip this sample - LOG.warn("Unknown status %s received on firewall %s, " - "skipping sample" % (fw['status'], fw['id'])) + LOG.warn(_("Unknown status %(stat)s received on fw %(id)s," + "skipping sample") % {'stat': fw['status'], + 'id': fw['id']}) continue yield sample.Sample( @@ -57,7 +61,7 @@ class FirewallPollster(base.BaseServicesPollster): class FirewallPolicyPollster(base.BaseServicesPollster): - """Pollster to capture firewalls status samples.""" + """Pollster to capture firewall policy samples.""" FIELDS = ['name', 'description', @@ -68,6 +72,8 @@ class FirewallPolicyPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for fw in resources: LOG.debug("Firewall Policy: %s" % fw) diff --git a/ceilometer/network/services/lbaas.py b/ceilometer/network/services/lbaas.py index c92555d6b..278262260 100644 --- a/ceilometer/network/services/lbaas.py +++ b/ceilometer/network/services/lbaas.py @@ -49,13 +49,16 @@ class LBPoolPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for pool in resources: LOG.debug("Load Balancer Pool : %s" % pool) status = self.get_status_id(pool['status']) if status == -1: # unknown status, skip this sample - LOG.warn("Unknown status %s received on pool %s, " - "skipping sample" % (pool['status'], pool['id'])) + LOG.warn(_("Unknown status %(stat)s received on pool %(id)s, " + "skipping sample") % {'stat': pool['status'], + 'id': pool['id']}) continue yield sample.Sample( @@ -90,13 +93,16 @@ class LBVipPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for vip in resources: LOG.debug("Load Balancer Vip : %s" % vip) status = self.get_status_id(vip['status']) if status == -1: # unknown status, skip this sample - LOG.warn("Unknown status %s received on vip %s, " - "skipping sample" % (vip['status'], vip['id'])) + LOG.warn(_("Unknown status %(stat)s received on vip %(id)s, " + "skipping sample") % {'stat': vip['status'], + 'id': vip['id']}) continue yield sample.Sample( @@ -125,12 +131,15 @@ class LBMemberPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for member in resources: LOG.debug("Load Balancer Member : %s" % member) status = self.get_status_id(member['status']) if status == -1: - LOG.warn("Unknown status %s received on member %s, " - "skipping sample" % (member['status'], member['id'])) + LOG.warn(_("Unknown status %(stat)s received on member %(id)s," + "skipping sample") % {'stat': member['status'], + 'id': member['id']}) continue yield sample.Sample( name='network.services.lb.member', diff --git a/ceilometer/network/services/vpnaas.py b/ceilometer/network/services/vpnaas.py index 034c561a8..3547a6567 100644 --- a/ceilometer/network/services/vpnaas.py +++ b/ceilometer/network/services/vpnaas.py @@ -16,6 +16,7 @@ # under the License. from ceilometer.network.services import base +from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log from ceilometer.openstack.common import timeutils from ceilometer import sample @@ -35,13 +36,16 @@ class VPNServicesPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for vpn in resources: LOG.debug("VPN : %s" % vpn) status = self.get_status_id(vpn['status']) if status == -1: # unknown status, skip this sample - LOG.warn("Unknown status %s received on vpn %s, " - "skipping sample" % (vpn['status'], vpn['id'])) + LOG.warn(_("Unknown status %(stat)s received on vpn %(id)s," + "skipping sample") % {'stat': vpn['status'], + 'id': vpn['id']}) continue yield sample.Sample( @@ -58,7 +62,7 @@ class VPNServicesPollster(base.BaseServicesPollster): class IPSecConnectionsPollster(base.BaseServicesPollster): - """Pollster to capture VPN status samples.""" + """Pollster to capture vpn ipsec connections status samples.""" FIELDS = ['name', 'description', @@ -77,6 +81,8 @@ class IPSecConnectionsPollster(base.BaseServicesPollster): ] def get_samples(self, manager, cache, resources=None): + resources = resources or [] + for conn in resources: LOG.debug("IPSec Connection Info: %s" % conn) diff --git a/ceilometer/neutron_client.py b/ceilometer/neutron_client.py index c70aa6dd1..4c73b0e4f 100644 --- a/ceilometer/neutron_client.py +++ b/ceilometer/neutron_client.py @@ -79,7 +79,6 @@ class Client(object): @logged def pool_get_all(self): - LOG.debug("NEUTRON POOL GET") resp = self.client.list_pools() return resp.get('pools')