本文整理汇总了Python中oslo_messaging.Notifier方法的典型用法代码示例。如果您正苦于以下问题:Python oslo_messaging.Notifier方法的具体用法?Python oslo_messaging.Notifier怎么用?Python oslo_messaging.Notifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_messaging
的用法示例。
在下文中一共展示了oslo_messaging.Notifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def init(conf):
global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER
exmods = get_allowed_exmods()
TRANSPORT = messaging.get_rpc_transport(conf,
allowed_remote_exmods=exmods)
NOTIFICATION_TRANSPORT = messaging.get_notification_transport(
conf,
allowed_remote_exmods=exmods)
if utils.notifications_enabled(conf):
json_serializer = messaging.JsonPayloadSerializer()
serializer = RequestContextSerializer(json_serializer)
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)
else:
NOTIFIER = utils.DO_NOTHING
示例2: __init__
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def __init__(self, ):
self.oslo_notifiers = {}
try:
notifier_plugins = CONF.notifiers
LOG.debug('notifier_plugins: %s', notifier_plugins)
if not notifier_plugins:
LOG.info('Evaluator Notifier is disabled')
return
topic_prefix = \
CONF.evaluator_actions.evaluator_notification_topic_prefix
for notifier in notifier_plugins:
LOG.debug('Adding evaluator notifier %s', notifier)
self.oslo_notifiers[notifier] = oslo_messaging.Notifier(
get_transport(),
driver='messagingv2',
publisher_id='vitrage.evaluator',
topics=[topic_prefix + '.' + notifier])
except Exception:
LOG.exception('Evaluator Notifier - missing configuration')
示例3: _get_topics
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def _get_topics(self):
topics = []
try:
notifier_topic = CONF.entity_graph.notifier_topic
notifier_plugins = CONF.notifiers
if notifier_topic and notifier_plugins:
topics.append(notifier_topic)
except Exception:
LOG.exception('Graph Notifier - missing configuration')
try:
machine_learning_topic = \
CONF.machine_learning.machine_learning_topic
machine_learning_plugins = CONF.machine_learning.plugins
if machine_learning_topic and machine_learning_plugins:
topics.append(machine_learning_topic)
except Exception:
LOG.info('Machine Learning - missing configuration')
return topics
示例4: setUp
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def setUp(self):
super(TestActionNotification, self).setUp()
p_get_notifier = mock.patch.object(rpc, 'get_notifier')
m_get_notifier = p_get_notifier.start()
self.addCleanup(p_get_notifier.stop)
self.m_notifier = mock.Mock(spec=om.Notifier)
def fake_get_notifier(publisher_id):
self.m_notifier.publisher_id = publisher_id
return self.m_notifier
m_get_notifier.side_effect = fake_get_notifier
self.goal = utils.create_test_goal(mock.Mock())
self.strategy = utils.create_test_strategy(mock.Mock())
self.audit = utils.create_test_audit(mock.Mock(),
strategy_id=self.strategy.id)
self.action_plan = utils.create_test_action_plan(mock.Mock())
示例5: test_batch_event_listener
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def test_batch_event_listener(self, mocked):
msg_notifier = oslo_messaging.Notifier(
self.transport, topics=['alarm.all'], driver='messaging',
publisher_id='test-publisher')
received_events = []
mocked.side_effect = lambda msg: received_events.append(msg)
event1 = {'event_type': 'compute.instance.update',
'traits': ['foo', 'bar'],
'message_id': '20d03d17-4aba-4900-a179-dba1281a3451',
'generated': '2016-04-23T06:50:21.622739'}
event2 = {'event_type': 'compute.instance.update',
'traits': ['foo', 'bar'],
'message_id': '20d03d17-4aba-4900-a179-dba1281a3452',
'generated': '2016-04-23T06:50:23.622739'}
msg_notifier.sample({}, 'event', event1)
msg_notifier.sample({}, 'event', event2)
svc = event.EventAlarmEvaluationService(0, self.CONF)
self.addCleanup(svc.terminate)
time.sleep(1)
self.assertEqual(1, len(received_events))
self.assertEqual(2, len(received_events[0]))
示例6: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def init(conf):
global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER
exmods = get_allowed_exmods()
TRANSPORT = messaging.get_rpc_transport(conf,
allowed_remote_exmods=exmods)
NOTIFICATION_TRANSPORT = messaging.get_notification_transport(
conf,
allowed_remote_exmods=exmods)
# get_notification_transport has loaded oslo_messaging_notifications config
# group, so we can now check if notifications are actually enabled.
if utils.notifications_enabled(conf):
json_serializer = messaging.JsonPayloadSerializer()
serializer = RequestContextSerializer(json_serializer)
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)
else:
NOTIFIER = utils.DO_NOTHING
示例7: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def init(conf, rpc_ext_mods=None):
"""Initialize the global RPC objects.
:param conf: The oslo conf to use for initialization.
:param rpc_ext_mods: Exception modules to expose via RPC.
:returns: None.
"""
global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER
if rpc_ext_mods is None:
rpc_ext_mods = _DFT_EXMODS
else:
rpc_ext_mods = list(set(rpc_ext_mods + _DFT_EXMODS))
TRANSPORT = oslo_messaging.get_rpc_transport(
conf, allowed_remote_exmods=rpc_ext_mods)
NOTIFICATION_TRANSPORT = oslo_messaging.get_notification_transport(
conf, allowed_remote_exmods=rpc_ext_mods)
serializer = RequestContextSerializer()
NOTIFIER = oslo_messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)
示例8: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def init(conf):
global TRANSPORT, NOTIFIER, NOTIFICATION_TRANSPORT
exmods = get_allowed_exmods()
TRANSPORT = create_transport(get_transport_url())
NOTIFICATION_TRANSPORT = messaging.get_notification_transport(
conf, allowed_remote_exmods=exmods)
serializer = RequestContextSerializer(JsonPayloadSerializer())
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)
示例9: __init__
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def __init__(self):
publisher_id = CONF.default_publisher_id
self._transport = get_transport()
self._notifier = oslo_messaging.Notifier(self._transport,
publisher_id=publisher_id)
示例10: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def init(conf):
global TRANSPORT, NOTIFIER
exmods = get_allowed_exmods()
TRANSPORT = messaging.get_rpc_transport(conf,
allowed_remote_exmods=exmods)
serializer = RequestContextSerializer(JsonPayloadSerializer())
NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer)
示例11: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def init(conf):
global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER
exmods = get_allowed_exmods()
TRANSPORT = create_transport(get_transport_url())
NOTIFICATION_TRANSPORT = messaging.get_notification_transport(
conf, allowed_remote_exmods=exmods)
serializer = RequestContextSerializer(JsonPayloadSerializer())
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer,
topics=['versioned_notifications'])
示例12: __init__
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def __init__(self, worker_id):
super(StressNotificationsService, self).__init__(worker_id)
self.oslo_notifier = None
topics = CONF.datasources.notification_topics
self.oslo_notifier = oslo_messaging.Notifier(
get_transport(),
driver='messagingv2',
publisher_id='vitrage.stress',
topics=topics)
self.periodic = periodics.PeriodicWorker.create(
[], executor_factory=lambda: ThreadPoolExecutor(max_workers=10))
示例13: __init__
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def __init__(self, publisher_id, topics):
transport = get_transport()
self.notifier = oslo_msg.Notifier(
transport,
driver='messagingv2',
publisher_id=publisher_id,
topics=topics)
示例14: notify
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def notify(self, event_type, data):
LOG.debug('notify : ' + event_type + ' ' + str(data))
if self.notifier:
try:
self.notifier.info({}, event_type, data)
except Exception:
LOG.exception('Notifier cannot notify.')
else:
LOG.error('Notifier cannot notify')
示例15: _init_oslo_notifier
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import Notifier [as 别名]
def _init_oslo_notifier(self):
self.oslo_notifier = None
try:
self.publisher = 'vitrage-snmp-parsing'
self.oslo_notifier = oslo_messaging.Notifier(
get_transport(),
driver='messagingv2',
publisher_id=self.publisher,
topics=['vitrage_notifications'])
except Exception:
LOG.exception('Failed to initialize oslo notifier')