diff --git a/keystoneauth1/loading/base.py b/keystoneauth1/loading/base.py index 1a93f2e3..31277d2c 100644 --- a/keystoneauth1/loading/base.py +++ b/keystoneauth1/loading/base.py @@ -28,6 +28,11 @@ __all__ = ('get_available_plugin_names', 'PLUGIN_NAMESPACE') +def _auth_plugin_available(ext): + """Read the value of available for whether to load this plugin.""" + return ext.obj.available + + def get_available_plugin_names(): """Get the names of all the plugins that are available on the system. @@ -37,7 +42,10 @@ def get_available_plugin_names(): :returns: A list of names. :rtype: frozenset """ - mgr = stevedore.ExtensionManager(namespace=PLUGIN_NAMESPACE) + mgr = stevedore.EnabledExtensionManager(namespace=PLUGIN_NAMESPACE, + check_func=_auth_plugin_available, + invoke_on_load=True, + propagate_map_exceptions=True) return frozenset(mgr.names()) @@ -48,9 +56,10 @@ def get_available_plugin_loaders(): loader as the value. :rtype: dict """ - mgr = stevedore.ExtensionManager(namespace=PLUGIN_NAMESPACE, - invoke_on_load=True, - propagate_map_exceptions=True) + mgr = stevedore.EnabledExtensionManager(namespace=PLUGIN_NAMESPACE, + check_func=_auth_plugin_available, + invoke_on_load=True, + propagate_map_exceptions=True) return dict(mgr.map(lambda ext: (ext.entry_point.name, ext.obj))) @@ -109,6 +118,18 @@ class BaseLoader(object): """ return [] + @property + def available(self): + """Return if the plugin is available for loading. + + If a plugin is missing dependencies or for some other reason should not + be available to the current system it should override this property and + return False to exclude itself from the plugin list. + + :rtype: bool + """ + return True + def load_from_options(self, **kwargs): """Create a plugin from the arguments retrieved from get_options.