Hi llian,
Good Morning,
could you suggest on the following .
i am trying to reconfigure an array of vms to change vcpu to 2vcpu and memory to 2GB.
since i dont know if there is any existing workflow avaibleout of the box i am creating vro workflow using scriptable task using for each and reconfigVM method as shown below.
could you please complete the following code iam not sure what needs to be put inside bracket for VcVirtualMachineConfigSpec.
There is an out of the box workflow (named change RAM and in the Library>vCenter>Virtual Machine management>Device Management folder) for changing the memory on a VM which can be used as a reference. That calls the action (com.vmware.library.vc.vm) changeVMRAM, which has the following code:
var configSpec = new VcVirtualMachineConfigSpec();
configSpec.memoryMB = memory;
var task = vm.reconfigVM_Task( configSpec );
return task;
Where the inputs are the variables memory and vm.
There is also an action (com.vmware.library.vc.vm) changeVMvCPU which has the same code except the configSpec contains the following line
configSpec.numCPUs = vcpu;
With vcpu being the value passed as an input into the action.
You can combine both the memory and cpu into a single spec and then just call it inside your for each loop if you want to update all VMs to the same cpu/ram values.
var configSpec = new VcVirtualMachineConfigSpec();
configSpec.memoryMB = memory;
configSpec.numCPUs = vcpu;
for each(vm in vms){
vm.reconfigVM_Task(configSpec);
}
The reconfigVM_Task method returns a VC:Task object which you can use to monitor the progress of each change if you want to i.e. make sure it completes successfully on each VM before it starts on the next one. You can monitor the task like this, where progress is type boolean to control whether you want vRO to report on the progress of the task while it is being actioned and pollRate is a number in seconds for how often you want to poll the task for the progress report.
var configSpec = new VcVirtualMachineConfigSpec();
configSpec.memoryMB = memory;
configSpec.numCPUs = vcpu;
for each(vm in vms){
var task = vm.reconfigVM_Task(configSpec);
System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,progress,pollRate) ;
}
There is an out of the box workflow (named change RAM and in the Library>vCenter>Virtual Machine management>Device Management folder) for changing the memory on a VM which can be used as a reference. That calls the action (com.vmware.library.vc.vm) changeVMRAM, which has the following code:
var configSpec = new VcVirtualMachineConfigSpec();
configSpec.memoryMB = memory;
var task = vm.reconfigVM_Task( configSpec );
return task;
Where the inputs are the variables memory and vm.
There is also an action (com.vmware.library.vc.vm) changeVMvCPU which has the same code except the configSpec contains the following line
configSpec.numCPUs = vcpu;
With vcpu being the value passed as an input into the action.
You can combine both the memory and cpu into a single spec and then just call it inside your for each loop if you want to update all VMs to the same cpu/ram values.
var configSpec = new VcVirtualMachineConfigSpec();
configSpec.memoryMB = memory;
configSpec.numCPUs = vcpu;
for each(vm in vms){
vm.reconfigVM_Task(configSpec);
}
The reconfigVM_Task method returns a VC:Task object which you can use to monitor the progress of each change if you want to i.e. make sure it completes successfully on each VM before it starts on the next one. You can monitor the task like this, where progress is type boolean to control whether you want vRO to report on the progress of the task while it is being actioned and pollRate is a number in seconds for how often you want to poll the task for the progress report.
var configSpec = new VcVirtualMachineConfigSpec();
configSpec.memoryMB = memory;
configSpec.numCPUs = vcpu;
for each(vm in vms){
var task = vm.reconfigVM_Task(configSpec);
System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,progress,pollRate) ;
}
Thanks .i am checking this.
Hi Heja,
thanks for yur time on this .
as per yur suggestion i declared three variable as below.
and write following code in scriptable task.
so this workflow run fine .Thanks for your support much appreciated.