Python oslo_messaging.get_rpc_transport() Examples

The following are 26 code examples of oslo_messaging.get_rpc_transport(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_messaging , or try the search function .
Example #1
Source File: messaging.py    From cloudkitty with Apache License 2.0 6 votes vote down vote up
def get_transport(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_rpc_transport(cfg.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 
Example #2
Source File: rpc.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: rpc.py    From karbor with Apache License 2.0 6 votes vote down vote up
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 
Example #4
Source File: messaging.py    From vitrage with Apache License 2.0 6 votes vote down vote up
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 
Example #5
Source File: rpc.py    From manila with Apache License 2.0 6 votes vote down vote up
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 
Example #6
Source File: rpc.py    From tacker with Apache License 2.0 5 votes vote down vote up
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) 
Example #7
Source File: rpc_service.py    From zun with Apache License 2.0 5 votes vote down vote up
def __init__(self, topic, server, endpoints, binary):
        super(Service, self).__init__()
        serializer = _init_serializer()
        transport = messaging.get_rpc_transport(CONF)
        access_policy = dispatcher.DefaultRPCAccessPolicy
        # TODO(asalkeld) add support for version='x.y'
        target = messaging.Target(topic=topic, server=server)
        self.endpoints = endpoints
        self._server = messaging.get_rpc_server(transport, target, endpoints,
                                                executor='eventlet',
                                                serializer=serializer,
                                                access_policy=access_policy)
        self.binary = binary
        profiler.setup(binary, CONF.host) 
Example #8
Source File: amphora.py    From octavia with Apache License 2.0 5 votes vote down vote up
def __init__(self, amp_id):
        super(AmphoraUpdateController, self).__init__()

        if CONF.api_settings.default_provider_driver == constants.AMPHORAV2:
            topic = constants.TOPIC_AMPHORA_V2
            version = "2.0"
        else:
            topic = cfg.CONF.oslo_messaging.topic
            version = "1.0"
        self.transport = messaging.get_rpc_transport(cfg.CONF)
        self.target = messaging.Target(
            namespace=constants.RPC_NAMESPACE_CONTROLLER_AGENT,
            topic=topic, version=version, fanout=False)
        self.client = messaging.RPCClient(self.transport, target=self.target)
        self.amp_id = amp_id 
Example #9
Source File: service.py    From qinling with Apache License 2.0 5 votes vote down vote up
def run(self):
        qinling_endpoint = keystone_utils.get_qinling_endpoint()
        orchestrator = orchestra_base.load_orchestrator(CONF, qinling_endpoint)
        db_api.setup_db()

        topic = CONF.engine.topic
        server = CONF.engine.host
        transport = messaging.get_rpc_transport(CONF)
        target = messaging.Target(topic=topic, server=server, fanout=False)
        endpoint = engine.DefaultEngine(orchestrator, qinling_endpoint)
        access_policy = dispatcher.DefaultRPCAccessPolicy
        self.server = messaging.get_rpc_server(
            transport,
            target,
            [endpoint],
            executor='threading',
            access_policy=access_policy,
            serializer=rpc.ContextSerializer(
                messaging.serializer.JsonPayloadSerializer())
        )

        LOG.info('Starting function mapping periodic task...')
        periodics.start_function_mapping_handler(endpoint)

        LOG.info('Starting engine...')
        self.server.start() 
Example #10
Source File: rpc.py    From qinling with Apache License 2.0 5 votes vote down vote up
def get_transport():
    global _TRANSPORT

    if not _TRANSPORT:
        _TRANSPORT = messaging.get_rpc_transport(cfg.CONF)

    return _TRANSPORT 
Example #11
Source File: rpc.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def init():
    global TRANSPORT
    TRANSPORT = messaging.get_rpc_transport(CONF) 
Example #12
Source File: rpc.py    From cyborg with Apache License 2.0 5 votes vote down vote up
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(messaging.JsonPayloadSerializer())
    NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
                                  serializer=serializer,
                                  topics=['notifications']) 
Example #13
Source File: messaging.py    From senlin with Apache License 2.0 5 votes vote down vote up
def setup(url=None, optional=False):
    """Initialise the oslo_messaging layer."""
    global TRANSPORT, GLOBAL_TRANSPORT, NOTIFIER

    if url and url.startswith("fake://"):
        # NOTE: oslo_messaging fake driver uses time.sleep
        # for task switch, so we need to monkey_patch it
        eventlet.monkey_patch(time=True)

    messaging.set_transport_defaults('senlin')
    if not TRANSPORT:
        exmods = ['senlin.common.exception']
        try:
            TRANSPORT = messaging.get_rpc_transport(
                cfg.CONF, url, allowed_remote_exmods=exmods)
        except messaging.InvalidTransportURL as e:
            TRANSPORT = None
            if not optional or e.url:
                # NOTE: oslo_messaging is configured but unloadable
                # so reraise the exception
                raise

    if not NOTIFIER:
        exmods = ['senlin.common.exception']
        try:
            NOTIFICATION_TRANSPORT = messaging.get_notification_transport(
                cfg.CONF, allowed_remote_exmods=exmods)
        except Exception:
            raise

        serializer = RequestContextSerializer(JsonPayloadSerializer())
        NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
                                      serializer=serializer,
                                      topics=cfg.CONF.notification_topics) 
Example #14
Source File: __init__.py    From barbican with Apache License 2.0 5 votes vote down vote up
def init(conf, is_server_side=True):
    global TRANSPORT, IS_SERVER_SIDE
    exmods = get_allowed_exmods()
    IS_SERVER_SIDE = is_server_side
    TRANSPORT = messaging.get_rpc_transport(conf, allowed_remote_exmods=exmods) 
Example #15
Source File: service.py    From watcher with Apache License 2.0 5 votes vote down vote up
def transport(self):
        if self._transport is None:
            self._transport = om.get_rpc_transport(CONF)
        return self._transport 
Example #16
Source File: rpc.py    From watcher with Apache License 2.0 5 votes vote down vote up
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) 
Example #17
Source File: rpc.py    From designate with Apache License 2.0 5 votes vote down vote up
def create_transport(url):
    exmods = get_allowed_exmods()
    return messaging.get_rpc_transport(CONF,
                                       url=url,
                                       allowed_remote_exmods=exmods) 
Example #18
Source File: rpc.py    From tacker with Apache License 2.0 5 votes vote down vote up
def init_action_rpc(conf):
    global TRANSPORT
    TRANSPORT = oslo_messaging.get_rpc_transport(conf) 
Example #19
Source File: rpc.py    From zun with Apache License 2.0 5 votes vote down vote up
def init(conf):
    global TRANSPORT
    exmods = get_allowed_exmods()
    TRANSPORT = messaging.get_rpc_transport(
        conf, allowed_remote_exmods=exmods) 
Example #20
Source File: base.py    From octavia with Apache License 2.0 5 votes vote down vote up
def _fake_create_transport(self, url):
        if url not in self._buses:
            self._buses[url] = messaging.get_rpc_transport(
                cfg.CONF,
                url=url)
        return self._buses[url] 
Example #21
Source File: messaging.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def get_rpc_transport(url=None, optional=False, cache=True):
    return get_transport(url, optional, cache, rpc=True) 
Example #22
Source File: rpc.py    From masakari with Apache License 2.0 5 votes vote down vote up
def create_transport(url):
    exmods = get_allowed_exmods()
    return messaging.get_rpc_transport(CONF,
                                       url=url,
                                       allowed_remote_exmods=exmods) 
Example #23
Source File: rpc.py    From octavia with Apache License 2.0 5 votes vote down vote up
def create_transport(url):
    return messaging.get_rpc_transport(cfg.CONF, url=url) 
Example #24
Source File: rpc_service.py    From magnum with Apache License 2.0 5 votes vote down vote up
def __init__(self, transport=None, context=None, topic=None, server=None,
                 timeout=None):
        serializer = _init_serializer()
        if transport is None:
            exmods = rpc.get_allowed_exmods()
            transport = messaging.get_rpc_transport(
                CONF, allowed_remote_exmods=exmods)
        self._context = context
        if topic is None:
            topic = ''
        target = messaging.Target(topic=topic, server=server)
        self._client = messaging.RPCClient(transport, target,
                                           serializer=serializer,
                                           timeout=timeout) 
Example #25
Source File: rpc_service.py    From magnum with Apache License 2.0 5 votes vote down vote up
def __init__(self, topic, server, handlers, binary):
        super(Service, self).__init__()
        serializer = _init_serializer()
        transport = messaging.get_rpc_transport(CONF)
        # TODO(asalkeld) add support for version='x.y'
        access_policy = dispatcher.DefaultRPCAccessPolicy
        target = messaging.Target(topic=topic, server=server)
        self._server = messaging.get_rpc_server(transport, target, handlers,
                                                executor='eventlet',
                                                serializer=serializer,
                                                access_policy=access_policy)
        self.binary = binary
        profiler.setup(binary, CONF.host) 
Example #26
Source File: rpc.py    From magnum with Apache License 2.0 5 votes vote down vote up
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)