mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-29 19:50:25 -07:00
VMware: Allow user to select disk_mode (#38951)
* VMware: Allow user to select disk_mode This fix allows user to select disk modes for given disk configuration in the given VM. Fixes: #37749 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * Review comments Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
2ecf1d35d3
commit
c021fd8e84
3 changed files with 140 additions and 2 deletions
|
@ -172,6 +172,11 @@ options:
|
|||
- ' Default: C(None) thick disk, no eagerzero.'
|
||||
- ' - C(datastore) (string): Datastore to use for the disk. If C(autoselect_datastore) is enabled, filter datastore selection.'
|
||||
- ' - C(autoselect_datastore) (bool): select the less used datastore. Specify only if C(datastore) is not specified.'
|
||||
- ' - C(disk_mode) (string): Type of disk mode. Added in version 2.6'
|
||||
- ' - Available options are :'
|
||||
- ' - C(persistent): Changes are immediately and permanently written to the virtual disk. This is default.'
|
||||
- ' - C(independent_persistent): Same as persistent, but not affected by snapshots.'
|
||||
- ' - C(independent_nonpersistent): Changes to virtual disk are made to a redo log and discarded at power off, but not affected by snapshots.'
|
||||
cdrom:
|
||||
description:
|
||||
- A CD-ROM configuration for the virtual machine.
|
||||
|
@ -588,7 +593,6 @@ class PyVmomiDeviceHelper(object):
|
|||
diskspec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create
|
||||
diskspec.device = vim.vm.device.VirtualDisk()
|
||||
diskspec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
|
||||
diskspec.device.backing.diskMode = 'persistent'
|
||||
diskspec.device.controllerKey = scsi_ctl.device.key
|
||||
|
||||
if self.next_disk_unit_number == 7:
|
||||
|
@ -1571,6 +1575,19 @@ class PyVmomiHelper(PyVmomi):
|
|||
diskspec = self.device_helper.create_scsi_disk(scsi_ctl, disk_index)
|
||||
disk_modified = True
|
||||
|
||||
if 'disk_mode' in expected_disk_spec:
|
||||
disk_mode = expected_disk_spec.get('disk_mode', 'persistent').lower()
|
||||
valid_disk_mode = ['persistent', 'independent_persistent', 'independent_nonpersistent']
|
||||
if disk_mode not in valid_disk_mode:
|
||||
self.module.fail_json(msg="disk_mode specified is not valid."
|
||||
" Should be one of ['%s']" % "', '".join(valid_disk_mode))
|
||||
|
||||
if (vm_obj and diskspec.device.backing.diskMode != disk_mode) or (vm_obj is None):
|
||||
diskspec.device.backing.diskMode = disk_mode
|
||||
disk_modified = True
|
||||
else:
|
||||
diskspec.device.backing.diskMode = "persistent"
|
||||
|
||||
# is it thin?
|
||||
if 'type' in expected_disk_spec:
|
||||
disk_type = expected_disk_spec.get('type', '').lower()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue