Skip to content

Commit

Permalink
check mode for delete operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Gevorg-Khachatryaan authored and Gevorg-Khachatryaan committed Oct 18, 2023
1 parent 923e9c7 commit fa7c5f6
Show file tree
Hide file tree
Showing 36 changed files with 216 additions and 3 deletions.
5 changes: 5 additions & 0 deletions plugins/modules/ntnx_acps.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ def delete_acp(module, result):
result["error"] = "Missing parameter acp_uuid in playbook"
module.fail_json(msg="Failed deleting acp", **result)

if module.check_mode:
result["acp_uuid"] = acp_uuid
result["response"] = "Acp with uuid:{0} will be deleted.".format(acp_uuid)
return

acp = ACP(module)
resp = acp.delete(acp_uuid)
result["changed"] = True
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_address_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ def update_address_group(module, result):
def delete_address_group(module, result):
address_group = AddressGroup(module)
uuid = module.params["address_group_uuid"]

if module.check_mode:
result["address_group_uuid"] = uuid
result["response"] = "Address group with uuid:{0} will be deleted.".format(uuid)
return

address_group.delete(uuid=uuid, no_response=True)
result["response"] = {"msg": "Address group deleted successfully"}
result["address_group_uuid"] = uuid
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ def delete_categories(module, result):
category_key_values.append(v["value"])
delete_category_values(module, name, category_key_values)

if module.check_mode:
result["category_name"] = name
result["response"] = "Category with name:{0} will be deleted.".format(name)
return

# delete the category
resp = _category_key.delete(uuid=name, no_response=True)
result["response"] = {
Expand All @@ -286,6 +291,7 @@ def delete_categories(module, result):
)
}

result["category_name"] = name
result["changed"] = True


Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/ntnx_floating_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ def create_floating_ip(module, result):
def delete_floating_ip(module, result):
fip_uuid = module.params["fip_uuid"]

if module.check_mode:
result["fip_uuid"] = fip_uuid
result["response"] = "Floating IP with uuid:{0} will be deleted.".format(fip_uuid)
return

floating_ip = FloatingIP(module)
resp = floating_ip.delete(fip_uuid)
result["changed"] = True
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/ntnx_foundation_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ def deleteCluster(module, result):
cluster_uuid = module.params.get("imaged_cluster_uuid")
cluster = ImagedCluster(module)

if module.check_mode:
result["imaged_cluster_uuid"] = cluster_uuid
result["response"] = "Cluster with uuid:{0} will be deleted.".format(cluster_uuid)
return

resp = cluster.delete(cluster_uuid, no_response=True)
result["response"] = resp
result["imaged_cluster_uuid"] = cluster_uuid
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/ntnx_foundation_image_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ def delete_image(module, result):
image = Image(module, delete_image=True)
fname = module.params["filename"]
itype = module.params["installer_type"]

if module.check_mode:
result["file_name"] = fname
result["response"] = "Image with name:{0} will be deleted.".format(fname)
return

resp = image.delete_image(fname, itype)

result["file_name"] = fname
result["changed"] = True
result["response"] = resp

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_image_placement_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,14 @@ def delete_policy(module, result):
result["error"] = "Missing parameter policy_uuid in task"
module.fail_json(msg="Failed deleting Image placement policy", **result)

if module.check_mode:
result["policy_uuid"] = policy_uuid
result["response"] = "Placement policy with uuid:{0} will be deleted.".format(policy_uuid)
return

policy_obj = ImagePlacementPolicy(module)
resp = policy_obj.delete(policy_uuid)
result["policy_uuid"] = policy_uuid
result["response"] = resp
result["changed"] = True
task_uuid = resp["status"]["execution_context"]["task_uuid"]
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,14 @@ def delete_image(module, result):
result["error"] = "Missing parameter image_uuid"
module.fail_json(msg="Failed deleting Image", **result)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Image with uuid:{0} will be deleted.".format(uuid)
return

image = Image(module)
resp = image.delete(uuid)
result["uuid"] = uuid
result["response"] = resp
result["changed"] = True
task_uuid = resp["status"]["execution_context"]["task_uuid"]
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/ntnx_karbon_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ def delete_cluster(module, result):
result["error"] = "Missing parameter name in playbook"
module.fail_json(msg="Failed deleting cluster", **result)

if module.check_mode:
result["cluster_name"] = cluster_name
result["response"] = "Cluster with name:{0} will be deleted.".format(cluster_name)
return

cluster = Cluster(module)
resp = cluster.delete(cluster_name)
result["changed"] = True
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_karbon_clusters_node_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ def delete_pool(module, result):

delete_nodes_of_pool(module, result)

if module.check_mode:
result["cluster_name"] = cluster_name
result["node_pool_name"] = pool_name
result["response"] = "Pool with name:{0} will be deleted.".format(pool_name)
return

node_pool = NodePool(module, resource_type="/v1-beta.1/k8s/clusters")
resp = node_pool.remove_node_pool(cluster_name, pool_name)

Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/ntnx_karbon_registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def delete_registry(module, result):
result["error"] = "Missing parameter name in playbook"
module.fail_json(msg="Failed deleting registry", **result)

if module.check_mode:
result["name"] = registry_name
result["response"] = "Registry with name:{0} will be deleted.".format(registry_name)
return

registry = Registry(module)
resp = registry.delete(registry_name)
result["changed"] = True
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ def delete_cluster(module, result):
cluster_uuid = module.params["uuid"]

cluster = Cluster(module)

if module.check_mode:
result["cluster_uuid"] = cluster_uuid
result["response"] = "Cluster with uuid:{0} will be deleted.".format(cluster_uuid)
return

resp, err = cluster.delete(cluster_uuid)
if err:
result["error"] = err
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/ntnx_ndb_database_clones.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,8 @@ def delete_db_clone(module, result):
)

if module.check_mode:
result["response"] = spec
result["uuid"] = uuid
result["response"] = "Db clone with uuid:{0} will be deleted.".format(uuid)
return

resp = _clones.delete(uuid, data=spec)
Expand All @@ -912,6 +913,7 @@ def delete_db_clone(module, result):
operations = Operation(module)
resp = operations.wait_for_completion(ops_uuid, delay=5)

result["uuid"] = uuid
result["response"] = resp
result["changed"] = True

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_database_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,18 @@ def delete_snapshot(module, result):
snapshots = Snapshot(module)
resp = snapshots.delete(uuid=snapshot_uuid)

if module.check_mode:
result["snapshot_uuid"] = snapshot_uuid
result["response"] = "Snapshot with uuid:{0} will be deleted.".format(snapshot_uuid)
return

if module.params.get("wait"):
ops_uuid = resp["operationId"]
operations = Operation(module)
time.sleep(3) # to get ops ID functional
resp = operations.wait_for_completion(ops_uuid, delay=2)

result["snapshot_uuid"] = snapshot_uuid
result["response"] = resp
result["changed"] = True

Expand Down
9 changes: 8 additions & 1 deletion plugins/modules/ntnx_ndb_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,12 @@ def delete_db_servers(module, result, database_info):
spec = db_servers.get_default_delete_spec(
delete=module.params.get("delete_db_server_vms", False)
)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Db server with uuid:{0} will be deleted.".format(uuid)
return

resp = db_servers.delete(uuid=uuid, data=spec)

ops_uuid = resp["operationId"]
Expand All @@ -1524,7 +1530,8 @@ def delete_instance(module, result):
spec = _databases.get_delete_spec()

if module.check_mode:
result["response"] = spec
result["uuid"] = uuid
result["response"] = "Instance with uuid:{0} will be deleted.".format(uuid)
return

resp = _databases.delete(uuid, data=spec)
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/ntnx_ndb_db_server_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ def delete_db_server(module, result):
spec["remove"] = not spec["delete"]

if module.check_mode:
result["response"] = spec
result["uuid"] = uuid
result["response"] = "Db server with uuid:{0} will be deleted.".format(uuid)
return

resp = db_servers.delete(data=spec, uuid=uuid)
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/ntnx_ndb_linked_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,19 @@ def remove_database(module, result):
err_msg = "database_uuid and instance_uuid are required fields for deleting database from database instance"
module.fail_json(msg=err_msg, **result)

if module.check_mode:
result["db_instance_uuid"] = instance_uuid
result["db_uuid"] = database_uuid
result["response"] = "Database with uuid:{0} will be removed.".format(database_uuid)
return

_databases = DatabaseInstance(module)
resp = _databases.remove_linked_database(
linked_database_uuid=database_uuid, database_instance_uuid=instance_uuid
)
result["response"] = resp
result["db_instance_uuid"] = instance_uuid
result["db_uuid"] = database_uuid

if module.params.get("wait"):
ops_uuid = resp["operationId"]
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_maintenance_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ def delete_window(module, result):
if not uuid:
module.fail_json(msg="uuid is required field for delete", **result)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Window with uuid:{0} will be deleted.".format(uuid)
return

resp = _maintenance_window.delete(uuid=uuid, data={})
result["uuid"] = uuid
result["response"] = resp
result["changed"] = True

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,14 @@ def delete_profile(module, result):
if not uuid:
return module.fail_json(msg="'profile_uuid' is a required for deleting profile")

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Profile with uuid:{0} will be deleted.".format(uuid)
return

resp = profiles.delete(uuid)

result["uuid"] = uuid
result["response"] = resp
result["changed"] = True

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_slas.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def delete_sla(module, result):
if not uuid:
module.fail_json(msg="uuid is required field for delete", **result)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Sla with uuid:{0} will be deleted.".format(uuid)
return

sla, err = _sla.get_sla(uuid=uuid)
if err:
module.fail_json(msg="Failed fetching sla info", **result)
Expand All @@ -221,6 +226,7 @@ def delete_sla(module, result):
msg="sla delete failed",
response=resp,
)
result["uuid"] = uuid
result["changed"] = True


Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_stretched_vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,14 @@ def delete_stretched_vlan(module, result):
msg="stretched_vlan_uuid is required field for delete", **result
)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Stretched vlan with uuid:{0} will be deleted.".format(uuid)
return

resp = stretched_vlan.delete_stretched_vlan(uuid)

result["uuid"] = uuid
result["response"] = resp
result["changed"] = True

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,13 @@ def delete_tags(module, result):
if not uuid:
module.fail_json(msg="'uuid' is required field for delete", **result)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Tag with uuid:{0} will be deleted.".format(uuid)
return

resp = tags.delete(uuid=uuid)
result["uuid"] = uuid
result["response"] = resp
result["changed"] = True

Expand Down
9 changes: 9 additions & 0 deletions plugins/modules/ntnx_ndb_time_machine_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,17 @@ def delete_data_access_instance(module, result):
result["error"] = err
err_msg = "'cluster' is required field for removing cluster from time machine"
module.fail_json(msg=err_msg, **result)

if module.check_mode:
result["cluster_uuid"] = cluster_uuid
result["time_machine_uuid"] = tm_uuid
result["response"] = "Cluster with uuid:{0} will be deleted from Time Machine.".format(cluster_uuid)
return

resp = tm.delete_data_access_instance(tm_uuid, cluster_uuid)

result["cluster_uuid"] = cluster_uuid
result["time_machine_uuid"] = tm_uuid
result["response"] = resp
result["changed"] = True

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,14 @@ def delete_vlan(module, result):
if not uuid:
module.fail_json(msg="vlan_uuid is required field for delete", **result)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Vlan with uuid:{0} will be deleted.".format(uuid)
return

resp = vlan.delete(uuid)

result["uuid"] = uuid
result["response"] = resp
result["changed"] = True

Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_pbrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ def delete_pbr(module, result):
pbr_uuid = module.params["pbr_uuid"]

pbr = Pbr(module)

if module.check_mode:
result["pbr_uuid"] = pbr_uuid
result["response"] = "Pbr with uuid:{0} will be deleted.".format(pbr_uuid)
return

resp = pbr.delete(pbr_uuid)
result["changed"] = True
result["response"] = resp
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/ntnx_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,14 @@ def delete_project(module, result):
module.fail_json(msg="Failed deleting Project", **result)

projects = Project(module)

if module.check_mode:
result["uuid"] = uuid
result["response"] = "Project with uuid:{0} will be deleted.".format(uuid)
return

resp = projects.delete(uuid)
result["uuid"] = uuid
result["response"] = resp
result["changed"] = True
task_uuid = resp["status"]["execution_context"]["task_uuid"]
Expand Down
Loading

0 comments on commit fa7c5f6

Please sign in to comment.