~ubuntu-branches/ubuntu/vivid/ceilometer/vivid-proposed

« back to all changes in this revision

Viewing changes to ceilometer/network/notifications.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-06-13 13:20:35 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20140613132035-42ibzh8j7ww2q31i
Tags: 2014.2~b1-0ubuntu1
* New upstream release.
* debian/control: Open up juno release
* debian/patches/fix-requirements.patch: Refreshed.
* debian/rules: Patch the ceilometer.conf.sample directly since
  the configuration files are generated by a tool.
* debian/ceilometer-common.install: Drop sources.json.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
1
#
3
 
# Copyright © 2012 New Dream Network, LLC (DreamHost)
 
2
# Copyright 2012 New Dream Network, LLC (DreamHost)
4
3
#
5
4
# Author: Julien Danjou <julien@danjou.info>
6
5
#
19
18
   events.
20
19
 
21
20
"""
 
21
import copy
22
22
 
23
23
from oslo.config import cfg
 
24
import oslo.messaging
24
25
 
25
 
from ceilometer.openstack.common.gettextutils import _  # noqa
 
26
from ceilometer.openstack.common.gettextutils import _
26
27
from ceilometer.openstack.common import log
27
28
from ceilometer import plugin
28
29
from ceilometer import sample
63
64
        ]
64
65
 
65
66
    @staticmethod
66
 
    def get_exchange_topics(conf):
67
 
        """Return a sequence of ExchangeTopics defining the exchange and topics
68
 
        to be connected for this plugin.
69
 
 
 
67
    def get_targets(conf):
 
68
        """Return a sequence of oslo.messaging.Target defining the exchange and
 
69
        topics to be connected for this plugin.
70
70
        """
71
 
        return [
72
 
            plugin.ExchangeTopics(
73
 
                exchange=conf.neutron_control_exchange,
74
 
                topics=set(topic + ".info"
75
 
                           for topic in conf.notification_topics)),
76
 
        ]
 
71
        return [oslo.messaging.Target(topic=topic,
 
72
                                      exchange=conf.neutron_control_exchange)
 
73
                for topic in conf.notification_topics]
77
74
 
78
75
    def process_notification(self, message):
79
76
        LOG.info(_('network notification %r') % message)
80
 
        message['payload'] = message['payload'][self.resource_name]
81
77
        counter_name = getattr(self, 'counter_name', self.resource_name)
82
78
        unit_value = getattr(self, 'unit', self.resource_name)
83
79
 
84
 
        yield sample.Sample.from_notification(
85
 
            name=counter_name,
86
 
            type=sample.TYPE_GAUGE,
87
 
            unit=unit_value,
88
 
            volume=1,
89
 
            user_id=message['_context_user_id'],
90
 
            project_id=message['_context_tenant_id'],
91
 
            resource_id=message['payload']['id'],
92
 
            message=message)
93
 
 
94
 
        event_type_split = message['event_type'].split('.')
95
 
        if len(event_type_split) > 2:
 
80
        payload = message['payload'].get(self.resource_name)
 
81
        payloads = message['payload'].get(self.resource_name + 's')
 
82
        payload_list = copy.copy([payload] if payload else payloads)
 
83
        for p in payload_list:
 
84
            message['payload'] = p
96
85
            yield sample.Sample.from_notification(
97
 
                name=counter_name
98
 
                + "." + event_type_split[1],
99
 
                type=sample.TYPE_DELTA,
 
86
                name=counter_name,
 
87
                type=sample.TYPE_GAUGE,
100
88
                unit=unit_value,
101
89
                volume=1,
102
90
                user_id=message['_context_user_id'],
103
91
                project_id=message['_context_tenant_id'],
104
92
                resource_id=message['payload']['id'],
105
93
                message=message)
 
94
            event_type_split = message['event_type'].split('.')
 
95
            if len(event_type_split) > 2:
 
96
                yield sample.Sample.from_notification(
 
97
                    name=counter_name
 
98
                    + "." + event_type_split[1],
 
99
                    type=sample.TYPE_DELTA,
 
100
                    unit=unit_value,
 
101
                    volume=1,
 
102
                    user_id=message['_context_user_id'],
 
103
                    project_id=message['_context_tenant_id'],
 
104
                    resource_id=message['payload']['id'],
 
105
                    message=message)
106
106
 
107
107
 
108
108
class Network(NetworkNotificationBase):