Last active
September 17, 2018 19:34
-
-
Save kclinden/61626c3cc8c92f19e949a338613cceb7 to your computer and use it in GitHub Desktop.
Filter VRM Locations By Reservation Policy ID
This file contains hidden or 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
| //Creator: Kasey Linden | |
| //Date: Sept. 17, 2018 | |
| //Description: This action is used to filter VrmDataCenterLocation by Rservation Policy Id | |
| //Inputs: tenant [string], resPolicyId[string] | |
| //Output: array/string | |
| if(!tenant){ | |
| throw "Error no tenant provided"; | |
| } | |
| if(!resPolicyId){ | |
| return null; | |
| } | |
| var host = vCACCAFEHostManager.getDefaultHostForTenant(tenant , true); | |
| var vcacHost = Server.findAllForType("vCAC:vCACHost")[0] //Eventually update this to get specific vCAC Host for CafeHost | |
| //Get all reservations for Cafe Host | |
| var allReservations = vCACCAFEEntitiesFinder.getReservations(host); | |
| var reservations = [] | |
| //Get reservations with reservation policy id | |
| for each(var reservation in allReservations) { | |
| if (reservation.reservationPolicyId == resPolicyId) { | |
| System.log("Found reservation " + reservation.name); | |
| reservations.push(reservation); | |
| } | |
| } | |
| //Create array of compute resource ids | |
| var computeResourceIds = [] | |
| for each (var res in reservations){ | |
| var computeResource = res.getExtensionData().get("computeResource"); | |
| System.log("Found compute resource " + computeResource.label + " - " + computeResource.id); | |
| computeResourceIds.push(computeResource.id); | |
| } | |
| //Get vCAC Entity by Compute HostID | |
| var locations = []; | |
| for each (var computeResourceId in computeResourceIds){ | |
| var computeResources = vCACEntityManager.readModelEntitiesBySystemExpandQuery(vcacHost.Id, "ManagementModelEntities.svc", "Hosts","HostID eq (guid'" + computeResourceId + "')", "HostProperties") | |
| for each (var compute in computeResources){ | |
| var hostProps = compute.getLinks(vcacHost).HostProperties; | |
| //Get location | |
| for each (var hostProp in hostProps){ | |
| if(hostProp.getProperty("PropertyName") == "Vrm.DataCenter.Location"){ | |
| System.log("Found a datacenter location of " + hostProp.getProperty("PropertyValue")); | |
| var location = hostProp.getProperty("PropertyValue"); | |
| locations.push(location); | |
| } | |
| } | |
| } | |
| } | |
| return removeDuplicates(locations); | |
| //Functions | |
| function removeDuplicates(arr) { | |
| var unique_array = [] | |
| for(i = 0;i < arr.length; i++){ | |
| if(unique_array.indexOf(arr[i]) == -1){ | |
| unique_array.push(arr[i]) | |
| } | |
| } | |
| return unique_array | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment