Resizing Disk with SDK

Hi all,

has anybody tried to resize a virtual disk with the SDK? All my attempts seems not to have an impact at all.

I have applied the patch ESX-6921838 (adding support for resizing).

The essential part of the code is the following:

my $datastore = "VMFS_007";

my $host_moref = get_host("myhost");

my $ds_info = get_datastore(host_view => $host_moref, datastore => $datastore );

my $disk_backing_info = VirtualDiskFlatVer2BackingInfo->new(

diskMode => 'persistent',

datastore => $ds_info,

fileName => "/vmfs/volumes/VMFS_007/TESTDEPLOY/TESTDEPLOY.vmdk");

my $disk = VirtualDisk->new(backing => $disk_backing_info,

#key => -1,

capacityInKB => "12000");

my $disk_vm_dev_conf_spec = VirtualDeviceConfigSpec->new(device => $disk,

operation => VirtualDeviceConfigSpecOperation->new('edit'));


I try to set the new size of the disk to 12 GB

get_host and get_datastore works in other scripts.

I'm not getting any errormessage at all.

0 Kudos
2 Replies


The code snippet provided by you works fine, I just wonna confirm that whether you have called ReconfigVM_Task to reconfigure your virtula machine or not. To reflect any changes in the settings of the devices attached you need to use this API.

Message was edited by:


0 Kudos

Hi and thank you for your response.

Actually i didn't call this, because i wanted to resize an existing disk, like with the vmkfstools, and I didn't thought that this is related to the actual VM.

I put in following lines:


my $machine_vm_conf_spec = VirtualMachineConfigSpec->new(deviceChange => \[ $disk_vm_dev_conf_spec ] );


$vm_moref->ReconfigVM(spec => $machine_vm_conf_spec);


if ($@) { print "Reconfiguration failed.\n $@";}

else {print "Resize disk ok.\n"; }


And it says that everything is ok, but when i check the vmdk-file, it still just has 4 gb (instead of 12 as expected). I think with the above code, I just make (temporarily) changes to the config-file of the VM, not to the vmdk-file.

Do you eventually have some sample-code to resize a vmdk-disk?

Best regards


0 Kudos