Skip to content

Instantly share code, notes, and snippets.

@joe-speedboat
Created March 16, 2018 13:35
Show Gist options
  • Save joe-speedboat/d0851a58b112bb695db8492d12451601 to your computer and use it in GitHub Desktop.
Save joe-speedboat/d0851a58b112bb695db8492d12451601 to your computer and use it in GitHub Desktop.
vRO: find objects by payload handed over via event broker
// Retrieve the machine properties ------------------
var machine = payload.get("machine");
if(machine == null) {
throw("no machine found in payload, burn with fire!");
}
var machineProperties = machine.get('properties');
vmName = machine.get('name'); // vra vm hostname
// Find vcacVm and its relatives ---------------------
var virtualMachineId = machine.get("id");
var vCACVm = Server.findForType("vCAC:VirtualMachine", virtualMachineId);
if (vCACVm == null) {
throw("vCACVm not found, burn with fire!");
}
System.log("Found vCACVm: "+vCACVm.displayName);
var hostId = vCACVm.getEntity().hostId;
var virtualMachineEntity = vCACVm.getEntity();
var vCACHost = Server.findForType("vCAC:VCACHost", hostId);
vCACVmProperties = System.getModule("com.vmware.library.vcac").getPropertiesFromVirtualMachine(vCACHost,vCACVm);
// find vcvm and its relatives ------------------------ (this works only POST, pre cloning there is no vcVM)
// get vmUuid
var vmUuid = vCACVmProperties.get('VirtualMachine.Admin.UUID');
if (vmUuid == null) {
throw("vmUuid not found, burn with fire!");
}
var vcVm = System.getModule("com.vmware.vcac.asd").findVcVmByUuid(vmUuid);
System.log("Found vcVm: "+vcVm.name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment