Ever since upgrading to vSphere 4, my code I've been using for months to resize disks doesn't work. Here's the code:
VirtualMachineConfigInfo vmConfigInfo = (VirtualMachineConfigInfo)PropertyFunctions.PropertyFunctions.getObjectProperty(vmRef, "config",service);
VirtualDevice newdisk = vmConfigInfo.hardware.device;
VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
vdcsArray = new VirtualDeviceConfigSpec;
vdcsArray = new VirtualDeviceConfigSpec();
VirtualDisk vdisk = new VirtualDisk();
vdisk = (VirtualDisk)newdisk;
vdisk.capacityInKB = newSizeGB * 1048576;
vdcsArray.device = (VirtualDevice)vdisk;
configSpec.deviceChange = vdcsArray;
I've verified a number of times that the array item 12 is the right one for the existing virtual disk.
The task succeeds, but nothing changes.
Thanks for any ideas.
The disk size is playing an important role when changes in the disk needs to done. I feel that, the issue which you are facing might be possible due to the size of the new disk compared to the existing size.If you check the VI Client for this functionality and specify the new expected disk size less than the existing disk size, then the task executes successfully, without any change in the disk size.
So, I think the same might be happening at your end and the expected size is less then the existing size. Please modify the code with the variable newSizeGB and make sure that the condition,expected size is greater then the existing size,is being met.
I hope this resolves your issue.
Good troubleshooting idea and I added this to my code, but unfortunately it didn't fix it.
I was able to finally fix it though. It turns out the ode probably should never have worked. the VirtualDeviceConfigSpec (in my code's case, vdcsArray) has a parameter called operation. This needs to be set and the property operationSpecified needs to be set to true. Maybe in VI2.5, it defaulted to edit and now it doesn't, but that fixed it.