From eb0766b15f0eba8acefe70a613116be9ff0bd603 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Sun, 2 Jun 2024 22:18:58 +0300 Subject: [PATCH 01/17] Fix if-condition for rg_name parameter check --- library/decort_lb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index aa2b0c9..39e419c 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -75,7 +75,7 @@ class decort_lb(DecortController): 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['msg'] = ("RG name must be specified with account present") self.amodule.fail_json(**self.result) From 56f7f354c18357c56ad305a3f6f14b2dc47f5ebf Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Sun, 2 Jun 2024 22:27:52 +0300 Subject: [PATCH 02/17] Fix access to acc_id class attrubute in decort_lb.__init__ method --- library/decort_lb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 39e419c..8605af2 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -86,7 +86,7 @@ class decort_lb(DecortController): self.result['msg'] = ("Current user does not have access to the requested account " "or non-existent account specified.") 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 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) From 9ce5a3d711290e7e33f5fb0249bc508e3e203d1d Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 3 Jun 2024 15:09:35 +0300 Subject: [PATCH 03/17] Add logic for processing vins_name parameter --- library/decort_lb.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 8605af2..815498b 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -66,13 +66,6 @@ class decort_lb(DecortController): self.result['msg'] = "Specified RG ID {} not found.".format(arg_amodule.params['vins_id']) 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'] != "": if not arg_amodule.params['rg_name']: @@ -88,6 +81,30 @@ class decort_lb(DecortController): 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']) + 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: self.lb_id, self.lb_facts = self.lb_find(0,arg_amodule.params['lb_name'],self.rg_id) return From 876ff5b98d1d86f6cd1d875fd32a6028c43d2d8c Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 3 Jun 2024 16:12:05 +0300 Subject: [PATCH 04/17] Fix API request parameter name for LB description in DecortController.lb_provision method --- module_utils/decort_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 0be52ea..167d213 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4138,7 +4138,7 @@ class DecortController(object): vinsId=vins_id, highlyAvailable=ha_status, start=start, - decs=annotation + desc=annotation ) 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. From ca45f49c2ef756dd3f6c4befbcf457f67d8976d1 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 3 Jun 2024 18:11:40 +0300 Subject: [PATCH 05/17] Fix logic of frontends creating in DecortController._lb_add_fronts method --- module_utils/decort_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 167d213..f3fd6fa 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4580,7 +4580,8 @@ class DecortController(object): bind['address']if "address" in bind else bind_ip, bind['port'], ) - return + + return def _lb_create_backends(self,back_list,mod_backs,mod_serv): ''' Create backends and add servers to them From db67a3b2d29b8227414398d0864ed3bb0c1a86d9 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 3 Jun 2024 19:14:02 +0300 Subject: [PATCH 06/17] Fix logic of LB frontends updating in DecortController._lb_update_fronts method --- module_utils/decort_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index f3fd6fa..32d8934 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4724,11 +4724,14 @@ class DecortController(object): lb_bind, = list(filter(lambda i: i['name'] == bind['name'],lb_front['bindings'])) del lb_bind['guid'] + if not bind.get('address'): + bind['address'] = bind_ip + if dict(sorted(bind.items())) != dict(sorted(lb_bind.items())): self._lb_bind_frontend( front, bind['name'], - bind['address'] if "address" in bind else bind_ip, + bind['address'], bind['port'], update=True, ) From 41731c3dd7c034a6922cdcbea829bdabd64dcda2 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 4 Jun 2024 11:49:14 +0300 Subject: [PATCH 07/17] Fix logic of DecortController.lb_update method running in decort_lb.create method --- library/decort_lb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 815498b..976f345 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -115,7 +115,8 @@ class decort_lb(DecortController): self.amodule.params['ext_net_id'], self.amodule.params['ha_lb'], 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_update( self.lb_facts['primaryNode'], From 90ae212d0c3ff514b84d853587c28d45acdd8ff4 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 4 Jun 2024 16:30:00 +0300 Subject: [PATCH 08/17] Fix logic of LB deleting from Recycle Bin and LB list getting --- library/decort_lb.py | 3 ++- module_utils/decort_utils.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 976f345..3015d13 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -322,7 +322,8 @@ def main(): elif decon.lb_facts['status'] == "DELETED": if amodule.params['state'] in ['present', 'enabled']: decon.action(restore=True) - elif amodule.params['state'] == 'absent': + elif (amodule.params['state'] == 'absent' and + amodule.params['permanently']): decon.delete() elif amodule.params['state'] == 'disabled': decon.error() diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 32d8934..129f7e5 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4056,8 +4056,8 @@ class DecortController(object): self.result['msg'] = "_rg_listlb(): zero RG ID specified." self.amodule.fail_json(**self.result) - api_params = dict(rgId=rg_id) - api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/rg/listLb", api_params) + api_params = dict(rgId=rg_id, includedeleted=True) + api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/list", api_params) if api_resp.status_code == 200: ret_rg_vins_list = json.loads(api_resp.content.decode('utf8')) else: @@ -4071,7 +4071,7 @@ class DecortController(object): @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_facts = None From 23ad78b1cffe6021082aa6bf2581d624d8fdf8f4 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 5 Jun 2024 10:30:03 +0300 Subject: [PATCH 09/17] Fix argument name of DecortController.lb_restore method call in decort_lb.action method --- library/decort_lb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 3015d13..73c7d27 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -132,7 +132,7 @@ class decort_lb(DecortController): def action(self,d_state='',restore=False): 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['status'] = "ENABLED" self.lb_facts['techStatus'] = "STARTED" From 0ae16ddc1dd2bc95c60c0f762e9a5ccb1be89f62 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 5 Jun 2024 10:39:34 +0300 Subject: [PATCH 10/17] Fix lb_dict argument of DecortController.lb_state method call in decort_lb.action method --- library/decort_lb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 73c7d27..8fcbbb2 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -133,7 +133,7 @@ class decort_lb(DecortController): def action(self,d_state='',restore=False): if restore == True: self.lb_restore(lb_id=self.lb_id) - self.lb_state(self.vins_facts, 'enabled') + self.lb_state(self.lb_facts, 'enabled') self.lb_facts['status'] = "ENABLED" self.lb_facts['techStatus'] = "STARTED" From a6a6954d4693490fc079c2be4f0e12a97abfe266 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 5 Jun 2024 11:03:33 +0300 Subject: [PATCH 11/17] Add lb_facts updating logic after DecortController.lb_restore method call in decort_lb.action method --- library/decort_lb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/library/decort_lb.py b/library/decort_lb.py index 8fcbbb2..5452d8e 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -133,6 +133,7 @@ class decort_lb(DecortController): def action(self,d_state='',restore=False): if restore == True: self.lb_restore(lb_id=self.lb_id) + _, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id) self.lb_state(self.lb_facts, 'enabled') self.lb_facts['status'] = "ENABLED" self.lb_facts['techStatus'] = "STARTED" From 4311eee4353bca70356e27b31b966351248bbc6c Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 5 Jun 2024 13:14:27 +0300 Subject: [PATCH 12/17] Add LB starting logic in LB restoring logic and fix DecortController.lb_state method VALID_TARGET_STATES list --- library/decort_lb.py | 5 ++--- module_utils/decort_utils.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index 5452d8e..d05a5cc 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -135,8 +135,7 @@ class decort_lb(DecortController): self.lb_restore(lb_id=self.lb_id) _, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id) self.lb_state(self.lb_facts, 'enabled') - self.lb_facts['status'] = "ENABLED" - self.lb_facts['techStatus'] = "STARTED" + _, self.lb_facts = self._lb_get_by_id(lb_id=self.lb_id) self.lb_update( self.lb_facts['primaryNode'], @@ -322,7 +321,7 @@ def main(): decon.action(amodule.params['state']) elif decon.lb_facts['status'] == "DELETED": if amodule.params['state'] in ['present', 'enabled']: - decon.action(restore=True) + decon.action(d_state='started', restore=True) elif (amodule.params['state'] == 'absent' and amodule.params['permanently']): decon.delete() diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 129f7e5..8b0404c 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4177,7 +4177,7 @@ class DecortController(object): NOP_STATES_FOR_LB_CHANGE = ["MODELED", "DISABLING", "ENABLING", "DELETING", "DELETED", "DESTROYING", "DESTROYED"] - VALID_TARGET_STATES = ["enabled", "disabled","restart"] + VALID_TARGET_STATES = ["enabled", "disabled","restart", 'started'] VALID_TARGET_TSTATES = ["STARTED","STOPPED"] if lb_dict['status'] in NOP_STATES_FOR_LB_CHANGE: From b1f2167d0020a3951ae35d33f52ad6116b5defc0 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 5 Jun 2024 17:39:27 +0300 Subject: [PATCH 13/17] Fix logic of LB state changing --- library/decort_lb.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index d05a5cc..e0fa09e 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -150,6 +150,14 @@ class decort_lb(DecortController): if 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 def delete(self): @@ -306,22 +314,22 @@ def main(): elif decon.lb_facts['status'] == "DISABLED": if amodule.params['state'] == 'absent': decon.delete() - elif amodule.params['state'] in ('present', 'disabled'): + elif amodule.params['state'] == 'disabled': decon.action() - elif amodule.params['state'] == 'enabled': + elif amodule.params['state'] in ('enabled', 'present'): decon.action('enabled') elif decon.lb_facts['status'] in ["CREATED", "ENABLED"]: if amodule.params['state'] == 'absent': decon.delete() elif amodule.params['state'] in ('present', 'enabled'): - decon.action() + decon.action(d_state='enabled') elif amodule.params['state'] == 'disabled': decon.action('disabled') elif amodule.params['state'] in ('stopped', 'started','restart'): decon.action(amodule.params['state']) elif decon.lb_facts['status'] == "DELETED": if amodule.params['state'] in ['present', 'enabled']: - decon.action(d_state='started', restore=True) + decon.action(d_state='enabled', restore=True) elif (amodule.params['state'] == 'absent' and amodule.params['permanently']): decon.delete() From 6b4957f8aa1c4402d46e8ae4534dbcd748b0a68e Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 6 Jun 2024 14:46:50 +0300 Subject: [PATCH 14/17] Fix deleting element of frontends list in DecortController._lb_delete_fronts method --- module_utils/decort_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 8b0404c..20e34dd 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4557,7 +4557,7 @@ class DecortController(object): api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/lb/frontendDelete", api_params) #del from cloud dict if type(front)==dict: - del self.lb_facts['frontends'][front['name']] + self.lb_facts['frontends'].remove(front) self.result['changed'] = True return From bb6394873b2ac0d730da1fce3ade2a219a029d2e Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 6 Jun 2024 14:54:16 +0300 Subject: [PATCH 15/17] Fix location of lb_front_list formation code in DecortController.lb_update method --- module_utils/decort_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 20e34dd..433a3d3 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4478,9 +4478,6 @@ class DecortController(object): #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: self._lb_delete_backends( @@ -4503,6 +4500,9 @@ class DecortController(object): 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) add_list_fronts = set(mod_front_list).difference(lb_front_list) upd_front_list = set(lb_front_list).intersection(mod_front_list) From ea63959289bc8d42dcc22454a67a1e169dd8ed90 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 6 Jun 2024 15:34:01 +0300 Subject: [PATCH 16/17] Fix API param values for servers adding in DecortController._lb_update_backends method --- module_utils/decort_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 433a3d3..9d16811 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4664,8 +4664,8 @@ class DecortController(object): serverName = server['name'], address = server['address'], port = mod_back['port'], - check = server['check'] if "check" in server else None, - **server['server_settings'] if "server_settings" in server else {}, + check = mod_back['check'] if "check" in mod_back else None, + **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) self.result['changed'] = True From 9449afa2acf29cb46dcd32f5296aae22e59bcb22 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 6 Jun 2024 16:29:22 +0300 Subject: [PATCH 17/17] Add check mode simple logic to DecortController.lb_update method --- module_utils/decort_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 9d16811..72dcb07 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -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=[]): 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 mod_backs_list = [back['name'] for back in mod_backends] lb_backs_list = [back['name'] for back in lb_backends]