Skip to content

Commit

Permalink
Adding fix for updating empty CD ROM with clone image attribute (#505)
Browse files Browse the repository at this point in the history
* Adding fix for updating empty CD ROM with clone image attribute

* Adding example and test for updating VM with cloning image into CD ROM

* refactoring examples

* Creating seperate example file for updating empty CD ROM
Moving update empty CD ROM test to CRUD operation for IDE disks section

* minor lint fix

* resolving comments

* Adding disk count assertion to assert that number of disks does not change when updating empty CD ROM
  • Loading branch information
george-ghawali authored Oct 1, 2024
1 parent 3b13ae2 commit 854442f
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 110 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 diks
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
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
Loading

0 comments on commit 854442f

Please sign in to comment.