Removed unnecessary moduleChanged=False
Added missing exceptions handling
This commit is contained in:
parent
f7a5013083
commit
1972df5a71
1 changed files with 17 additions and 8 deletions
|
@ -101,7 +101,7 @@ def waitForNoTask(client, name, timeout):
|
||||||
currentTimeout-=1
|
currentTimeout-=1
|
||||||
if currentTimeout < 0:
|
if currentTimeout < 0:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -143,8 +143,11 @@ def main():
|
||||||
module.fail_json(msg='IP LoadBalancing {} does not exist'.format(name))
|
module.fail_json(msg='IP LoadBalancing {} does not exist'.format(name))
|
||||||
|
|
||||||
# Check that no task is pending before going on
|
# Check that no task is pending before going on
|
||||||
if not waitForNoTask(client, name, timeout):
|
try :
|
||||||
module.fail_json(msg='Timeout of {} seconds while waiting for no pending tasks before executing the module '.format(timeout))
|
if not waitForNoTask(client, name, timeout):
|
||||||
|
module.fail_json(msg='Timeout of {} seconds while waiting for no pending tasks before executing the module '.format(timeout))
|
||||||
|
except APIError as apiError:
|
||||||
|
module.fail_json(msg='Unable to call OVH api for getting the list of pending tasks of the loadBalancing, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
||||||
|
|
||||||
try :
|
try :
|
||||||
backends = client.get('/ip/loadBalancing/{}/backend'.format(name))
|
backends = client.get('/ip/loadBalancing/{}/backend'.format(name))
|
||||||
|
@ -163,13 +166,14 @@ def main():
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(msg='Unable to call OVH api for deleting the backend, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
module.fail_json(msg='Unable to call OVH api for deleting the backend, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
||||||
moduleChanged = True
|
moduleChanged = True
|
||||||
else :
|
|
||||||
moduleChanged = False
|
|
||||||
else :
|
else :
|
||||||
if backendExists :
|
if backendExists :
|
||||||
moduleChanged = False
|
|
||||||
# Get properties
|
# Get properties
|
||||||
backendProperties = client.get('/ip/loadBalancing/{}/backend/{}'.format(name, backend))
|
try :
|
||||||
|
backendProperties = client.get('/ip/loadBalancing/{}/backend/{}'.format(name, backend))
|
||||||
|
except APIError as apiError:
|
||||||
|
module.fail_json(msg='Unable to call OVH api for getting the backend properties, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
||||||
|
|
||||||
if (backendProperties['weight'] != weight):
|
if (backendProperties['weight'] != weight):
|
||||||
# Change weight
|
# Change weight
|
||||||
try :
|
try :
|
||||||
|
@ -179,6 +183,7 @@ def main():
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(msg='Unable to call OVH api for updating the weight of the backend, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
module.fail_json(msg='Unable to call OVH api for updating the weight of the backend, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
||||||
moduleChanged = True
|
moduleChanged = True
|
||||||
|
|
||||||
if (backendProperties['probe'] != probe):
|
if (backendProperties['probe'] != probe):
|
||||||
# Change probe
|
# Change probe
|
||||||
backendProperties['probe'] = probe
|
backendProperties['probe'] = probe
|
||||||
|
@ -193,7 +198,11 @@ def main():
|
||||||
else :
|
else :
|
||||||
# Creates backend
|
# Creates backend
|
||||||
try:
|
try:
|
||||||
client.post('/ip/loadBalancing/{}/backend'.format(name), ipBackend=backend, probe=probe, weight=weight)
|
try:
|
||||||
|
client.post('/ip/loadBalancing/{}/backend'.format(name), ipBackend=backend, probe=probe, weight=weight)
|
||||||
|
except APIError as apiError:
|
||||||
|
module.fail_json(msg='Unable to call OVH api for creating the backend, check application key, secret, consumerkey and parameters. Error returned by OVH api was : {}'.format(apiError))
|
||||||
|
|
||||||
if not waitForNoTask(client, name, timeout):
|
if not waitForNoTask(client, name, timeout):
|
||||||
module.fail_json(msg='Timeout of {} seconds while waiting for completion of backend creation task'.format(timeout))
|
module.fail_json(msg='Timeout of {} seconds while waiting for completion of backend creation task'.format(timeout))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
|
|
Loading…
Reference in a new issue