1
# Copyright 2013 Red Hat, Inc.
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
16
A temporary helper which emulates ceilometer.messaging.Notifier.
18
This helper method allows us to do the tedious porting to the new Notifier API
19
as a standalone commit so that the commit which switches us to ceilometer.messaging
20
is smaller and easier to review. This file will be removed as part of that
24
from oslo.config import cfg
26
from ceilometer.openstack.common.notifier import api as notifier_api
31
class Notifier(object):
33
def __init__(self, publisher_id):
34
super(Notifier, self).__init__()
35
self.publisher_id = publisher_id
39
def prepare(self, publisher_id=_marker):
40
ret = self.__class__(self.publisher_id)
41
if publisher_id is not self._marker:
42
ret.publisher_id = publisher_id
45
def _notify(self, ctxt, event_type, payload, priority):
46
notifier_api.notify(ctxt,
52
def audit(self, ctxt, event_type, payload):
53
# No audit in old notifier.
54
self._notify(ctxt, event_type, payload, 'INFO')
56
def debug(self, ctxt, event_type, payload):
57
self._notify(ctxt, event_type, payload, 'DEBUG')
59
def info(self, ctxt, event_type, payload):
60
self._notify(ctxt, event_type, payload, 'INFO')
62
def warn(self, ctxt, event_type, payload):
63
self._notify(ctxt, event_type, payload, 'WARN')
67
def error(self, ctxt, event_type, payload):
68
self._notify(ctxt, event_type, payload, 'ERROR')
70
def critical(self, ctxt, event_type, payload):
71
self._notify(ctxt, event_type, payload, 'CRITICAL')
74
def get_notifier(service=None, host=None, publisher_id=None):
76
publisher_id = "%s.%s" % (service, host or CONF.host)
77
return Notifier(publisher_id)