當前位置: 首頁>>代碼示例>>Python>>正文


Python oslo_messaging.get_notification_transport方法代碼示例

本文整理匯總了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() 
開發者ID:openstack,項目名稱:searchlight,代碼行數:26,代碼來源:listener.py

示例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) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:21,代碼來源:listener.py

示例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 
開發者ID:openstack,項目名稱:manila,代碼行數:18,代碼來源:rpc.py

示例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 
開發者ID:openstack,項目名稱:vitrage,代碼行數:23,代碼來源:messaging.py

示例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 
開發者ID:openstack,項目名稱:aodh,代碼行數:21,代碼來源:messaging.py

示例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 
開發者ID:openstack,項目名稱:karbor,代碼行數:21,代碼來源:rpc.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:23,代碼來源:rpc.py

示例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) 
開發者ID:openstack,項目名稱:designate,代碼行數:11,代碼來源:rpc.py

示例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) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:4,代碼來源:notifier.py

示例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']) 
開發者ID:openstack,項目名稱:masakari,代碼行數:13,代碼來源:rpc.py

示例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..') 
開發者ID:openstack,項目名稱:vitrage,代碼行數:34,代碼來源:kapacitor_vitrage.py

示例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) 
開發者ID:openstack,項目名稱:vitrage,代碼行數:12,代碼來源:vitrageplugin.py

示例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..') 
開發者ID:openstack,項目名稱:vitrage,代碼行數:36,代碼來源:zabbix_vitrage.py

示例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) 
開發者ID:openstack,項目名稱:tacker,代碼行數:13,代碼來源:rpc.py

示例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) 
開發者ID:openstack,項目名稱:watcher,代碼行數:17,代碼來源:rpc.py


注:本文中的oslo_messaging.get_notification_transport方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。