1 # Copyright 2011, OpenStack Foundation
2 # Copyright 2012, Red Hat, Inc.
3 # Copyright 2013 IBM Corp.
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
17 from oslo_config import cfg
18 from oslo_log import log as logging
21 from escalator import i18n
27 cfg.StrOpt('default_publisher_id', default="image.localhost",
28 help='Default publisher_id for outgoing notifications.'),
29 cfg.ListOpt('disabled_notifications', default=[],
30 help='List of disabled notifications. A notification can be '
31 'given either as a notification type to disable a single '
32 'event, or as a notification group prefix to disable all '
33 'events within a group. Example: if this config option '
34 'is set to ["image.create", "metadef_namespace"], then '
35 '"image.create" notification will not be sent after '
36 'image is created and none of the notifications for '
37 'metadefinition namespaces will be sent.'),
41 CONF.register_opts(notifier_opts)
43 LOG = logging.getLogger(__name__)
47 return oslo_messaging.get_transport(CONF)
50 class Notifier(object):
51 """Uses a notification strategy to send out messages about events."""
54 publisher_id = CONF.default_publisher_id
55 self._transport = get_transport()
56 self._notifier = oslo_messaging.Notifier(self._transport,
57 publisher_id=publisher_id)
59 def warn(self, event_type, payload):
60 self._notifier.warn({}, event_type, payload)
62 def info(self, event_type, payload):
63 self._notifier.info({}, event_type, payload)
65 def error(self, event_type, payload):
66 self._notifier.error({}, event_type, payload)