aenagy
Hot Shot
Hot Shot

How to reference vRA machines from vRO [vRA + vRO 7.5]

I have been asked to update the IaaS machine description field with the vRA request number.  Updating the description field of the deployment request seems easy enough. First I need to find the machine(s) within vRA.

I can easily find the vRA catalog request using either vCACCAFEEntitiesFinder.getCatalogItemRequest( cafeHost , requestId ) or cafeHost.createRestClient( vCACCAFEServicesEnum.CATALOG_PROVIDER_SERVICE ).get( "consumer/requests/" + requestId ). Looking inside the result I can see the object 'requestData' which contains the machines. These machines don't seem to have an ID that I can use to find or reference them.

Is there a way to reference the individual machines within the request? If so how?

Thanks in advance.

0 Kudos
1 Reply
Hejahida82
VMware Employee
VMware Employee

I'm not sure reading your question whether you are looking for the deployment object or the VMs inside the deployment and what format you need but its possible to get each of these.

If you have the catalog request id and the cafe host then you can get the vCACCAFE:CatalogResource objects provisioned by the request. From the catalog resource for the VM you can get the IaaS VM object VCAC:VirtualMachine if you need that object.

To get the catalog resources I use this action against a vRA request (IaaS not XaaS request). Inputs are the vRA request id (requestId type string) and the vRA appliance (vCACCAFEHost type vCACCAFE:VCACHost). The action returns an array of vCACCAFE:CatalogResource objects which are the VMs provisioned by the request.

System.log("request id at the start of action: " + requestId);

System.log("host at start of action: " + vCACCAFEHost);

if(requestId){

var vmCatalogResources = new Array();

//create an instance of vCACCAFECatalogClient to make REST calls to vRA

var client = vCACCAFEHost.createCatalogClient();

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

//create an instance of vCACCAFECatalogConsumerRequestService, the api service responsible for catalog requests

var requestService = client.getCatalogConsumerRequestService();

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

//get resources provisioned by the request. This call returns type vCACCAFEPagedResources, .getContent() will return an array of vCACCAFECatalogResource objects

var catalogResources = requestService.getResourcesProvisionedByRequest(requestId, null).getContent();

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

//check each of the resources found to check if it is a virtual machine object and push it to the return array if it is

for each(var resource in catalogResources){

if(resource.resourceTypeRef.getLabel() == "Virtual Machine"){

System.log("Found a virtual machine object associated with the request. The VM name is: " + resource.name);

vmCatalogResources.push(resource);

}

else{

continue;

}

}

return vmCatalogResources;

}

else{

throw "No IaaS request id was passed in to the action to retrieve the IaaS provisioned resources. Unable to continue.";

}

Then if you need the IaaS VM object you can use this action to retrieve the VM for a catalog resource. Input is the catalog resource you want to find the IaaS VM object for (catalogResource type vCACCAFE:CatalogResource) and the output is a vCAC:VirtualMachine object.

var resourceId = catalogResource.getId();

var resourceType = catalogResource.getResourceTypeRef().getLabel();

var providerBinding = catalogResource.getProviderBinding();

var bindingId = providerBinding.getBindingId();

var provider = providerBinding.getProviderRef();

//check this is a VM object

if((resourceType == 'Virtual Machine') && (provider.getLabel() == "Infrastructure Service")){

System.log("IaaS VM found");

var vm = Server.findForType("vCAC:VirtualMachine",bindingId);

return vm;

}

If you actually want the deployment resource then you can use the resourceType of 'Deployment' and the label of 'Blueprint Service' rather than the values of 'Virtual Machine' and 'Infrastructure Service' used in the current code.

0 Kudos