Task Name | Configure number of virtual sockets and number of cores per socket of a VM |
Description | |
Prerequisites | - Tested on 5.4.0.2
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs | e-mail address |
Output | e-mail with counter |
Instructions for Regular Workflow Use:
- Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
- Unzip the file on your computer. Should end up with a .WFD file.
- Log in to UCS Director as a user that has "system-admin" privileges.
- Navigate to "Policies-->Orchestration" and click on "Import".
- Click "Browse" and navigate to the location on your computer where the .WFDX file resides. Choose the .WFDX file and click "Open".
- Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
- Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
- Click "Submit".
- A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment
A big thank you goes to:
Credit goes to Logesh Kandasamy and Tejeswar Sahu for developing the custom task
The import:
The workflow:
User input to the task:
(VM Context could be set in global variable section and linked to the task input!)
The code:
importPackage(com.cloupia.model.cIM);//VMWareVMSummary,Account
importPackage(com.cloupia.service.cIM.inframgr);//InfraPersistenceUtil
importPackage(com.cloupia.lib.cIaaS.vmware);//VCenterConnectionManager
importPackage(com.vmware.vim25.mo);
importPackage(com.vmware.vim25);
importPackage(java.lang);
importPackage(java.util);
var vmId = input.vmid;
var noOfVirtualSockets = input.noOfVSockets;
var noOfCoresPerSocket = input.noOfCoresPerSocket;
var totalNoOfCores = noOfVirtualSockets*noOfCoresPerSocket;
logger.addInfo("vmId:"+vmId+",noOfVirtualSockets:"+noOfVirtualSockets+",noOfCoresPerSocket:"+noOfCoresPerSocket+",totalNoOfCores:"+totalNoOfCores);
//VMWareVMSummary getVMwareVMSummary(int vmId)
var vmwareVMSummary = InfraPersistenceUtil.getVMwareVMSummary(parseInt(vmId));
var accountName = vmwareVMSummary.getAccountName();
var vmName = vmwareVMSummary.getName();
logger.addInfo("Account name:"+accountName);
logger.addInfo("Vm name is:"+vmName);
//Account getAccount(String accountName)
var acc = InfraPersistenceUtil.getAccount(accountName);
try{
var si = new VCenterConnectionManager(acc).getServiceInstance();
}catch(e1){
logger.addError("Connection to the account "+accountName+" got failed."+e1);
ctxt.exit();
}
logger.addInfo("Service Instance is:"+si)
try {
var rootFolder = si.getRootFolder();
var vm = new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine",vmName);
if (vm != null) {
if(vm.getSummary().runtime.powerState.toString().equals("poweredOn")){
logger.addError(" The vm "+vmName+" is powered on.The vm needs to be powered off first in order to change CPUs.....");
ctxt.setFailed("The vm needs to be powered off first in order to change CPUs.....");
ctxt.exit();
}
//Thread.sleep(10000);
while(true){
var vmConfigSpec = new VirtualMachineConfigSpec();
vmConfigSpec.setNumCoresPerSocket(parseInt(noOfCoresPerSocket));
vmConfigSpec.setNumCPUs(parseInt(totalNoOfCores));
var task = vm.reconfigVM_Task(vmConfigSpec);
waitForTask = task.waitForTask();
if("success"!=waitForTask){
logger.addInfo("waiting for completion of the reconfiguration of the vm......");
Thread.sleep(10000);
}
else{
logger.addInfo("Reconfiguration of the vm got completed....");
break;
}
}
logger.addInfo("Task got completed successfully...");
}
} catch (e) {
logger.addError("Exception occured " + e);
} finally {
si.getServerConnection().logout();
}