Esempio n. 1
0
def fetch(name, conf, namespace=BACKEND_NAMESPACE, **kwargs):
    """Fetch a jobboard backend with the given configuration.

    This fetch method will look for the entrypoint name in the entrypoint
    namespace, and then attempt to instantiate that entrypoint using the
    provided name, configuration and any board specific kwargs.

    NOTE(harlowja): to aid in making it easy to specify configuration and
    options to a board the configuration (which is typical just a dictionary)
    can also be a URI string that identifies the entrypoint name and any
    configuration specific to that board.

    For example, given the following configuration URI::

        zookeeper://<not-used>/?a=b&c=d

    This will look for the entrypoint named 'zookeeper' and will provide
    a configuration object composed of the URI's components, in this case that
    is ``{'a': 'b', 'c': 'd'}`` to the constructor of that board
    instance (also including the name specified).
    """
    board, conf = misc.extract_driver_and_conf(conf, 'board')
    LOG.debug('Looking for %r jobboard driver in %r', board, namespace)
    try:
        mgr = driver.DriverManager(namespace, board,
                                   invoke_on_load=True,
                                   invoke_args=(name, conf),
                                   invoke_kwds=kwargs)
        return mgr.driver
    except RuntimeError as e:
        raise exc.NotFound("Could not find jobboard %s" % (board), e)
Esempio n. 2
0
def fetch(conf, namespace=BACKEND_NAMESPACE, **kwargs):
    """Fetch a persistence backend with the given configuration.

    This fetch method will look for the entrypoint name in the entrypoint
    namespace, and then attempt to instantiate that entrypoint using the
    provided configuration and any persistence backend specific kwargs.

    NOTE(harlowja): to aid in making it easy to specify configuration and
    options to a backend the configuration (which is typical just a dictionary)
    can also be a URI string that identifies the entrypoint name and any
    configuration specific to that backend.

    For example, given the following configuration URI::

        mysql://<not-used>/?a=b&c=d

    This will look for the entrypoint named 'mysql' and will provide
    a configuration object composed of the URI's components, in this case that
    is ``{'a': 'b', 'c': 'd'}`` to the constructor of that persistence backend
    instance.
    """
    backend, conf = misc.extract_driver_and_conf(conf, 'connection')
    # If the backend is like 'mysql+pymysql://...' which informs the
    # backend to use a dialect (supported by sqlalchemy at least) we just want
    # to look at the first component to find our entrypoint backend name...
    if backend.find("+") != -1:
        backend = backend.split("+", 1)[0]
    LOG.debug('Looking for %r backend driver in %r', backend, namespace)
    try:
        mgr = driver.DriverManager(namespace,
                                   backend,
                                   invoke_on_load=True,
                                   invoke_args=(conf, ),
                                   invoke_kwds=kwargs)
        return mgr.driver
    except RuntimeError as e:
        raise exc.NotFound("Could not find backend %s: %s" % (backend, e))
Esempio n. 3
0
def fetch(conf, namespace=BACKEND_NAMESPACE, **kwargs):
    """Fetch a persistence backend with the given configuration.

    This fetch method will look for the entrypoint name in the entrypoint
    namespace, and then attempt to instantiate that entrypoint using the
    provided configuration and any persistence backend specific kwargs.

    NOTE(harlowja): to aid in making it easy to specify configuration and
    options to a backend the configuration (which is typical just a dictionary)
    can also be a URI string that identifies the entrypoint name and any
    configuration specific to that backend.

    For example, given the following configuration URI::

        mysql://<not-used>/?a=b&c=d

    This will look for the entrypoint named 'mysql' and will provide
    a configuration object composed of the URI's components, in this case that
    is ``{'a': 'b', 'c': 'd'}`` to the constructor of that persistence backend
    instance.
    """
    backend, conf = misc.extract_driver_and_conf(conf, 'connection')
    # If the backend is like 'mysql+pymysql://...' which informs the
    # backend to use a dialect (supported by sqlalchemy at least) we just want
    # to look at the first component to find our entrypoint backend name...
    if backend.find("+") != -1:
        backend = backend.split("+", 1)[0]
    LOG.debug('Looking for %r backend driver in %r', backend, namespace)
    try:
        mgr = driver.DriverManager(namespace, backend,
                                   invoke_on_load=True,
                                   invoke_args=(conf,),
                                   invoke_kwds=kwargs)
        return mgr.driver
    except RuntimeError as e:
        raise exc.NotFound("Could not find backend %s: %s" % (backend, e))