VMware Aria Automation Orchestrator

 View Only
Expand all | Collapse all

Resizing VM disk through VCO

  • 1.  Resizing VM disk through VCO

    Posted Aug 08, 2011 11:46 AM

    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?



  • 2.  RE: Resizing VM disk through VCO
    Best Answer

    Broadcom Employee
    Posted Aug 08, 2011 12:37 PM

    Hi,

    It might seem strange but could you try change these lines:

    _virtualMachineConfigSpec.deviceChange = new Array();
    _virtualMachineConfigSpec.deviceChange.push(_virtualDeviceConfigSpec);

    with

    var changedDevices = new Array();

    changedDevices.push(_virtualDeviceConfigSpec);

    _virtualMachineConfigSpec.deviceChange = changedDevices;

    There is a problem with modifying directly properties of type Array.

    Regards,

    --Martin



  • 3.  RE: Resizing VM disk through VCO

    Posted Aug 08, 2011 01:40 PM

    Hi Martin!

    It worked like a charm.

    Thank you for your quick answer.

    (P.S. I also had to remove the line _virtualDeviceConfigSpec.fileOperation = VcVirtualDeviceConfigSpecFileOperation.replace;)



  • 4.  RE: Resizing VM disk through VCO

    Posted Mar 31, 2014 12:58 PM

    Hey,

    I'm getting error "invalid return" in this line if (!vm) return null;

    I had added out param as VC:Task.....



  • 5.  RE: Resizing VM disk through VCO

    Broadcom Employee
    Posted Mar 31, 2014 01:08 PM

    This entire thread is in the wrong community...



  • 6.  RE: Resizing VM disk through VCO

    Broadcom Employee
    Posted Nov 21, 2014 10:47 PM

    moved to the right Orchestrator community.



  • 7.  RE: Resizing VM disk through VCO

    Posted May 06, 2015 04:09 PM

    I know this is an old post but i get the same error. Did you ever find the fix? if so would you mind sharing?



  • 8.  RE: Resizing VM disk through VCO

    Posted Nov 29, 2018 05:22 AM

    Hello,

    I am trying the same thing to resize the existing disk. For me, the workflow runs with any error but the disk size does not increase (you have mentioned that you were facing same issue) As suggested in one of the answers by Martin and you , I changed few lines of script as well. But could get any solution.

    If you could provide some help ?

    Sakshi Singh



  • 9.  RE: Resizing VM disk through VCO

    Posted Sep 08, 2021 03:26 PM
    Is this still the case? can not change array property directly?


  • 10.  RE: Resizing VM disk through VCO

    Posted Dec 19, 2014 06:01 PM

    Hey Folks,

    I was trying to run the workflow, but I have got an error.

    Seems like the reconfig is not working. Follows the logs.

    If anyone has a hint, please, let me know.

    Running on VCO 5.1;

    [2014-12-19 15:52:49.797] [D] Found disk: DynamicWrapper (Instance) : [VcVirtualDisk]-[class com.vmware.vim.vi4.VirtualDisk] -- VALUE : com.vmware.vim.vi4.VirtualDisk@df621e50

    [2014-12-19 15:52:49.799] [D] diskAry: ,2000

    [2014-12-19 15:52:49.800] [D] diskArray: ,2000

    [2014-12-19 15:52:49.804] [D] diskkey: 2000

    [2014-12-19 15:52:49.808] [D] disk: DynamicWrapper (Instance) : [VcVirtualDisk]-[class com.vmware.vim.vi4.VirtualDisk] -- VALUE : com.vmware.vim.vi4.VirtualDisk@df621e50

    [2014-12-19 15:52:49.811] [D] oldSize: 20971520

    [2014-12-19 15:52:49.815] [D] dcs: DynamicWrapper (Instance) : [VcVirtualDeviceConfigSpec]-[class com.vmware.vim.vi4.VirtualDeviceConfigSpec] -- VALUE : com.vmware.vim.vi4.VirtualDeviceConfigSpec@e0318c5b

    [2014-12-19 15:52:49.817] [D] deviceSpec: DynamicWrapper (Instance) : [VcVirtualDeviceConfigSpec]-[class com.vmware.vim.vi4.VirtualDeviceConfigSpec] -- VALUE : com.vmware.vim.vi4.VirtualDeviceConfigSpec@e0318c5b

    [2014-12-19 15:52:49.820] [D] deviceSpec.operationDynamicWrapper (Instance) : [VcVirtualDeviceConfigSpecOperation]-[class com.vmware.vim.vi4.VirtualDeviceConfigSpecOperation] -- VALUE : edit

    [2014-12-19 15:52:49.825] [D] deviceSpec.device DynamicWrapper (Instance) : [VcVirtualDisk]-[class com.vmware.vim.vi4.VirtualDisk] -- VALUE : com.vmware.vim.vi4.VirtualDisk@e0021e50

    [2014-12-19 15:52:49.828] [D] new Size: 31457280

    [2014-12-19 15:52:49.831] [D] configSpec.deviceChange: DynamicWrapper (Instance) : [VcVirtualDeviceConfigSpec]-[class com.vmware.vim.vi4.VirtualDeviceConfigSpec] -- VALUE : com.vmware.vim.vi4.VirtualDeviceConfigSpec@e0318c5b

    [2014-12-19 15:52:53.864] [I] VIM Task is null (Dynamic Script Module name : vim3WaitTaskEnd#35)

    Thanks,

    Bruno Costa



  • 11.  RE: Resizing VM disk through VCO

    Posted Dec 19, 2014 07:29 PM

    Folks,

    For those who got the same error as I did, should check for VMO log.

    NotAuthenticated : The session is not authenticated., privilege id 'System.View'

    I restarted the Vcenter Orchestrator service, and the workflow worked 100%!

    Regards,

    Bruno Costa



  • 12.  RE: Resizing VM disk through VCO

    Posted Jun 11, 2025 03:36 PM

    This will resize SCSI Controller 0 Hard Disk 1 to the value of new_disk_size_gb

    devices = vm.config.hardware.device;
    
    for each (device in devices) {
        if (device instanceof VcVirtualDisk) {
            if (device.controllerKey == 1000 && device.unitNumber == 0) {
                device.capacityInKB = new_disk_size_gb * 1024 * 1024
                
                config_spec = new VcVirtualMachineConfigSpec()
                device_config_specs = new Array()
                device_config_spec = new VcVirtualDeviceConfigSpec()
                device_config_spec.device = device
                device_config_spec.operation = VcVirtualDeviceConfigSpecOperation.edit
                device_config_specs.push(device_config_spec)
                config_spec.deviceChange = device_config_specs
    
                vm.reconfigVM_Task(config_spec)
            }
        }
    }