pyvmomi
pyvmomi copied to clipboard
Specified datastore when adding a new disk not take effect
Purpose: Add a new disk in the specified datastore, not in the same path of the VM files.
Sample code:
...
disk_spec = vim.vm.device.VirtualDeviceSpec()
disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
disk_spec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create
disk_spec.device = vim.vm.device.VirtualDisk()
disk_spec.device.capacityInKB = disk_size
disk_spec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
**disk_spec.device.backing.datastore = disk_datastore**
disk_spec.device.controllerKey = scsi_ctl_key
disk_spec.device.unitNumber = disk_unit_number
config_spec.deviceChange.append(disk_spec)
...
If use above code only set disk_spec.device.backing.datastore = disk_datastore, the new added disk will be in the same folder and datastore with the VM files. But if adding this line disk_spec.device.backing.fileName = '[disk_datastore] test_file/test_file.vmdk', the new added disk will be in the specified datastore. Is setting this "fileName" the only way to do this? We do not want to set the file name explicitly since it will cause file duplication issue, only want to specify the datastore name.
Thanks.