Last active
November 15, 2018 22:04
-
-
Save standit/4a4c730d02cdc6aac32d2b8594d7f4cf to your computer and use it in GitHub Desktop.
Get vRA Catalog Resource of vCenter VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VMware vRealize Orchestrator action sample. Valid for vRA/vRO 7.0+ | |
// | |
// Get vRA Catalog Resource from vCenter VM Object | |
// | |
// Action Inputs: | |
// vCVM VC:VirtualMachine vCenter Virtual Machine object | |
// | |
// Action Output: | |
// return type: vCACCAFE:CatalogResource | |
var vCVMInstanceUUID = vCVM.config.instanceUuid; | |
System.log("VCenter VM Instance UUID: "+vCVMInstanceUUID); | |
var vRAVMs = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + vCVMInstanceUUID + "'"); | |
var vRAVM = null; | |
findvRAVM: | |
for(var i=0; i<vRAVMs.length; i++) { | |
if(vRAVMs[i].vmUniqueID == vCVMInstanceUUID) { | |
System.log(vRAVMs[i].virtualMachineName); | |
vRAVM = vRAVMs[i]; | |
break findvRAVM; | |
} | |
} | |
var iaasHost = Server.findForType("vCAC:vCACHost", vRAVM.getEntity().hostId); | |
System.log("IaaS Host: "+iaasHost.name); | |
var allItems = vCACCAFEEntitiesFinder.getCatalogResources(cafeHost); | |
findResource: | |
for(var i=0; i<allItems.length; i++) { | |
var r = allItems[i]; | |
//System.log("Resource Name: "+ r.name); | |
//System.log("Resource Type: "+r.resourceTypeRef.getLabel()); | |
if(r.resourceTypeRef.getLabel() == "Virtual Machine") { | |
var rVmId = null; | |
try { | |
var rVmId = r.resourceData.get("VirtualMachine.Admin.UUID").getValue(); | |
} catch (e) { | |
//System.error("Resource VM ID not found"); | |
continue; | |
} | |
//System.log("ResourceVMID: "+ rVmId); | |
if(rVmId == vCVMInstanceUUID) { | |
System.log("ResourceVMID: "+ rVmId); | |
vRACatalogResource = r; | |
break findResource; | |
} | |
} | |
} | |
System.log("Found Resource: "+vRACatalogResource.name); | |
return vRACatalogResource; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment