Skip to content

Commit

Permalink
stable-4.x: Fix disk creation resulting in 'invalid configuration for…
Browse files Browse the repository at this point in the history
… device' error (ansible-collections#2245)

Backport ansible-collections#2009
SUMMARY
Under some circumstances, disk creation fails with an invalid configuration for device error.
Once this error shows up for a VM, it persistently happens whenever trying to add disks, however, I do not know how to make it show up for a VM, sometimes it is just there.
In comparing the API calls done by VCenter (which works) and ansible (which fails with the error above), I noticed that VCenter sets fileOperation to create. Setting this in ansible, as done in this patch, fixes the disk creation in ansible.
The docs describe the fileOperation parameter like this:

Type of operation being performed on the backing of the specified virtual device. If no file operation is specified in the VirtualDeviceSpec, then any backing filenames in the VirtualDevice must refer to files that already exist. The "replace" and "delete" values for this property are only applicable to virtual disk backing files.

So it really must  be set when the backing file does not exist, (which it ofc doesn't when creating a disk).
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
vm_device_helper
  • Loading branch information
mariolenz authored Nov 12, 2024
1 parent d93bff2 commit 67a6933
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- vm_device_helper - Fix 'invalid configuration for device' error caused by missing fileoperation parameter.
(https://github.com/ansible-collections/community.vmware/pull/2009).
1 change: 1 addition & 0 deletions plugins/module_utils/vm_device_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def remove_cdrom(self, cdrom_device):
def create_hard_disk(self, disk_ctl, disk_index=None):
diskspec = vim.vm.device.VirtualDeviceSpec()
diskspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
diskspec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create
diskspec.device = vim.vm.device.VirtualDisk()
diskspec.device.key = -randint(20000, 24999)
diskspec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
Expand Down

0 comments on commit 67a6933

Please sign in to comment.