Python stevedore.ExtensionManager() Examples

The following are 14 code examples of stevedore.ExtensionManager(). 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 stevedore , or try the search function .
Example #1
Source File: cli.py    From nidaba with GNU General Public License v2.0 6 votes vote down vote up
def plugins(ctx):
    """
    Displays available plugins and if they're enabled.
    """
    try:
        from nidaba.config import nidaba_cfg
    except IOError as e:
        if e.errno == 2:
            click.echo('plugins command only available for local installations.')
            ctx.exit()

    import stevedore

    mgr = stevedore.ExtensionManager(namespace='nidaba.plugins')
    enabled = set(nidaba_cfg['plugins_load'].keys()).intersection(set(mgr.names()))
    disabled = set(mgr.names()) - enabled
    for plugin in mgr.names():
        click.echo(plugin, nl=False)
        if plugin in disabled:
            click.secho(u' (disabled)', fg='red')
        else:
            click.secho(u' (enabled)', fg='green') 
Example #2
Source File: mapreduce.py    From edx-analytics-pipeline with GNU Affero General Public License v3.0 6 votes vote down vote up
def job_runner(self):
        # Lazily import this since this module will be loaded on hadoop worker nodes however stevedore will not be
        # available in that environment.
        from stevedore import ExtensionManager

        extension_manager = ExtensionManager('mapreduce.engine')
        try:
            engine_class = extension_manager[self.mapreduce_engine].plugin
        except KeyError:
            raise KeyError('A map reduce engine must be specified in order to run MapReduceJobTasks')

        if issubclass(engine_class, MapReduceJobRunner):
            engine_kwargs = self._get_engine_parameters_from_targets()
            return engine_class(**engine_kwargs)
        else:
            return engine_class() 
Example #3
Source File: test_entry_points.py    From oslo.middleware with Apache License 2.0 6 votes vote down vote up
def test_entry_points(self):
        factory_classes = {
            'catch_errors': 'CatchErrors',
            'correlation_id': 'CorrelationId',
            'cors': 'CORS',
            'debug': 'Debug',
            'healthcheck': 'Healthcheck',
            'http_proxy_to_wsgi': 'HTTPProxyToWSGI',
            'request_id': 'RequestId',
            'sizelimit': 'RequestBodySizeLimiter',
            'ssl': 'SSLMiddleware',
        }

        em = stevedore.ExtensionManager('paste.filter_factory')

        # Ensure all the factories are defined by their names
        factory_names = [extension.name for extension in em]
        self.assertThat(factory_names,
                        matchers.ContainsAll(factory_classes)) 
Example #4
Source File: common.py    From sushy with Apache License 2.0 6 votes vote down vote up
def _get_extension_manager_of_resource(resource_name):
    """Get the resource specific ExtensionManager instance.

    :param resource_name: The name of the resource e.g.
        'system' / 'ethernet_interface' / 'update_service'
    :returns: the ExtensionManager instance
    :raises ExtensionError: on resource OEM extension load error.
    """
    global _global_extn_mgrs_by_resource

    if resource_name not in _global_extn_mgrs_by_resource:
        resource_namespace = 'sushy.resources.' + resource_name + '.oems'
        _global_extn_mgrs_by_resource[resource_name] = (
            _create_extension_manager(resource_namespace)
        )
    return _global_extn_mgrs_by_resource[resource_name] 
Example #5
Source File: options.py    From castellan with Apache License 2.0 5 votes vote down vote up
def list_opts():
    """Returns a list of oslo.config options available in the library.

    The returned list includes all oslo.config options which may be registered
    at runtime by the library.

    Each element of the list is a tuple. The first element is the name of the
    group under which the list of elements in the second element will be
    registered. A group name of None corresponds to the [DEFAULT] group in
    config files.

    The purpose of this is to allow tools like the Oslo sample config file
    generator to discover the options exposed to users by this library.

    :returns: a list of (group_name, opts) tuples
    """
    key_manager_opts = []
    key_manager_opts.extend(key_manager.key_manager_opts)
    key_manager_opts.extend(utils.credential_opts)
    opts = [('key_manager', key_manager_opts)]

    ext_mgr = ExtensionManager(
        "castellan.drivers",
        invoke_on_load=True,
        invoke_args=[cfg.CONF])

    for driver in ext_mgr.names():
        opts.extend(ext_mgr[driver].obj.list_options_for_discovery())

    return opts 
Example #6
Source File: complete.py    From cliff with Apache License 2.0 5 votes vote down vote up
def __init__(self, app, app_args, cmd_name=None):
        super(CompleteCommand, self).__init__(app, app_args, cmd_name)
        self._formatters = stevedore.ExtensionManager(
            namespace='cliff.formatter.completion',
        ) 
Example #7
Source File: display.py    From cliff with Apache License 2.0 5 votes vote down vote up
def _load_formatter_plugins(self):
        # Here so tests can override
        return stevedore.ExtensionManager(
            self.formatter_namespace,
            invoke_on_load=True,
        ) 
Example #8
Source File: auth.py    From eclcli with Apache License 2.0 5 votes vote down vote up
def get_plugin_list():
    """Gather plugin list and cache it"""

    global PLUGIN_LIST

    if PLUGIN_LIST is None:
        PLUGIN_LIST = stevedore.ExtensionManager(
            base.PLUGIN_NAMESPACE,
            invoke_on_load=False,
            propagate_map_exceptions=True,
        )
    return PLUGIN_LIST 
Example #9
Source File: all.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def load_all_extensions():
    """Load all available modules with DF models"""
    manager = stevedore.ExtensionManager(  # noqa F841
        'dragonflow.db.models',
    )
    # NOTE(oanson) In case Stevedore changes and we need to manually load
    # the extensions:
    # modules = [extension.plugin for extension in manager] 
Example #10
Source File: _checks.py    From oslo.policy with Apache License 2.0 5 votes vote down vote up
def get_extensions():
    global extension_checks
    if extension_checks is None:
        em = stevedore.ExtensionManager('oslo.policy.rule_checks',
                                        invoke_on_load=False)
        extension_checks = {
            extension.name: extension.plugin
            for extension in em
        }
    return extension_checks 
Example #11
Source File: base.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def rule_conditions_manager():
    """Create a Stevedore extension manager for conditions in rules."""
    global _CONDITIONS_MGR
    if _CONDITIONS_MGR is None:
        _CONDITIONS_MGR = stevedore.ExtensionManager(
            'ironic_inspector.rules.conditions',
            invoke_on_load=True)
    return _CONDITIONS_MGR 
Example #12
Source File: base.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def rule_actions_manager():
    """Create a Stevedore extension manager for actions in rules."""
    global _ACTIONS_MGR
    if _ACTIONS_MGR is None:
        _ACTIONS_MGR = stevedore.ExtensionManager(
            'ironic_inspector.rules.actions',
            invoke_on_load=True)
    return _ACTIONS_MGR 
Example #13
Source File: base.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def introspection_data_manager():
    global _INTROSPECTION_DATA_MGR
    if _INTROSPECTION_DATA_MGR is None:
        _INTROSPECTION_DATA_MGR = stevedore.ExtensionManager(
            'ironic_inspector.introspection_data.store',
            invoke_on_load=True)
    return _INTROSPECTION_DATA_MGR 
Example #14
Source File: common.py    From sushy with Apache License 2.0 5 votes vote down vote up
def _create_extension_manager(namespace):
    """Create the resource specific ExtensionManager instance.

    Use stevedore to find all vendor extensions of resource from their
    namespace and return the ExtensionManager instance.
    :param namespace: The namespace for the entry points. It maps to a
        specific Sushy resource type.
    :returns: the ExtensionManager instance
    :raises ExtensionError: on resource OEM extension load error.
    """
    # namespace format is:
    # ``sushy.resources.<underscore_joined_resource_name>.oems``
    resource_name = namespace.split('.')[-2]

    extension_manager = (
        stevedore.ExtensionManager(namespace=namespace,
                                   propagate_map_exceptions=True,
                                   on_load_failure_callback=_raise))

    LOG.debug('Resource OEM extensions for "%(resource)s" under namespace '
              '"%(namespace)s":',
              {'resource': resource_name, 'namespace': namespace})
    for extension in extension_manager:
        LOG.debug('Found vendor: %(name)s target: %(target)s',
                  {'name': extension.name,
                   'target': extension.entry_point_target})

    if not extension_manager.names():
        m = (('No extensions found for "%(resource)s" under namespace '
              '"%(namespace)s"') %
             {'resource': resource_name,
              'namespace': namespace})
        LOG.error(m)
        raise exceptions.ExtensionError(error=m)

    return extension_manager