Using C# I am trying to remove a virtual disk from a VM and I am getting the error "A specified parameter was not correct."
Any ideas as to missing or bad parameters?
Which fields in configSpec need to be set to remove a virtual disk?
I am retrieving delUnitNumber, controllerKey, and deviceKey from the ESX server so they should be correct.
VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();
VirtualDisk disk = new VirtualDisk();
diskSpec.fileOperationSpecified = false;
diskSpec.operation = VirtualDeviceConfigSpecOperation.remove;
diskSpec.operationSpecified = true;
disk.unitNumber = delUnitNumber;
disk.unitNumberSpecified = true;
disk.controllerKey = controllerKey;
disk.controllerKeySpecified = true;
disk.key = deviceKey;
diskSpec.device = disk;
deviceConfigSpec[[0]] = diskSpec;
configSpec.deviceChange = deviceConfigSpec;
ManagedObjectReference taskmor = vimsvc.ReconfigVM_Task(vmRef, configSpec);
According to the API ref, the capacityInKB is required. In theory, you shouldn't need to provide that. But the API ref (and WSDL) says yes.
Since you already retrieve the information about the VirtualDisk, I would suggest you grab the whole VirtualDisk object from the config.hardware.device property and assign it directly to your diskSpec.
Good luck!
Steve JIN, VMware Engineering
According to the API ref, the capacityInKB is required. In theory, you shouldn't need to provide that. But the API ref (and WSDL) says yes.
Since you already retrieve the information about the VirtualDisk, I would suggest you grab the whole VirtualDisk object from the config.hardware.device property and assign it directly to your diskSpec.
Good luck!
Steve JIN, VMware Engineering
To get a virtual machine config info dataobject
VirtualMachineConfigInfo vmConfigInfo
= (VirtualMachineConfigInfo)cb.getServiceUtil().getDynamicProperty(
_virtualMachine,"config");
Next you should drill down or locate the disk that you want to remove:
VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();
for(int k=0;k<test.length;k++){
if(test[k].getDeviceInfo().getLabel().equalsIgnoreCase(
cb.get_option("diskName"))){
disk = (VirtualDisk)test[k];
}
}
Now for removing the above found virtual disk, following need to set for the VirtualDeviceConfigSpec:
diskSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy);
diskSpec.setDevice(disk);
Next, you should set the vm config spec as follows
VirtualMachineConfigSpec cspec = new VirtualMachineConfigSpec();
cspec.setDeviceChange( new VirtualDeviceConfigSpec[] );
Be careful with the file operation as follows. If you just want to remove the virtual disk, but not the vmdk file, pls skip the following.
diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy);
Steve JIN, VMware Engineering
Steve and dk,
Thanks for the info. I have it working now.
Good tip on the destroy. I want to just unlink the disk from the vm, not destroy it.
Thanks again!