VMware {code} Community
daniellynn
Enthusiast
Enthusiast

can't resize disks after vsphere upgrade

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

VirtualDeviceConfigSpec[] vdcsArray;

vdcsArray = new VirtualDeviceConfigSpec[1];

vdcsArray[0] = new VirtualDeviceConfigSpec();

VirtualDisk vdisk = new VirtualDisk();

vdisk = (VirtualDisk)newdisk[12];

vdisk.capacityInKB = newSizeGB * 1048576;

vdcsArray[0].device = (VirtualDevice)vdisk;

configSpec.deviceChange = vdcsArray;

service.ReconfigVM_Task(vmRef, configSpec);

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.

Reply
0 Kudos
2 Replies
storm27
Enthusiast
Enthusiast

Hi,

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.

Thanks.

Angela

daniellynn
Enthusiast
Enthusiast

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[0]) 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.

Reply
0 Kudos