Last active
June 2, 2017 04:17
-
-
Save trisharia/337e2df485aa78a507700a53db8b7718 to your computer and use it in GitHub Desktop.
Get the Reservation of a vRA 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 | |
// | |
// Get the Reservation of a vRA VM | |
// | |
// For vRO/VRA 7.0+ | |
// | |
// Action Inputs: | |
// host - vCAC:VCACHost - vRA IaaS Host | |
// virtualMachine - vCAC:VirtualMachine - vRA IaaS VM | |
// | |
// Return type: vCAC:Reservation - the IaaS Reservation of the VM | |
var id = virtualMachine.getEntity().getProperty("HostReservationID"); | |
var entity; | |
var idprop = new Properties( { | |
"HostReservationID" : id | |
}); | |
if (!id || id == "") throw "Error getting Reservation ID of VM."; | |
if (host != null) { | |
entity = vCACEntityManager.readModelEntity(host.id, "ManagementModelEntities.svc", "HostReservations", idprop, null); | |
} else { | |
var hosts = Server.findAllForType("vCAC:VCACHost"); | |
System.debug("hosts: " + hosts); | |
for each (var host in hosts) { | |
try { | |
entity = vCACEntityManager.readModelEntity(host.id, "ManagementModelEntities.svc", "HostReservations", idprop, null); | |
} catch (e) { | |
throw "Error reading model entity."; | |
} | |
} | |
} | |
var reservation = entity.getInventoryObject(); | |
if (!reservation) throw "Reservation with ID '" + id + "' not found"; | |
return reservation; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment