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
This commit is contained in:
parent
f36ade4009
commit
fc46164d5f
@ -21,22 +21,11 @@ How to write an Action Plugin
|
|||||||
::
|
::
|
||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
myproject.plugins.example =
|
mistral.actions =
|
||||||
runner = solum.mistral_plugins.somefile:RunnerAction
|
example.runner = my.mistral_plugins.somefile:RunnerAction
|
||||||
|
|
||||||
3. Add the namespace into /etc/mistral/mistral.conf
|
3. Use your plugin
|
||||||
(don't overwrite "mistral.plugins.std")
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
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"
|
* Now you can call the action "example.runner"
|
||||||
|
|
||||||
::
|
::
|
||||||
|
@ -198,9 +198,6 @@
|
|||||||
# Options defined in mistral.config
|
# 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
|
# Specifies which mistral server to start by the launch
|
||||||
# script. Valid options are all or any combination of api,
|
# script. Valid options are all or any combination of api,
|
||||||
# engine, and executor. (list value)
|
# engine, and executor. (list value)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
from oslo.config import cfg
|
from stevedore import extension
|
||||||
|
|
||||||
from mistral.actions import base
|
from mistral.actions import base
|
||||||
from mistral.actions import std_actions
|
from mistral.actions import std_actions
|
||||||
@ -30,12 +30,11 @@ _ACTION_CTX_PARAM = 'action_context'
|
|||||||
_NAMESPACES = {}
|
_NAMESPACES = {}
|
||||||
|
|
||||||
|
|
||||||
def _find_or_create_namespace(full_name):
|
def _find_or_create_namespace(name):
|
||||||
name = full_name.split('.')[-1]
|
|
||||||
ns = _NAMESPACES.get(name)
|
ns = _NAMESPACES.get(name)
|
||||||
|
|
||||||
if not ns:
|
if not ns:
|
||||||
ns = base.Namespace(full_name)
|
ns = base.Namespace(name)
|
||||||
_NAMESPACES[name] = ns
|
_NAMESPACES[name] = ns
|
||||||
|
|
||||||
return ns
|
return ns
|
||||||
@ -46,10 +45,16 @@ def get_registered_namespaces():
|
|||||||
|
|
||||||
|
|
||||||
def _register_action_classes():
|
def _register_action_classes():
|
||||||
cfg.CONF.import_opt('action_plugins', 'mistral.config')
|
mgr = extension.ExtensionManager(
|
||||||
for py_ns in cfg.CONF.action_plugins:
|
namespace='mistral.actions',
|
||||||
ns = _find_or_create_namespace(py_ns)
|
invoke_on_load=False)
|
||||||
ns.log()
|
|
||||||
|
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):
|
def get_action_class(action_full_name):
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
from stevedore import extension
|
|
||||||
|
|
||||||
from mistral.openstack.common import log as logging
|
from mistral.openstack.common import log as logging
|
||||||
|
|
||||||
@ -87,25 +86,22 @@ class Namespace(object):
|
|||||||
"""Action namespace."""
|
"""Action namespace."""
|
||||||
|
|
||||||
def __init__(self, namespace):
|
def __init__(self, namespace):
|
||||||
self.name = namespace.split('.')[-1]
|
self.name = namespace
|
||||||
self.mgr = extension.ExtensionManager(
|
self.actions = {}
|
||||||
namespace=namespace,
|
|
||||||
invoke_on_load=False)
|
|
||||||
|
|
||||||
def contains_action_name(self, name):
|
def contains_action_name(self, name):
|
||||||
return name in self.mgr.names()
|
return name in self.actions
|
||||||
|
|
||||||
def get_action_class(self, name):
|
def get_action_class(self, name):
|
||||||
# ExtensionManager has no "get"
|
return self.actions.get(name)
|
||||||
if self.contains_action_name(name):
|
|
||||||
return self.mgr[name].plugin
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
# ExtensionManager has no len()
|
return len(self.actions)
|
||||||
return len(self.mgr.names())
|
|
||||||
|
|
||||||
def log(self):
|
def log(self):
|
||||||
for ext in self.mgr:
|
for ext in self.actions:
|
||||||
LOG.debug('%s:%s' % (self.name, ext.name))
|
LOG.debug('%s:%s' % (self.name, ext))
|
||||||
|
|
||||||
|
def add(self, name, action):
|
||||||
|
if name not in self.actions:
|
||||||
|
self.actions[name] = action
|
||||||
|
@ -87,12 +87,6 @@ launch_opt = cfg.ListOpt(
|
|||||||
'api, engine, and executor.'
|
'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',
|
wf_trace_log_name_opt = cfg.StrOpt('workflow_trace_log_name',
|
||||||
default='workflow_trace',
|
default='workflow_trace',
|
||||||
help='Logger name for pretty '
|
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(db_opts, group='database')
|
||||||
CONF.register_opts(executor_opts, group='executor')
|
CONF.register_opts(executor_opts, group='executor')
|
||||||
CONF.register_opt(wf_trace_log_name_opt)
|
CONF.register_opt(wf_trace_log_name_opt)
|
||||||
CONF.register_opt(action_plugins_opt)
|
|
||||||
|
|
||||||
CONF.register_cli_opt(use_debugger)
|
CONF.register_cli_opt(use_debugger)
|
||||||
CONF.register_cli_opt(launch_opt)
|
CONF.register_cli_opt(launch_opt)
|
||||||
|
12
setup.cfg
12
setup.cfg
@ -39,9 +39,9 @@ mistral.engine.drivers =
|
|||||||
mistral.executor.drivers =
|
mistral.executor.drivers =
|
||||||
default = mistral.engine.drivers.default.executor:DefaultExecutor
|
default = mistral.engine.drivers.default.executor:DefaultExecutor
|
||||||
|
|
||||||
mistral.actions.std =
|
mistral.actions =
|
||||||
echo = mistral.actions.std_actions:EchoAction
|
std.echo = mistral.actions.std_actions:EchoAction
|
||||||
http = mistral.actions.std_actions:HTTPAction
|
std.http = mistral.actions.std_actions:HTTPAction
|
||||||
mistral_http = mistral.actions.std_actions:MistralHTTPAction
|
std.mistral_http = mistral.actions.std_actions:MistralHTTPAction
|
||||||
ssh = mistral.actions.std_actions:SSHAction
|
std.ssh = mistral.actions.std_actions:SSHAction
|
||||||
email = mistral.actions.std_actions:SendEmailAction
|
std.email = mistral.actions.std_actions:SendEmailAction
|
||||||
|
Loading…
Reference in New Issue
Block a user