VMWarevRO

On-demand change the CPU Count the virtual machine

/*

Purpose:

This workflow is used on-demand change the CPU Count the virtual machine.

Parameters:

– noOfCpu(string)

– vm (VC:VirtualMachine)

*/

try

{

              //vm = System.getModule(“org.kumar.module”).getVirtualMachine(vmName) ;

              if(vm == null){

                             var msg = “The VM not found.”;

                             throw msg;

              }

              System.log(“VM object- “+vm);

              System.log(“VM Name- “+vm.Id);

              //cpuRatio = vm.config.cpuAllocation.shares.level.value;

              var currentCpu = vm.summary.config.numCpu;

              // Getting the CPU that is being increased to the VM

              numCpu = Number(noOfCpu) – currentCpu;

              if(numCpu < 0 && vm.runtime.powerState.value == “poweredOn”){

                             var task = System.getModule(“com.vmware.library.vc.vm.power”).forcePowerOff(vm) ;

                             var actionResult = System.getModule(“com.vmware.library.vc.basic”).vim3WaitTaskEnd(task,”No”,2) ;

              }

              if(vm != null){

                             //vcpu = vm.cpu.split(‘ ‘)[0];

                             var configSpec = new VcVirtualMachineConfigSpec();

                             configSpec.numCPUs = Number(noOfCpu);

                             var task = vm.reconfigVM_Task(configSpec);

                             //var actionResult = System.getModule(“com.vmware.library.vc.basic”).vim3WaitTaskEnd(task) ;

                             var actionResult = System.getModule(“com.vmware.library.vc.basic”).vim3WaitTaskEnd(task,”No”,2) ;

              }

}

catch(error){

                             throw error;

}

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close