Fix some logical issues with enabling/disabling a server on the A10.
This commit is contained in:
parent
19e688b017
commit
797d8893d6
1 changed files with 37 additions and 16 deletions
|
@ -184,27 +184,34 @@ def main():
|
||||||
json_post = {
|
json_post = {
|
||||||
'server': {
|
'server': {
|
||||||
'name': slb_server,
|
'name': slb_server,
|
||||||
'host': slb_server_ip,
|
|
||||||
'status': axapi_enabled_disabled(slb_server_status),
|
|
||||||
'port_list': slb_server_ports,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# add optional module parameters
|
||||||
|
if slb_server_ip:
|
||||||
|
json_post['server']['host'] = slb_server_ip
|
||||||
|
|
||||||
|
if slb_server_ports:
|
||||||
|
json_post['server']['port_list'] = slb_server_ports
|
||||||
|
|
||||||
|
if slb_server_status:
|
||||||
|
json_post['server']['status'] = axapi_enabled_disabled(slb_server_status)
|
||||||
|
|
||||||
slb_server_data = axapi_call(module, session_url + '&method=slb.server.search', json.dumps({'name': slb_server}))
|
slb_server_data = axapi_call(module, session_url + '&method=slb.server.search', json.dumps({'name': slb_server}))
|
||||||
slb_server_exists = not axapi_failure(slb_server_data)
|
slb_server_exists = not axapi_failure(slb_server_data)
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
if not slb_server_exists:
|
||||||
if not slb_server_ip:
|
if not slb_server_ip:
|
||||||
module.fail_json(msg='you must specify an IP address when creating a server')
|
module.fail_json(msg='you must specify an IP address when creating a server')
|
||||||
|
|
||||||
if not slb_server_exists:
|
|
||||||
result = axapi_call(module, session_url + '&method=slb.server.create', json.dumps(json_post))
|
result = axapi_call(module, session_url + '&method=slb.server.create', json.dumps(json_post))
|
||||||
if axapi_failure(result):
|
if axapi_failure(result):
|
||||||
module.fail_json(msg="failed to create the server: %s" % result['response']['err']['msg'])
|
module.fail_json(msg="failed to create the server: %s" % result['response']['err']['msg'])
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
def needs_update(src_ports, dst_ports):
|
def port_needs_update(src_ports, dst_ports):
|
||||||
'''
|
'''
|
||||||
Checks to determine if the port definitions of the src_ports
|
Checks to determine if the port definitions of the src_ports
|
||||||
array are in or different from those in dst_ports. If there is
|
array are in or different from those in dst_ports. If there is
|
||||||
|
@ -227,12 +234,26 @@ def main():
|
||||||
# every port from the src exists in the dst, and none of them were different
|
# every port from the src exists in the dst, and none of them were different
|
||||||
return False
|
return False
|
||||||
|
|
||||||
defined_ports = slb_server_data.get('server', {}).get('port_list', [])
|
def status_needs_update(current_status, new_status):
|
||||||
|
'''
|
||||||
|
Check to determine if we want to change the status of a server.
|
||||||
|
If there is a difference between the current status of the server and
|
||||||
|
the desired status, return true, otherwise false.
|
||||||
|
'''
|
||||||
|
if current_status != new_status:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# we check for a needed update both ways, in case ports
|
defined_ports = slb_server_data.get('server', {}).get('port_list', [])
|
||||||
# are missing from either the ones specified by the user
|
current_status = slb_server_data.get('server', {}).get('status')
|
||||||
# or from those on the device
|
|
||||||
if needs_update(defined_ports, slb_server_ports) or needs_update(slb_server_ports, defined_ports):
|
# we check for a needed update several ways
|
||||||
|
# - in case ports are missing from the ones specified by the user
|
||||||
|
# - in case ports are missing from those on the device
|
||||||
|
# - in case we are change the status of a server
|
||||||
|
if port_needs_update(defined_ports, slb_server_ports)
|
||||||
|
or port_needs_update(slb_server_ports, defined_ports)
|
||||||
|
or status_needs_update(current_status, axapi_enabled_disabled(slb_server_status)):
|
||||||
result = axapi_call(module, session_url + '&method=slb.server.update', json.dumps(json_post))
|
result = axapi_call(module, session_url + '&method=slb.server.update', json.dumps(json_post))
|
||||||
if axapi_failure(result):
|
if axapi_failure(result):
|
||||||
module.fail_json(msg="failed to update the server: %s" % result['response']['err']['msg'])
|
module.fail_json(msg="failed to update the server: %s" % result['response']['err']['msg'])
|
||||||
|
@ -251,8 +272,8 @@ def main():
|
||||||
else:
|
else:
|
||||||
result = dict(msg="the server was not present")
|
result = dict(msg="the server was not present")
|
||||||
|
|
||||||
# if the config has changed, save the config unless otherwise requested
|
# if the config has changed, or we want to force a save, save the config unless otherwise requested
|
||||||
if changed and write_config:
|
if changed or write_config:
|
||||||
write_result = axapi_call(module, session_url + '&method=system.action.write_memory')
|
write_result = axapi_call(module, session_url + '&method=system.action.write_memory')
|
||||||
if axapi_failure(write_result):
|
if axapi_failure(write_result):
|
||||||
module.fail_json(msg="failed to save the configuration: %s" % write_result['response']['err']['msg'])
|
module.fail_json(msg="failed to save the configuration: %s" % write_result['response']['err']['msg'])
|
||||||
|
|
Loading…
Reference in a new issue