vmware / pyvmomi-community-samples

A place for community contributed samples for the pyVmomi library.
Apache License 2.0
1.01k stars 922 forks source link

Attach multi writer SCSI disk #711

Closed Christop1964 closed 1 year ago

Christop1964 commented 1 year ago

Describe the bug

I'm not sure if I 'm correct here ! I'm fighting with attaching shared disks (multi-writer disks) to multiple VM's using pyVmomi. May someone have an idea how this works or have an example for me. So far I have added a second iscsi controller to the existing VM that has "bus sharing = virtual" The disk that should be added to the second scsi controller will be created but at the end it failed with

msg = "Incompatible device backing specified for device '0'.",

Does anyone has an idea how I can add multi-writer disks ?

Here some code about the disk attachment :

    disk_spec = vim.vm.device.VirtualDeviceSpec()
    disk_spec.fileOperation = "create"
    disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add

    disk_spec.device = vim.vm.device.VirtualDisk()
    disk_spec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
    disk_spec.device.backing.diskMode = "persistent"
    disk_spec.device.backing.thinProvisioned = False
    disk_spec.device.backing.sharing = "sharingMultiWriter"
    disk_spec.device.capacityInKB = disk_capacity
    disk_spec.device.controllerKey = controller.key
    disk_spec.device.unitNumber = unit_number

    disk_device = []
    disk_device.append(disk_spec)

    vm_spec = vim.vm.ConfigSpec()
    vm_spec.deviceChange = disk_device
    task = vm_obj.ReconfigVM_Task (spec=vm_spec )
    WaitForTask(task, si)

Reproduction steps

  1. Add a second scsi controler to the vm with bus sharing "virtual"
  2. Attach a new disk to the new scsi controller. The disk should have backing.sharing = "sharingMultiWriter"

Expected behavior

Here some code about ther disk attachment :


    disk_spec = vim.vm.device.VirtualDeviceSpec()
    disk_spec.fileOperation = "create"
    disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add

    disk_spec.device = vim.vm.device.VirtualDisk()
    disk_spec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
    disk_spec.device.backing.diskMode = "persistent"
    disk_spec.device.backing.thinProvisioned = False
    disk_spec.device.backing.sharing = "sharingMultiWriter"
    disk_spec.device.capacityInKB = disk_capacity
    disk_spec.device.controllerKey = controller.key
    disk_spec.device.unitNumber = unit_number

    disk_device = []
    disk_device.append(disk_spec)

    vm_spec = vim.vm.ConfigSpec()
    vm_spec.deviceChange = disk_device
    task = vm_obj.ReconfigVM_Task (spec=vm_spec )
    WaitForTask(task, si)

### Additional context

pyVmomi.VmomiSupport.InvalidDeviceBacking: (vim.fault.InvalidDeviceBacking) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = "Incompatible device backing specified for device '0'.",
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) [],
   property = 'backing.sharing',
   deviceIndex = 0
}