mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
VMware: Add option to modify disk type while cloning template (#47859)
* Add parameters to module vmware_guest for conversion of disk to thin or thick when vm is cloned or deployed with template * unit test for convert clone vm Co-Authored-By: chris93111 <christopheferreira@ymail.com>
This commit is contained in:
parent
880390ca0a
commit
7c8b5a407d
5 changed files with 124 additions and 0 deletions
|
@ -336,6 +336,11 @@ options:
|
|||
- For example, when user has different datastore or datastore cluster for templates and virtual machines.
|
||||
- Please see example for more usage.
|
||||
version_added: '2.7'
|
||||
convert:
|
||||
description:
|
||||
- Specify convert disk type while cloning template or virtual machine.
|
||||
choices: [ thin, thick, eagerzeroedthick ]
|
||||
version_added: '2.8'
|
||||
extends_documentation_fragment: vmware.documentation
|
||||
'''
|
||||
|
||||
|
@ -2080,6 +2085,22 @@ class PyVmomiHelper(PyVmomi):
|
|||
relospec.host = self.select_host()
|
||||
relospec.datastore = datastore
|
||||
|
||||
# Convert disk present in template if is set
|
||||
if self.params['convert']:
|
||||
for device in vm_obj.config.hardware.device:
|
||||
if hasattr(device.backing, 'fileName'):
|
||||
disk_locator = vim.vm.RelocateSpec.DiskLocator()
|
||||
disk_locator.diskBackingInfo = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
|
||||
if self.params['convert'] in ['thin']:
|
||||
disk_locator.diskBackingInfo.thinProvisioned = True
|
||||
if self.params['convert'] in ['eagerzeroedthick']:
|
||||
disk_locator.diskBackingInfo.eagerlyScrub = True
|
||||
if self.params['convert'] in ['thick']:
|
||||
disk_locator.diskBackingInfo.diskMode = "persistent"
|
||||
disk_locator.diskId = device.key
|
||||
disk_locator.datastore = datastore
|
||||
relospec.disk.append(disk_locator)
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.RelocateSpec.html
|
||||
# > pool: For a clone operation from a template to a virtual machine, this argument is required.
|
||||
relospec.pool = resource_pool
|
||||
|
@ -2352,6 +2373,7 @@ def main():
|
|||
customization_spec=dict(type='str', default=None),
|
||||
vapp_properties=dict(type='list', default=[]),
|
||||
datastore=dict(type='str'),
|
||||
convert=dict(type='str', choices=['thin', 'thick', 'eagerzeroedthick']),
|
||||
)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue