Hi to all,
I'm trying to resize a VM disk through the VCO, without success.
Actually I wrote the following script:
//*************************************************
//vm is a VC:VirtualMachine parameter
//newSize is a number parameter
//return type is VC:Task
if (!vm) return null;
var devices = vm.config.hardware.device;
var firstDisk = null;
var diskSize = -1;
var newSizeInKB = newSize * 1024 * 1024;
//Finds the first VM disk
for (var i in devices) {
if (devices[i] instanceof VcVirtualDisk) {
firstDisk = devices[i];
}
}
diskSize = firstDisk.capacityInKB;
if (diskSize < 0 || newSizeInKB <= diskSize) return null; //No disk found, or the newSize is too small
var _key = firstDisk.key;
var _controllerKey = firstDisk.controllerKey;
var _unitNumber = firstDisk.unitNumber;
var _backing = firstDisk.backing;
var _newDiskSizeInKB = newSizeInKB;
System.log("key:" + _key + "\nControllerKey:" + _controllerKey + "\nUnitNumber:" + _unitNumber + "\nBacking:" + _backing);
var _newVirtualDevice = new VcVirtualDisk();
_newVirtualDevice.controllerKey = _controllerKey;
_newVirtualDevice.key = _key;
_newVirtualDevice.backing = _backing;
_newVirtualDevice.unitNumber = _unitNumber;
_newVirtualDevice.capacityInKB = _newDiskSizeInKB;
System.log("key:" + _newVirtualDevice.key + "\nControllerKey:" + _newVirtualDevice.controllerKey + "\nUnitNumber:" + _newVirtualDevice.unitNumber + "\nBacking:" + _newVirtualDevice.backing + "\nNew Size:" + _newVirtualDevice.capacityInKB);
var _virtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec();
_virtualDeviceConfigSpec.device = _newVirtualDevice;
_virtualDeviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
_virtualDeviceConfigSpec.fileOperation = VcVirtualDeviceConfigSpecFileOperation.replace;
var _virtualMachineConfigSpec = new VcVirtualMachineConfigSpec();
_virtualMachineConfigSpec.deviceChange = new Array();
_virtualMachineConfigSpec.deviceChange.push(_virtualDeviceConfigSpec);
return vm.reconfigVM_Task(_virtualMachineConfigSpec);
//*************************************************
Executing the code I can see the task starting and immediately ending in vCenter without errors, but the vm disk size remains the same.
Could you help me?