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/8c5771e86ce1512ef4f3973fce0bf954 to your computer and use it in GitHub Desktop.
Save trisharia/8c5771e86ce1512ef4f3973fce0bf954 to your computer and use it in GitHub Desktop.
Get the reservation policy IDs of all the reservations of a compute resource in a vRA IaaS instance
// VMware vRealize Orchestrator action sample
//
// Get the reservation policy IDs 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 reservation policies of enabled reservations
//
// Return type: Array/strings - reservation policy IDs
if (vcacHost == null) return null;
var reservationPolicyIds = [];
var computeResourceEntity = getComputeResourceEntity(vcacHost, computeResourceName);
var reservationEntities = computeResourceEntity.getLink(vcacHost, "HostReservations");
var resPolicy;
if (reservationEntities.length !== 0) {
for each (var r in reservationEntities) {
if (onlyEnabledReservations) {
if (r.getProperty("Enabled") == true) {
resPolicy = getReservationPolicy(vcacHost, r);
}
} else {
resPolicy = getReservationPolicy(vcacHost, r);
}
if (resPolicy) {
// Note: Can alternatively return resPolicy.name to get names rather than IDs
reservationPolicyIds.push(resPolicy.id);
}
}
}
return reservationPolicyIds;
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];
}
function getReservationPolicy(host, reservationEntity) {
var policies = reservationEntity.getLink(host, "HostReservationPolicy");
if (policies.length == 0) {
System.warn("No Reservation Policy found for the Reservation");
return null;
}
var policyEntity = policies[0];
var policyName = policyEntity.getProperty("name");
var policyId = policyEntity.getProperty("id");
//System.log("Found Reservation Policy '" + policyName + "' with ID '" + policyId + "'");
return { "name" : policyName, "id" : policyId };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment