Esempio n. 1
0
    def init(self) -> bool:
        log.debug('Initialising job: check %s, paction %s, naction %s',
                  self._check_module,
                  self._paction_module,
                  self._naction_module)

        try:
            log.info('Attempting to load check plugin %s', self._check_module)
            self._check = stevedore.DriverManager(namespace='skutter.plugins.checks',
                                                  name=self._check_module,
                                                  invoke_on_load=True,
                                                  invoke_args=(self._check_config,)
                                                  )
        except NoMatches as e:
            log.error("%s unable to find check plugin called %s", self._name, self._check_module)
            log.debug(e)
            return False
        except (FileNotFoundError, ImportError) as e:
            log.error("%s encountered an exception while loading check plugin called %s", self._name, self._naction_module)
            log.debug(e)
            return False

        try:
            log.info('Attempting to load paction plugin %s', self._paction_module)
            self._paction = stevedore.DriverManager(namespace='skutter.plugins.actions',
                                                    name=self._paction_module,
                                                    invoke_on_load=True,
                                                    invoke_args=(self._paction_config,)
                                                    )
        except NoMatches as e:
            log.error("%s unable to find action plugin called %s", self._name, self._paction_module)
            return False
        except (FileNotFoundError, ImportError) as e:
            log.error("%s encountered an exception while loading action plugin called %s", self._name, self._paction_module)
            log.debug(e)
            return False

        try:
            log.info('Attempting to load naction plugin %s', self._naction_module)
            self._naction = stevedore.DriverManager(namespace='skutter.plugins.actions',
                                                    name=self._naction_module,
                                                    invoke_on_load=True,
                                                    invoke_args=(self._naction_config,)
                                                    )
        except NoMatches:
            log.error("%s unable to find action plugin called %s", self._name, self._naction_module)
            return False
        except (FileNotFoundError, ImportError) as e:
            log.error("%s encountered an exception while loading action plugin called %s", self._name, self._naction_module)
            log.debug(e)
            return False

        return True
Esempio n. 2
0
def _load_driver(namespace, name):
    extension_manager = stevedore.DriverManager(namespace=namespace,
                                                name=name,
                                                invoke_on_load=True)
    LOG.info(_LI("Driver {name} successfully loaded").format(name=name))

    return extension_manager.driver
Esempio n. 3
0
def _main(namespace, module_type, module_name, module_conf):
    setproctitle.setproctitle('python-zabbix-modules: Module %s/%s' %
                              (module_type, module_name))

    _log.info('Loading module "%s"...', module_name)

    manager = stevedore.DriverManager(namespace,
                                      module_name,
                                      True,
                                      invoke_kwds=dict(
                                          module_type=module_type,
                                          module_name=module_name,
                                          module_conf=module_conf))

    _log.info('Module "%s" loaded successfully, running...', module_name)

    try:
        loop = trollius.get_event_loop()

        for sig_num in signal.SIGINT, signal.SIGTERM:
            loop.add_signal_handler(sig_num, lambda: _stop(sig_num, loop))

        socket_path = modules.get_sock_path(_conf, module_type, module_name)
        module_coroutine = loop.create_unix_server(
            functools.partial(_ModuleServer, manager.driver), socket_path)
        loop.run_until_complete(module_coroutine)
        # Access to sockets will be restricted on directory level.
        os.chmod(socket_path, 0o666)

        try:
            loop.run_forever()
        finally:
            loop.close()
    finally:
        manager.driver.on_module_terminate()
def load_auth_method(method):
    plugin_name = CONF.auth.get(method) or 'default'
    namespace = 'keystone.auth.%s' % method
    try:
        driver_manager = stevedore.DriverManager(namespace,
                                                 plugin_name,
                                                 invoke_on_load=True)
        return driver_manager.driver
    except RuntimeError:
        LOG.debug(
            'Failed to load the %s driver (%s) using stevedore, will '
            'attempt to load using import_object instead.', method,
            plugin_name)

    driver = importutils.import_object(plugin_name)

    msg = (_(
        'Direct import of auth plugin %(name)r is deprecated as of Liberty in '
        'favor of its entrypoint from %(namespace)r and may be removed in '
        'N.') % {
            'name': plugin_name,
            'namespace': namespace
        })
    versionutils.report_deprecated_feature(LOG, msg)

    return driver
Esempio n. 5
0
 def driver(self) -> "protocol.source.Base":
     return typing.cast(
         protocol.source.Base,
         stevedore.DriverManager(namespace.SOURCE,
                                 self.source,
                                 invoke_on_load=True).driver,
     )
Esempio n. 6
0
def _get_remote_driver():
    LOG.info("Loading '%s' remote" % CONF.remote)

    extension_manager = stevedore.DriverManager(namespace='sahara.remote',
                                                name=CONF.remote,
                                                invoke_on_load=True)

    return extension_manager.driver
Esempio n. 7
0
def _load_driver(namespace, name):
    extension_manager = stevedore.DriverManager(
        namespace=namespace,
        name=name,
        invoke_on_load=True
    )

    return extension_manager.driver
Esempio n. 8
0
def node_not_found_hook_manager(*args):
    global _NOT_FOUND_HOOK_MGR
    if _NOT_FOUND_HOOK_MGR is None:
        name = CONF.processing.node_not_found_hook
        if name:
            _NOT_FOUND_HOOK_MGR = stevedore.DriverManager(
                'ironic_inspector.hooks.node_not_found', name=name)

    return _NOT_FOUND_HOOK_MGR
Esempio n. 9
0
    def get_handler(self, name: str) -> Callable[..., EventHandler]:
        """Get an handler class by name.

        Available handler classes are registered using the e3.event.handler
        entry_points in your setup.py

        :param name: handler name
        :return: an handler class
        """
        return stevedore.DriverManager("e3.event.handler", name).driver
Esempio n. 10
0
def load_driver(namespace, driver_name, *args):
    try:
        driver_manager = stevedore.DriverManager(namespace,
                                                 driver_name,
                                                 invoke_on_load=True,
                                                 invoke_args=args)
        return driver_manager.driver
    except stevedore.exception.NoMatches:
        msg = (_('Unable to find %(name)r driver in %(namespace)r.'))
        raise ImportError(msg % {'name': driver_name, 'namespace': namespace})
Esempio n. 11
0
def get_download_driver(delegate: str) -> BaseDownloadService:
    try:
        return cast(
            BaseDownloadService,
            stevedore.DriverManager(namespace.DOWNLOAD_DELEGATE,
                                    name=delegate,
                                    invoke_on_load=True).driver,
        )
    except NoMatches:
        print_error(f"can't load download delegate {delegate}")
        raise
Esempio n. 12
0
    def get_handler(self, name):
        """Get an handler class by name.

        Available handler classes are registered using the e3.event.handler
        entry_points in your setup.py

        :param name: handler name
        :type name: str
        :return: an handler class
        :rtype: obj
        """
        return stevedore.DriverManager("e3.event.handler", name).driver
Esempio n. 13
0
def _get_infrastructure_engine():
    """That should import and return one of
    sahara.service.instances*.py modules
    """

    LOG.info("Loading '%s' infrastructure engine" % CONF.infrastructure_engine)

    extension_manager = stevedore.DriverManager(
        namespace='sahara.infrastructure.engine',
        name=CONF.infrastructure_engine,
        invoke_on_load=True)

    return extension_manager.driver
Esempio n. 14
0
File: core.py Progetto: Boye-Z/123
def setup_app_middleware(app):
    # NOTE(morgan): Load the middleware, in reverse order, we wrap the app
    # explicitly; reverse order to ensure the first element in _APP_MIDDLEWARE
    # processes the request first.

    MW = _APP_MIDDLEWARE
    IMW = _KEYSTONE_MIDDLEWARE

    # Add in optional (config-based) middleware
    # NOTE(morgan): Each of these may need to be in a specific location
    # within the pipeline therefore cannot be magically appended/prepended
    if CONF.wsgi.debug_middleware:
        # Add in the Debug Middleware
        MW = (_Middleware(namespace='keystone.server_middleware',
                          ep='debug',
                          conf={}), ) + _APP_MIDDLEWARE

    # Apply internal-only Middleware (e.g. AuthContextMiddleware). These
    # are below all externally loaded middleware in request processing.
    for mw in reversed(IMW):
        app.wsgi_app = mw(app.wsgi_app)

    # Apply the middleware to the application.
    for mw in reversed(MW):
        # TODO(morgan): Explore moving this to ExtensionManager, but we
        # want to be super careful about what middleware we load and in
        # what order. DriverManager gives us that capability and only loads
        # the entry points we care about rather than all of them.

        # Load via Stevedore, initialize the class via the factory so we can
        # initialize the "loaded" entrypoint with the currently bound
        # object pointed at "application". We may need to eventually move away
        # from the "factory" mechanism.
        loaded = stevedore.DriverManager(mw.namespace,
                                         mw.ep,
                                         invoke_on_load=False)
        # NOTE(morgan): global_conf (args[0]) to the factory is always empty
        # and local_conf (args[1]) will be the mw.conf dict. This allows for
        # configuration to be passed for middleware such as oslo CORS which
        # expects oslo_config_project or "allowed_origin" to be in the
        # local_conf, this is all a hold-over from paste-ini and pending
        # reworking/removal(s)
        factory_func = loaded.driver.factory({}, **mw.conf)
        app.wsgi_app = factory_func(app.wsgi_app)

    # Apply werkzeug specific middleware
    app.wsgi_app = proxy_fix.ProxyFix(app.wsgi_app)
    return app
Esempio n. 15
0
def load_driver(namespace, driver_name, *args):
    try:
        driver_manager = stevedore.DriverManager(namespace,
                                                 driver_name,
                                                 invoke_on_load=True,
                                                 invoke_args=args)
        return driver_manager.driver
    except RuntimeError as e:
        LOG.debug('Failed to load %r using stevedore: %s', driver_name, e)
        # Ignore failure and continue on.

    def _load_using_import(driver_name, *args):
        return importutils.import_object(driver_name, *args)

    # For backwards-compatibility, an unregistered class reference can
    # still be used.
    return _load_using_import(driver_name, *args)
Esempio n. 16
0
File: cli.py Progetto: jstaf/farmer
    def get_command(self, ctx, name):
        """
        Load the given command.

        Args:
            ctx (object): The ``click`` context object. This is populated
                automatically when using the decorator syntax.
            name (str): Name of the command.

        Returns:
            The command's ``cli()`` entry point.
        """
        try:
            return stevedore.DriverManager('farmer.commands', name).driver
        # Let click handle missing commands internally.
        except RuntimeError:
            pass
Esempio n. 17
0
def get_plugin_class(name):
    """Retrieve a plugin class by its entrypoint name.

    :param str name: The name of the object to get.

    :returns: An auth plugin class.

    :raises exceptions.NoMatchingPlugin: if a plugin cannot be created.
    """
    try:
        mgr = stevedore.DriverManager(namespace=PLUGIN_NAMESPACE,
                                      name=name,
                                      invoke_on_load=False)
    except RuntimeError:
        msg = 'The plugin %s could not be found' % name
        raise exceptions.NoMatchingPlugin(msg)

    return mgr.driver
Esempio n. 18
0
def load_auth_method(method):
    plugin_name = CONF.auth.get(method) or 'default'
    try:
        namespace = 'keystone.auth.%s' % method
        driver_manager = stevedore.DriverManager(namespace, plugin_name,
                                                 invoke_on_load=True)
        return driver_manager.driver
    except RuntimeError:
        LOG.debug('Failed to load the %s driver (%s) using stevedore, will '
                  'attempt to load using import_object instead.',
                  method, plugin_name)

    @versionutils.deprecated(as_of=versionutils.deprecated.LIBERTY,
                             in_favor_of='entrypoints',
                             what='direct import of driver')
    def _load_using_import(plugin_name):
        return importutils.import_object(plugin_name)

    return _load_using_import(plugin_name)
Esempio n. 19
0
def get_plugin_loader(name):
    """Retrieve a plugin class by its entrypoint name.

    :param str name: The name of the object to get.

    :returns: An auth plugin class.
    :rtype: :py:class:`keystoneauth1.loading.BaseLoader`

    :raises keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin:
        if a plugin cannot be created.
    """
    try:
        mgr = stevedore.DriverManager(namespace=PLUGIN_NAMESPACE,
                                      invoke_on_load=True,
                                      name=name)
    except RuntimeError:
        raise exceptions.NoMatchingPlugin(name)

    return mgr.driver
Esempio n. 20
0
def load_driver(namespace, driver_name, *args):
    try:
        driver_manager = stevedore.DriverManager(namespace,
                                                 driver_name,
                                                 invoke_on_load=True,
                                                 invoke_args=args)
        return driver_manager.driver
    except RuntimeError:
        # Ignore failure to load driver using stevedore and continue on.
        pass

    @versionutils.deprecated(as_of=versionutils.deprecated.LIBERTY,
                             in_favor_of='entrypoints',
                             what='direct import of driver')
    def _load_using_import(driver_name, *args):
        return importutils.import_object(driver_name, *args)

    # For backwards-compatibility, an unregistered class reference can
    # still be used.
    return _load_using_import(driver_name, *args)
Esempio n. 21
0
def load_driver(namespace, driver_name, *args):
    try:
        driver_manager = stevedore.DriverManager(namespace,
                                                 driver_name,
                                                 invoke_on_load=True,
                                                 invoke_args=args)
        return driver_manager.driver
    except RuntimeError as e:
        LOG.debug('Failed to load %r using stevedore: %s', driver_name, e)
        # Ignore failure and continue on.

    driver = importutils.import_object(driver_name, *args)

    msg = (_(
        'Direct import of driver %(name)r is deprecated as of Liberty in '
        'favor of its entrypoint from %(namespace)r and may be removed in '
        'N.') %
        {'name': driver_name, 'namespace': namespace})
    versionutils.report_deprecated_feature(LOG, msg)

    return driver
Esempio n. 22
0
def config_wrapper(ret: Any) -> None:
    if ret.name == "DOWNLOAD_DELEGATE" and ret.value is not None:
        try:
            driver_cls: Type[BaseDownloadService] = stevedore.DriverManager(
                namespace=namespace.DOWNLOAD_DELEGATE,
                name=ret.value,
                invoke_on_load=False,
            ).driver

            driver_cls.check_dep()

        except NoMatches:
            entry_points = importlib_metadata.entry_points(
                group=namespace.DOWNLOAD_DELEGATE)
            available = ", ".join([f"'{x.name}'" for x in entry_points])
            print_error(f"{ret.value} if not a registered download delegate\n"
                        f"available download delegate are {available}")

    result = config(ret.name, ret.value)
    if (not ret.name) and (not ret.value):
        print(result["message"])
    else:
        globals()["print_{}".format(result["status"])](result["message"])
Esempio n. 23
0
def load_store(name, configuration, cache):
    plugin = stevedore.DriverManager(
        'e3.store',
        name)

    return plugin.driver(configuration, cache)
Esempio n. 24
0
def load_cache(name="file-cache", configuration=None):
    plugin = stevedore.DriverManager(namespace="e3.store.cache.backend",
                                     name=name)
    return plugin.driver(configuration)
Esempio n. 25
0
def _get_auth_driver_manager(namespace, plugin_name):
    return stevedore.DriverManager(namespace, plugin_name, invoke_on_load=True)
Esempio n. 26
0
def load_store(name: str, configuration: Any, cache: Cache) -> Store:
    plugin = stevedore.DriverManager("e3.store", name)

    return plugin.driver(configuration, cache)
Esempio n. 27
0
def load_event_manager(name, configuration):
    plugin = stevedore.DriverManager('e3.event.manager', name)

    return plugin.driver(configuration)