VMware {code} Community
ssand
Contributor
Contributor
Jump to solution

ReconfigureVM_task parameter question

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);

Reply
0 Kudos
1 Solution

Accepted Solutions
Steve_Jin
Expert
Expert
Jump to solution

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

Creator of VI Java API:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org

View solution in original post

Reply
0 Kudos
4 Replies
Steve_Jin
Expert
Expert
Jump to solution

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

Creator of VI Java API:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

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[] );

Steve_Jin
Expert
Expert
Jump to solution

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

Creator of VI Java API:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
ssand
Contributor
Contributor
Jump to solution

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!

Reply
0 Kudos