Get vmId by vmName in Cloupia Script
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)
Cisco UCS Director – Hello World in Cloupia script
Cloupia script is THE scripting language from Cisco UCS Director. Cloupia is a mix between Javascript and Java. The code is interpreted by Nashorn (the Javascript engine from JRE/JDK).
1 2 3 4 5 |
importPackage(java.lang); var sHelloWorld = "Hello the world !"; logger.addInfo(sHelloWorld); |
imporPackage has the same role as import from a pure Java code. import java.lang.* is in cloupia importPackage(java.lang);