From cdf03c88e48e8cf3d1a66d4f12e101c87c092bca Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Thu, 28 Sep 2023 11:33:13 +0530 Subject: [PATCH 1/6] Create cluster url when it is required --- plugins/modules/ntnx_foundation.py | 4 +- .../tasks/image_nodes.yml | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ntnx_foundation.py b/plugins/modules/ntnx_foundation.py index 9b2abd41e..ac2eb278b 100644 --- a/plugins/modules/ntnx_foundation.py +++ b/plugins/modules/ntnx_foundation.py @@ -15,7 +15,7 @@ description: 'Nutanix module to image nodes and optionally create clusters' options: hypervisor_nameserver: - description: to-write + description: name servers for hypervisors type: str required: false cvm_gateway: @@ -1244,7 +1244,7 @@ def image_nodes(module, result): # add cluster urls if any cluster created cluster_urls = [] - if spec["clusters"]: + if spec.get("clusters"): for cluster in spec["clusters"]: cluster_urls.append( { diff --git a/tests/integration/targets/ntnx_foundation_sanity/tasks/image_nodes.yml b/tests/integration/targets/ntnx_foundation_sanity/tasks/image_nodes.yml index 49e4b651b..5705fb3a1 100644 --- a/tests/integration/targets/ntnx_foundation_sanity/tasks/image_nodes.yml +++ b/tests/integration/targets/ntnx_foundation_sanity/tasks/image_nodes.yml @@ -116,6 +116,43 @@ fail_msg: " Fail : unable to create spec for imaging nodes" success_msg: "Succes: spec generated successfully" + - name: Image nodes without cluster creation + ntnx_foundation: + timeout: 4500 + cvm_gateway: "{{cvm_gateway}}" + cvm_netmask: "{{cvm_netmask}}" + hypervisor_gateway: "{{hypervisor_gateway}}" + hypervisor_netmask: "{{hypervisor_netmask}}" + default_ipmi_user: "{{default_ipmi_user}}" + current_cvm_vlan_tag: "{{nodes.current_cvm_vlan_tag}}" + nos_package: "{{images.aos_packages[0]}}" + blocks: + - block_id: "{{nodes.block_id}}" + nodes: + - manual_mode: + cvm_ip: "{{nodes.node2.cvm_ip}}" + cvm_gb_ram: 50 + hypervisor_hostname: "{{nodes.node2.hypervisor_hostname}}" + ipmi_netmask: "{{nodes.node2.ipmi_netmask}}" + ipmi_gateway: "{{nodes.node2.ipmi_gateway}}" + ipmi_ip: "{{nodes.node2.ipmi_ip}}" + ipmi_password: "{{nodes.node2.ipmi_password}}" + hypervisor: "{{nodes.node2.hypervisor}}" + hypervisor_ip: "{{nodes.node2.hypervisor_ip}}" + node_position: "{{nodes.node2.node_position}}" + register: result + no_log: true + ignore_errors: True + + - name: Creation Status + assert: + that: + - result.response is defined + - result.failed==false + - result.changed==true + fail_msg: " Fail : unable to image nodes" + success_msg: "Succes: node imaging done successfully" + - name: Image nodes and create cluster out of it ntnx_foundation: timeout: 4500 From d0dfb22db85609dbfa10b0d1c4583da02b015b65 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Thu, 28 Sep 2023 11:33:45 +0530 Subject: [PATCH 2/6] Minor fix --- plugins/modules/ntnx_foundation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ntnx_foundation.py b/plugins/modules/ntnx_foundation.py index ac2eb278b..f5b7a3d15 100644 --- a/plugins/modules/ntnx_foundation.py +++ b/plugins/modules/ntnx_foundation.py @@ -15,7 +15,7 @@ description: 'Nutanix module to image nodes and optionally create clusters' options: hypervisor_nameserver: - description: name servers for hypervisors + description: name server for hypervisors type: str required: false cvm_gateway: From 1501ab76bf727fe67771d956f3ea63efa88bf121 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Tue, 17 Oct 2023 00:43:03 +0530 Subject: [PATCH 3/6] Change api url for fetching time machine using name to get complete info same as uuid --- plugins/module_utils/ndb/time_machines.py | 7 +++++-- plugins/modules/ntnx_ndb_time_machines_info.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/ndb/time_machines.py b/plugins/module_utils/ndb/time_machines.py index dc54b0dc0..a5ed83b73 100644 --- a/plugins/module_utils/ndb/time_machines.py +++ b/plugins/module_utils/ndb/time_machines.py @@ -37,8 +37,11 @@ def get_time_machine(self, uuid=None, name=None, query=None): if uuid: resp = self.read(uuid=uuid, query=query) elif name: - endpoint = "{0}/{1}".format("name", name) - resp = self.read(endpoint=endpoint, query=query) + if not query: + query = {} + query["vaue_type"] = "name" + query["value"] = name + resp = self.read(query=query) if isinstance(resp, list): if not resp: return None, "Time machine with name {0} not found".format(name) diff --git a/plugins/modules/ntnx_ndb_time_machines_info.py b/plugins/modules/ntnx_ndb_time_machines_info.py index f3d9dc861..8fce6fdae 100644 --- a/plugins/modules/ntnx_ndb_time_machines_info.py +++ b/plugins/modules/ntnx_ndb_time_machines_info.py @@ -307,7 +307,7 @@ def get_time_machine(module, result): resp, err = tm.get_time_machine(uuid=uuid, name=name, query=query_params) if err: result["error"] = err - module.fail_json(msg="Failed fetching sla info", **result) + module.fail_json(msg="Failed fetching time machine info", **result) result["response"] = resp From 4348d279646350cce5cb4da52e41b207e7fdf8b3 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Wed, 18 Oct 2023 12:19:02 +0530 Subject: [PATCH 4/6] Add attribute in clone modules in ndb for creation or refresh using latestSnapshot --- plugins/module_utils/ndb/database_clones.py | 8 ++++++-- plugins/modules/ntnx_ndb_database_clone_refresh.py | 5 +++-- plugins/modules/ntnx_ndb_database_clones.py | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/module_utils/ndb/database_clones.py b/plugins/module_utils/ndb/database_clones.py index 721bfddd0..8493faa80 100644 --- a/plugins/module_utils/ndb/database_clones.py +++ b/plugins/module_utils/ndb/database_clones.py @@ -200,10 +200,12 @@ def get_clone_refresh_spec(self): payload["snapshotId"] = self.module.params.get("snapshot_uuid") elif self.module.params.get("pitr_timestamp"): payload["userPitrTimestamp"] = self.module.params.get("pitr_timestamp") + elif self.module.params.get("latest_snapshot", False): + payload["latestSnapshot"] = True else: return ( None, - "snapshot_uuid or pitr_timestamp is required for database clone refresh", + "One of snapshot_uuid, pitr_timestamp or latest_snapshot is required for database clone refresh", ) payload["timeZone"] = self.module.params.get("timezone") @@ -237,10 +239,12 @@ def _build_spec_time_machine(self, payload, time_machine): payload["snapshotId"] = time_machine.get("snapshot_uuid") elif time_machine.get("pitr_timestamp"): payload["userPitrTimestamp"] = time_machine.get("pitr_timestamp") + elif time_machine.get("latest_snapshot", False): + payload["latestSnapshot"] = True else: return ( None, - "Required snapshot_uuid or pitr_timestamp for source of db clone", + "Required one of snapshot_uuid, pitr_timestamp or latest_snapshot for source of db clone", ) payload["timeZone"] = time_machine.get("timezone") diff --git a/plugins/modules/ntnx_ndb_database_clone_refresh.py b/plugins/modules/ntnx_ndb_database_clone_refresh.py index 687145e37..7af780220 100644 --- a/plugins/modules/ntnx_ndb_database_clone_refresh.py +++ b/plugins/modules/ntnx_ndb_database_clone_refresh.py @@ -301,6 +301,7 @@ def get_module_spec(): snapshot_uuid=dict(type="str", required=False), timezone=dict(type="str", default="Asia/Calcutta", required=False), pitr_timestamp=dict(type="str", required=False), + latest_snapshot=dict(tyoe="bool", required=False) ) return module_args @@ -340,12 +341,12 @@ def refresh_clone(module, result): def run_module(): mutually_exclusive_list = [ - ("snapshot_uuid", "pitr_timestamp"), + ("snapshot_uuid", "pitr_timestamp", "latest_snapshot"), ] module = NdbBaseModule( argument_spec=get_module_spec(), supports_check_mode=True, - required_if=[("state", "present", ("snapshot_uuid", "pitr_timestamp"), True)], + required_if=[("state", "present", ("snapshot_uuid", "pitr_timestamp", "latest_snapshot"), True)], mutually_exclusive=mutually_exclusive_list, ) remove_param_with_none_value(module.params) diff --git a/plugins/modules/ntnx_ndb_database_clones.py b/plugins/modules/ntnx_ndb_database_clones.py index a6485ee76..cfaa38451 100644 --- a/plugins/modules/ntnx_ndb_database_clones.py +++ b/plugins/modules/ntnx_ndb_database_clones.py @@ -652,6 +652,7 @@ def get_module_spec(): uuid=dict(type="str", required=False), snapshot_uuid=dict(type="str", required=False), pitr_timestamp=dict(type="str", required=False), + latest_snapshot=dict(type="bool", required=False), timezone=dict(type="str", default="Asia/Calcutta", required=False), ) @@ -700,7 +701,7 @@ def get_module_spec(): time_machine=dict( type="dict", options=time_machine, - mutually_exclusive=[("snapshot_uuid", "pitr_timestamp")], + mutually_exclusive=[("snapshot_uuid", "pitr_timestamp", "latest_snapshot")], required=False, ), postgres=dict(type="dict", options=postgres, required=False), From d087e4884d24a0e17facaf148fbb6d0cd5d99f94 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Wed, 25 Oct 2023 15:55:31 +0530 Subject: [PATCH 5/6] Minor typo fix --- plugins/module_utils/ndb/time_machines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/ndb/time_machines.py b/plugins/module_utils/ndb/time_machines.py index a5ed83b73..7f78858c7 100644 --- a/plugins/module_utils/ndb/time_machines.py +++ b/plugins/module_utils/ndb/time_machines.py @@ -39,7 +39,7 @@ def get_time_machine(self, uuid=None, name=None, query=None): elif name: if not query: query = {} - query["vaue_type"] = "name" + query["value_type"] = "name" query["value"] = name resp = self.read(query=query) if isinstance(resp, list): From 2bf64271027ab8bb369076187c41b186c7cb9b44 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Wed, 25 Oct 2023 16:22:28 +0530 Subject: [PATCH 6/6] Minor typo fix --- plugins/modules/ntnx_ndb_database_clone_refresh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ntnx_ndb_database_clone_refresh.py b/plugins/modules/ntnx_ndb_database_clone_refresh.py index 7af780220..8b0934c23 100644 --- a/plugins/modules/ntnx_ndb_database_clone_refresh.py +++ b/plugins/modules/ntnx_ndb_database_clone_refresh.py @@ -301,7 +301,7 @@ def get_module_spec(): snapshot_uuid=dict(type="str", required=False), timezone=dict(type="str", default="Asia/Calcutta", required=False), pitr_timestamp=dict(type="str", required=False), - latest_snapshot=dict(tyoe="bool", required=False) + latest_snapshot=dict(type="bool", required=False) ) return module_args