blob: a1f3173bf07caa6c219fc685a21919c55bfac841 [file] [log] [blame]
rdudyalab086cf32016-08-11 00:07:45 -04001#
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
20import oslo_messaging
21from oslo_config import cfg
22
23from ceilometer.agent import plugin_base
24from oslo_log import log
25from ceilometer import sample
26
27OPTS = [
28 cfg.StrOpt('voltservice_control_exchange',
29 default='voltlistener',
30 help="Exchange name for VOLT notifications."),
31]
32
33cfg.CONF.register_opts(OPTS)
34
35LOG = log.getLogger(__name__)
36
37
38class VOLTNotificationBase(plugin_base.NotificationBase):
39
40 resource_name = None
41
42 def get_targets(self,conf):
43 """Return a sequence of oslo.messaging.Target
44
45 This sequence is defining the exchange and topics to be connected for
46 this plugin.
47 """
48 LOG.info("SRIKANTH: get_targets for VOLT Notification Listener")
49 return [oslo_messaging.Target(topic=topic,
50 exchange=conf.voltservice_control_exchange)
51 for topic in self.get_notification_topics(conf)]
52
53class VOLTDeviceNotification(VOLTNotificationBase):
54 resource_name = 'volt.device'
55 event_types = ['volt.device','volt.device.disconnect']
56
57 def process_notification(self, message):
58 LOG.info('SRIKANTH: Received VOLT notification')
59 yield sample.Sample.from_notification(
60 name=message['event_type'],
61 type=sample.TYPE_GAUGE,
62 unit='olt',
63 volume=1,
64 user_id=message['payload']['user_id'],
65 project_id=message['payload']['project_id'],
66 resource_id=message['payload']['id'],
67 message=message)
68
69class VOLTDeviceSubscriberNotification(VOLTNotificationBase):
70 resource_name = 'volt.device.subscriber'
71 event_types = ['volt.device.subscriber','volt.device.subscriber.unregister']
72
73 def process_notification(self, message):
74 LOG.info('SRIKANTH: Received VOLT notification')
75 resource_id = message['payload']['id'] + '-' + message['payload']['subscriber_id']
76 yield sample.Sample.from_notification(
77 name=message['event_type'],
78 type=sample.TYPE_GAUGE,
79 unit='subscriber',
80 volume=1,
81 user_id=message['payload']['user_id'],
82 project_id=message['payload']['project_id'],
83 resource_id=resource_id,
84 message=message)
85
86