In Mistral, we have keywords that should be taken care of such as action, workflow, yaql. In fact, we can easily create customized actions, workflows to execute processes we want and use yaql language to filter, process or access to some data. We also have documentation to describe it as below:
YAQL: https://wiki.openstack.org/wiki/Mistral/UsingYAQL
ACTION PLUGIN: http://docs.openstack.org/developer/mistral/developer/creating_custom_action.html
In this blog, what we can go through is nothing else just getting familiar with customizing/developing your own actions, workflows to fulfill the purpose of your requirements. In the source code of mistral, there is a base class that define action which is mistral/actions/base.py. If we want to write a new action plugin, based on the documentation of mistral, we should subclass it. However, this class is nothing else just a class that built on top of metaclass and it defines some abstract methods such as “run”, “test” that should be re-define in a action plugin, therefore we can rewrite another base class for action if we would like to have. Note that, the action will be triggered to run through the executor. Check the file of mistral/engine/default_executor.py to see the action.run() triggered.
The environment for this test bed is ubuntu 14.04 and devstack newton. So let’s moving on.
Based on the instruction of writing custom action in mistral, we have to subclass the Action() class which is a base of every action in mistral. This custom class example uses the action base of mistral:
Besides, if we would like we can re-write an action base to be not dependent on that base of Mistral. The below is such an example:
I created a folder call ‘openstack_access’ to put the method get_client() into which is the way to connect to Nova client. The below is get_client()
For the action, we can create something very basic as below. Here I do not want to depend on the base class of mistral (actually, we have to depend on the run() and test() methods if we use mistral action base), therefore I use my own action base class as VietStackAction() and create other actions Action1 and Action2 as below:
And now, we can write our own workflow which is actually a yaml file. After finishing our own workflow, put it into the mistral/resources/workflows and re-run mistral db-manage (check it on Internet) to store its information in to db. (db-manage is also needed after finishing the action). The below is a simple example of workflow. Note that in the workflow (especially in inputs of actions) we can use yaql to filter or access to the value of inputs.
Problem: When we try to write custom workflow, we would like to have something so called validator that validate the jsonschema of inputs of each workflow. Inside the architect of mistral, there is nothing to validate for inputs of each action. This problem is also given out to discuss in the mistral community.
Have fun!!!!!!
3/12/2016
VietStack team
Comments