VMware {code} Community
avasilsg
Contributor
Contributor

Incompatible device backing specified for device '0' + one other question

Hello All,

at the moment I am trying to add vmdk disks to my virtual machine and receive sometimes that error. Here is the sample code and I do not think that error should occur:

Header 1
VirtualDeviceConfigSpec[] vdiskSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();
vdiskSpecArray[0] = diskSpec;
diskSpec.operation = VirtualDeviceConfigSpecOperation.add;
String fileName = "[datastore2] RDM/60GBDisk.vmdk";
VirtualMachineConfigInfo vmConfigInfo = (VirtualMachineConfigInfo) vm.getConfig();
VirtualDevice[] test = vmConfigInfo.getHardware().getDevice();
Integer ckey = null;
for (int k = 0; k < test.length; k++) {
if (test[k].getDeviceInfo().getLabel().equalsIgnoreCase("SCSI Controller 0")) {
ckey = test[k].getKey();
  }
}

VirtualDisk disk = new VirtualDisk();
disk.setKey(-100);
VirtualDiskRawDiskMappingVer1BackingInfo rawBacking = new VirtualDiskRawDiskMappingVer1BackingInfo();
disk.backing = rawBacking;
rawBacking.fileName = fileName;
rawBacking.compatibilityMode = "";
rawBacking.diskMode = "independent_persistent";

VirtualDeviceConnectInfo conn= new VirtualDeviceConnectInfo();
disk.connectable = conn;
conn.startConnected = true;
conn.allowGuestControl = false;
conn.connected = true;

disk.controllerKey = ckey;
disk.unitNumber = test.length + 1;
disk.capacityInKB = 60408536;
diskSpec.setDevice(disk);

return vdiskSpecArray;

The second question that I have is how to get with VMWare Management API the size of the vmdk if I already now where it is located.

Reply
0 Kudos
0 Replies