From 0054cc95131dbc172496b3df7689fd1490e4af90 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Wed, 25 Oct 2023 16:23:21 +0530 Subject: [PATCH] Fix #391 and #418 (#419) * Create cluster url when it is required * Minor fix * Change api url for fetching time machine using name to get complete info same as uuid * Add attribute in clone modules in ndb for creation or refresh using latestSnapshot * Minor typo fix * Minor typo fix --- plugins/module_utils/ndb/database_clones.py | 8 ++++++-- plugins/module_utils/ndb/time_machines.py | 7 +++++-- plugins/modules/ntnx_ndb_database_clone_refresh.py | 5 +++-- plugins/modules/ntnx_ndb_database_clones.py | 3 ++- plugins/modules/ntnx_ndb_time_machines_info.py | 2 +- 5 files changed, 17 insertions(+), 8 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/module_utils/ndb/time_machines.py b/plugins/module_utils/ndb/time_machines.py index dc54b0dc0..7f78858c7 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["value_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_database_clone_refresh.py b/plugins/modules/ntnx_ndb_database_clone_refresh.py index 687145e37..8b0934c23 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(type="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), 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