Merge branch 'dev_rc-5.2.6' into 'rc-5.2.6'
decort_lb module bug fixes See merge request rudecs/dev/decort-ansible!67
This commit is contained in:
@@ -66,16 +66,9 @@ class decort_lb(DecortController):
|
|||||||
self.result['msg'] = "Specified RG ID {} not found.".format(arg_amodule.params['vins_id'])
|
self.result['msg'] = "Specified RG ID {} not found.".format(arg_amodule.params['vins_id'])
|
||||||
self.amodule.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
if arg_amodule.params['vins_id']:
|
|
||||||
self.vins_id, self.vins_facts = self.vins_find(arg_amodule.params['vins_id'])
|
|
||||||
if not self.vins_id:
|
|
||||||
self.result['failed'] = True
|
|
||||||
self.result['msg'] = "Specified ViNS ID {} not found.".format(arg_amodule.params['vins_id'])
|
|
||||||
self.amodule.fail_json(**self.result)
|
|
||||||
|
|
||||||
elif arg_amodule.params['account_id'] or arg_amodule.params['account_name'] != "":
|
elif arg_amodule.params['account_id'] or arg_amodule.params['account_name'] != "":
|
||||||
|
|
||||||
if arg_amodule.params['rg_name']:
|
if not arg_amodule.params['rg_name']:
|
||||||
self.result['failed'] = True
|
self.result['failed'] = True
|
||||||
self.result['msg'] = ("RG name must be specified with account present")
|
self.result['msg'] = ("RG name must be specified with account present")
|
||||||
self.amodule.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
@@ -86,8 +79,32 @@ class decort_lb(DecortController):
|
|||||||
self.result['msg'] = ("Current user does not have access to the requested account "
|
self.result['msg'] = ("Current user does not have access to the requested account "
|
||||||
"or non-existent account specified.")
|
"or non-existent account specified.")
|
||||||
self.amodule.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
self.rg_id, self.rg_facts = self.rg_find(self._acc_id,0, arg_rg_name=arg_amodule.params['rg_name'])
|
self.rg_id, self.rg_facts = self.rg_find(self.acc_id,0, arg_rg_name=arg_amodule.params['rg_name'])
|
||||||
|
|
||||||
|
if arg_amodule.params['vins_id']:
|
||||||
|
self.vins_id, self.vins_facts = self.vins_find(
|
||||||
|
vins_id=arg_amodule.params['vins_id']
|
||||||
|
)
|
||||||
|
if not self.vins_id:
|
||||||
|
self.result['failed'] = True
|
||||||
|
self.result['msg'] = (
|
||||||
|
f'Specified ViNS ID {arg_amodule.params["vins_id"]}'
|
||||||
|
f' not found'
|
||||||
|
)
|
||||||
|
self.amodule.fail_json(**self.result)
|
||||||
|
elif arg_amodule.params['vins_name']:
|
||||||
|
self.vins_id, self.vins_facts = self.vins_find(
|
||||||
|
vins_id=arg_amodule.params['vins_id'],
|
||||||
|
vins_name=arg_amodule.params['vins_name'],
|
||||||
|
rg_id=self.rg_id)
|
||||||
|
if not self.vins_id:
|
||||||
|
self.result['failed'] = True
|
||||||
|
self.result['msg'] = (
|
||||||
|
f'Specified ViNS name {arg_amodule.params["vins_name"]}'
|
||||||
|
f' not found in RG ID {self.rg_id}'
|
||||||
|
)
|
||||||
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
if self.rg_id and self.vins_id:
|
if self.rg_id and self.vins_id:
|
||||||
self.lb_id, self.lb_facts = self.lb_find(0,arg_amodule.params['lb_name'],self.rg_id)
|
self.lb_id, self.lb_facts = self.lb_find(0,arg_amodule.params['lb_name'],self.rg_id)
|
||||||
return
|
return
|
||||||
@@ -98,7 +115,8 @@ class decort_lb(DecortController):
|
|||||||
self.amodule.params['ext_net_id'],
|
self.amodule.params['ext_net_id'],
|
||||||
self.amodule.params['ha_lb'],
|
self.amodule.params['ha_lb'],
|
||||||
self.amodule.params['annotation'])
|
self.amodule.params['annotation'])
|
||||||
if self.amodule.params['backends'] or self.amodule.params['frontends']:
|
if self.lb_id and (self.amodule.params['backends'] or
|
||||||
|
self.amodule.params['frontends']):
|
||||||
self.lb_id, self.lb_facts = self.lb_find(0,self.amodule.params['lb_name'],self.rg_id)
|
self.lb_id, self.lb_facts = self.lb_find(0,self.amodule.params['lb_name'],self.rg_id)
|
||||||
self.lb_update(
|
self.lb_update(
|
||||||
self.lb_facts['primaryNode'],
|
self.lb_facts['primaryNode'],
|
||||||
@@ -114,10 +132,10 @@ class decort_lb(DecortController):
|
|||||||
|
|
||||||
def action(self,d_state='',restore=False):
|
def action(self,d_state='',restore=False):
|
||||||
if restore == True:
|
if restore == True:
|
||||||
self.lb_restore(arg_vins_id=self.lb_id)
|
self.lb_restore(lb_id=self.lb_id)
|
||||||
self.lb_state(self.vins_facts, 'enabled')
|
_, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id)
|
||||||
self.lb_facts['status'] = "ENABLED"
|
self.lb_state(self.lb_facts, 'enabled')
|
||||||
self.lb_facts['techStatus'] = "STARTED"
|
_, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id)
|
||||||
|
|
||||||
self.lb_update(
|
self.lb_update(
|
||||||
self.lb_facts['primaryNode'],
|
self.lb_facts['primaryNode'],
|
||||||
@@ -132,6 +150,14 @@ class decort_lb(DecortController):
|
|||||||
|
|
||||||
if d_state != '':
|
if d_state != '':
|
||||||
self.lb_state(self.lb_facts, d_state)
|
self.lb_state(self.lb_facts, d_state)
|
||||||
|
_, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id)
|
||||||
|
|
||||||
|
if (d_state == 'enabled' and
|
||||||
|
self.lb_facts.get('status') == 'ENABLED' and
|
||||||
|
self.lb_facts.get('techStatus') == 'STOPPED'):
|
||||||
|
self.lb_state(self.lb_facts, 'started')
|
||||||
|
_, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
@@ -288,23 +314,24 @@ def main():
|
|||||||
elif decon.lb_facts['status'] == "DISABLED":
|
elif decon.lb_facts['status'] == "DISABLED":
|
||||||
if amodule.params['state'] == 'absent':
|
if amodule.params['state'] == 'absent':
|
||||||
decon.delete()
|
decon.delete()
|
||||||
elif amodule.params['state'] in ('present', 'disabled'):
|
elif amodule.params['state'] == 'disabled':
|
||||||
decon.action()
|
decon.action()
|
||||||
elif amodule.params['state'] == 'enabled':
|
elif amodule.params['state'] in ('enabled', 'present'):
|
||||||
decon.action('enabled')
|
decon.action('enabled')
|
||||||
elif decon.lb_facts['status'] in ["CREATED", "ENABLED"]:
|
elif decon.lb_facts['status'] in ["CREATED", "ENABLED"]:
|
||||||
if amodule.params['state'] == 'absent':
|
if amodule.params['state'] == 'absent':
|
||||||
decon.delete()
|
decon.delete()
|
||||||
elif amodule.params['state'] in ('present', 'enabled'):
|
elif amodule.params['state'] in ('present', 'enabled'):
|
||||||
decon.action()
|
decon.action(d_state='enabled')
|
||||||
elif amodule.params['state'] == 'disabled':
|
elif amodule.params['state'] == 'disabled':
|
||||||
decon.action('disabled')
|
decon.action('disabled')
|
||||||
elif amodule.params['state'] in ('stopped', 'started','restart'):
|
elif amodule.params['state'] in ('stopped', 'started','restart'):
|
||||||
decon.action(amodule.params['state'])
|
decon.action(amodule.params['state'])
|
||||||
elif decon.lb_facts['status'] == "DELETED":
|
elif decon.lb_facts['status'] == "DELETED":
|
||||||
if amodule.params['state'] in ['present', 'enabled']:
|
if amodule.params['state'] in ['present', 'enabled']:
|
||||||
decon.action(restore=True)
|
decon.action(d_state='enabled', restore=True)
|
||||||
elif amodule.params['state'] == 'absent':
|
elif (amodule.params['state'] == 'absent' and
|
||||||
|
amodule.params['permanently']):
|
||||||
decon.delete()
|
decon.delete()
|
||||||
elif amodule.params['state'] == 'disabled':
|
elif amodule.params['state'] == 'disabled':
|
||||||
decon.error()
|
decon.error()
|
||||||
|
|||||||
@@ -4056,8 +4056,8 @@ class DecortController(object):
|
|||||||
self.result['msg'] = "_rg_listlb(): zero RG ID specified."
|
self.result['msg'] = "_rg_listlb(): zero RG ID specified."
|
||||||
self.amodule.fail_json(**self.result)
|
self.amodule.fail_json(**self.result)
|
||||||
|
|
||||||
api_params = dict(rgId=rg_id)
|
api_params = dict(rgId=rg_id, includedeleted=True)
|
||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/rg/listLb", api_params)
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/list", api_params)
|
||||||
if api_resp.status_code == 200:
|
if api_resp.status_code == 200:
|
||||||
ret_rg_vins_list = json.loads(api_resp.content.decode('utf8'))
|
ret_rg_vins_list = json.loads(api_resp.content.decode('utf8'))
|
||||||
else:
|
else:
|
||||||
@@ -4071,7 +4071,7 @@ class DecortController(object):
|
|||||||
|
|
||||||
@returns: LB ID and dictionary with LB facts.
|
@returns: LB ID and dictionary with LB facts.
|
||||||
"""
|
"""
|
||||||
LB_INVALID_STATES = ["ENABLING", "DISABLING", "DELETING", "DELETED", "DESTROYING", "DESTROYED"]
|
LB_INVALID_STATES = ["ENABLING", "DISABLING", "DELETING", "DESTROYING", "DESTROYED"]
|
||||||
|
|
||||||
ret_lb_id = 0
|
ret_lb_id = 0
|
||||||
ret_lb_facts = None
|
ret_lb_facts = None
|
||||||
@@ -4138,7 +4138,7 @@ class DecortController(object):
|
|||||||
vinsId=vins_id,
|
vinsId=vins_id,
|
||||||
highlyAvailable=ha_status,
|
highlyAvailable=ha_status,
|
||||||
start=start,
|
start=start,
|
||||||
decs=annotation
|
desc=annotation
|
||||||
)
|
)
|
||||||
api_resp = self.decort_api_call(requests.post, api_url, api_params)
|
api_resp = self.decort_api_call(requests.post, api_url, 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.
|
||||||
@@ -4177,7 +4177,7 @@ class DecortController(object):
|
|||||||
|
|
||||||
NOP_STATES_FOR_LB_CHANGE = ["MODELED", "DISABLING", "ENABLING", "DELETING", "DELETED", "DESTROYING",
|
NOP_STATES_FOR_LB_CHANGE = ["MODELED", "DISABLING", "ENABLING", "DELETING", "DELETED", "DESTROYING",
|
||||||
"DESTROYED"]
|
"DESTROYED"]
|
||||||
VALID_TARGET_STATES = ["enabled", "disabled","restart"]
|
VALID_TARGET_STATES = ["enabled", "disabled","restart", 'started']
|
||||||
VALID_TARGET_TSTATES = ["STARTED","STOPPED"]
|
VALID_TARGET_TSTATES = ["STARTED","STOPPED"]
|
||||||
|
|
||||||
if lb_dict['status'] in NOP_STATES_FOR_LB_CHANGE:
|
if lb_dict['status'] in NOP_STATES_FOR_LB_CHANGE:
|
||||||
@@ -4468,6 +4468,15 @@ class DecortController(object):
|
|||||||
def lb_update(self,prime,front_ha_ip,back_ha_ip,lb_backends=[],lb_frontends=[],mod_backends=[],mod_servers=[],mod_frontends=[]):
|
def lb_update(self,prime,front_ha_ip,back_ha_ip,lb_backends=[],lb_frontends=[],mod_backends=[],mod_servers=[],mod_frontends=[]):
|
||||||
|
|
||||||
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_update")
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "lb_update")
|
||||||
|
|
||||||
|
if self.amodule.check_mode:
|
||||||
|
result_msg = 'lb_update() in check mode: No changing.'
|
||||||
|
if self.result.get('msg'):
|
||||||
|
self.result['msg'] += f'\n{result_msg}'
|
||||||
|
else:
|
||||||
|
self.result['msg'] = result_msg
|
||||||
|
return
|
||||||
|
|
||||||
#lists from module and cloud
|
#lists from module and cloud
|
||||||
mod_backs_list = [back['name'] for back in mod_backends]
|
mod_backs_list = [back['name'] for back in mod_backends]
|
||||||
lb_backs_list = [back['name'] for back in lb_backends]
|
lb_backs_list = [back['name'] for back in lb_backends]
|
||||||
@@ -4478,9 +4487,6 @@ class DecortController(object):
|
|||||||
|
|
||||||
#FE
|
#FE
|
||||||
|
|
||||||
mod_front_list = [front['name'] for front in mod_frontends]
|
|
||||||
lb_front_list = [front['name'] for front in lb_frontends]
|
|
||||||
|
|
||||||
if del_list_backs:
|
if del_list_backs:
|
||||||
|
|
||||||
self._lb_delete_backends(
|
self._lb_delete_backends(
|
||||||
@@ -4503,6 +4509,9 @@ class DecortController(object):
|
|||||||
mod_servers
|
mod_servers
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mod_front_list = [front['name'] for front in mod_frontends]
|
||||||
|
lb_front_list = [front['name'] for front in lb_frontends]
|
||||||
|
|
||||||
del_list_fronts = set(lb_front_list).difference(mod_front_list)
|
del_list_fronts = set(lb_front_list).difference(mod_front_list)
|
||||||
add_list_fronts = set(mod_front_list).difference(lb_front_list)
|
add_list_fronts = set(mod_front_list).difference(lb_front_list)
|
||||||
upd_front_list = set(lb_front_list).intersection(mod_front_list)
|
upd_front_list = set(lb_front_list).intersection(mod_front_list)
|
||||||
@@ -4557,7 +4566,7 @@ class DecortController(object):
|
|||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/frontendDelete", api_params)
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/frontendDelete", api_params)
|
||||||
#del from cloud dict
|
#del from cloud dict
|
||||||
if type(front)==dict:
|
if type(front)==dict:
|
||||||
del self.lb_facts['frontends'][front['name']]
|
self.lb_facts['frontends'].remove(front)
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -4580,7 +4589,8 @@ class DecortController(object):
|
|||||||
bind['address']if "address" in bind else bind_ip,
|
bind['address']if "address" in bind else bind_ip,
|
||||||
bind['port'],
|
bind['port'],
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
return
|
||||||
def _lb_create_backends(self,back_list,mod_backs,mod_serv):
|
def _lb_create_backends(self,back_list,mod_backs,mod_serv):
|
||||||
'''
|
'''
|
||||||
Create backends and add servers to them
|
Create backends and add servers to them
|
||||||
@@ -4663,8 +4673,8 @@ class DecortController(object):
|
|||||||
serverName = server['name'],
|
serverName = server['name'],
|
||||||
address = server['address'],
|
address = server['address'],
|
||||||
port = mod_back['port'],
|
port = mod_back['port'],
|
||||||
check = server['check'] if "check" in server else None,
|
check = mod_back['check'] if "check" in mod_back else None,
|
||||||
**server['server_settings'] if "server_settings" in server else {},
|
**mod_back['server_settings'] if "server_settings" in mod_back else {},
|
||||||
)
|
)
|
||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/backendServerAdd", api_params)
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/backendServerAdd", api_params)
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
@@ -4723,11 +4733,14 @@ class DecortController(object):
|
|||||||
lb_bind, = list(filter(lambda i: i['name'] == bind['name'],lb_front['bindings']))
|
lb_bind, = list(filter(lambda i: i['name'] == bind['name'],lb_front['bindings']))
|
||||||
del lb_bind['guid']
|
del lb_bind['guid']
|
||||||
|
|
||||||
|
if not bind.get('address'):
|
||||||
|
bind['address'] = bind_ip
|
||||||
|
|
||||||
if dict(sorted(bind.items())) != dict(sorted(lb_bind.items())):
|
if dict(sorted(bind.items())) != dict(sorted(lb_bind.items())):
|
||||||
self._lb_bind_frontend(
|
self._lb_bind_frontend(
|
||||||
front,
|
front,
|
||||||
bind['name'],
|
bind['name'],
|
||||||
bind['address'] if "address" in bind else bind_ip,
|
bind['address'],
|
||||||
bind['port'],
|
bind['port'],
|
||||||
update=True,
|
update=True,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user