Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check mode for delete operations #422

Open
wants to merge 7 commits into
base: release/1.9.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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["msg"] = "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["msg"] = "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["msg"] = "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["msg"] = "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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhati-pradeep no test

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["msg"] = "Cluster with uuid:{0} will be deleted.".format(cluster_uuid)
return

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhati-pradeep could not find any test for deletion

resp = cluster.delete(cluster_uuid, no_response=True)
result["response"] = resp
result["imaged_cluster_uuid"] = cluster_uuid
Expand Down
9 changes: 8 additions & 1 deletion plugins/modules/ntnx_foundation_image_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ def get_module_spec():

def upload_image(module, result):
image = Image(module)
fname = module.params["filename"]
result["image_name"] = fname
if module.check_mode:
result["response"] = module.params
return
fname = module.params["filename"]
itype = module.params["installer_type"]
source = module.params["source"]
timeout = module.params["timeout"]
Expand All @@ -96,6 +97,12 @@ def delete_image(module, result):
image = Image(module, delete_image=True)
fname = module.params["filename"]
itype = module.params["installer_type"]
result["image_name"] = fname

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

resp = image.delete_image(fname, itype)

result["changed"] = True
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["msg"] = "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["msg"] = "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["msg"] = "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
alaa-bish marked this conversation as resolved.
Show resolved Hide resolved
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["msg"] = "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["msg"] = "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["msg"] = "Cluster with uuid:{0} will be deleted.".format(cluster_uuid)
return

resp, err = cluster.delete(cluster_uuid)
if err:
result["error"] = err
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/ntnx_ndb_database_clones.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,8 @@ def delete_db_clone(module, result):
_clones = DatabaseClone(module)

uuid = module.params.get("uuid")
result["uuid"] = uuid

if not uuid:
module.fail_json(msg="uuid is required field for delete", **result)

Expand All @@ -902,6 +904,7 @@ def delete_db_clone(module, result):

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

resp = _clones.delete(uuid, data=spec)
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ntnx_ndb_database_snapshots.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhati-pradeep there is no delete tests

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["msg"] = "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
8 changes: 8 additions & 0 deletions plugins/modules/ntnx_ndb_databases.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test missing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have check_sum for delete_db_servers, as we have it for delete_instance

result["uuid"] = uuid
result["msg"] = "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 @@ -1525,6 +1531,8 @@ def delete_instance(module, result):

if module.check_mode:
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved Hide resolved
result["response"] = spec
result["uuid"] = uuid
result["msg"] = "Instance with uuid:{0} will be deleted.".format(uuid)
return

resp = _databases.delete(uuid, data=spec)
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/ntnx_ndb_db_server_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ def delete_db_server(module, result):

if module.check_mode:
result["response"] = spec
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved Hide resolved
result["uuid"] = uuid
result["msg"] = "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["msg"] = "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["msg"] = "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["msg"] = "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["msg"] = "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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhati-pradeep there is no any test for delete stretched vlan

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["msg"] = "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["msg"] = "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["msg"] = "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["msg"] = "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["msg"] = "Pbr with uuid:{0} will be deleted.".format(pbr_uuid)
return

resp = pbr.delete(pbr_uuid)
result["changed"] = True
result["response"] = resp
Expand Down
Loading
Loading