VCO 6.2 Reference Card
Jump to navigation
Jump to search
Contents
1 vRealize Orchestrator Notes
this notes are based on vCO 6.2
2 find important resources
2.1 get vcacHost / infrastructureHost / IaaSHost
var vcacHost = Server.findAllForType("vCAC:VCACHost")[0];
2.2 get cafe host
var cafeHost = Server.findAllForType("vCACCAFE:VCACHost", "vCAC-CAFE")[0];
3 translate VM objects
3.1 get cafeVm by name
var cafeVm = vCACCAFEEntitiesFinder.findCatalogResources(cafeHost,vcVm.name)[0];
3.2 get vcacVm by vcVm
var vcacVm=Server.findAllForType("vCAC:VirtualMachine", "IsDeleted eq false and ExternalReferenceId eq '" + vcVm.id + "'"[0]); // var vcacVm= Server.findAllForType("vCAC:VirtualMachine", "ExternalReferenceId eq '" + vcVm.id + "'")[0]; // var vcacVm=Server.findAllForType("vCAC:VirtualMachine", "ExternalReferenceId eq '" + vcVm.config.instanceUuid + "'")[0];
3.3 get vcVm by vcacVm
var sdkConnections = VcPlugin.allSdkConnections; System.log(sdkConnections.length + " sdk Connections found..."); for each (var sdkConnection in sdkConnections) { try { vCenterVm = sdkConnection.searchIndex.findByUuid(null, vCACVm.vmUniqueID, true, false); } catch(e) {System.log("Error for SDK connection " + sdkConnection.name + " : " + e);} if (vCenterVm != null) { System.log("Resolved vCenter VM " + vCenterVm.name); return vCenterVm; break; } }
3.4 find vm type for later case decision
var vmType = null; var vcacVm = new vCACVirtualMachine() ; vcacVm=Server.findAllForType("vCAC:VirtualMachine", "IsDeleted eq false and ExternalReferenceId eq '" + vcVm.id + "'")[0]; if (vcVm.config.template == true){ vmType = "VcTemplate"; System.log(vcVm.name+" is VcTemplate"); } if(vcacVm != null && vmType == null){ // only search for managed flag if vcacVm is found (avoid error) if (vcacVm.isManaged == true){ vmType = "vCACVirtualMachine"; System.log(vcacVm.displayName+" is vCACVirtualMachine"); } } if(vmType == null){ vmType = "VcVirtualMachine"; System.log(vcVm.name+" is VcVirtualMachine"); }
3.5 get owner of vcacVm(cafeVm)
var cafeVmOwnerName=cafeVM.getOwners()[0].getValue(); var cafeVmOwnerAccount=cafeVM.getOwners()[0].getRef();
4 vRA/vCAC VM examples
4.1 update property of vCAC virtual machine action
var prop="org.domain.monitoring.sla"; var val="7x24"; var vcacHost=Server.findAllForType("vCAC:VCACHost")[0]; var vcacVM= actionResult = System.getModule("com.vmware.library.vcac").addUpdatePropertyFromVirtualMachineEntity(vcacHost, vcacVM.getEntity(),prop,val,false,false,false,false); return actionResult;
4.2 read property of vCAC virtual machine
var vcVm= var vcVmName = vcVm.name; var vcacHost = Server.findAllForType("vCAC:VCACHost")[0]; var vcVmProperty="bitbull.monitoring.sla"; var vcVmPropertyValue = null; System.log("vcVm.config.instanceUuid : " + vcVm.config.instanceUuid); var vcacVMEntity = System.getModule("com.vmware.library.vcac").getVirtualMachineByExternalRefId(vcacHost, vcVm.config.instanceUuid); var properties = vcacVMEntity.getLink(vcacHost, "VirtualMachineProperties"); for(var i = 0 ;i < properties.length; i++){ var PropertyName = properties[i].getProperty("PropertyName"); var PropertyValue = properties[i].getProperty("PropertyValue"); if(PropertyName == vcVmProperty){ vcVmPropertyValue = PropertyValue; System.log("found "+vcVmProperty+" : "+vcVmPropertyValue); break; } }
4.3 get vcacVm properties
var entity = vCACVm.getEntity(); var managed = entity.getProperty("IsManaged"); if(managed){ var currentVMName = entity.getProperty("VirtualMachineName"); vcacVmProperties = new Properties(); var virtualMachinePropertiesEntities = entity.getLink(vcacHost, "VirtualMachineProperties"); for each (var virtualMachinePropertiesEntity in virtualMachinePropertiesEntities) { var propertyName = virtualMachinePropertiesEntity.getProperty("PropertyName"); var propertyValue = virtualMachinePropertiesEntity.getProperty("PropertyValue"); System.log("Found property " + propertyName + " = " + propertyValue); vcacVmProperties.put(propertyName, propertyValue); } }
emailAddress = vcacVmProperties.get("machine.user.email"); serviceLevel = vcacVmProperties.get("dd.backup.levels"); userLogin = vcacVmProperties.get("__Legacy.Workflow.User");
5 vCenter VM examples
5.1 vcVm esxi host
hostSystem = vcVm.runtime.host;
5.2 vcVm cluster
computeResource = vcVm.runtime.host.parent;
5.3 vcVm resource pool
resourcePool = vcVm.runtime.host.parent.resourcePool;
5.4 vcVm parent folder name
vcVmFolderName = vcVm.parent.name;
5.5 get vcVms by regex
var vmPattern="[a-z]{5}[0-9][3]" var allVms = VcPlugin.getAllVirtualMachines(); var foundVms = new Array(); // Check if the VM match the regexp for (var i in allVms) { if (allVms[i].name.match(vmPattern)) { foundVms.push(allVms[i]); System.log("found Vm: "+allVms[i].name); } } return foundVms;
5.6 push vm into bios next boot
var spec = new VcVirtualMachineConfigSpec() ; spec.bootOptions= new VcVirtualMachineBootOptions() ; spec.bootOptions.enterBIOSSetup = true; task=vcvm.reconfigVM_Task(spec);
6 file handling
6.1 write file
var tempDir = System.getTempDirectory() ; var fileWriter = new FileWriter(tempDir + "/readme.txt") ; System.log(tempDir + "/readme.txt"); fileWriter.open() ; fileWriter.writeLine("File written at : "+new Date()) ; fileWriter.writeLine("Another line") ; fileWriter.close() ;
6.2 read file
var tempDir = System.getTempDirectory() ; var fileReader = new FileReader(tempDir + "/readme.txt") ; fileReader.open() ; var fileContentAsString = fileReader.readAll(); fileReader.close() ; System.log(fileContentAsString);
7 time
7.1 get date
var date = new Date(), yy=date.getFullYear().toString().substr(2,2); mm=(date.getMonth() < 10 ? "0" : "") + (date.getMonth()+1); dd=(date.getDate() < 10 ? "0" : "") + date.getDate(); HH=(date.getHours() < 10 ? "0" : "") + date.getHours(); MM=(date.getMinutes() < 10 ? "0" : "") + date.getMinutes();
8 helpers
8.1 find type of object
function typeOf (obj) { return {}.toString.call(obj).split(' ')[1].slice(0, -1); }