CannedOnion
Contributor
Contributor

Adding Compute Resources to Fabric Groups programmatically through vRO

vRealize Orchestrator version 7.3
vRealize Automation version 7.3    

We're planning on either programmatically create a new fabric group or update an existing fabric group, however i'm sitting here looking at vRO and I dont see (image below) an option to set Compute Resources on a Fabric Group. Is there no way to add/edit Compute Resources on a Fabric Group or is there some other method I have to use in order to add/edit Compute Resources?

found this VRA 7.1 - API Calls to create Fabric Groups here in the forums either im not understanding whats being said or Compute Resources was not being addressed in that thread. If it was, can someone who has a better understanding please explain it better, thanks.

fabricGroups.png

0 Kudos
1 Reply
carlosaya
Contributor
Contributor

I know this is an old post, but it shows up in Google searches for this topic, so thought I would post the solution.  Fabric Groups are associated with compute resources via a link on the compute resource's entity object.  The code below can be used to setup the link...

 

// get entity objects for all fabric groups (a.k.a. "Enterprise Admin Groups")
var allFabrics = vCACEntityManager.readModelEntitiesBySystemQuery(vcacHost.id, "ManagementModelEntities.svc", "EnterpriseAdminGroups", null, null, null, null, null, null);

// Find the desired group.  In our case this is run as part of a workflow, so we have a dropdown input that lists all of our fabrics as "Fabric Name (Fabric GUID)"
// Find the selected fabric group's resource entity object
var fabricName = fabricGroupInput.split(" (")[0];
var fabricId = fabricGroupInput.split(" (")[1].split(")")[0];
for each (fabric in allFabrics) {
  if (fabric.entityKey.get("EnterpriseAdminID") == fabricId) {
    System.log("Found matching Fabric Group with ID: " + fabricId);
    var fabricGroup = fabric;
    break;
  }
}
if (!fabricGroup) throw "Unable to locate the specified Fabric Group: " + fabricGroupInput;

// Find the selected compute resource's entity object.  In our case this is run as part of a workflow, so we have a dropdown input that lists all of our compute resources as "Compute Resource Name (Compute Resource GUID)"
var computeResourceName = computeResourceInput.split(" (")[0];
var computeResourceId = computeResourceInput.split(" (")[1].split(")")[0];
for each (cr in computeResources) {
  if (cr.getProperty("HostID") == computeResourceId) {
    System.log("Found matching compute resource with ID: " + computeResourceId);
    var computeResource = cr;
    break;
  }
}
if (!computeResource) throw "Unable to locate the specified compute resource: " + computeResourceInput;


// If necessary, add the compute resource to the fabric group
if (computeResource.getProperty("IsVRMManaged") != true || computeResource.getLink(vcacHost, "EnterpriseAdminGroups")[0] == null) {
  System.log("Adding " + computeResourceName + " to fabric...");
  var properties = computeResource.getProperties();
  var links = computeResource.getLinks(vcacHost);

  // Set IsVRMManaged property, and configure link to add to fabric group
  properties.put("IsVRMManaged", true);
  links.put("EnterpriseAdminGroups", fabricGroup);

  // Update the compute resource's vCACEntity object
  var result = System.getModule("com.vmware.library.vcac").updateVCACEntity(vcacHost.id,
  computeResource.modelName, computeResource.entitySetName,
  computeResource.keyString, properties, links, null);

  System.debug(result);
}

0 Kudos