On-demand change the memory size of the virtual machine

/*

Purpose:
This workflow is used on-demand change the memory size of the virtual machine.

Parameters:
– memorySize (string)
– vm (VC:VirtualMachine)

*/





try
{
              if(vm != null){
                             var currentMemory = vm.summary.config.memorySizeMB;
                             System.log("Current Memory - "+currentMemory);
                             // Getting the Memory that is being increased/decreased to the VM
                             var memoryToBeIncreased = (Number(memorySize)*1024) - (currentMemory);
                             if(memoryToBeIncreased < 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) ;
                             }
                             var configSpec = new VcVirtualMachineConfigSpec();
                             configSpec.memoryMB = (Number(memorySize)*1024);
                             var task = vm.reconfigVM_Task( configSpec );
                             var actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task) ;
              }
              else{
                                           var msg = "virtual machine not found.";
                                           throw msg;
              }
}
catch(error){
              System.log(error);
              throw error;

}

Comments

Popular posts from this blog

Creating Snapshots for Unmanaged VMs in Aria Automation (vRealize Automation)

Bulk import security policies into Palo Alto Networks firewalls

Automating Tag Creation & Assignment to VMs with vRA + vRO