1
# Copyright 2011 OpenStack LLC.
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
16
from nova import flags
17
from nova.openstack.common import cfg
18
from nova.openstack.common import importutils
19
from nova.openstack.common import log as logging
22
list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers',
23
default=['nova.notifier.no_op_notifier'],
24
help='List of drivers to send notifications')
27
FLAGS.register_opt(list_notifier_drivers_opt)
29
LOG = logging.getLogger(__name__)
34
class ImportFailureNotifier(object):
35
"""Noisily re-raises some exception over-and-over when notify is called."""
37
def __init__(self, exception):
38
self.exception = exception
40
def notify(self, context, message):
45
"""Instantiates and returns drivers based on the flag values."""
49
for notification_driver in FLAGS.list_notifier_drivers:
51
drivers.append(importutils.import_module(notification_driver))
52
except ImportError as e:
53
drivers.append(ImportFailureNotifier(e))
57
def notify(context, message):
58
"""Passes notification to multiple notifiers in a list."""
59
for driver in _get_drivers():
61
driver.notify(context, message)
62
except Exception as e:
63
LOG.exception(_("Problem '%(e)s' attempting to send to "
64
"notification driver %(driver)s."), locals())
68
"""Used by unit tests to reset the drivers."""