Merge "Make plugins easier to use"

This commit is contained in:
Jenkins 2014-07-07 16:15:35 +00:00 committed by Gerrit Code Review
commit 4dcd1d76c8
6 changed files with 33 additions and 53 deletions

View File

@ -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"
::

View File

@ -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)

View File

@ -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):

View File

@ -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

View File

@ -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)

View File

@ -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