rdudyala | b086cf3 | 2016-08-11 00:07:45 -0400 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2012 New Dream Network, LLC (DreamHost) |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | """Handler for producing network counter messages from Neutron notification |
| 16 | events. |
| 17 | |
| 18 | """ |
| 19 | |
| 20 | import oslo_messaging |
| 21 | from oslo_config import cfg |
| 22 | |
| 23 | from ceilometer.agent import plugin_base |
| 24 | from oslo_log import log |
| 25 | from ceilometer import sample |
| 26 | |
| 27 | OPTS = [ |
| 28 | cfg.StrOpt('openstack_infra_service_control_exchange', |
| 29 | default='openstack_infra', |
| 30 | help="Exchange name for INFRA notifications."), |
| 31 | ] |
| 32 | |
| 33 | cfg.CONF.register_opts(OPTS) |
| 34 | |
| 35 | LOG = log.getLogger(__name__) |
| 36 | |
| 37 | |
| 38 | class OPENSTACK_INFRANotificationBase(plugin_base.NotificationBase): |
| 39 | |
| 40 | resource_name = None |
| 41 | |
| 42 | def get_targets(self,conf): |
| 43 | """Return a sequence of oslo.messaging.Target |
| 44 | This sequence is defining the exchange and topics to be connected for |
| 45 | this plugin. |
| 46 | """ |
| 47 | LOG.info("get_targets for OPENSTACK INFRA Notification Listener") |
| 48 | return [oslo_messaging.Target(topic=topic, |
| 49 | exchange=conf.openstack_infra_service_control_exchange) |
| 50 | for topic in self.get_notification_topics(conf)] |
| 51 | |
| 52 | class OPENSTACK_INFRANotification(OPENSTACK_INFRANotificationBase): |
| 53 | |
| 54 | resource_name = None |
| 55 | event_types = ['infra$'] |
| 56 | |
| 57 | def process_notification(self, message): |
| 58 | LOG.info('Received OPENSTACK INFRA notification: resource_id =%(resource_id)s' % {'resource_id': message['payload']['resource_id']}) |
| 59 | yield sample.Sample.from_notification( |
| 60 | name=message['payload']['counter_name'], |
| 61 | type=message['payload']['counter_type'], |
| 62 | unit=message['payload']['counter_unit'], |
| 63 | volume=message['payload']['counter_volume'], |
| 64 | user_id=message['payload']['user_id'], |
| 65 | project_id=message['payload']['project_id'], |
| 66 | resource_id=message['payload']['resource_id'], |
| 67 | message=message) |