Debug PFW module and minor fixes to the rest of the modules
This commit is contained in:
@@ -29,7 +29,7 @@ requirements:
|
|||||||
- PyJWT module
|
- PyJWT module
|
||||||
- requests module
|
- requests module
|
||||||
- decort_utils utility library (module)
|
- decort_utils utility library (module)
|
||||||
- DECORT cloud platform version 3.4.1 or higher
|
- DECORT cloud platform version 3.4.2 or higher
|
||||||
notes:
|
notes:
|
||||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ requirements:
|
|||||||
- PyJWT module
|
- PyJWT module
|
||||||
- requests module
|
- requests module
|
||||||
- decort_utils utility library (module)
|
- decort_utils utility library (module)
|
||||||
- DECORT cloud platform version 3.4.1 or higher
|
- DECORT cloud platform version 3.4.2 or higher
|
||||||
notes:
|
notes:
|
||||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ requirements:
|
|||||||
- PyJWT module
|
- PyJWT module
|
||||||
- requests module
|
- requests module
|
||||||
- decort_utils utility library (module)
|
- decort_utils utility library (module)
|
||||||
- DECORT cloud platform version 3.4.1 or higher.
|
- DECORT cloud platform version 3.4.2 or higher.
|
||||||
notes:
|
notes:
|
||||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: decort_disk
|
module: decort_pfw
|
||||||
short_description: Manage network Port Forward rules for Compute instances in DECORT cloud
|
short_description: Manage network Port Forward rules for Compute instances in DECORT cloud
|
||||||
description: >
|
description: >
|
||||||
This module can be used to create new port forwarding rules in DECORT cloud platform,
|
This module can be used to create new port forwarding rules in DECORT cloud platform,
|
||||||
@@ -29,7 +29,7 @@ requirements:
|
|||||||
- PyJWT module
|
- PyJWT module
|
||||||
- requests module
|
- requests module
|
||||||
- decort_utils utility library (module)
|
- decort_utils utility library (module)
|
||||||
- DECORT cloud platform version 3.4.1 or higher
|
- DECORT cloud platform version 3.4.2 or higher
|
||||||
notes:
|
notes:
|
||||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||||
@@ -105,7 +105,9 @@ options:
|
|||||||
be created, which maps specified external port range to local ports starting from I(local_port).'
|
be created, which maps specified external port range to local ports starting from I(local_port).'
|
||||||
- ' - (int) local_port - port number on the local interface of the Compute. For ranged rule it is
|
- ' - (int) local_port - port number on the local interface of the Compute. For ranged rule it is
|
||||||
interpreted as a base port to translate public port range to internal port range.'
|
interpreted as a base port to translate public port range to internal port range.'
|
||||||
- ' - (string) porot - protocol, specify either I(tcp) or I(udp).'
|
- ' - (string) proto - protocol, specify either I(tcp) or I(udp).'
|
||||||
|
- 'Note that rules are meaningful only if I(state=present). If I(state=absent) is specified, rules set
|
||||||
|
will be ignored, and all rules for the specified Compute will be deleted.'
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- 'Specify the desired state of the port forwarding rules set for the Compute instance identified by
|
- 'Specify the desired state of the port forwarding rules set for the Compute instance identified by
|
||||||
@@ -192,7 +194,7 @@ def decort_pfw_package_facts(pfw_facts, check_mode=False):
|
|||||||
ret_dict = dict(id=0,
|
ret_dict = dict(id=0,
|
||||||
name="none",
|
name="none",
|
||||||
state="CHECK_MODE",
|
state="CHECK_MODE",
|
||||||
comp_id=0,
|
compute_id=0,
|
||||||
vins_id=0,
|
vins_id=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -205,7 +207,7 @@ def decort_pfw_package_facts(pfw_facts, check_mode=False):
|
|||||||
ret_dict['state'] = "ABSENT"
|
ret_dict['state'] = "ABSENT"
|
||||||
return ret_dict
|
return ret_dict
|
||||||
|
|
||||||
ret_dict['comp_id'] = pfw_facts['com_id']
|
ret_dict['compute_id'] = pfw_facts['compute_id']
|
||||||
|
|
||||||
return ret_dict
|
return ret_dict
|
||||||
|
|
||||||
@@ -268,7 +270,7 @@ def main():
|
|||||||
|
|
||||||
decon = DecortController(amodule)
|
decon = DecortController(amodule)
|
||||||
|
|
||||||
pfw_facts = None # will hold PFW facts
|
pfw_facts = None # will hold PFW facts as returned by pfw_configure
|
||||||
|
|
||||||
#
|
#
|
||||||
# Validate module arguments:
|
# Validate module arguments:
|
||||||
@@ -278,10 +280,10 @@ def main():
|
|||||||
# 4) Compute is connected to this ViNS
|
# 4) Compute is connected to this ViNS
|
||||||
#
|
#
|
||||||
|
|
||||||
validated_comp_id, comp_facts, rg_id = decon.compute_find(amodule.params['comp_id'])
|
validated_comp_id, comp_facts, rg_id = decon.compute_find(amodule.params['compute_id'])
|
||||||
if not validated_comp_id:
|
if not validated_comp_id:
|
||||||
decon.result['failed'] = True
|
decon.result['failed'] = True
|
||||||
decon.result['msg'] = "Cannot find specified Compute ID {}.".format(amodule.params['comp_id'])
|
decon.result['msg'] = "Cannot find specified Compute ID {}.".format(amodule.params['compute_id'])
|
||||||
amodule.fail_json(**decon.result)
|
amodule.fail_json(**decon.result)
|
||||||
|
|
||||||
validated_vins_id, vins_facts = decon.vins_find(amodule.params['vins_id'])
|
validated_vins_id, vins_facts = decon.vins_find(amodule.params['vins_id'])
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ requirements:
|
|||||||
- PyJWT module
|
- PyJWT module
|
||||||
- requests module
|
- requests module
|
||||||
- decort_utils utility library (module)
|
- decort_utils utility library (module)
|
||||||
- DECORT cloud platform version 3.4.0 or higher
|
- DECORT cloud platform version 3.4.2 or higher
|
||||||
notes:
|
notes:
|
||||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ requirements:
|
|||||||
- PyJWT module
|
- PyJWT module
|
||||||
- requests module
|
- requests module
|
||||||
- decort_utils utility library (module)
|
- decort_utils utility library (module)
|
||||||
- DECORT cloud platform version 3.4.1 or higher
|
- DECORT cloud platform version 3.4.2 or higher
|
||||||
notes:
|
notes:
|
||||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||||
|
|||||||
@@ -532,14 +532,16 @@ class DecortController(object):
|
|||||||
api_params = dict(computeId = comp_dict['id'], diskId=did)
|
api_params = dict(computeId = comp_dict['id'], diskId=did)
|
||||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/diskDetach", api_params)
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/diskDetach", api_params)
|
||||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
|
self.result['changed'] = True
|
||||||
|
|
||||||
for did in attach_list:
|
for did in attach_list:
|
||||||
api_params = dict(computeId = comp_dict['id'], diskId=did)
|
api_params = dict(computeId = comp_dict['id'], diskId=did)
|
||||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/diskAttach", api_params)
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/diskAttach", api_params)
|
||||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
|
self.result['changed'] = True
|
||||||
|
|
||||||
self.result['failed'] = False
|
self.result['failed'] = False
|
||||||
self.result['changed'] = True
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def compute_delete(self, comp_id, permanently=False):
|
def compute_delete(self, comp_id, permanently=False):
|
||||||
@@ -841,6 +843,7 @@ class DecortController(object):
|
|||||||
#
|
#
|
||||||
# then all values (including those for 'id' key) when entering this method will be of
|
# then all values (including those for 'id' key) when entering this method will be of
|
||||||
# type string. We need to explicitly cast int type on all of them.
|
# type string. We need to explicitly cast int type on all of them.
|
||||||
|
|
||||||
for repair in new_networks:
|
for repair in new_networks:
|
||||||
repair['id'] = int(repair['id'])
|
repair['id'] = int(repair['id'])
|
||||||
|
|
||||||
@@ -931,13 +934,14 @@ class DecortController(object):
|
|||||||
for api_params in detach_list:
|
for api_params in detach_list:
|
||||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/netDetach", api_params)
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/netDetach", api_params)
|
||||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
|
self.result['changed'] = True
|
||||||
|
|
||||||
for api_params in attach_list:
|
for api_params in attach_list:
|
||||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/netAttach", api_params)
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/netAttach", api_params)
|
||||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
|
self.result['changed'] = True
|
||||||
|
|
||||||
self.result['failed'] = False
|
self.result['failed'] = False
|
||||||
self.result['changed'] = True
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -2473,14 +2477,12 @@ class DecortController(object):
|
|||||||
"for Compute ID {} are empty - nothing to do.").format(comp_facts['id'])
|
"for Compute ID {} are empty - nothing to do.").format(comp_facts['id'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not len(new_rules):
|
if new_rules == None or len(new_rules) == 0:
|
||||||
# delete all existing rules for this Compute
|
# delete all existing rules for this Compute
|
||||||
api_params = dict(vinsId=vins_facts['id'])
|
api_params = dict(vinsId=vins_facts['id'],
|
||||||
for runner in existing_rules:
|
ruleId=-1)
|
||||||
api_params['ruleId'] = runner['id']
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/vins/natRuleDel", api_params)
|
||||||
self.decort_api_call(requests.post, "/restmachine/cloudapi/vins/natRuleDel", api_params)
|
self.result['changed'] = True
|
||||||
self.result['failed'] = False
|
|
||||||
self.result['chnaged'] = True
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -2540,6 +2542,8 @@ class DecortController(object):
|
|||||||
# tells what kind of action is expected on this rule - 'add' or 'del'
|
# tells what kind of action is expected on this rule - 'add' or 'del'
|
||||||
# We first iterate to delete, then iterate again to add rules
|
# We first iterate to delete, then iterate again to add rules
|
||||||
|
|
||||||
|
# Sort pfw_delta_list so that the items with action="del" come first, and those with
|
||||||
|
# action='add' come last.
|
||||||
# Iterate over pfw_delta_list and first delete port forwarding rules marked for deletion,
|
# Iterate over pfw_delta_list and first delete port forwarding rules marked for deletion,
|
||||||
# next create the rules marked for creation.
|
# next create the rules marked for creation.
|
||||||
api_base = "/restmachine/cloudapi/vins/"
|
api_base = "/restmachine/cloudapi/vins/"
|
||||||
@@ -2549,6 +2553,7 @@ class DecortController(object):
|
|||||||
ruleId=delta_rule['id'])
|
ruleId=delta_rule['id'])
|
||||||
self.decort_api_call(requests.post, api_base + 'natRuleDel', api_params)
|
self.decort_api_call(requests.post, api_base + 'natRuleDel', api_params)
|
||||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
|
self.result['changed'] = True
|
||||||
elif delta_rule['action'] == 'add':
|
elif delta_rule['action'] == 'add':
|
||||||
api_params = dict(vinsId=vins_facts['id'],
|
api_params = dict(vinsId=vins_facts['id'],
|
||||||
intIp=iface_ipaddr,
|
intIp=iface_ipaddr,
|
||||||
@@ -2558,7 +2563,8 @@ class DecortController(object):
|
|||||||
proto=delta_rule['protocol'])
|
proto=delta_rule['protocol'])
|
||||||
self.decort_api_call(requests.post, api_base + 'natRuleAdd', api_params)
|
self.decort_api_call(requests.post, api_base + 'natRuleAdd', api_params)
|
||||||
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
# On success the above call will return here. On error it will abort execution by calling fail_json.
|
||||||
|
self.result['changed'] = True
|
||||||
|
|
||||||
self.result['failed'] = False
|
self.result['failed'] = False
|
||||||
self.result['changed'] = True
|
|
||||||
return
|
return
|
||||||
Reference in New Issue
Block a user