# License for the specific language governing permissions and limitations
# under the License.
+import socket
import uuid
from oslo.config import cfg
from cinder.openstack.common import context
-from cinder.openstack.common.gettextutils import _
+from cinder.openstack.common.gettextutils import _ # noqa
from cinder.openstack.common import importutils
from cinder.openstack.common import jsonutils
from cinder.openstack.common import log as logging
default='INFO',
help='Default notification level for outgoing notifications'),
cfg.StrOpt('default_publisher_id',
- default='$host',
+ default=None,
help='Default publisher_id for outgoing notifications'),
]
ctxt = context.get_context_from_function_and_args(fn, args, kwarg)
notify(ctxt,
- CONF.default_publisher_id,
+ CONF.default_publisher_id or socket.gethostname(),
name,
CONF.default_notification_level,
body)
def publisher_id(service, host=None):
if not host:
- host = CONF.host
+ try:
+ host = CONF.host
+ except AttributeError:
+ host = CONF.default_publisher_id or socket.gethostname()
return "%s.%s" % (service, host)
if _drivers is None:
_drivers = {}
for notification_driver in CONF.notification_driver:
- add_driver(notification_driver)
-
+ try:
+ driver = importutils.import_module(notification_driver)
+ _drivers[notification_driver] = driver
+ except ImportError:
+ LOG.exception(_("Failed to load notifier %s. "
+ "These notifications will not be sent.") %
+ notification_driver)
return _drivers.values()
-def add_driver(notification_driver):
- """Add a notification driver at runtime."""
- # Make sure the driver list is initialized.
- _get_drivers()
- if isinstance(notification_driver, basestring):
- # Load and add
- try:
- driver = importutils.import_module(notification_driver)
- _drivers[notification_driver] = driver
- except ImportError:
- LOG.exception(_("Failed to load notifier %s. "
- "These notifications will not be sent.") %
- notification_driver)
- else:
- # Driver is already loaded; just add the object.
- _drivers[notification_driver] = notification_driver
-
-
def _reset_drivers():
"""Used by unit tests to reset the drivers."""
global _drivers
from oslo.config import cfg
from cinder.openstack.common import context as req_context
-from cinder.openstack.common.gettextutils import _
+from cinder.openstack.common.gettextutils import _ # noqa
from cinder.openstack.common import log as logging
from cinder.openstack.common import rpc
notification_topic_opt = cfg.ListOpt(
'notification_topics', default=['notifications', ],
- help='AMQP topic used for openstack notifications')
+ help='AMQP topic used for OpenStack notifications')
CONF = cfg.CONF
CONF.register_opt(notification_topic_opt)
from oslo.config import cfg
from cinder.openstack.common import context as req_context
-from cinder.openstack.common.gettextutils import _
+from cinder.openstack.common.gettextutils import _ # noqa
from cinder.openstack.common import log as logging
from cinder.openstack.common import rpc
notification_topic_opt = cfg.ListOpt(
'topics', default=['notifications', ],
- help='AMQP topic(s) used for openstack notifications')
+ help='AMQP topic(s) used for OpenStack notifications')
opt_group = cfg.OptGroup(name='rpc_notifier2',
title='Options for rpc_notifier2')
# Options defined in cinder.openstack.common.notifier.rpc_notifier
#
-# AMQP topic used for openstack notifications (list value)
+# AMQP topic used for OpenStack notifications (list value)
#notification_topics=notifications
# Options defined in cinder.openstack.common.notifier.rpc_notifier2
#
-# AMQP topic(s) used for openstack notifications (list value)
+# AMQP topic(s) used for OpenStack notifications (list value)
#topics=notifications