How to get the Virtual Machine Identity (vmId) with its name.
Create a custom task with this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
importPackage(java.util); importPackage(java.lang); importPackage(java.io); importPackage(com.cloupia.lib.util); importPackage(com.cloupia.service.cIM.inframgr); importPackage(com.cloupia.model.cEvent.notify); importPackage(com.cloupia.lib.util.mail); importPackage(com.cloupia.fw.objstore); importPackage(com.cloupia.lib.util.managedreports); importPackage(com.cloupia.model.cIM); logger.addInfo("Looking for vmId of " + input.VMname); try { // Call Static Function getVMByVMName from InfraPersistenceUtil // ... I like the documentation from Cisco ... Empty var gvm = InfraPersistenceUtil.getVMByVMName(input.accountName,input.VMname); if(gvm != null){ logger.addInfo("Virtual Machine Status: " + gvm.getStatus()); logger.addInfo("Guest OS: " + gvm.getGuestOS()); logger.addInfo("Virtual Machine ID: " + gvm.getVmId()); output.vmId = gvm.getVmId(); output.VMSelector = gvm.getVmId(); } else { ctxt.setFailed("(NULL) The virtual machine " + input.VMname + " doesn't exist !"); } } catch(e) { logger.addError("Error when looking for a vmId. (" + e + ")"); ctxt.setFailed("The virtual machine " + input.VMname + " doesn't exist !"); } finally { } |
Inputs:
- VMname (Virtual machine Name) in a string
- accountName (vCenter Account Name in UCS Director)
Outputs:
- vmId (Virtual Machine Identity for UCS Director)