From fc46164d5f07bb9509b74bae97bd250c4690414f Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 3 Jul 2014 18:24:57 -1000 Subject: [PATCH] Make plugins easier to use This removes the need for editing mistral.conf and makes the naming of the plugin more obvious. Change-Id: Ie6e043eacfd0e413d81690f7c5978fd7bbec171d --- doc/source/writing_a_plugin_action.rst | 17 +++-------------- etc/mistral.conf.sample | 3 --- mistral/actions/action_factory.py | 21 +++++++++++++-------- mistral/actions/base.py | 26 +++++++++++--------------- mistral/config.py | 7 ------- setup.cfg | 12 ++++++------ 6 files changed, 33 insertions(+), 53 deletions(-) diff --git a/doc/source/writing_a_plugin_action.rst b/doc/source/writing_a_plugin_action.rst index 83f8ffcb..1bf6422a 100644 --- a/doc/source/writing_a_plugin_action.rst +++ b/doc/source/writing_a_plugin_action.rst @@ -21,22 +21,11 @@ How to write an Action Plugin :: [entry_points] - myproject.plugins.example = - runner = solum.mistral_plugins.somefile:RunnerAction + mistral.actions = + example.runner = my.mistral_plugins.somefile:RunnerAction -3. Add the namespace into /etc/mistral/mistral.conf - (don't overwrite "mistral.plugins.std") +3. Use your plugin -:: - - action_plugins = mistral.plugins.std,myproject.plugins.example - -4. Use your plugin - -Note on naming the plugin. - - * The namespace is "myproject.plugins.example" - * The class is named "runner" * Now you can call the action "example.runner" :: diff --git a/etc/mistral.conf.sample b/etc/mistral.conf.sample index e2a7f230..0de38579 100644 --- a/etc/mistral.conf.sample +++ b/etc/mistral.conf.sample @@ -198,9 +198,6 @@ # Options defined in mistral.config # -# List of namespaces to search for plug-ins. (list value) -#action_plugins=mistral.actions.std - # Specifies which mistral server to start by the launch # script. Valid options are all or any combination of api, # engine, and executor. (list value) diff --git a/mistral/actions/action_factory.py b/mistral/actions/action_factory.py index 65699a42..a7153fb3 100644 --- a/mistral/actions/action_factory.py +++ b/mistral/actions/action_factory.py @@ -15,7 +15,7 @@ # limitations under the License. import inspect -from oslo.config import cfg +from stevedore import extension from mistral.actions import base from mistral.actions import std_actions @@ -30,12 +30,11 @@ _ACTION_CTX_PARAM = 'action_context' _NAMESPACES = {} -def _find_or_create_namespace(full_name): - name = full_name.split('.')[-1] +def _find_or_create_namespace(name): ns = _NAMESPACES.get(name) if not ns: - ns = base.Namespace(full_name) + ns = base.Namespace(name) _NAMESPACES[name] = ns return ns @@ -46,10 +45,16 @@ def get_registered_namespaces(): def _register_action_classes(): - cfg.CONF.import_opt('action_plugins', 'mistral.config') - for py_ns in cfg.CONF.action_plugins: - ns = _find_or_create_namespace(py_ns) - ns.log() + mgr = extension.ExtensionManager( + namespace='mistral.actions', + invoke_on_load=False) + + for name in mgr.names(): + ns = _find_or_create_namespace(name.split('.')[0]) + ns.add(name.split('.')[1], mgr[name].plugin) + + for ns in _NAMESPACES: + _NAMESPACES[ns].log() def get_action_class(action_full_name): diff --git a/mistral/actions/base.py b/mistral/actions/base.py index ca9f7917..6fc492e9 100644 --- a/mistral/actions/base.py +++ b/mistral/actions/base.py @@ -15,7 +15,6 @@ # limitations under the License. import abc -from stevedore import extension from mistral.openstack.common import log as logging @@ -87,25 +86,22 @@ class Namespace(object): """Action namespace.""" def __init__(self, namespace): - self.name = namespace.split('.')[-1] - self.mgr = extension.ExtensionManager( - namespace=namespace, - invoke_on_load=False) + self.name = namespace + self.actions = {} def contains_action_name(self, name): - return name in self.mgr.names() + return name in self.actions def get_action_class(self, name): - # ExtensionManager has no "get" - if self.contains_action_name(name): - return self.mgr[name].plugin - else: - return None + return self.actions.get(name) def __len__(self): - # ExtensionManager has no len() - return len(self.mgr.names()) + return len(self.actions) def log(self): - for ext in self.mgr: - LOG.debug('%s:%s' % (self.name, ext.name)) + for ext in self.actions: + LOG.debug('%s:%s' % (self.name, ext)) + + def add(self, name, action): + if name not in self.actions: + self.actions[name] = action diff --git a/mistral/config.py b/mistral/config.py index a52ca1d2..3da206c9 100644 --- a/mistral/config.py +++ b/mistral/config.py @@ -87,12 +87,6 @@ launch_opt = cfg.ListOpt( 'api, engine, and executor.' ) -action_plugins_opt = cfg.ListOpt( - 'action_plugins', - default=['mistral.actions.std'], - help='List of namespaces to search for plug-ins.') - - wf_trace_log_name_opt = cfg.StrOpt('workflow_trace_log_name', default='workflow_trace', help='Logger name for pretty ' @@ -106,7 +100,6 @@ CONF.register_opts(pecan_opts, group='pecan') CONF.register_opts(db_opts, group='database') CONF.register_opts(executor_opts, group='executor') CONF.register_opt(wf_trace_log_name_opt) -CONF.register_opt(action_plugins_opt) CONF.register_cli_opt(use_debugger) CONF.register_cli_opt(launch_opt) diff --git a/setup.cfg b/setup.cfg index b0182e26..731cf3f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,9 +39,9 @@ mistral.engine.drivers = mistral.executor.drivers = default = mistral.engine.drivers.default.executor:DefaultExecutor -mistral.actions.std = - echo = mistral.actions.std_actions:EchoAction - http = mistral.actions.std_actions:HTTPAction - mistral_http = mistral.actions.std_actions:MistralHTTPAction - ssh = mistral.actions.std_actions:SSHAction - email = mistral.actions.std_actions:SendEmailAction +mistral.actions = + std.echo = mistral.actions.std_actions:EchoAction + std.http = mistral.actions.std_actions:HTTPAction + std.mistral_http = mistral.actions.std_actions:MistralHTTPAction + std.ssh = mistral.actions.std_actions:SSHAction + std.email = mistral.actions.std_actions:SendEmailAction