11.0.0
This commit is contained in:
@@ -86,60 +86,65 @@ class decort_pfw(DecortController):
|
||||
|
||||
return
|
||||
|
||||
@DecortController.handle_sdk_exceptions
|
||||
def run(self):
|
||||
amodule = self.amodule
|
||||
|
||||
pfw_facts = None # will hold PFW facts as returned by pfw_configure
|
||||
|
||||
#
|
||||
# Validate module arguments:
|
||||
# 1) specified Compute instance exists in correct state
|
||||
# 2) specified ViNS exists
|
||||
# 3) ViNS has GW function
|
||||
# 4) Compute is connected to this ViNS
|
||||
#
|
||||
|
||||
validated_comp_id, comp_facts, rg_id = self.compute_find(amodule.params['compute_id'])
|
||||
if not validated_comp_id:
|
||||
self.result['failed'] = True
|
||||
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)
|
||||
|
||||
gw_vnf_facts = vins_facts['vnfs'].get('GW')
|
||||
if not gw_vnf_facts or gw_vnf_facts['status'] == "DESTROYED":
|
||||
self.result['failed'] = True
|
||||
self.result['msg'] = "ViNS ID {} does not have a configured external connection.".format(validated_vins_id)
|
||||
amodule.fail_json(**self.result)
|
||||
|
||||
#
|
||||
# Initial validation of module arguments is complete
|
||||
#
|
||||
|
||||
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)
|
||||
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'])
|
||||
else:
|
||||
pfw_facts = self._pfw_get(comp_facts['id'], vins_facts['id'])
|
||||
|
||||
#
|
||||
# complete module run
|
||||
#
|
||||
if self.result['failed']:
|
||||
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)
|
||||
amodule.exit_json(**self.result)
|
||||
|
||||
|
||||
def main():
|
||||
decon = decort_pfw()
|
||||
amodule = decon.amodule
|
||||
decort_pfw().run()
|
||||
|
||||
pfw_facts = None # will hold PFW facts as returned by pfw_configure
|
||||
|
||||
#
|
||||
# Validate module arguments:
|
||||
# 1) specified Compute instance exists in correct state
|
||||
# 2) specified ViNS exists
|
||||
# 3) ViNS has GW function
|
||||
# 4) Compute is connected to this ViNS
|
||||
#
|
||||
|
||||
validated_comp_id, comp_facts, rg_id = decon.compute_find(amodule.params['compute_id'])
|
||||
if not validated_comp_id:
|
||||
decon.result['failed'] = True
|
||||
decon.result['msg'] = "Cannot find specified Compute ID {}.".format(amodule.params['compute_id'])
|
||||
amodule.fail_json(**decon.result)
|
||||
|
||||
validated_vins_id, vins_facts = decon.vins_find(amodule.params['vins_id'])
|
||||
if not validated_vins_id:
|
||||
decon.result['failed'] = True
|
||||
decon.result['msg'] = "Cannot find specified ViNS ID {}.".format(amodule.params['vins_id'])
|
||||
amodule.fail_json(**decon.result)
|
||||
|
||||
gw_vnf_facts = vins_facts['vnfs'].get('GW')
|
||||
if not gw_vnf_facts or gw_vnf_facts['status'] == "DESTROYED":
|
||||
decon.result['failed'] = True
|
||||
decon.result['msg'] = "ViNS ID {} does not have a configured external connection.".format(validated_vins_id)
|
||||
amodule.fail_json(**decon.result)
|
||||
|
||||
#
|
||||
# Initial validation of module arguments is complete
|
||||
#
|
||||
|
||||
if amodule.params['state'] == 'absent':
|
||||
# ignore amodule.params['rules'] and remove all rules associated with this Compute
|
||||
pfw_facts = decon.pfw_configure(comp_facts, vins_facts, None)
|
||||
elif amodule.params['rules'] is not None:
|
||||
# manage PFW rules accodring to the module arguments
|
||||
pfw_facts = decon.pfw_configure(comp_facts, vins_facts, amodule.params['rules'])
|
||||
else:
|
||||
pfw_facts = decon._pfw_get(comp_facts['id'], vins_facts['id'])
|
||||
|
||||
#
|
||||
# complete module run
|
||||
#
|
||||
if decon.result['failed']:
|
||||
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'] = decon.decort_pfw_package_facts(comp_facts, vins_facts, pfw_facts, amodule.check_mode)
|
||||
amodule.exit_json(**decon.result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user