Optimizing PFW management workflows

This commit is contained in:
Sergey Shubin svs1370
2020-07-09 01:11:20 +03:00
parent c870989ed7
commit c7a3b5d6b2
3 changed files with 54 additions and 14 deletions

View File

@@ -32,7 +32,7 @@ requirements:
- PyJWT module
- requests module
- decort_utils utility library (module)
- DECORT cloud platform version 3.4.0 or higher
- DECORT cloud platform version 3.4.2 or higher
options:
app_id:
description:

View File

@@ -182,7 +182,7 @@ from ansible.module_utils.basic import env_fallback
from ansible.module_utils.decort_utils import *
def decort_pfw_package_facts(pfw_facts, check_mode=False):
def decort_pfw_package_facts(comp_id, vins_id, pfw_facts, check_mode=False):
"""Package a dictionary of PFW rules facts according to the decort_pfw module specification.
This dictionary will be returned to the upstream Ansible engine at the completion of
the module run.
@@ -191,11 +191,10 @@ def decort_pfw_package_facts(pfw_facts, check_mode=False):
@param (bool) check_mode: boolean that tells if this Ansible module is run in check mode
"""
ret_dict = dict(id=0,
name="none",
state="CHECK_MODE",
ret_dict = dict(state="CHECK_MODE",
compute_id=0,
vins_id=0,
rules=[],
)
if check_mode:
@@ -207,7 +206,14 @@ def decort_pfw_package_facts(pfw_facts, check_mode=False):
ret_dict['state'] = "ABSENT"
return ret_dict
ret_dict['compute_id'] = pfw_facts['compute_id']
ret_dict['compute_id'] = comp_id
ret_dict['vins_id'] = vins_id
if len(pfw_facts) != 0:
ret_dict['state'] = 'PRESENT'
ret_dict['rules'] = pfw_facts
else:
ret_dict['state'] = 'ABSENT'
return ret_dict
@@ -316,7 +322,7 @@ def main():
amodule.fail_json(**decon.result)
else:
# prepare PFW facts to be returned as part of decon.result and then call exit_json(...)
decon.result['facts'] = decort_pfw_package_facts(pfw_facts, amodule.check_mode)
decon.result['facts'] = decort_pfw_package_facts(comp_facts['id'], vins_facts['id'], pfw_facts, amodule.check_mode)
amodule.exit_json(**decon.result)