This commit is contained in:
2026-06-01 18:27:15 +03:00
parent ae986fa9e6
commit 1ab446e05d
34 changed files with 5135 additions and 2113 deletions

View File

@@ -43,7 +43,13 @@ class decort_pfw(DecortController):
supports_check_mode=True,
)
def decort_pfw_package_facts(self, comp_facts, vins_facts, pfw_facts, check_mode=False):
def decort_pfw_package_facts(
self,
comp_facts,
vins_model: sdk_types.CloudapiVinsGetResultModel,
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.
@@ -68,9 +74,13 @@ class decort_pfw(DecortController):
ret_dict['state'] = "ABSENT"
return ret_dict
gw_vnf = vins_model.vnfs.gw
ret_dict['compute_id'] = comp_facts['id']
ret_dict['vins_id'] = vins_facts['id']
ret_dict['public_ip'] = vins_facts['vnfs']['GW']['config']['ext_net_ip']
ret_dict['vins_id'] = vins_model.id
if gw_vnf:
ret_dict['public_ip'] = gw_vnf.config.ext_net_ip
else:
raise RuntimeError('VINS GW VNF must exist.')
if len(pfw_facts) != 0:
ret_dict['state'] = 'PRESENT'
@@ -106,16 +116,15 @@ class decort_pfw(DecortController):
self.result['msg'] = "Cannot find specified Compute ID {}.".format(amodule.params['compute_id'])
amodule.fail_json(**self.result)
validated_vins_id, vins_facts = self.vins_find(amodule.params['vins_id'])
if not validated_vins_id:
self.result['failed'] = True
self.result['msg'] = "Cannot find specified ViNS ID {}.".format(amodule.params['vins_id'])
amodule.fail_json(**self.result)
vins_model = self._vins_get_by_id(vins_id=amodule.params['vins_id'])
gw_vnf_facts = vins_facts['vnfs'].get('GW')
if not gw_vnf_facts or gw_vnf_facts['status'] == "DESTROYED":
gw_vnf = vins_model.vnfs.gw
if not gw_vnf or gw_vnf.status == sdk_types.VNFStatus.DESTROYED:
self.result['failed'] = True
self.result['msg'] = "ViNS ID {} does not have a configured external connection.".format(validated_vins_id)
self.result['msg'] = (
f'ViNS ID {vins_model.id} does not '
f'have a configured external connection.'
)
amodule.fail_json(**self.result)
#
@@ -124,12 +133,20 @@ class decort_pfw(DecortController):
if amodule.params['state'] == 'absent':
# ignore amodule.params['rules'] and remove all rules associated with this Compute
pfw_facts = self.pfw_configure(comp_facts, vins_facts, None)
pfw_facts = self.pfw_configure(
comp_facts,
vins_model,
None,
)
elif amodule.params['rules'] is not None:
# manage PFW rules accodring to the module arguments
pfw_facts = self.pfw_configure(comp_facts, vins_facts, amodule.params['rules'])
pfw_facts = self.pfw_configure(
comp_facts,
vins_model,
amodule.params['rules'],
)
else:
pfw_facts = self._pfw_get(comp_facts['id'], vins_facts['id'])
pfw_facts = self._pfw_get(comp_facts['id'], vins_model.id)
#
# complete module run
@@ -138,7 +155,12 @@ class decort_pfw(DecortController):
amodule.fail_json(**self.result)
else:
# prepare PFW facts to be returned as part of self.result and then call exit_json(...)
self.result['facts'] = self.decort_pfw_package_facts(comp_facts, vins_facts, pfw_facts, amodule.check_mode)
self.result['facts'] = self.decort_pfw_package_facts(
comp_facts,
vins_model,
pfw_facts,
amodule.check_mode,
)
amodule.exit_json(**self.result)