From d622dd84535899d0c93438c6577555de9a1b853b Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 20 Mar 2024 14:58:02 +0300 Subject: [PATCH 01/76] fix account vins find logic --- 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 70c2765..0a2c1d0 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -2250,9 +2250,9 @@ class DecortController(object): # self.result['msg'] = "vins_find(): cannot find Account ID {}.".format(account_id) # self.amodule.fail_json(**self.result) # NOTE: account's 'vins' attribute does not list destroyed ViNSes! - for runner in rg_facts['vins']: - # api_params['vinsId'] = runner - ret_vins_id, ret_vins_facts = self._vins_get_by_id(runner) + account_vinses = self._get_all_account_vinses(account_id) + for vins in account_vinses: + ret_vins_id, ret_vins_facts = self._vins_get_by_id(vins['id']) if ret_vins_id and ret_vins_facts['name'] == vins_name: if not check_state or ret_vins_facts['status'] not in VINS_INVALID_STATES: return ret_vins_id, ret_vins_facts From 058de4884f1ff3d7a2e13601711d53d79d6d2816 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 22 Mar 2024 13:39:06 +0300 Subject: [PATCH 02/76] exclude call of compute_bootdisk_size method with new_size=None --- library/decort_kvmvm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/decort_kvmvm.py b/library/decort_kvmvm.py index 5753f51..d5e99c5 100644 --- a/library/decort_kvmvm.py +++ b/library/decort_kvmvm.py @@ -624,7 +624,11 @@ class decort_kvmvm(DecortController): Note that it does not modify power state of KVM VM. """ self.compute_networks(self.comp_info, self.amodule.params['networks']) - self.compute_bootdisk_size(self.comp_info, self.amodule.params['boot_disk']) + + boot_disk_new_size = self.amodule.params['boot_disk'] + if boot_disk_new_size: + self.compute_bootdisk_size(self.comp_info, boot_disk_new_size) + self.compute_data_disks(self.comp_info, self.amodule.params['data_disks']) self.compute_resize(self.comp_info, self.amodule.params['cpu'], self.amodule.params['ram'], From 1c6b46c535164a611b862895fc85764aa2ac6f88 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 22 Mar 2024 17:01:50 +0300 Subject: [PATCH 03/76] remove new_ram value conversion from GB to MB --- module_utils/decort_utils.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 70c2765..b11c299 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1102,10 +1102,6 @@ class DecortController(object): elif not new_ram: new_ram = comp_dict['ram'] - # stupid hack? - if new_ram > 1 and new_ram < 512: - new_ram = new_ram * 1024 - if comp_dict['cpus'] == new_cpu and comp_dict['ram'] == new_ram: # no need to call API in this case, as requested size is not different from the current one self.result['failed'] = False From 21e853c1f21d3b4c3c97a403fe4456ae2aa7e63a Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 22 Mar 2024 18:42:44 +0300 Subject: [PATCH 04/76] Add response text to error msg of decort_api_call method --- module_utils/decort_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 70c2765..f6c3499 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -392,10 +392,11 @@ class DecortController(object): retry_counter = retry_counter - 1 else: self.result['failed'] = True - self.result['msg'] = ("Error when calling DECORT API '{}', HTTP status code '{}', " - "reason '{}', parameters '{}'.").format(api_resp.url, - api_resp.status_code, - api_resp.reason, arg_params) + self.result['msg'] =\ + (f'Error when calling DECORT API {api_resp.url}' + f', HTTP status code {api_resp.status_code}' + f', reason "{api_resp.reason}"' + f', parameters {arg_params}, text {api_resp.text}.') self.amodule.fail_json(**self.result) return None # actually, this directive will never be executed as fail_json aborts the script From b18bdef269e6be80f920f69e0669c4cc01adcbd7 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 22 Mar 2024 18:54:57 +0300 Subject: [PATCH 05/76] fix code style --- module_utils/decort_utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index f6c3499..7322838 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -392,11 +392,12 @@ class DecortController(object): retry_counter = retry_counter - 1 else: self.result['failed'] = True - self.result['msg'] =\ - (f'Error when calling DECORT API {api_resp.url}' - f', HTTP status code {api_resp.status_code}' - f', reason "{api_resp.reason}"' - f', parameters {arg_params}, text {api_resp.text}.') + self.result['msg'] = ( + f'Error when calling DECORT API {api_resp.url}' + f', HTTP status code {api_resp.status_code}' + f', reason "{api_resp.reason}"' + f', parameters {arg_params}, text {api_resp.text}.' + ) self.amodule.fail_json(**self.result) return None # actually, this directive will never be executed as fail_json aborts the script From 1304a0fcbfd1db177d75ad19fb3fc2f752c65aad Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 3 Apr 2024 11:00:56 +0300 Subject: [PATCH 06/76] Add call of API /cloudapi/rg/getResourceConsumption to DecortController._rg_get_by_id and update its logic and code style --- module_utils/decort_utils.py | 45 ++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 6d04c75..414a425 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1561,9 +1561,10 @@ class DecortController(object): @param (int) )rg_id: ID of the RG to find and return facts for. - @return: RG ID and a dictionary of RG facts as provided by rg/get API call. Note that if it fails - to find the RG with the specified ID, it may return 0 for ID and empty dictionary for the facts. So - it is suggested to check the return values accordingly. + @return: RG ID and a dictionary of RG facts as provided by rg/get + API call. Note that if it fails to find the RG with the specified ID, + it may return 0 for ID and empty dictionary for the facts. So it is + suggested to check the return values accordingly. """ ret_rg_id = 0 ret_rg_dict = dict() @@ -1573,14 +1574,38 @@ class DecortController(object): self.result['msg'] = "rg_get_by_id(): 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/get", api_params) - if api_resp.status_code == 200: - ret_rg_id = rg_id - ret_rg_dict = json.loads(api_resp.content.decode('utf8')) + api_params = {'rgId': rg_id} + + # Get RG base info + api_rg_resp = self.decort_api_call( + arg_req_function=requests.post, + arg_api_name='/restmachine/cloudapi/rg/get', + arg_params=api_params + ) + if api_rg_resp.status_code != 200: + self.result['warning'] = ( + f'rg_get_by_id(): failed to get RG by ID {rg_id}.' + f' HTTP code {api_rg_resp.status_code}' + f', response {api_rg_resp.reason}.' + ) + return ret_rg_id, ret_rg_dict + ret_rg_id = rg_id + ret_rg_dict = api_rg_resp.json() + + # Get RG resources info + api_rg_res_resp = self.decort_api_call( + arg_req_function=requests.post, + arg_api_name='/restmachine/cloudapi/rg/getResourceConsumption', + arg_params=api_params + ) + if api_rg_res_resp.status_code != 200: + self.result['warning'] = ( + f'rg_get_by_id(): failed to get RG Resources by ID {rg_id}.' + f' HTTP code {api_rg_res_resp.status_code}' + f', response {api_rg_res_resp.reason}.' + ) else: - self.result['warning'] = ("rg_get_by_id(): failed to get RG by ID {}. HTTP code {}, " - "response {}.").format(rg_id, api_resp.status_code, api_resp.reason) + ret_rg_dict['Resources'] = api_rg_res_resp.json() return ret_rg_id, ret_rg_dict From 19534384a8db771be05397d78d737ef50c02191f Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 3 Apr 2024 13:18:53 +0300 Subject: [PATCH 07/76] Fix value for query_key_map['disk'] in method DecortController.rg_update: 'CU_D' -> 'CU_DM' --- 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 6d04c75..c39c3b8 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1839,7 +1839,7 @@ class DecortController(object): # - when quering resource limits, the keys are in the form of cloud units (CU_*) query_key_map = dict(cpu='CU_C', ram='CU_M', - disk='CU_D', + disk='CU_DM', ext_ips='CU_I', net_transfer='CU_NP',) set_key_map = dict(cpu='maxCPUCapacity', From f11ec8fefb21bb6292331dffbc7192d63cba8abf Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 4 Apr 2024 11:11:18 +0300 Subject: [PATCH 08/76] Update logic to only request RG resources info if the RG is not deleted. --- module_utils/decort_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 414a425..b71fa02 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1593,6 +1593,9 @@ class DecortController(object): ret_rg_dict = api_rg_resp.json() # Get RG resources info + rg_status = ret_rg_dict.get('status') + if not rg_status or rg_status == 'DELETED': + return ret_rg_id, ret_rg_dict api_rg_res_resp = self.decort_api_call( arg_req_function=requests.post, arg_api_name='/restmachine/cloudapi/rg/getResourceConsumption', From 200e8f7151094f3f36b869db826814d2f6268378 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 4 Apr 2024 15:53:29 +0300 Subject: [PATCH 09/76] Add execution of restoring in the case of state=disabled and state=enabled --- library/decort_rg.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/decort_rg.py b/library/decort_rg.py index 78260e6..44d2f29 100644 --- a/library/decort_rg.py +++ b/library/decort_rg.py @@ -493,8 +493,12 @@ def main(): elif decon.rg_facts['status'] == "DELETED": if amodule.params['state'] == 'absent' and amodule.params['permanently'] == True: decon.destroy() - elif amodule.params['state'] == 'present': + elif (amodule.params['state'] == 'present' + or amodule.params['state'] == 'disabled'): decon.restore() + elif amodule.params['state'] == 'enabled': + decon.restore() + decon.enable() elif decon.rg_facts['status'] in ("DISABLED"): if amodule.params['state'] == 'absent': decon.destroy() From a45ab19d387cfcd060f000c0b5d0defbb8597de1 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 4 Apr 2024 18:30:07 +0300 Subject: [PATCH 10/76] Add check for "rg_name" parameter in case of resource group creating --- library/decort_rg.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/decort_rg.py b/library/decort_rg.py index 44d2f29..750c9a7 100644 --- a/library/decort_rg.py +++ b/library/decort_rg.py @@ -507,9 +507,16 @@ def main(): else: if amodule.params['state'] in ('present', 'enabled'): - decon.create() - if amodule.params['access']: - decon.access() + if not amodule.params['rg_name']: + decon.result['failed'] = True + decon.result['msg'] = ( + 'Resource group could not be created because' + ' the "rg_name" parameter was not specified.' + ) + else: + decon.create() + if amodule.params['access']: + decon.access() elif amodule.params['state'] in ('disabled'): decon.error() From d50509e0c384dbe3982989f16b8b76c1818640ad Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 5 Apr 2024 11:10:40 +0300 Subject: [PATCH 11/76] Enable output of deleted RGs for API request /restmachine/cloudapi/rg/list in the DecortController.rg_find 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 523d383..3274f8d 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1684,7 +1684,7 @@ class DecortController(object): self.amodule.fail_json(**self.result) # try to locate RG by name - start with getting all RGs IDs within the specified account #api_params['accountId'] = arg_account_id - api_params['includedeleted'] = False + api_params['includedeleted'] = True #api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/account/listRG", api_params) api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/rg/list",api_params) if api_resp.status_code == 200: From 6cd828d031e3573ad7f47d054079bc3c8714cf16 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 5 Apr 2024 12:17:05 +0300 Subject: [PATCH 12/76] Add status DESTROYED for condition excluding of API request /restmachine/cloudapi/rg/getResourceConsumption in the DecortController._rg_get_by_id 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 523d383..b535ddc 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1594,7 +1594,7 @@ class DecortController(object): # Get RG resources info rg_status = ret_rg_dict.get('status') - if not rg_status or rg_status == 'DELETED': + if not rg_status or rg_status in ('DELETED', 'DESTROYED'): return ret_rg_id, ret_rg_dict api_rg_res_resp = self.decort_api_call( arg_req_function=requests.post, From 9e7a33a44a1318b3c5d9d05fb4a697c7e22bfe11 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 15 Apr 2024 17:03:51 +0300 Subject: [PATCH 13/76] Add NoneType check for the 'aff' argument to Affinity Rules management logic of the 'Decort.Controller.compute_affinity' 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 41f9d46..b6cc733 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1245,7 +1245,7 @@ class DecortController(object): if comp_dict['affinityRules']: for rule in comp_dict['affinityRules']: del rule['guid'] - if rule not in aff: + if not aff or rule not in aff: affrule_del.append(rule) if aff: From 694e68fe22d0c1bcd4a172a49d4ae1b06720bc8d Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 15 Apr 2024 18:02:50 +0300 Subject: [PATCH 14/76] Add NoneType check for the 'aaff' argument to Affinity Rules management logic of the 'Decort.Controller.compute_affinity' 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 41f9d46..cf7efc6 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1257,7 +1257,7 @@ class DecortController(object): if comp_dict['antiAffinityRules']: for rule in comp_dict['antiAffinityRules']: del rule['guid'] - if rule not in aaff: + if not aaff or rule not in aaff: aaffrule_del.append(rule) if aaff: From 240e2ce2df75453a0af65bed327d505efd6f78e2 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 6 May 2024 18:48:08 +0300 Subject: [PATCH 15/76] Assign upload_files variable outside of if construction in DecortController.k8s_provision method --- module_utils/decort_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index c2918e8..84ad388 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3514,6 +3514,7 @@ class DecortController(object): extnetOnly=extnet_only, ) + upload_files = None if oidc_cert: upload_files = {'oidcCertificate': ('cert.pem', str(oidc_cert),'application/x-x509-ca-cert')} From 4c4be07550680f5a9691b2201c3e1523d2a6048b Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 8 May 2024 14:34:33 +0300 Subject: [PATCH 16/76] Add rg_name parameter to the arguments of the DecortController.rg_find method call in library/decort_k8s.py --- library/decort_k8s.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/decort_k8s.py b/library/decort_k8s.py index 13ea565..f466f19 100644 --- a/library/decort_k8s.py +++ b/library/decort_k8s.py @@ -102,8 +102,11 @@ class decort_k8s(DecortController): self.amodule.fail_json(**self.result) # fail the module -> exit # now validate RG - validated_rg_id, validated_rg_facts = self.rg_find(validated_acc_id, - arg_amodule.params['rg_id'],) + validated_rg_id, validated_rg_facts = self.rg_find( + arg_account_id=validated_acc_id, + arg_rg_id=arg_amodule.params['rg_id'], + arg_rg_name=arg_amodule.params['rg_name'] + ) if not validated_rg_id: self.result['failed'] = True self.result['changed'] = False From 8b407c6f692edf5b0b7cd0e852984f97f6396ce5 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 8 May 2024 16:06:39 +0300 Subject: [PATCH 17/76] Change cluster_conf, kublet_conf, kubeproxy_conf, join_conf decort_k8s parameter types to dict. --- library/decort_k8s.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/decort_k8s.py b/library/decort_k8s.py index 13ea565..bfad2c6 100644 --- a/library/decort_k8s.py +++ b/library/decort_k8s.py @@ -333,10 +333,10 @@ class decort_k8s(DecortController): extnet_only=dict(type='bool', default=False), additionalSANs=dict(type='list',required=False, default=None), init_conf=dict(type='dict', required=False, default=None), - cluster_conf=dict(type='str', required=False, default=None), - kublet_conf=dict(type='str', required=False, default=None), - kubeproxy_conf=dict(type='str', required=False, default=None), - join_conf=dict(type='str', required=False, default=None), + cluster_conf=dict(type='dict', required=False, default=None), + kublet_conf=dict(type='dict', required=False, default=None), + kubeproxy_conf=dict(type='dict', required=False, default=None), + join_conf=dict(type='dict', required=False, default=None), oidc_cert=dict(type='raw',required=False,default=None), verify_ssl=dict(type='bool', required=False, default=True), workflow_callback=dict(type='str', required=False), From 5da120f2d3ceb04fa923063332cd3f4303f88c5c Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 17 May 2024 14:11:51 +0300 Subject: [PATCH 18/76] Fix logic for the case when DecortController.k8s_provision method returns 0 --- library/decort_k8s.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/decort_k8s.py b/library/decort_k8s.py index f3dbe57..421fc98 100644 --- a/library/decort_k8s.py +++ b/library/decort_k8s.py @@ -235,10 +235,13 @@ class decort_k8s(DecortController): self.amodule.params['description'], self.amodule.params['extnet_only'], ) - + if not k8s_id: - self.result['failed'] = True - self.amodule.fail_json(**self.result) + if k8s_id == 0: + return + else: + self.result['failed'] = True + self.amodule.fail_json(**self.result) self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=k8s_id, k8s_name=self.amodule.params['name'], From bcf384a91095b3d8a2513f03d4d0f148ebdb3053 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 17 May 2024 16:37:35 +0300 Subject: [PATCH 19/76] Fix logic for permanently deleting k8s from recycle bin --- library/decort_k8s.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/decort_k8s.py b/library/decort_k8s.py index 421fc98..3566318 100644 --- a/library/decort_k8s.py +++ b/library/decort_k8s.py @@ -394,7 +394,10 @@ def main(): subj.k8s_restore(subj.k8s_id) subj.action(amodule.params['state']) if amodule.params['state'] == 'absent': - subj.nop() + if amodule.params['permanent']: + subj.destroy() + else: + subj.nop() elif subj.k8s_info['techStatus'] in ("STARTED","STOPPED"): if amodule.params['state'] == 'disabled': subj.action(amodule.params['state']) From 6a99ea4d85f3680bd6d02d10c4633e2fbeb981ec Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 20 May 2024 12:41:06 +0300 Subject: [PATCH 20/76] Fix parameter name 'vinsId' for API request in DecortController.k8s_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 84ad388..ff7b240 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3482,7 +3482,7 @@ class DecortController(object): api_params = dict(name=k8s_name, rgId=rg_id, k8ciId=k8ci_id, - vins_Id=vins_id, + vinsId=vins_id, workerGroupName=def_wg_name, networkPlugin=plugin, masterNum=master_count, From 5003991cf5dae03d5b464c82c0f6aeb7fae4521e Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 20 May 2024 16:37:41 +0300 Subject: [PATCH 21/76] Fix logic for 'changed' setting in DecortController.k8s_workers_modify method --- module_utils/decort_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index ff7b240..85c9899 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3563,7 +3563,6 @@ class DecortController(object): if self.k8s_info['techStatus'] != "STARTED": - self.result['changed'] = False self.result['msg'] = ("k8s_workers_modify(): Can't modify with TechStatus other then STARTED") return From 6725e4342ebb8d1c10ba7b4b3ef1c0a8d39470ab Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 20 May 2024 20:45:45 +0300 Subject: [PATCH 22/76] Fix logic of starting k8s after restore it from recycle bin --- library/decort_k8s.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/decort_k8s.py b/library/decort_k8s.py index 3566318..e415812 100644 --- a/library/decort_k8s.py +++ b/library/decort_k8s.py @@ -260,8 +260,10 @@ class decort_k8s(DecortController): self.k8s_should_exist = False return - def action(self,disared_state,started=True): - + def action(self, disared_state, started=True, preupdate: bool = False): + if preupdate: + # K8s info updating + self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id) #k8s state self.k8s_state(self.k8s_info, disared_state, started) self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=self.amodule.params['id'], @@ -392,7 +394,8 @@ def main(): elif subj.k8s_info['status'] == "DELETED": if amodule.params['state'] in ('disabled', 'enabled', 'present'): subj.k8s_restore(subj.k8s_id) - subj.action(amodule.params['state']) + subj.action(disared_state=amodule.params['state'], + preupdate=True) if amodule.params['state'] == 'absent': if amodule.params['permanent']: subj.destroy() From abcb7d52f8da999fdd9074f65498ff0f3b4696d6 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 21 May 2024 16:17:12 +0300 Subject: [PATCH 23/76] Move execution of getConfig before if-condition of check mode in decort_k8s.package_facts method --- library/decort_k8s.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/decort_k8s.py b/library/decort_k8s.py index e415812..27d92e9 100644 --- a/library/decort_k8s.py +++ b/library/decort_k8s.py @@ -153,6 +153,9 @@ class decort_k8s(DecortController): config=None, ) + if self.amodule.params['getConfig'] and self.k8s_info['techStatus'] == "STARTED": + ret_dict['config'] = self.k8s_getConfig() + if check_mode: # in check mode return immediately with the default values return ret_dict @@ -172,9 +175,6 @@ class decort_k8s(DecortController): ret_dict['k8s_Masters'] = self.k8s_info['k8sGroups']['masters'] ret_dict['k8s_Workers'] = self.k8s_info['k8sGroups']['workers'] - if self.amodule.params['getConfig'] and self.k8s_info['techStatus'] == "STARTED": - ret_dict['config'] = self.k8s_getConfig() - return ret_dict def nop(self): From 3f4cfd40d6d76f911f6fc46793b8b197534ba27e Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 22 May 2024 11:50:06 +0300 Subject: [PATCH 24/76] Add check mode logic to DecortController.k8s_workers_modify method. --- module_utils/decort_utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 85c9899..59b0c15 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3561,6 +3561,13 @@ class DecortController(object): self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "k8s_workers_modify") + if self.amodule.check_mode: + result_msg = 'k8s_workers_modify() in check mode: No changing.' + if self.result.get('msg'): + self.result['msg'] += f'\n{result_msg}' + else: + self.result['msg'] = result_msg + return if self.k8s_info['techStatus'] != "STARTED": self.result['msg'] = ("k8s_workers_modify(): Can't modify with TechStatus other then STARTED") From 51707cbb6988a96ae256173f2e73d90defc7a1ba Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 22 May 2024 12:53:22 +0300 Subject: [PATCH 25/76] Fix call of AnsibleModule.fail_json method in decort_disk.__init__ method. --- library/decort_disk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/decort_disk.py b/library/decort_disk.py index 0df148b..d90fca0 100644 --- a/library/decort_disk.py +++ b/library/decort_disk.py @@ -276,7 +276,7 @@ class decort_disk(DecortController): self.result['msg'] = ("Current user does not have access to the account ID {} / " "name '{}' or non-existent account specified.").format(arg_amodule.params['account_id'], arg_amodule.params['account_name']) - self.fail_json(**self.result) + self.amodule.fail_json(**self.result) else: self.acc_id = validated_acc_id self.acc_info = validated_acc_info @@ -289,7 +289,7 @@ class decort_disk(DecortController): else: self.result['failed'] = True self.result['msg'] = ("Cannot manage Disk when its ID is 0 and name is empty") - self.fail_json(**self.result) + self.amodule.fail_json(**self.result) if arg_amodule.params['place_with']: image_id, image_facts = self.image_find(arg_amodule.params['place_with'], "", 0) From df619e79989b829fc6d3ab4117e4741d9a403ad1 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 22 May 2024 17:59:38 +0300 Subject: [PATCH 26/76] Fix incorrect access to MIN_IOPS variable in DecortController.disk_check_iotune_arg 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 59b0c15..ccb6261 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -2755,7 +2755,7 @@ class DecortController(object): "write_iops_sec_max", "size_iops_sec", ): - if val and val < self.MIN_IOPS: + if val and val < MIN_IOPS: self.result['msg'] = (f"{arg} was set below the minimum iops {MIN_IOPS}: {val} provided") return From 53634b7fa51d72439fc4b193dde175891532880b Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 22 May 2024 19:34:40 +0300 Subject: [PATCH 27/76] Fix call of DecortController.disk_limitIO method in decort_disk.create method --- library/decort_disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/decort_disk.py b/library/decort_disk.py index d90fca0..ec22681 100644 --- a/library/decort_disk.py +++ b/library/decort_disk.py @@ -311,7 +311,8 @@ class decort_disk(DecortController): ) #IO tune if self.amodule.params['limitIO']: - self.disk_limitIO(self.amodule.params['limitIO'],self.disk_id) + self.disk_limitIO(disk_id=self.disk_id, + limits=self.amodule.params['limitIO']) #set share status if self.amodule.params['shareable'] and self.amodule.params['type'] == "D": self.dick_share(self.disk_id,self.amodule.params['shareable']) From fde986bb421a080f8f2afa6fea400a6d141a7206 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 23 May 2024 13:56:35 +0300 Subject: [PATCH 28/76] Fix call of DecortController.disk_share method in decort_disk.create method --- library/decort_disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_disk.py b/library/decort_disk.py index ec22681..0a1c838 100644 --- a/library/decort_disk.py +++ b/library/decort_disk.py @@ -315,7 +315,7 @@ class decort_disk(DecortController): limits=self.amodule.params['limitIO']) #set share status if self.amodule.params['shareable'] and self.amodule.params['type'] == "D": - self.dick_share(self.disk_id,self.amodule.params['shareable']) + self.disk_share(self.disk_id,self.amodule.params['shareable']) return def action(self,restore=False): From 35fe2bdf0e9cf8c493a29f9306f3cb5b33930826 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 23 May 2024 16:41:45 +0300 Subject: [PATCH 29/76] Fix disk deleting logic for permanently deleting from recycle bin --- library/decort_disk.py | 3 +++ module_utils/decort_utils.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/library/decort_disk.py b/library/decort_disk.py index 0a1c838..f779b71 100644 --- a/library/decort_disk.py +++ b/library/decort_disk.py @@ -520,6 +520,9 @@ def main(): elif decon.disk_info['status'] == "DELETED": if amodule.params['state'] in ('present'): decon.action(restore=True) + elif (amodule.params['state'] == 'absent' and + amodule.params['permanently']): + decon.delete() else: decon.nop() else: diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index ccb6261..bd0cfe9 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -2859,10 +2859,18 @@ class DecortController(object): return 0, None elif name: if account_id: - api_params = dict(accountId=account_id,name=name) + api_params = { + 'accountId': account_id, + 'name': name, + 'show_all': True + } api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/disks/search", api_params) + disks_list = api_resp.json() + # Filtering disks by status + excluded_statuses = ('PURGED', 'DESTROYED') + filter_f = lambda x: x.get('status') not in excluded_statuses + disks_list = [d for d in disks_list if filter_f(d)] # the above call may return more than one matching disk - disks_list = json.loads(api_resp.content.decode('utf8')) if len(disks_list) == 0: return 0, None elif len(disks_list) > 1: From 772f389d98084c3197bdf5f07804bd35bd61d180 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 23 May 2024 19:00:29 +0300 Subject: [PATCH 30/76] Fix call of DecortController.disk_rename method in decort_disk.action method --- library/decort_disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_disk.py b/library/decort_disk.py index f779b71..b4d4078 100644 --- a/library/decort_disk.py +++ b/library/decort_disk.py @@ -325,7 +325,7 @@ class decort_disk(DecortController): self.disk_restore(self.disk_id) #rename if id present if self.amodule.params['name'] != self.disk_info['name']: - self.disk_rename(diskId=self.disk_id, + self.disk_rename(disk_id=self.disk_id, name=self.amodule.params['name']) self.disk_info['name'] = self.amodule.params['name'] #resize From 2873e4da8256d2ff466cfd89b345fdefce34be56 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 24 May 2024 14:08:43 +0300 Subject: [PATCH 31/76] Remove if-condition for check mode from DecortController.disk_find method --- module_utils/decort_utils.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index bd0cfe9..53f71c9 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -2838,12 +2838,6 @@ class DecortController(object): DISK_INVALID_STATES = ["MODELED", "CREATING", "DELETING", "DESTROYING"] - if self.amodule.check_mode: - self.result['failed'] = False - self.result['msg'] = "disk_find() in check mode: find Disk ID {} / name '{}' was requested.".format(disk_id, - name) - return - ret_disk_id = 0 ret_disk_facts = None From 007c7f4bad222c21a4618dd17ce33db8ad8f8fe6 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 27 May 2024 12:20:33 +0300 Subject: [PATCH 32/76] Fix if-condition in DecortController.pfw_configure method for excluding case of TypeError --- 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 53f71c9..7eb3bd1 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3136,7 +3136,7 @@ class DecortController(object): if runner['vmId'] == comp_facts['id']: existing_rules.append(runner) - if not len(existing_rules) and not len(new_rules): + if not existing_rules and not new_rules: self.result['failed'] = False self.result['warning'] = ("pfw_configure(): both existing and new port forwarding rule lists " "for Compute ID {} are empty - nothing to do.").format(comp_facts['id']) From 5b731d009bb64da7701c08a7f3d5138449007446 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 28 May 2024 16:26:42 +0300 Subject: [PATCH 33/76] Add validated_image_id check to if-condition of deleting image logic --- library/decort_osimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index b78c89e..8aef066 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -522,7 +522,7 @@ def main(): decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] - elif amodule.params['state'] == "absent": + elif amodule.params['state'] == "absent" and decon.validated_image_id: if amodule.params['image_name'] or amodule.params['image_id'] and\ decort_osimage.decort_osimage_package_facts(image_facts)['accountId'] == amodule.params['account_Id']: amodule.image_id_delete = decon.validated_image_id From ff32b509f83b3743070404fafa766e9384ffeb3c Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 28 May 2024 16:41:17 +0300 Subject: [PATCH 34/76] Exclude failed setting in case when image not found in DecortController.image_find method --- module_utils/decort_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 7eb3bd1..ea19522 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1386,7 +1386,6 @@ class DecortController(object): return image_record['id'], image_record self.result['failed'] = False - self.result['failed'] = True self.result['msg'] = ("Failed to find OS image by name '{}', SEP ID {}, pool '{}' for " "account ID '{}'.").format(image_name, sepid, pool, From 9dc3a5e780f90d2f953ae7d3a7c26d616a1c8dd9 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 28 May 2024 17:31:44 +0300 Subject: [PATCH 35/76] Fix account_Id parameter value for call of decort_osimage.decort_image_create method --- library/decort_osimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index b78c89e..22f0a49 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -350,7 +350,7 @@ class decort_osimage(DecortController): hotresize=amodule.params['hotresize'], username=amodule.params['image_username'], password=amodule.params['image_password'], - account_Id=amodule.params['account_Id'], + account_Id=self.validated_account_id, usernameDL=amodule.params['usernameDL'], passwordDL=amodule.params['passwordDL'], sepId=amodule.params['sepId'], From 76a1ff1788709b9f751da1951a6c2974e1cb0abf Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 29 May 2024 13:18:12 +0300 Subject: [PATCH 36/76] Fix image renaming logic in decort_osimage.__init__ method --- library/decort_osimage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index b78c89e..0b95c39 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -314,8 +314,9 @@ class decort_osimage(DecortController): if amodule.params['image_id'] != 0 and amodule.params['image_name']: - self.validated_image_id = amodule.params['image_id'] - if amodule.params['image_name']: + self.validated_image_id, image_facts = self.decort_image_find(amodule) + if (self.validated_image_id and + amodule.params['image_name'] != image_facts['name']): decort_osimage.decort_image_rename(self,amodule) self.result['msg'] = ("Image renamed successfully") From a39ab95c1f710ce908c378558601d68b2bb13b49 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 29 May 2024 14:55:47 +0300 Subject: [PATCH 37/76] Fix access to API response image list in DecortController.virt_image_find 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 7eb3bd1..851d6a1 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1439,7 +1439,7 @@ class DecortController(object): api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/image/list", api_params) # On success the above call will return here. On error it will abort execution by calling fail_json. images_list = json.loads(api_resp.content.decode('utf8')) - for image_record in images_list: + for image_record in images_list['data']: if image_record['name'] == virt_name and image_record['status'] == "CREATED" and image_record['type'] == "virtual": if sepid == 0 and pool == "": # if no filtering by SEP ID or pool name is requested, return the first match From aa96af1455e3c502d95baf9cf2977688536388c0 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 29 May 2024 18:11:05 +0300 Subject: [PATCH 38/76] Exclude 'failed' setting in case when image not found in DecortController.virt_image_find method --- module_utils/decort_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 7eb3bd1..0d481fb 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -1448,7 +1448,6 @@ class DecortController(object): if full_match: return image_record['id'], image_record - self.result['failed'] = True self.result['msg'] = ("Failed to find virtual OS image by name '{}', SEP ID {}, pool '{}' for " "account ID '{}'.").format(virt_name, sepid, pool, From 2eb43815e79cce2ad87d4157c72b12e51a0cebfb Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 29 May 2024 19:02:27 +0300 Subject: [PATCH 39/76] Fix if-condition logic in main function in decort_osimage.py --- library/decort_osimage.py | 45 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index 8aef066..c08fba8 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -507,29 +507,6 @@ def main(): decon = decort_osimage(amodule) - if amodule.params['image_name'] or amodule.params['image_id']: - image_id, image_facts = decort_osimage.decort_image_find(decon, amodule) - decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] - if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0: - decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode) - - if amodule.params['state'] == "present" and decon.validated_image_id == 0 and amodule.params['image_name'] and amodule.params['url']: - decort_osimage.decort_image_create(decon,amodule) - decon.result['changed'] = True - image_id, image_facts = decort_osimage.decort_image_find(decon, amodule) - decon.result['msg'] = ("OS image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id']) - decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode) - decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] - - - elif amodule.params['state'] == "absent" and decon.validated_image_id: - if amodule.params['image_name'] or amodule.params['image_id'] and\ - decort_osimage.decort_osimage_package_facts(image_facts)['accountId'] == amodule.params['account_Id']: - amodule.image_id_delete = decon.validated_image_id - decort_osimage.decort_image_delete(decon,amodule) - - - if amodule.params['virt_name'] or amodule.params['virt_id']: image_id, image_facts = decort_osimage.decort_virt_image_find(decon, amodule) @@ -538,7 +515,6 @@ def main(): decon.validated_virt_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] decon.validated_virt_image_name = decort_osimage.decort_osimage_package_facts(image_facts)['name'] - if decort_osimage.decort_osimage_package_facts(image_facts)['id'] == 0 and amodule.params['state'] == "present" and decon.validated_image_id > 0: image_id, image_facts = decort_osimage.decort_virt_image_create(decon,amodule) decon.result['msg'] = ("Virtual image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id']) @@ -547,19 +523,36 @@ def main(): decon.result['msg'] = ("Cannot find OS image") amodule.fail_json(**decon.result) - if decon.validated_image_id: if decort_osimage.decort_osimage_package_facts(image_facts)['linkto'] != decon.validated_image_id: decort_osimage.decort_virt_image_link(decon,amodule) decon.result['changed'] = True amodule.exit_json(**decon.result) - if decon.validated_virt_image_id > 0 and amodule.params['state'] == "absent": decon.result['msg'] = ("Osimage module cannot delete virtual images.") decon.result['failed'] = True amodule.exit_json(**decon.result) + elif amodule.params['image_name'] or amodule.params['image_id']: + image_id, image_facts = decort_osimage.decort_image_find(decon, amodule) + decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] + if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0: + decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode) + + if amodule.params['state'] == "present" and decon.validated_image_id == 0 and amodule.params['image_name'] and amodule.params['url']: + decort_osimage.decort_image_create(decon,amodule) + decon.result['changed'] = True + image_id, image_facts = decort_osimage.decort_image_find(decon, amodule) + decon.result['msg'] = ("OS image '{}' created").format(decort_osimage.decort_osimage_package_facts(image_facts)['id']) + decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode) + decon.validated_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] + + elif amodule.params['state'] == "absent" and decon.validated_image_id: + if amodule.params['image_name'] or amodule.params['image_id'] and\ + decort_osimage.decort_osimage_package_facts(image_facts)['accountId'] == amodule.params['account_Id']: + amodule.image_id_delete = decon.validated_image_id + decort_osimage.decort_image_delete(decon,amodule) if decon.result['failed'] == True: # we failed to find the specified image - fail the module From e5504b3ac9ca1223336c43c0c0925527ac5c1d88 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 30 May 2024 14:30:10 +0300 Subject: [PATCH 40/76] Add if-condition logic correction in main function in decort_osimage.py --- library/decort_osimage.py | 1 + 1 file changed, 1 insertion(+) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index c08fba8..b75470a 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -510,6 +510,7 @@ def main(): if amodule.params['virt_name'] or amodule.params['virt_id']: image_id, image_facts = decort_osimage.decort_virt_image_find(decon, amodule) + decon.validated_image_id, _ = decort_osimage.decort_image_find(decon, amodule) if decort_osimage.decort_osimage_package_facts(image_facts)['id'] > 0: decon.result['facts'] = decort_osimage.decort_osimage_package_facts(image_facts, amodule.check_mode) decon.validated_virt_image_id = decort_osimage.decort_osimage_package_facts(image_facts)['id'] From 2777059b6bf217f4a1b0ae296f0f8ae6e4922453 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 30 May 2024 16:06:25 +0300 Subject: [PATCH 41/76] Add logic for virtual image renaming in decort_osimage class --- library/decort_osimage.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index e93009c..f607769 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -313,7 +313,14 @@ class decort_osimage(DecortController): amodule.fail_json(**self.result) - if amodule.params['image_id'] != 0 and amodule.params['image_name']: + if amodule.params['virt_id'] != 0 and amodule.params['virt_name']: + self.validated_virt_image_id, image_facts =\ + self.decort_virt_image_find(amodule) + if (self.validated_virt_image_id and + amodule.params['virt_name'] != image_facts['name']): + self.decort_virt_image_rename(amodule) + self.result['msg'] = 'Virtual image renamed successfully' + elif amodule.params['image_id'] != 0 and amodule.params['image_name']: self.validated_image_id, image_facts = self.decort_image_find(amodule) if (self.validated_image_id and amodule.params['image_name'] != image_facts['name']): @@ -390,6 +397,12 @@ class decort_osimage(DecortController): image_id, image_facts = decort_osimage.decort_image_find(self, amodule) return image_id, image_facts + def decort_virt_image_rename(self, amodule): + image_facts = self.image_rename(imageId=self.validated_virt_image_id, + name=amodule.params['virt_name']) + self.result['msg'] = ("Virtual image renamed successfully") + image_id, image_facts = self.decort_virt_image_find(amodule) + return image_id, image_facts def decort_osimage_package_facts(arg_osimage_facts, arg_check_mode=False): """Package a dictionary of OS image according to the decort_osimage module specification. This From 1e994410fe5b8bbfafbd19ba40ff71a02dbb9193 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 30 May 2024 16:24:28 +0300 Subject: [PATCH 42/76] Fix if-condition for executing logic of virtual image link changing --- library/decort_osimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index f607769..cbe84e5 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -538,7 +538,7 @@ def main(): decon.result['msg'] = ("Cannot find OS image") amodule.fail_json(**decon.result) - if decon.validated_image_id: + if decon.validated_virt_image_id: if decort_osimage.decort_osimage_package_facts(image_facts)['linkto'] != decon.validated_image_id: decort_osimage.decort_virt_image_link(decon,amodule) decon.result['changed'] = True From eb0766b15f0eba8acefe70a613116be9ff0bd603 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Sun, 2 Jun 2024 22:18:58 +0300 Subject: [PATCH 43/76] 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 44/76] 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 45/76] 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 46/76] 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 47/76] 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 48/76] 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 49/76] 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 50/76] 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 51/76] 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 52/76] 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 53/76] 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 54/76] 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 55/76] 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 56/76] 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 57/76] 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 58/76] 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 59/76] 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] From 5c3194b94dd8ef017620a350f44455bb4b68a7ff Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 7 Jun 2024 12:39:29 +0300 Subject: [PATCH 60/76] Fix variable name for if-condition in decort_bservice.nop method --- library/decort_bservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_bservice.py b/library/decort_bservice.py index 5e1270e..1b771db 100644 --- a/library/decort_bservice.py +++ b/library/decort_bservice.py @@ -76,7 +76,7 @@ class decort_bservice(DecortController): """ self.result['failed'] = False self.result['changed'] = False - if self.k8s_id: + if self.bservice_id: self.result['msg'] = ("No state change required for B-service ID {} because of its " "current status '{}'.").format(self.bservice_id, self.bservice_info['status']) else: From 3dc9cbcbd8897bfef487638a69c8d8262c99125f Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 7 Jun 2024 12:56:04 +0300 Subject: [PATCH 61/76] Add rg_name param value to call of DecortController.rg_find method in decort_bservice.__init__ method --- library/decort_bservice.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/decort_bservice.py b/library/decort_bservice.py index 1b771db..87b3310 100644 --- a/library/decort_bservice.py +++ b/library/decort_bservice.py @@ -43,8 +43,11 @@ class decort_bservice(DecortController): self.fail_json(**self.result) # fail the module -> exit # now validate RG - validated_rg_id, validated_rg_facts = self.rg_find(validated_acc_id, - arg_amodule.params['rg_id'],) + validated_rg_id, validated_rg_facts = self.rg_find( + arg_account_id=validated_acc_id, + arg_rg_id=arg_amodule.params['rg_id'], + arg_rg_name=arg_amodule.params['rg_name'] + ) if not validated_rg_id: self.result['failed'] = True self.result['changed'] = False From 3fec6f014b8266336986523ae8a57b798f0717b0 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 7 Jun 2024 14:12:45 +0300 Subject: [PATCH 62/76] Add existing check for 'groupsName' key of self.bservice_info dict in decort_bservice.package_facts method --- library/decort_bservice.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/decort_bservice.py b/library/decort_bservice.py index 87b3310..a23c979 100644 --- a/library/decort_bservice.py +++ b/library/decort_bservice.py @@ -151,7 +151,9 @@ class decort_bservice(DecortController): ret_dict['state'] = self.bservice_info['status'] ret_dict['rg_id'] = self.bservice_info['rgId'] ret_dict['account_id'] = self.acc_id - ret_dict['groupsName'] = self.bservice_info['groupsName'] + bservice_info_groupsName = self.bservice_info.get('groupsName') + if bservice_info_groupsName: + ret_dict['groupsName'] = bservice_info_groupsName ret_dict['groupsIds'] = self.bservice_info['groups'] return ret_dict @staticmethod From 7e372511bcd046ede8bb022b762463dc1f528828 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 7 Jun 2024 14:53:28 +0300 Subject: [PATCH 63/76] Add check mode simple logic in DecortController.bservice_provision method --- module_utils/decort_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 0be52ea..073c2c8 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3731,6 +3731,14 @@ class DecortController(object): self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "bservice_provision") + if self.amodule.check_mode: + result_msg = 'bservice_provision() in check mode: No changing.' + if self.result.get('msg'): + self.result['msg'] += f'\n{result_msg}' + else: + self.result['msg'] = result_msg + return 0 + api_url = "/restmachine/cloudapi/bservice/create" api_params = dict( name = bs_name, From cb13649586138d7b5120257333617cc0362b44f5 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 7 Jun 2024 14:54:30 +0300 Subject: [PATCH 64/76] Fix executing logic of DecortController.bservice_state method call in decort_bservice.create method --- library/decort_bservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_bservice.py b/library/decort_bservice.py index a23c979..da52fef 100644 --- a/library/decort_bservice.py +++ b/library/decort_bservice.py @@ -112,7 +112,7 @@ class decort_bservice(DecortController): ) if self.bservice_id: _, self.bservice_info = self.bservice_get_by_id(self.bservice_id) - self.bservice_state(self.bservice_info,'enabled',self.amodule.params['started']) + self.bservice_state(self.bservice_info,'enabled',self.amodule.params['started']) return def action(self,d_state,started=False): From 7998046cfb911cf733b359d8c3157fd1fa85ec15 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 10 Jun 2024 16:02:19 +0300 Subject: [PATCH 65/76] Fix return value for DecortController.group_provision method. --- module_utils/decort_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 073c2c8..18675f1 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -4006,10 +4006,11 @@ class DecortController(object): vinses = list_vins, timeoutStart = arg_timeout ) - self.decort_api_call(requests.post, api_url, api_params) + api_resp = self.decort_api_call(requests.post, api_url, api_params) + new_bsgroup_id = int(api_resp.text) self.result['failed'] = False self.result['changed'] = True - return + return new_bsgroup_id def group_delete(self,bs_id,gr_id): From 27e7c2749f7bc868b8c5866f51d26f91fbb61744 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 10 Jun 2024 17:01:41 +0300 Subject: [PATCH 66/76] Fix adding networks logic in DecortController.group_provision method --- module_utils/decort_utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 18675f1..9a18a5c 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3987,11 +3987,7 @@ class DecortController(object): ): self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "group_provision") - - list_vins= list() - for net in arg_network: - if net['type'] == 'VINS': - list_vins.append(net['id']) + api_url = "/restmachine/cloudapi/bservice/groupAdd" api_params = dict( serviceId = bs_id, @@ -4003,7 +3999,8 @@ class DecortController(object): imageId = arg_image_id, driver = arg_driver, role = arg_role, - vinses = list_vins, + vinses = [n['id'] for n in arg_network if n['type'] == 'VINS'], + extnets = [n['id'] for n in arg_network if n['type'] == 'EXTNET'], timeoutStart = arg_timeout ) api_resp = self.decort_api_call(requests.post, api_url, api_params) From 3a2d9904cf663a32150ab54dbc3972b93cc81f38 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 11 Jun 2024 12:46:57 +0300 Subject: [PATCH 67/76] Update DecortController.group_find method logic for >=3.8.6 Dynamix version. --- module_utils/decort_utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 9a18a5c..9290b37 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3868,11 +3868,12 @@ class DecortController(object): self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "group_find") if group_id == 0: - try: - i = bs_info['groupsName'].index(group_name) - except: - return 0,None - group_id = int(bs_info['groups'][i]) + for group in bs_info['groups']: + if group['name'] == group_name: + return self._group_get_by_id(bs_id=bs_id, + g_id=group['id']) + return 0, None + return self._group_get_by_id(bs_id,group_id) def group_state(self,bs_id,gr_id,desired_state): From f22be4fe08755f8e05b176032142e5e1b9563b23 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 11 Jun 2024 14:16:23 +0300 Subject: [PATCH 68/76] Add default value '' for 'role' parameter in decort_group module. --- library/decort_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_group.py b/library/decort_group.py index 8162f0d..f8a1f9a 100644 --- a/library/decort_group.py +++ b/library/decort_group.py @@ -206,7 +206,7 @@ class decort_group(DecortController): bservice_id=dict(type='int', required=True), count=dict(type='int', required=True), timeoutStart=dict(type='int', required=False), - role=dict(type='str', required=False), + role=dict(type='str', required=False, default=''), cpu=dict(type='int', required=False), ram=dict(type='int', required=False), networks=dict(type='list', default=[], required=False), From 190a1d302c710c83f94abf7a15d7cea0b158da9e Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 11 Jun 2024 16:16:35 +0300 Subject: [PATCH 69/76] Add sub-elements specification for 'networks' parameter of decort_group module --- library/decort_group.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/decort_group.py b/library/decort_group.py index f8a1f9a..129c7cd 100644 --- a/library/decort_group.py +++ b/library/decort_group.py @@ -209,7 +209,20 @@ class decort_group(DecortController): role=dict(type='str', required=False, default=''), cpu=dict(type='int', required=False), ram=dict(type='int', required=False), - networks=dict(type='list', default=[], required=False), + networks=dict( + type='list', default=[], elements='dict', + options=dict( + type=dict( + type='str', + required=True, + choices=['VINS', 'EXTNET'] + ), + id=dict( + type='int', + required=True + ) + ) + ), description=dict(type='str', default="Created by decort ansible module"), verify_ssl=dict(type='bool', required=False, default=True), workflow_callback=dict(type='str', required=False), From 825ce068c8717ac2999df2fc91e40d7cbf8ad433 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 11 Jun 2024 17:30:23 +0300 Subject: [PATCH 70/76] Fix logic of decort_group.destroy method --- library/decort_group.py | 1 + 1 file changed, 1 insertion(+) diff --git a/library/decort_group.py b/library/decort_group.py index 129c7cd..9c29ff8 100644 --- a/library/decort_group.py +++ b/library/decort_group.py @@ -132,6 +132,7 @@ class decort_group(DecortController): self.bservice_id, self.group_id ) + self.group_should_exist = False return From b51136b711aafe9c070cb0390108a141341d4b78 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Fri, 14 Jun 2024 15:26:23 +0300 Subject: [PATCH 71/76] Fix ViNS list comparison in DecortController.group_update_net 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 9290b37..197c3a9 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3967,7 +3967,7 @@ class DecortController(object): else: list_extnet.append(net['id']) - if gr_dict['vinses'] != list_vins: + if sorted(gr_dict['vinses']) != sorted(list_vins): api_url = "/restmachine/cloudapi/bservice/groupUpdateVins" api_params = dict( serviceId=bs_id, From db854acc11fe42d24cb02219fd0212e5164606c0 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Mon, 17 Jun 2024 12:31:04 +0300 Subject: [PATCH 72/76] Fix check mode logic for RG creating in decort_rg module --- library/decort_rg.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/decort_rg.py b/library/decort_rg.py index 750c9a7..8f1f5a8 100644 --- a/library/decort_rg.py +++ b/library/decort_rg.py @@ -324,11 +324,14 @@ class decort_rg(DecortController): "", # this is location code. TODO: add module argument ) - self.validated_rg_id, self.rg_facts = self.rg_find(self.validated_acc_id, - self.validated_rg_id, - arg_rg_name="", - arg_check_state=False) - self.rg_should_exist = True + if self.validated_rg_id: + self.validated_rg_id, self.rg_facts = self.rg_find( + arg_account_id=self.validated_acc_id, + arg_rg_id=self.validated_rg_id, + arg_rg_name="", + arg_check_state=False + ) + self.rg_should_exist = True return def enable(self): @@ -515,7 +518,7 @@ def main(): ) else: decon.create() - if amodule.params['access']: + if amodule.params['access'] and not amodule.check_mode: decon.access() elif amodule.params['state'] in ('disabled'): decon.error() From d287c8829341db72c7e2501d5fb3520944ca1509 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 19 Jun 2024 10:35:36 +0300 Subject: [PATCH 73/76] Fix bs groups info keys in decort_bservice.package_facts method --- library/decort_bservice.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/decort_bservice.py b/library/decort_bservice.py index da52fef..a7b3ab7 100644 --- a/library/decort_bservice.py +++ b/library/decort_bservice.py @@ -151,10 +151,7 @@ class decort_bservice(DecortController): ret_dict['state'] = self.bservice_info['status'] ret_dict['rg_id'] = self.bservice_info['rgId'] ret_dict['account_id'] = self.acc_id - bservice_info_groupsName = self.bservice_info.get('groupsName') - if bservice_info_groupsName: - ret_dict['groupsName'] = bservice_info_groupsName - ret_dict['groupsIds'] = self.bservice_info['groups'] + ret_dict['groups'] = self.bservice_info['groups'] return ret_dict @staticmethod def build_parameters(): From 36930bda0d69c6725db1055ef79dbed8dab6cdc8 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Wed, 26 Jun 2024 13:35:11 +0300 Subject: [PATCH 74/76] Fix ci_user_data param type in decort_kvmvm module --- library/decort_kvmvm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/decort_kvmvm.py b/library/decort_kvmvm.py index d5e99c5..a0be17a 100644 --- a/library/decort_kvmvm.py +++ b/library/decort_kvmvm.py @@ -782,7 +782,7 @@ class decort_kvmvm(DecortController): affinity_label=dict(type='str', required=False), aff_rule=dict(type='list', required=False), aaff_rule=dict(type='list', required=False), - ci_user_data=dict(type='list',elements='dict', required=False), + ci_user_data=dict(type='dict', required=False), state=dict(type='str', default='present', choices=['absent', 'paused', 'poweredoff', 'halted', 'poweredon', 'present', 'check']), From 614c7d98d919769326e8f20b94eeaae8d70368cd Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Tue, 2 Jul 2024 14:50:44 +0300 Subject: [PATCH 75/76] Fix logic of deleting all port forwarding rules for compute in DecortController.pfw_configure method --- module_utils/decort_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/module_utils/decort_utils.py b/module_utils/decort_utils.py index 29aeb55..b3cd0be 100644 --- a/module_utils/decort_utils.py +++ b/module_utils/decort_utils.py @@ -3142,9 +3142,15 @@ class DecortController(object): if new_rules == None or len(new_rules) == 0: # delete all existing rules for this Compute - api_params = dict(vinsId=vins_facts['id'], - ruleId=-1) - self.decort_api_call(requests.post, "/restmachine/cloudapi/vins/natRuleDel", api_params) + for rule in existing_rules: + self.decort_api_call( + arg_req_function=requests.post, + arg_api_name="/restmachine/cloudapi/vins/natRuleDel", + arg_params={ + 'vinsId': vins_facts['id'], + 'ruleId': rule['id'] + } + ) self.result['changed'] = True return ret_rules From 3ce022a8007c2e53b39757caf0792cc74c1f3cce Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 4 Jul 2024 17:54:26 +0300 Subject: [PATCH 76/76] Fix access to lb_facts attribute in decort_lb class (in two places) --- library/decort_lb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/decort_lb.py b/library/decort_lb.py index e0fa09e..042691a 100644 --- a/library/decort_lb.py +++ b/library/decort_lb.py @@ -174,7 +174,7 @@ class decort_lb(DecortController): self.result['changed'] = False if self.lb_id: self.result['msg'] = ("No state change required for LB ID {} because of its " - "current status '{}'.").format(self.lb_id, self.vins_facts['status']) + "current status '{}'.").format(self.lb_id, self.lb_facts['status']) else: self.result['msg'] = ("No state change to '{}' can be done for " "non-existent LB instance.").format(self.amodule.params['state']) @@ -213,7 +213,7 @@ class decort_lb(DecortController): # in check mode return immediately with the default values return ret_dict - if self.vins_facts is None: + if self.lb_facts is None: # if void facts provided - change state value to ABSENT and return ret_dict['state'] = "ABSENT" return ret_dict