Fixed multiline string formatting issues
This commit is contained in:
parent
eb5fcca80b
commit
f3f40095f1
1 changed files with 78 additions and 73 deletions
|
@ -19,12 +19,12 @@ module: ovh_ip_loadbalancing_backend
|
||||||
short_description: Manage OVH IP LoadBalancing backends
|
short_description: Manage OVH IP LoadBalancing backends
|
||||||
description:
|
description:
|
||||||
- Manage OVH (French European hosting provider) LoadBalancing IP backends
|
- Manage OVH (French European hosting provider) LoadBalancing IP backends
|
||||||
version_added: "2.1"
|
version_added: "2.2"
|
||||||
author: Pascal HERAUD @pascalheraud
|
author: Pascal HERAUD @pascalheraud
|
||||||
notes:
|
notes:
|
||||||
- Uses the python OVH Api U(https://github.com/ovh/python-ovh). \
|
- Uses the python OVH Api U(https://github.com/ovh/python-ovh).
|
||||||
You have to create an application (a key and secret) with a consummer \
|
You have to create an application (a key and secret) with a consummer
|
||||||
key as described into U(https://eu.api.ovh.com/g934.first_step_with_api)
|
key as described into U(https://eu.api.ovh.com/g934.first_step_with_api)
|
||||||
requirements:
|
requirements:
|
||||||
- ovh > 0.3.5
|
- ovh > 0.3.5
|
||||||
options:
|
options:
|
||||||
|
@ -41,8 +41,8 @@ options:
|
||||||
default: present
|
default: present
|
||||||
choices: ['present', 'absent']
|
choices: ['present', 'absent']
|
||||||
description:
|
description:
|
||||||
- Determines wether the backend is to be created/modified \
|
- Determines wether the backend is to be created/modified
|
||||||
or deleted
|
or deleted
|
||||||
probe:
|
probe:
|
||||||
required: false
|
required: false
|
||||||
default: none
|
default: none
|
||||||
|
@ -75,22 +75,24 @@ options:
|
||||||
type: "int"
|
type: "int"
|
||||||
default: 120
|
default: 120
|
||||||
description:
|
description:
|
||||||
- The timeout in seconds used to wait for a task to be \
|
- The timeout in seconds used to wait for a task to be
|
||||||
completed. Default is 120 seconds.
|
completed. Default is 120 seconds.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Adds or modify a backend to a loadbalancing
|
# Adds or modify the backend '212.1.1.1' to a
|
||||||
- ovh_ip_loadbalancing name=ip-1.1.1.1 ip=212.1.1.1 state=present \
|
# loadbalancing 'ip-1.1.1.1'
|
||||||
probe=none weight=8 \
|
- ovh_ip_loadbalancing name=ip-1.1.1.1 backend=212.1.1.1
|
||||||
endpoint=ovh-eu application_key=yourkey \
|
state=present probe=none weight=8
|
||||||
application_secret=yoursecret consumer_key=yourconsumerkey
|
endpoint=ovh-eu application_key=yourkey
|
||||||
|
application_secret=yoursecret consumer_key=yourconsumerkey
|
||||||
|
|
||||||
# Removes a backend from a loadbalancing
|
# Removes a backend '212.1.1.1' from a loadbalancing
|
||||||
- ovh_ip_loadbalancing name=ip-1.1.1.1 ip=212.1.1.1 state=absent \
|
# 'ip-1.1.1.1'
|
||||||
endpoint=ovh-eu application_key=yourkey \
|
- ovh_ip_loadbalancing name=ip-1.1.1.1 backend=212.1.1.1
|
||||||
application_secret=yoursecret consumer_key=yourconsumerkey
|
state=absent endpoint=ovh-eu application_key=yourkey
|
||||||
|
application_secret=yoursecret consumer_key=yourconsumerkey
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -121,7 +123,7 @@ def getOvhClient(ansibleModule):
|
||||||
|
|
||||||
def waitForNoTask(client, name, timeout):
|
def waitForNoTask(client, name, timeout):
|
||||||
currentTimeout = timeout
|
currentTimeout = timeout
|
||||||
while len(client.get('/ip/loadBalancing/{}/task'.format(name))) > 0:
|
while len(client.get('/ip/loadBalancing/{0}/task'.format(name))) > 0:
|
||||||
time.sleep(1) # Delay for 1 sec
|
time.sleep(1) # Delay for 1 sec
|
||||||
currentTimeout -= 1
|
currentTimeout -= 1
|
||||||
if currentTimeout < 0:
|
if currentTimeout < 0:
|
||||||
|
@ -147,8 +149,8 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_OVH:
|
if not HAS_OVH:
|
||||||
module.fail_json(msg='ovh-api python module\
|
module.fail_json(msg='ovh-api python module'
|
||||||
is required to run this module ')
|
'is required to run this module ')
|
||||||
|
|
||||||
# Get parameters
|
# Get parameters
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
|
@ -166,34 +168,34 @@ def main():
|
||||||
loadBalancings = client.get('/ip/loadBalancing')
|
loadBalancings = client.get('/ip/loadBalancing')
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for getting the list of loadBalancing, \
|
msg='Unable to call OVH api for getting the list of loadBalancing, '
|
||||||
check application key, secret, consumerkey and parameters. \
|
'check application key, secret, consumerkey and parameters. '
|
||||||
Error returned by OVH api was : {}'.format(apiError))
|
'Error returned by OVH api was : {0}'.format(apiError))
|
||||||
|
|
||||||
if name not in loadBalancings:
|
if name not in loadBalancings:
|
||||||
module.fail_json(msg='IP LoadBalancing {} does not exist'.format(name))
|
module.fail_json(msg='IP LoadBalancing {0} does not exist'.format(name))
|
||||||
|
|
||||||
# Check that no task is pending before going on
|
# Check that no task is pending before going on
|
||||||
try:
|
try:
|
||||||
if not waitForNoTask(client, name, timeout):
|
if not waitForNoTask(client, name, timeout):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Timeout of {} seconds while waiting for no pending \
|
msg='Timeout of {0} seconds while waiting for no pending '
|
||||||
tasks before executing the module '.format(timeout))
|
'tasks before executing the module '.format(timeout))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for getting the list of pending tasks \
|
msg='Unable to call OVH api for getting the list of pending tasks '
|
||||||
of the loadBalancing, check application key, secret, consumerkey \
|
'of the loadBalancing, check application key, secret, consumerkey '
|
||||||
and parameters. Error returned by OVH api was : {}\
|
'and parameters. Error returned by OVH api was : {0}'
|
||||||
'.format(apiError))
|
.format(apiError))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backends = client.get('/ip/loadBalancing/{}/backend'.format(name))
|
backends = client.get('/ip/loadBalancing/{0}/backend'.format(name))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for getting the list of backends \
|
msg='Unable to call OVH api for getting the list of backends '
|
||||||
of the loadBalancing, check application key, secret, consumerkey \
|
'of the loadBalancing, check application key, secret, consumerkey '
|
||||||
and parameters. Error returned by OVH api was : {}\
|
'and parameters. Error returned by OVH api was : {0}'
|
||||||
'.format(apiError))
|
.format(apiError))
|
||||||
|
|
||||||
backendExists = backend in backends
|
backendExists = backend in backends
|
||||||
moduleChanged = False
|
moduleChanged = False
|
||||||
|
@ -202,47 +204,48 @@ def main():
|
||||||
# Remove backend
|
# Remove backend
|
||||||
try:
|
try:
|
||||||
client.delete(
|
client.delete(
|
||||||
'/ip/loadBalancing/{}/backend/{}'.format(name, backend))
|
'/ip/loadBalancing/{0}/backend/{1}'.format(name, backend))
|
||||||
if not waitForNoTask(client, name, timeout):
|
if not waitForNoTask(client, name, timeout):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Timeout of {} seconds while waiting for completion \
|
msg='Timeout of {0} seconds while waiting for completion '
|
||||||
of removing backend task'.format(timeout))
|
'of removing backend task'.format(timeout))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for deleting the backend, \
|
msg='Unable to call OVH api for deleting the backend, '
|
||||||
check application key, secret, consumerkey and \
|
'check application key, secret, consumerkey and '
|
||||||
parameters. Error returned by OVH api was : {}\
|
'parameters. Error returned by OVH api was : {0}'
|
||||||
'.format(apiError))
|
.format(apiError))
|
||||||
moduleChanged = True
|
moduleChanged = True
|
||||||
else:
|
else:
|
||||||
if backendExists:
|
if backendExists:
|
||||||
# Get properties
|
# Get properties
|
||||||
try:
|
try:
|
||||||
backendProperties = client.get(
|
backendProperties = client.get(
|
||||||
'/ip/loadBalancing/{}/backend/{}'.format(name, backend))
|
'/ip/loadBalancing/{0}/backend/{1}'.format(name, backend))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for getting the backend properties, \
|
msg='Unable to call OVH api for getting the backend properties, '
|
||||||
check application key, secret, consumerkey and \
|
'check application key, secret, consumerkey and '
|
||||||
parameters. Error returned by OVH api was : {}\
|
'parameters. Error returned by OVH api was : {0}'
|
||||||
'.format(apiError))
|
.format(apiError))
|
||||||
|
|
||||||
if (backendProperties['weight'] != weight):
|
if (backendProperties['weight'] != weight):
|
||||||
# Change weight
|
# Change weight
|
||||||
try:
|
try:
|
||||||
client.post(
|
client.post(
|
||||||
'/ip/loadBalancing/{}/backend/{}/setWeight\
|
'/ip/loadBalancing/{0}/backend/{1}/setWeight'
|
||||||
'.format(name, backend), weight=weight)
|
.format(name, backend), weight=weight)
|
||||||
if not waitForNoTask(client, name, timeout):
|
if not waitForNoTask(client, name, timeout):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Timeout of {} seconds while waiting for completion \
|
msg='Timeout of {0} seconds while waiting for completion '
|
||||||
of setWeight to backend task'.format(timeout))
|
'of setWeight to backend task'
|
||||||
|
.format(timeout))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for updating the weight of the \
|
msg='Unable to call OVH api for updating the weight of the '
|
||||||
backend, check application key, secret, consumerkey \
|
'backend, check application key, secret, consumerkey '
|
||||||
and parameters. Error returned by OVH api was : {}\
|
'and parameters. Error returned by OVH api was : {0}'
|
||||||
'.format(apiError))
|
.format(apiError))
|
||||||
moduleChanged = True
|
moduleChanged = True
|
||||||
|
|
||||||
if (backendProperties['probe'] != probe):
|
if (backendProperties['probe'] != probe):
|
||||||
|
@ -250,42 +253,44 @@ def main():
|
||||||
backendProperties['probe'] = probe
|
backendProperties['probe'] = probe
|
||||||
try:
|
try:
|
||||||
client.put(
|
client.put(
|
||||||
'/ip/loadBalancing/{}/backend/{}\
|
'/ip/loadBalancing/{0}/backend/{1}'
|
||||||
'.format(name, backend), probe=probe)
|
.format(name, backend), probe=probe)
|
||||||
if not waitForNoTask(client, name, timeout):
|
if not waitForNoTask(client, name, timeout):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Timeout of {} seconds while waiting for completion of \
|
msg='Timeout of {0} seconds while waiting for completion of '
|
||||||
setProbe to backend task'.format(timeout))
|
'setProbe to backend task'
|
||||||
|
.format(timeout))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for updating the propbe of \
|
msg='Unable to call OVH api for updating the propbe of '
|
||||||
the backend, check application key, secret, \
|
'the backend, check application key, secret, '
|
||||||
consumerkey and parameters. Error returned by OVH api \
|
'consumerkey and parameters. Error returned by OVH api '
|
||||||
was : {}\
|
'was : {0}'
|
||||||
'.format(apiError))
|
.format(apiError))
|
||||||
moduleChanged = True
|
moduleChanged = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Creates backend
|
# Creates backend
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
client.post('/ip/loadBalancing/{}/backend'.format(name),
|
client.post('/ip/loadBalancing/{0}/backend'.format(name),
|
||||||
ipBackend=backend, probe=probe, weight=weight)
|
ipBackend=backend, probe=probe, weight=weight)
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for creating the backend, check \
|
msg='Unable to call OVH api for creating the backend, check '
|
||||||
application key, secret, consumerkey and parameters. \
|
'application key, secret, consumerkey and parameters. '
|
||||||
Error returned by OVH api was : {}'.format(apiError))
|
'Error returned by OVH api was : {0}'
|
||||||
|
.format(apiError))
|
||||||
|
|
||||||
if not waitForNoTask(client, name, timeout):
|
if not waitForNoTask(client, name, timeout):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Timeout of {} seconds while waiting for completion of \
|
msg='Timeout of {0} seconds while waiting for completion of '
|
||||||
backend creation task'.format(timeout))
|
'backend creation task'.format(timeout))
|
||||||
except APIError as apiError:
|
except APIError as apiError:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Unable to call OVH api for creating the backend, check \
|
msg='Unable to call OVH api for creating the backend, check '
|
||||||
application key, secret, consumerkey and parameters. \
|
'application key, secret, consumerkey and parameters. '
|
||||||
Error returned by OVH api was : {}'.format(apiError))
|
'Error returned by OVH api was : {0}'.format(apiError))
|
||||||
moduleChanged = True
|
moduleChanged = True
|
||||||
|
|
||||||
module.exit_json(changed=moduleChanged)
|
module.exit_json(changed=moduleChanged)
|
||||||
|
|
Loading…
Reference in a new issue