VMware Cloud Community
Uridium454
Enthusiast
Enthusiast
Jump to solution

vCACEntityManager and provisioningGroupId

I am running into a bit of a snag attempting to retrieve the provisioningGroupId value while using vCACEntityManager.vCACEntityManager.readModelEntitiesBySystemQuery.  The goal of this is to retrieve the business group a given VM is owned by.  I am able to retrieve what appears to be all of the VMs VirtualMachineProperties with the exception of provisioningGroupId.  I can see said ID if I use LINQPad to explore.  I am hoping someone can shed some light on the subject, or perhaps provide a better means of obtaining the Business Group for a given VM.  Any assistance would be quite appreciated.

Code used below to show properties from VM (note: vm name hard coded below just for testing purposes):

var hostid = vCACHost.id;

var modelName = "ManagementModelEntities.svc";

var linkName = "VirtualMachineProperties";

var vmEntity = vCACEntityManager.readModelEntitiesBySystemQuery(hostid, modelName, "VirtualMachines", "VirtualMachineName eq enttst0062'");

var linkEntity = vmEntity[0].getLink(vCACHost, linkName);

for each(var l in linkEntity){

     System.log("key: " + l.getProperty("PropertyName"));

     System.log("value: " + l.getProperty("PropertyValue"));

}

Reply
0 Kudos
1 Solution

Accepted Solutions
Hejahida82
VMware Employee
VMware Employee
Jump to solution

Hi Uridium454​,

You have already got the code you need to get the provisioningGroupId which is now the business group id in vRA 7. This is the property named subtenantId within the VM properties you are retrieving.

Add an if statement into your code as part of the for each loop to check whether the property name is subtenantId, and if a match is found return the value of that property and you will have the business group id.

for each(var l in linkEntity){

  if(l.getProperty("PropertyName") == "subtenantId"){

       var businessGroupId = l.getProperty("PropertyValue");

       System.log("businessGroupId: " + businessGroupId);

  }

  else{

       continue;

  }   

}

View solution in original post

5 Replies
Hejahida82
VMware Employee
VMware Employee
Jump to solution

Hi Uridium454​,

You have already got the code you need to get the provisioningGroupId which is now the business group id in vRA 7. This is the property named subtenantId within the VM properties you are retrieving.

Add an if statement into your code as part of the for each loop to check whether the property name is subtenantId, and if a match is found return the value of that property and you will have the business group id.

for each(var l in linkEntity){

  if(l.getProperty("PropertyName") == "subtenantId"){

       var businessGroupId = l.getProperty("PropertyValue");

       System.log("businessGroupId: " + businessGroupId);

  }

  else{

       continue;

  }   

}

Uridium454
Enthusiast
Enthusiast
Jump to solution

Doh!  A complete oversight on my part.  I forgot about the subtenantId.  Thank you so much for your quick response.  I went back to look at my output, and guess what was hanging out waiting for me?  :smileysilly:

Thanks again!

Reply
0 Kudos
Uridium454
Enthusiast
Enthusiast
Jump to solution

Just out of curiosity, is there a delay from the time a machine is provisioned in which you can populate this value?  I have tested on machines that have been created for some time and I am able to pull the subtenantId without issue, however when attempting to perform this action on a newly created vm, the value is not retrieved.  I have verified the value is populated in the VirtualMachineProperties in LINQPad.

Reply
0 Kudos
Hejahida82
VMware Employee
VMware Employee
Jump to solution

Not sure, I used an old VM to test it on as well but I can't think of a reason why it would not be populated immediately after the VM was created.

When using the business group id in vRO I normally use the vRA Catalog Resource object to retrieve the business group name/id rather than pulling it from the IaaS vCAC VM object. This value is available immediately after the catalog request to provision the VM is completed successfully in vRA.

Here is the code I use in an action to get the catalog resource from the vCAC VM object, you need to pass in the vCACCafeHost (vCACCAFE:VCACHOST object) and the vCACVm (VCAC:VirtualMachine object) as the inputs to the action. The return object is an array of vCACCAFE:CatalogResources.

//get the Id of the provisioned vCAC virtual machine which will be the filter for the search

var catalogResources = new Array();

var bindingId = vCACVm.virtualMachineID;

System.debug("bindingId is: " + bindingId);

//build the Odata query and filter using the binding id

var service = vCACCafeHost.createCatalogClient().getCatalogConsumerResourceService();

var filter = new Array();

filter[0] = vCACCAFEFilterParam.substringOf("providerBinding/bindingId",vCACCAFEFilterParam.string(bindingId));

var query = vCACCAFEOdataQuery.query().addFilter(filter);

//now perform the query to get an array of catalog resources with a matching id to our VM

var catalogResources = service.getResourcesList(new vCACCAFEPageOdataRequest(query));

System.debug(catalogResources.length + " " + "catalog resources were found");

return catalogResources;

That returns an array of catalog resources, but if the search has worked there should only be one entry in the array. Then you can get the business group id using

catalogResources[0].organization.getSubtenantRef());

May not be suitable for the scenerio you are working with but thought it would be worth including it as a reference.

Uridium454
Enthusiast
Enthusiast
Jump to solution

This method seems to be a more logical approach to what I am attempting to do.  I wasn't quite sure how to retrieve the data using a vCAC vm, so I started digging in the other direction.  I ran the provided script, and got the results I was after on the newly created machine.  I ran through the other script I was working on, and was getting the same null value result.  Thank you very much for the follow up script. 

Reply
0 Kudos