本文整理汇总了Python中oslo_messaging.get_notification_transport方法的典型用法代码示例。如果您正苦于以下问题:Python oslo_messaging.get_notification_transport方法的具体用法?Python oslo_messaging.get_notification_transport怎么用?Python oslo_messaging.get_notification_transport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_messaging
的用法示例。
在下文中一共展示了oslo_messaging.get_notification_transport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def main():
if len(sys.argv) < 2:
print("Supply an exchange")
sys.exit(0)
exchange = sys.argv[1]
pool = sys.argv[2] if len(sys.argv) > 2 else None
transport = oslo_messaging.get_notification_transport(
cfg.CONF,
url='rabbit://%s:%s@%s' % (username, password, host))
targets = [oslo_messaging.Target(topic=topic, exchange=exchange)]
endpoints = [EP()]
oslo_listener = oslo_messaging.get_notification_listener(
transport, targets, endpoints, pool=pool, executor='threading')
try:
print("Started")
oslo_listener.start()
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Stopping")
oslo_listener.stop()
oslo_listener.wait()
示例2: start
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def start(self):
super(ListenerService, self).start()
transport = oslo_messaging.get_notification_transport(CONF)
targets = [
oslo_messaging.Target(topic=pl_topic, exchange=pl_exchange)
for pl_topic, pl_exchange in self.topics_exchanges_set
]
endpoints = [
NotificationEndpoint(self.plugins, PipelineManager(self.plugins))
]
listener = oslo_messaging.get_notification_listener(
transport,
targets,
endpoints,
executor='threading',
pool=CONF.listener.notifications_pool)
listener.start()
self.listeners.append(listener)
示例3: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [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
示例4: get_transport
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def get_transport(url=None, optional=False, cache=True, rpc=False):
"""Initialise the oslo_messaging layer."""
global TRANSPORTS, DEFAULT_URL
cache_key = url or DEFAULT_URL + '_rpc' if rpc else ''
transport = TRANSPORTS.get(cache_key)
if not transport or not cache:
try:
if rpc:
transport = oslo_msg.get_rpc_transport(CONF, url)
else:
transport = oslo_msg.get_notification_transport(CONF, url)
except oslo_msg.InvalidTransportURL as e:
if not optional or e.url:
# NOTE(sileht): oslo_messaging is configured but unloadable
# so reraise the exception
raise
return None
else:
if cache:
TRANSPORTS[cache_key] = transport
return transport
示例5: get_transport
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def get_transport(conf, url=None, optional=False, cache=True):
"""Initialise the oslo_messaging layer."""
global TRANSPORTS, DEFAULT_URL
cache_key = url or DEFAULT_URL
transport = TRANSPORTS.get(cache_key)
if not transport or not cache:
try:
transport = oslo_messaging.get_notification_transport(conf, url)
except (oslo_messaging.InvalidTransportURL,
oslo_messaging.DriverLoadFailure):
if not optional or url:
# NOTE(sileht): oslo_messaging is configured but unloadable
# so reraise the exception
raise
return None
else:
if cache:
TRANSPORTS[cache_key] = transport
return transport
示例6: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [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 get_notification_transport [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 get_notification_transport [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: get_transport
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def get_transport():
return oslo_messaging.get_notification_transport(CONF)
示例10: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [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'])
示例11: main
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('sendto', help='url')
args = parser.parse_args()
data = sys.stdin.readlines()[0]
transport_url = args.sendto
transport = messaging.get_notification_transport(cfg.CONF, transport_url)
driver = 'messagingv2'
publisher = 'kapacitor_%s' % socket.gethostname()
notifier = messaging.Notifier(transport,
driver=driver,
publisher_id=publisher,
topics=['vitrage_notifications'])
alarm = json.loads(data)
host = alarm['data']['series'][0]['tags']['host']
priority = alarm['level'].lower()
alarm.update({'host': host,
'priority': priority})
alarm.pop('data', None)
alarm_status = alarm['level'].lower()
event_type = '%s.%s' % (KAPACITOR_EVENT_TYPE, alarm_status)
logging.info('Send to: %s', transport_url)
logging.info('BODY:\n----\n%s\n', data)
logging.info('PUBLISHER: %s', publisher)
logging.info('EVENT_TYPE: %s', event_type)
logging.info('\nALARM:\n%s', alarm)
notifier.info(ctxt={'message_id': uuidutils.generate_uuid(),
'publisher_id': publisher},
event_type=event_type,
payload=alarm)
logging.info('MESSAGE SENT..')
示例12: initialize
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def initialize(self):
"""Set up the Vitrage API client and add the notification callback. """
url = self.config['transport_url']
transport = messaging.get_notification_transport(cfg.CONF, url)
self.notifier = messaging.Notifier(transport,
driver='messagingv2',
publisher_id=COLLECTD_DATASOURCE,
topics=['vitrage_notifications'])
self.add_notification_callback(self.notify)
示例13: main
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('sendto', help='Vitrage message bus path')
parser.add_argument('topic', help='zabbix topic')
parser.add_argument('body', help='zabbix body')
args = parser.parse_args()
logging.info('SENDTO: %s', args.sendto)
logging.info('TOPIC: %s', args.topic)
logging.info('BODY:\n----\n%s\n', args.body)
transport_url = args.sendto
transport = messaging.get_notification_transport(cfg.CONF, transport_url)
driver = 'messagingv2'
publisher = 'zabbix_%s' % socket.gethostname()
notifier = messaging.Notifier(transport,
driver=driver,
publisher_id=publisher,
topics=['vitrage_notifications'])
alarm_status = args.topic.lower()
event_type = '%s.%s' % (ZABBIX_EVENT_TYPE, alarm_status)
payload = create_payload(args.body)
logging.info('PUBLISHER: %s', publisher)
logging.info('EVENT_TYPE: %s', event_type)
logging.info('\nPAYLOAD:\n%s', payload)
notifier.info(ctxt={'message_id': uuidutils.generate_uuid(),
'publisher_id': publisher,
'timestamp': datetime.utcnow()},
event_type=event_type,
payload=payload)
logging.info('MESSAGE SENT..')
示例14: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [as 别名]
def init(conf):
global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER
exmods = get_allowed_exmods()
TRANSPORT = oslo_messaging.get_rpc_transport(conf,
allowed_remote_exmods=exmods)
NOTIFICATION_TRANSPORT = oslo_messaging.get_notification_transport(
conf, allowed_remote_exmods=exmods)
json_serializer = oslo_messaging.JsonPayloadSerializer()
serializer = RequestContextSerializer(json_serializer)
NOTIFIER = oslo_messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)
示例15: init
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import get_notification_transport [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)
serializer = RequestContextSerializer(JsonPayloadSerializer())
if not conf.notification_level:
NOTIFIER = messaging.Notifier(
NOTIFICATION_TRANSPORT, serializer=serializer, driver='noop')
else:
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)