Skip to content

Commit

Permalink
Adding support for Plugin runnable type
Browse files Browse the repository at this point in the history
Adding support for device arrays in vdirect_runnable module.
Adding "output" dictionary to the vdirect_runnable module result dictionary.
  • Loading branch information
evgenyfedoruk committed Aug 29, 2019
1 parent f905870 commit ee83db8
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 85 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/radware/vdirect_commit.py
Expand Up @@ -111,7 +111,7 @@
default: 'yes'
requirements:
- "vdirect-client >= 4.1.1"
- "vdirect-client >= 4.9.0-post4"
'''

EXAMPLES = '''
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/radware/vdirect_file.py
Expand Up @@ -91,7 +91,7 @@
required: true
requirements:
- "vdirect-client >= 4.1.1"
- "vdirect-client >= 4.9.0-post4"
'''

EXAMPLES = '''
Expand Down
52 changes: 34 additions & 18 deletions lib/ansible/modules/network/radware/vdirect_runnable.py
Expand Up @@ -88,7 +88,7 @@
description:
- vDirect runnable type.
required: true
choices: ['ConfigurationTemplate', 'Workflow', 'WorkflowTemplate']
choices: ['ConfigurationTemplate', 'Workflow', 'WorkflowTemplate', 'Plugin']
runnable_name:
description:
- vDirect runnable name to run.
Expand All @@ -104,7 +104,7 @@
- the device connection details should always be passed as a parameter.
requirements:
- "vdirect-client >= 4.1.1"
- "vdirect-client >= 4.9.0-post4"
'''

EXAMPLES = '''
Expand Down Expand Up @@ -138,10 +138,12 @@
CONFIGURATION_TEMPLATE_RUNNABLE_TYPE = 'ConfigurationTemplate'
WORKFLOW_TEMPLATE_RUNNABLE_TYPE = 'WorkflowTemplate'
WORKFLOW_RUNNABLE_TYPE = 'Workflow'
PLUGIN_RUNNABLE_TYPE = 'Plugin'

TEMPLATE_SUCCESS = 'Configuration template run completed.'
WORKFLOW_CREATION_SUCCESS = 'Workflow created.'
WORKFLOW_ACTION_SUCCESS = 'Workflow action run completed.'
PLUGIN_ACTION_SUCCESS = 'Plugin action run completed.'

meta_args = dict(
vdirect_ip=dict(required=True, fallback=(env_fallback, ['VDIRECT_IP'])),
Expand Down Expand Up @@ -172,7 +174,7 @@
default=2188, type='int'),
runnable_type=dict(
required=True,
choices=[CONFIGURATION_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_RUNNABLE_TYPE]),
choices=[CONFIGURATION_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_RUNNABLE_TYPE, PLUGIN_RUNNABLE_TYPE]),
runnable_name=dict(required=True),
action_name=dict(required=False, default=None),
parameters=dict(required=False, type='dict', default={})
Expand Down Expand Up @@ -222,29 +224,39 @@ def __init__(self, params):
https_port=params['vdirect_https_port'],
http_port=params['vdirect_http_port'],
timeout=params['vdirect_timeout'],
strict_http_results=True,
https=params['vdirect_use_ssl'],
verify=params['validate_certs'])
self.params = params
self.type = self.params['runnable_type']
self.name = self.params['runnable_name']
if 'parameters' in self.params:
self.action_params = self.params['parameters']
else:
self.action_params = []

def _validate_runnable_exists(self):
res = self.client.runnable.get_runnable_objects(self.type)
runnable_names = res[rest_client.RESP_DATA]['names']
if self.name not in runnable_names:
raise MissingRunnableException(self.name)

def _validate_action_name(self):
if self.type == WORKFLOW_TEMPLATE_RUNNABLE_TYPE:
self.action_name = VdirectRunnable.CREATE_WORKFLOW_ACTION
elif self.type == CONFIGURATION_TEMPLATE_RUNNABLE_TYPE:
self.action_name = VdirectRunnable.RUN_ACTION
else:
self.action_name = self.params['action_name']

if 'parameters' in self.params and self.params['parameters']:
self.action_params = self.params['parameters']
else:
self.action_params = {}

def _validate_runnable_exists(self):
if self.type == WORKFLOW_RUNNABLE_TYPE:
res = self.client.runnable.get_runnable_objects(self.type)
runnable_names = res[rest_client.RESP_DATA]['names']
if self.name not in runnable_names:
raise MissingRunnableException(self.name)
else:
try:
self.client.catalog.get_catalog_item(self.type, self.name)
except rest_client.RestClientException:
raise MissingRunnableException(self.name)

def _validate_action_name(self):
if self.type in [WORKFLOW_RUNNABLE_TYPE, PLUGIN_RUNNABLE_TYPE]:
res = self.client.runnable.get_available_actions(self.type, self.name)
available_actions = res[rest_client.RESP_DATA]['names']
if self.action_name not in available_actions:
Expand All @@ -263,6 +275,9 @@ def _validate_required_action_params(self):
if p['type'] == 'alteon' or
p['type'] == 'defensePro' or
p['type'] == 'appWall' or
p['type'] == 'alteon[]' or
p['type'] == 'defensePro[]' or
p['type'] == 'appWall[]' or
p['direction'] != 'out']
required_action_params_names = [n['name'] for n in required_action_params_dict]

Expand All @@ -284,11 +299,11 @@ def run(self):
result_to_return['msg'] = WORKFLOW_CREATION_SUCCESS
elif self.type == CONFIGURATION_TEMPLATE_RUNNABLE_TYPE:
result_to_return['msg'] = TEMPLATE_SUCCESS
elif self.type == PLUGIN_RUNNABLE_TYPE:
result_to_return['msg'] = PLUGIN_ACTION_SUCCESS
else:
result_to_return['msg'] = WORKFLOW_ACTION_SUCCESS

if 'parameters' in result[rest_client.RESP_DATA]:
result_to_return['parameters'] = result[rest_client.RESP_DATA]['parameters']
result_to_return['output'] = result[rest_client.RESP_DATA]

else:
if 'exception' in result[rest_client.RESP_DATA]:
Expand All @@ -307,7 +322,8 @@ def run(self):
def main():

module = AnsibleModule(argument_spec=meta_args,
required_if=[['runnable_type', WORKFLOW_RUNNABLE_TYPE, ['action_name']]])
required_if=[['runnable_type', WORKFLOW_RUNNABLE_TYPE, ['action_name']],
['runnable_type', PLUGIN_RUNNABLE_TYPE, ['action_name']]])

if not HAS_REST_CLIENT:
module.fail_json(msg="The python vdirect-client module is required")
Expand Down

0 comments on commit ee83db8

Please sign in to comment.