~tnurlygayanov/murano/reliase-0.1a

« back to all changes in this revision

Viewing changes to murano-api/muranoapi/openstack/common/notifier/rpc_notifier2.py

  • Committer: Timur Nurlygayanov
  • Date: 2013-05-30 22:18:42 UTC
  • Revision ID: tnulrygayanov@mirantis.com-20130530221842-8e7xd8e89e99n3xz
murano-0.1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 OpenStack LLC.
 
2
# All Rights Reserved.
 
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
 
 
16
'''messaging based notification driver, with message envelopes'''
 
17
 
 
18
from oslo.config import cfg
 
19
 
 
20
from muranoapi.openstack.common import context as req_context
 
21
from muranoapi.openstack.common.gettextutils import _
 
22
from muranoapi.openstack.common import log as logging
 
23
from muranoapi.openstack.common import rpc
 
24
 
 
25
LOG = logging.getLogger(__name__)
 
26
 
 
27
notification_topic_opt = cfg.ListOpt(
 
28
    'topics', default=['notifications', ],
 
29
    help='AMQP topic(s) used for openstack notifications')
 
30
 
 
31
opt_group = cfg.OptGroup(name='rpc_notifier2',
 
32
                         title='Options for rpc_notifier2')
 
33
 
 
34
CONF = cfg.CONF
 
35
CONF.register_group(opt_group)
 
36
CONF.register_opt(notification_topic_opt, opt_group)
 
37
 
 
38
 
 
39
def notify(context, message):
 
40
    """Sends a notification via RPC"""
 
41
    if not context:
 
42
        context = req_context.get_admin_context()
 
43
    priority = message.get('priority',
 
44
                           CONF.default_notification_level)
 
45
    priority = priority.lower()
 
46
    for topic in CONF.rpc_notifier2.topics:
 
47
        topic = '%s.%s' % (topic, priority)
 
48
        try:
 
49
            rpc.notify(context, topic, message, envelope=True)
 
50
        except Exception:
 
51
            LOG.exception(_("Could not send notification to %(topic)s. "
 
52
                            "Payload=%(message)s"), locals())