deqcan
Contributor
Contributor

Resizing VM disk through VCO

Jump to solution

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?

1 Solution

Accepted Solutions
mmarinov
VMware Employee
VMware Employee

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

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points

View solution in original post

10 Replies
mmarinov
VMware Employee
VMware Employee

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

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points
deqcan
Contributor
Contributor

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

0 Kudos
ZbyszekS
Enthusiast
Enthusiast

Hey,

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

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

0 Kudos
Burke-
VMware Employee
VMware Employee

This entire thread is in the wrong community...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
tschoergez
Leadership
Leadership

moved to the right Orchestrator community.

0 Kudos
brunocosta001
Contributor
Contributor

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

0 Kudos
brunocosta001
Contributor
Contributor

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

0 Kudos
Mr_G_Grant
Enthusiast
Enthusiast

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?

0 Kudos
Sak_123
Contributor
Contributor

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

0 Kudos
manojksamtani
Contributor
Contributor
@Burke Is this still the case? can not change array property directly?
0 Kudos