Skip to content

Commit

Permalink
Merge branch 'release/1.9.3' into imprv/spelling-Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
george-ghawali authored Oct 2, 2024
2 parents d3c306d + 854442f commit c26da2b
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 56 deletions.
106 changes: 53 additions & 53 deletions examples/vm_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
nutanix_password: <pass>
validate_certs: false
tasks:
- name: Setting Variables
set_fact:
- name: Setting Variables
set_fact:
cluster_name: ""
script_path: ""
subnet_name: ""
Expand All @@ -26,56 +26,56 @@
remove_disk_uuid: ""
subnet_uuid: ""

- name: Update VM
ntnx_vms:
vm_uuid: "{{ vm_uuid }}"
name: updated
desc: updated
categories:
AppType:
- Apache_Spark
disks:
- type: "DISK"
clone_image:
name: "{{ image_name }}"
bus: "SCSI"
size_gb: 20
- type: DISK
size_gb: 3
bus: PCI
- type: DISK
size_gb: 1
bus: SCSI
storage_container:
uuid: "{{ storage_container_uuid }}"
networks:
- is_connected: true
subnet:
uuid: "{{ network_dhcp_uuid }}"
- is_connected: false
subnet:
uuid: "{{ static.uuid }}"
private_ip: "{{ network_static_ip }}"
register: result
- name: Update VM
ntnx_vms:
vm_uuid: "{{ vm_uuid }}"
name: updated
desc: updated
categories:
AppType:
- Apache_Spark
disks:
- type: "DISK"
clone_image:
name: "{{ image_name }}"
bus: "SCSI"
size_gb: 20
- type: DISK
size_gb: 3
bus: PCI
- type: DISK
size_gb: 1
bus: SCSI
storage_container:
uuid: "{{ storage_container_uuid }}"
networks:
- is_connected: true
subnet:
uuid: "{{ network_dhcp_uuid }}"
- is_connected: false
subnet:
uuid: "{{ static.uuid }}"
private_ip: "{{ network_static_ip }}"
register: result

- name: Update VM by deleting and editing disks and subnets
ntnx_vms:
vm_uuid: "{{ vm_uuid }}"
name: update disks
desc: update disks
disks:
- type: "DISK"
uuid: "{{ disk_uuid }}"
size_gb: 30
- state: absent
uuid: "{{ remove_disk_uuid }}"
networks:
- state: absent
uuid: "{{ subnet_uuid }}"
register: result
- name: Update VM by deleting and editing disks and subnets
ntnx_vms:
vm_uuid: "{{ vm_uuid }}"
name: update disks
desc: update disks
disks:
- type: "DISK"
uuid: "{{ disk_uuid }}"
size_gb: 30
- state: absent
uuid: "{{ remove_disk_uuid }}"
networks:
- state: absent
uuid: "{{ subnet_uuid }}"
register: result

- name: Update VM by deleting it
ntnx_vms:
state: absent
vm_uuid: "{{ vm_uuid }}"
register: result
- name: Update VM by deleting it
ntnx_vms:
state: absent
vm_uuid: "{{ vm_uuid }}"
register: result
41 changes: 41 additions & 0 deletions examples/vm_update_cdrom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
########################### UPDATE_VM_CDROM ################################
---
- name: Create a VM with empty CD ROM and Update that disk with image
hosts: localhost
gather_facts: false
module_defaults:
group/nutanix.ncp.ntnx:
nutanix_host: <pc_ip>
nutanix_username: <user>
nutanix_password: <pass>
validate_certs: false
tasks:
- name: Setting Variables
ansible.builtin.set_fact:
vm_uuid: ""
disk_uuid: ""

- name: Create VM with empty CD ROM
nutanix.ncp.ntnx_vms:
name: "VM with empty CD ROM"
cluster:
name: "{{ cluster.name }}"
categories:
Environment:
- Production
disks:
- type: "CDROM"
bus: "IDE"
empty_cdrom: true
register: result

- name: Update VM by cloning image into CD ROM
nutanix.ncp.ntnx_vms:
vm_uuid: "{{ result.vm_uuid }}"
name: "VM with CD ROM updated"
disks:
- type: "CDROM"
uuid: "{{ result.response.spec.resources.disk_list[0].uuid }}"
clone_image:
name: "{{ iso_image_name }}"
register: result
7 changes: 6 additions & 1 deletion plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,13 @@ def _fetch_url(
return {"status_code": status_code}

if resp_json is None:
if info.get("msg"):
resp_json_msg = "{}".format(info.get("msg"))
else:
resp_json_msg = "Failed to convert API response to json"

self.module.fail_json(
msg="Failed to convert API response to json",
msg=resp_json_msg,
status_code=status_code,
error=body,
response=resp_json,
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/prism/user_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _build_spec_project(self, payload, config):
return payload, None

def _build_spec_user_distinguished_name(self, payload, config):
if "ou=" in config:
if config[0:3] == "ou=":
payload["spec"]["resources"]["directory_service_ou"] = {
"distinguished_name": config
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ def _generate_disk_spec(
if error:
return None, error

disk["data_source_reference"]["uuid"] = uuid
disk.setdefault("data_source_reference", {})["uuid"] = uuid
disk.setdefault("data_source_reference", {})["kind"] = "image"

if (
not disk.get("storage_config", {})
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/ntnx_protection_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ def check_rule_idempotency(rule_spec, update_spec):
):
return False

#check if start_time has been updated
if rule_spec["spec"]["resources"].get("start_time") != update_spec["spec"]["resources"].get("start_time"):
return False

return True


Expand Down
47 changes: 47 additions & 0 deletions tests/integration/targets/nutanix_vms/tasks/vm_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,52 @@
fail_msg: " Unable to update vm by increasing the size of the IDE disks with force_power_off "
success_msg: " VM updated successfully by increasing the size of the IDE disks with force_power_off "

- name: Get UUID of CDROM
ansible.builtin.set_fact:
cdrom_uuid: "{{ result.response.spec.resources.disk_list | json_query(query) }}"
vars:
query: "[?device_properties.device_type == 'CDROM'].uuid"
ignore_errors: true

- name: Get number of disks attached to VM
ansible.builtin.set_fact:
disk_count: "{{ result.response.spec.resources.disk_list | length }}"
ignore_errors: true

- name: Update VM by cloning image into CD ROM
ntnx_vms:
vm_uuid: "{{ result.vm_uuid }}"
disks:
- type: "CDROM"
uuid: "{{ cdrom_uuid[0] }}"
clone_image:
name: "{{ centos }}"
register: result
ignore_errors: true

- name: Get index of CDROM
ansible.builtin.set_fact:
item_index: "{{ index }}"
loop: "{{ result.response.spec.resources.disk_list }}"
loop_control:
index_var: index
when: item.uuid == cdrom_uuid[0]
no_log: true

- name: Update Status
ansible.builtin.assert:
that:
- result.response is defined
- result.vm_uuid
- result.task_uuid
- result.response.spec.resources.disk_list[item_index].device_properties.device_type == "CDROM"
- result.response.spec.resources.disk_list[item_index].data_source_reference.kind == "image"
- result.response.spec.resources.disk_list[item_index].data_source_reference.uuid is defined
- result.response.spec.resources.disk_list | length == {{ disk_count }}
- result.response.status.state == "COMPLETE"
fail_msg: " Unable to update vm by cloning image into CD ROM "
success_msg: " VM updated successfully by cloning image into CD ROM"

- name: Update VM by removing IDE disks with force_power_off
ntnx_vms:
vm_uuid: "{{ result.vm_uuid }}"
Expand Down Expand Up @@ -545,6 +591,7 @@
- result.task_uuid
fail_msg: " Unable to update vm by deleting a subnet "
success_msg: " VM updated successfully by deleting a subnet "

# ####################################################################

- name: Update VM by deleting it
Expand Down

0 comments on commit c26da2b

Please sign in to comment.