Find vRA DataCenterLocation Compute Resources from vRO

A short time ago Christopher Lewis (@thecloudxpert) asked me for a bit of help to create a vRealize Orchestrator Action to find all vSphere based vRealize Automation Compute Resources for a specific DataCenterLocation.

I have both added the code for the action on the VMware {code} Sample Exchange and here below.

I am also providing the Action here for download: findVsphereComputeResourcesForDataCenterLocation.action.zip Just unzip and import the Action into your desired Action Module in vRealize Orchestrator Client.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//////////////////////////////////////////////////
//                    INPUTS                    //
//////////////////////////////////////////////////

/*

vraIaasHost (Type = vCAC:VCACHost)
dataCenterLocationName (Type = string) 

*/

//////////////////////////////////////////////////
//                    OUTPUT                    //
//////////////////////////////////////////////////

/*

Return type = Array/vCAC:HostMachine

*/

// Filter used for searching in the Hosts "table" of the vRA IaaS SQL Database
var filter = "IsVRMManaged eq true and ManagementEndpoint/InterfaceType eq 'vSphere'";

// Search Hosts "table" in the vRA IaaS SQL Database, using above filter
var hostEntities = vCACEntityManager.readModelEntitiesBySystemQuery(vraIaasHost.id , "ManagementModelEntities.svc" , "Hosts" , filter);

// Create empty array for collecting found Compute Resources
var dataCenterLocationComputeResources = new Array();

// Loop thru hostEntities, get their hostProperties, chceck of Property "Vrm.DataCenter.Location" is present, then check if value of that property matches the DataCenterLocation Name provided
for each (var hostEntity in hostEntities) {
	var hostPropertiesEntities = hostEntity.getLink(vraIaasHost, "HostProperties");
	for each (hostPropertiesEntity in hostPropertiesEntities) {
		if (hostPropertiesEntity.getProperty("PropertyName") == "Vrm.DataCenter.Location") {
			if (hostPropertiesEntity.getProperty("PropertyValue") == dataCenterLocationName) {
				dataCenterLocationComputeResources.push(hostEntity.getInventoryObject());
			}
		}
	}
}

return dataCenterLocationComputeResources;