A python module to execute ansible-dellemc-unity (Ansible modules for DellEMC Unity).
This SDK provides common functions for all Ansible modules and special interface to communicate with Unity.
You have several ways to install this SDK
pip install dellemc-unity-sdk
git clone https://github.com/ansible-dellemc-unity/dellemc-unity-sdk.git
cd dellemc-unity-sdk
python setup.py sdist
sudo pip install dist/dellemc_unity_sdk.xxxx.tar.gz
git clone https://github.com/ansible-dellemc-unity/dellemc-unity-sdk.git
cd dellemc-unity-sdk
python setup.py sdist bdist_wheel
sudo pip install dist/dellemc_unity_sdk-XXXX-pyY-none-any.whl
According to our experience and issue #4 , you should create an instance of AnsibleModule in your module. So to create you should argument_spec use:
supportive_functions.create_arguments_for_ansible_module(array_of_dictionaries)
or
supportive_functions.create_arguments_for_ansible_module(template)
After that make an instance of AnsibleModule and put it next to template into
runner.run(ansible_module, template)
Your module will be automatically executed by SDK.
template is a dictionary that should have following keys:
constants.REST_OBJECT = 'rest_object'
value of this key should be a REST objectconstants.ACTIONS = 'actions'
value of this key should be a dictionary of actions, for example, {'create:{...}', 'delete':{...},...}
To execute actions automatically dictionary of action should have following parameters:
constants.ACTION_TYPE
value of this key should beconstants.ActionType.UPDATE
orconstants.ActionType.QUERY
constants.PARAMETER_TYPES = 'parameter_types'
value of this key should be a dictionary that should have keys: 'required' and 'optional' and value of each key should be iterable.
For example:
{
constants.REST_OBJECT: 'pool',
constants.ACTIONS: {
'delete':
{constants.ACTION_TYPE: constants.ActionType.UPDATE,
constants.PARAMETER_TYPES: parameters_all.get('delete')}
}
}
constants.REST_OBJECT_FOR_GET_REQUEST
use this key for making GET request to REST object that is different fromconstants.REST_OBJECT
-
constants.DO_ACTION = 'do action'
use this constant if you want the parameter name in the playbook to be different from the one in the REST model. For example,{ constants.REST_OBJECT: 'lun', constants.ACTIONS: { 'create': { constants.ACTION_TYPE: constants.ActionType.UPDATE, constants.PARAMETER_TYPES: parameters_all.get('create'), constants.DO_ACTION: " } } }
It should be a dictionary that can be written in two ways
{
"required_argument_var1" : dict(required=True, type=<type of this object>, default=<default_value>),
"required_argument_var2" : dict(required=True),
"optional_argument": dict(required=False),
"optional_argument_var_2": dict()...
}
you can skip some keys in dictionary, by default it will be
dict(required=False, type=None, default=None)
supported types of arguments:
- None - validator doesn't check type of this argument
- dict - validator expect type dictionary
- object - same as dict
- bool
- int
- str
- list
- any others python's object
- supported enums from dellemc_unity_sdk.rest_supported_enums
Dictionary should have keys: "required" and "optional". For example:
{
'required': {'type', 'name'},
'optional': {'description','osType','tenant'},
}
If your request can't be made by functions runner.do_update_request(...)
or runner.do_query_request(...)
you can
execute your own function by using key constants.EXECUTED_BY = 'executed_by'
For example:
{
constants.REST_OBJECT: 'pool',
constants.ACTIONS: {'create': {constants.EXECUTED_BY: function}}
}
Your function should have 2 parameters (parameters, unity). parameters = parameters from *.yml file,
unity = instance of class Unity and also function must have return statement,
that will be add to output in parameter 'output'
All REST objects have action "get" (constants.GET
), that sends GET requests, you are allowed to redefine this action