You can get request resources via the API. This is similar, but via a REST call.
incoming parameter from event subscription:
- payload
// get the vRA vCAC IAAS Host endpoint (one Tenant = one vCACCAFE host)
var vCACHosts = Server.findAllForType("VCAC:VCACHost");
if (vCACHosts.length > 1) {
System.warn('More than one tenant. Using first tenant ...');
}
var vCACHost = vCACHosts[0];
System.debug('Connected to vCACHost: ' + vCACHost.name + ' (' + vCACHost.url + ')' );
// get vRA vCACCAFE Host endpoint
var vCACCafeHosts = Server.findAllForType("vCACCAFE:VCACHost");
if (vCACCafeHosts.length > 1) {
System.warn('More than one vCAC Cafe host. Using first host ...');
}
var vCACCafeHost = vCACCafeHosts[0];
System.debug('Connected to vCACHost: ' + vCACCafeHost.name );
// create REST client on vRA host:
var requestId = payload.get('catalogRequestId');
var httpClient = vraHost.createCatalogClient();
// get the resources that are a part of the catalogRequestId
var httpResp = httpClient.get("/consumer/requests/" + requestId + "/resources").getBodyAsJson();
// get the VMs from the response resources. Store the vm name and id in vmInfoArr[]
var vmInfoArr = [];
var deploymentName = "";
for (var x in httpResp.content) {
var resource = httpResp.content[x];
// Infrastructure.Virtual = VM
if ( resource.resourceTypeRef.id == "Infrastructure.Virtual") {
// construct an array to hold the VM info that we want to store and save it to vm_list for later use
var vmInfo = [];
vmInfo['name'] = resource.name;
vmInfo['id'] = resource.id;
vmInfoArr.push(vmInfo);
}
// get the deployment
if( resource.resourceTypeRef.id == "composition.resource.type.deployment") {
deploymentName = resource.name;
}
}
Syntax to get VM from vRO 7.6 via REST from Ansible Automation Platform or a terminal (curl or wget):
{{vRAFQDN}}/catalog-service/api/consumer/resources?$filter=name+eq+%27%24vmmachinename%27
previous page
|