Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
This commit updates the existing add_disk method which was used
Browse files Browse the repository at this point in the history
to add a new hard disk to a VM. It adds a new attribute `name`
that represents a disk name. As per the updated method, it will
check the given disk name is already present in the vm before adding
a new one.

Work towards: #140

Signed-off-by: mukultaneja <[email protected]>
  • Loading branch information
mukultaneja committed Nov 17, 2020
1 parent bb6f236 commit ab2779b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 23 additions & 7 deletions modules/vcd_vapp_vm_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
disks:
- size: 3
controller: lsilogic
name: Hard disk 1
state = "present"
'''

Expand Down Expand Up @@ -181,17 +182,32 @@ def add_disk(self):
response = dict()
response['msg'] = list()
response['changed'] = False
available_disks = self.read_disks().get("disks").keys()
warnings = list()

for disk in disks:
disk_size = int(disk.get("size"))
disk_controller = disk.get("controller")
add_disk_task = self.vapp.add_disk_to_vm(
vm_name, disk_size, disk_controller)
self.execute_task(add_disk_task)
msg = "A disk with size {0} and controller {1} has been added to VM {2}"
msg = msg.format(disk_size, disk_controller, vm_name)
response['msg'].append(msg)
response['changed'] = True
disk_name = disk.get("name")
'''
here the condition covers both the situtation
1. if someone has given the disk name then it will check for the disk
availability first before adding it.
2. if someone has ignored giving the disk name then it will add a new disk
any way.
'''
if disk_name not in available_disks:
add_disk_task = self.vapp.add_disk_to_vm(vm_name, disk_size, disk_controller)
self.execute_task(add_disk_task)
msg = "A disk with size {0} and controller {1} has been added to VM {2}"
msg = msg.format(disk_size, disk_controller, vm_name)
response['changed'] = True
response['msg'].append(msg)
else:
warnings.append(disk_name)
if warnings:
warnings = ','.join(warnings)
response["warnings"] = "Hard disk(s) with name {0} are already present".format(warnings)

return response

Expand Down
2 changes: 2 additions & 0 deletions roles/vappvmdisk/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
disks:
- size: 1
controller: lsilogic
name: "Hard disk 1"
- size: 1
controller: VirtualSCSI
name: "Hard disk 2"
state: present
register: myResult

Expand Down

0 comments on commit ab2779b

Please sign in to comment.