Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trisharia/c754a00a612b38e3e6a9776e876561b3 to your computer and use it in GitHub Desktop.
Save trisharia/c754a00a612b38e3e6a9776e876561b3 to your computer and use it in GitHub Desktop.
Get the names of all the reservations of a compute resource in a vRA IaaS instance
// VMware vRealize Orchestrator action sample
//
// Get the names of all the reservations of a compute resource in a vRA IaaS instance
//
// For vRO/VRA 7.0+
//
// Action Inputs:
// host - vCAC:VCACHost - vRA IaaS Host
// computeResourceName - string - Compute resource name
// onlyEnabledReservations - boolean - Set to true to only return the names of enabled reservations
//
// Return type: Array/strings - names of reservations
if (vcacHost == null) return null;
var reservationNames = [];
var computeResourceEntity = getComputeResourceEntity(vcacHost, computeResourceName);
var reservationEntities = computeResourceEntity.getLink(vcacHost, "HostReservations");
if (reservationEntities.length !== 0) {
for each (var r in reservationEntities) {
if (onlyEnabledReservations) {
if (r.getProperty("Enabled") == true) {
reservationNames.push(r.getProperty("HostReservationName"));
}
} else {
reservationNames.push(r.getProperty("HostReservationName"));
}
}
}
return reservationNames;
function getComputeResourceEntity(host, name) {
var model = "ManagementModelEntities.svc";
var entitySetName = "Hosts";
var filter = "MachineType eq 0 and IsVRMManaged eq true and HostName eq '" + name + "'";
var entities = vCACEntityManager.readModelEntitiesBySystemQuery(host.id, model, entitySetName, filter);
if (entities.length === 0) {
throw "No compute resource entity found with name '" + name + "'";
}
if (entities.length > 1) {
throw "Too many compute resource entities found with name '" + name + "'";
}
return entities[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment