Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain 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, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Srikanth Vavilapalli | b66304b | 2017-01-19 20:25:19 +0000 | [diff] [blame] | 17 | # |
| 18 | # Copyright 2012 New Dream Network, LLC (DreamHost) |
| 19 | # |
| 20 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | # not use this file except in compliance with the License. You may obtain |
| 22 | # a copy of the License at |
| 23 | # |
| 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | # |
| 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 29 | # License for the specific language governing permissions and limitations |
| 30 | # under the License. |
| 31 | """Handler for producing network counter messages from Neutron notification |
| 32 | events. |
| 33 | |
| 34 | """ |
| 35 | |
| 36 | import oslo_messaging |
| 37 | from oslo_config import cfg |
| 38 | |
| 39 | from ceilometer.agent import plugin_base |
| 40 | from oslo_log import log |
| 41 | from ceilometer import sample |
| 42 | |
| 43 | OPTS = [ |
| 44 | cfg.StrOpt('cord_control_exchange', |
| 45 | default='cord', |
| 46 | help="Exchange name for CORD related notifications."), |
| 47 | ] |
| 48 | |
| 49 | cfg.CONF.register_opts(OPTS) |
| 50 | |
| 51 | LOG = log.getLogger(__name__) |
| 52 | |
| 53 | |
| 54 | class CORDNotificationBase(plugin_base.NotificationBase): |
| 55 | |
| 56 | resource_name = None |
| 57 | event_types = ['cord*'] |
| 58 | |
| 59 | def get_targets(self,conf): |
| 60 | """Return a sequence of oslo.messaging.Target |
| 61 | |
| 62 | This sequence is defining the exchange and topics to be connected for |
| 63 | this plugin. |
| 64 | """ |
| 65 | LOG.info("get_targets for CORD Notification Listener") |
| 66 | return [oslo_messaging.Target(topic=topic, |
| 67 | exchange=conf.cord_control_exchange) |
| 68 | for topic in self.get_notification_topics(conf)] |
| 69 | |
| 70 | def process_notification(self, message): |
| 71 | LOG.info('Received CORD notification') |
| 72 | if 'counter_type' not in message['payload']: |
| 73 | meter_type = sample.TYPE_GAUGE |
| 74 | else: |
| 75 | meter_type = sample.TYPE_GAUGE if 'gauge' in message['payload']['counter_type'].lower() else sample.TYPE_DELTA if 'delta' in message['payload']['counter_type'].lower() else sample.TYPE_GAUGE |
| 76 | |
| 77 | yield sample.Sample.from_notification( |
| 78 | name=message['payload']['counter_name'], |
| 79 | type=meter_type, |
| 80 | unit=message['payload']['counter_unit'], |
| 81 | volume=message['payload']['counter_volume'], |
| 82 | user_id=message['payload']['user_id'], |
| 83 | project_id=message['payload']['tenant_id'], |
| 84 | resource_id=message['payload']['resource_id'], |
| 85 | message=message) |