vRA Developer: Part 2 – Dynamically Discover vCAC and vCACCAFE endpoints in vRO


When I work with endpoints in vRO, I like to use actions to discover these instead of hard coding them as attributes or within configuration elements. Hard coding of these endpoints requires manual configuration steps when moving code between environments, which is not ideal. I felt it would be a good idea to include this post early on within this series, as these hosts are often dependencies when working with a lot of my code.

All code that I have provided or talked about in this post can be downloaded as a vRO package for your consumption here.

Discover vRealize Automation Infrastructure (vCAC IaaS) Endpoint

You will generally only have a single vCAC IaaS endpoint in your vRO inventory. I have never worked in an environment where there was more than one. Therefore, the action I have created below requires no inputs and will attempt to discover this single vCAC IaaS endpoint. If you have more than one host for some reason then it should be fairly easy to incorporate this.

/*global System Server*/

/**
 * Searches the vRO inventory for any instance of a vCACHost object and returns it.
 * Note that this action assumes that only a single vCACHost is present (as is usually the case).
 * @author Gavin Stephens <gavin.stephens@simplygeek.co.uk>
 * @version 1.1.0
 * @function getVcacHost
 * @returns {vCAC:vCACHost} returns the vCAC host object.
 */

var logType = "Action";
var logName = "getVcacHost";
var Logger = System.getModule("com.simplygeek.library.util").logger(logType, logName);
var log = new Logger(logType, logName);
var vcacHosts = [];
var vcacHost;

try {
    log.log("Locating vCAC IaaS Host...");
    vcacHosts = Server.findAllForType("VCAC:VCACHost");
    if (vcacHosts.length === 1) {
        vcacHost = vcacHosts[0];
        log.log("Found vCAC IaaS host: " + vcacHost.name + " [" + vcacHost.url + "]");
    } else if (vcacHosts.length > 1) {
        log.error("More than 1 vCAC IaaS host was found, which this action does not support.");
    } else {
        log.error("Unable to find vCAC IaaS host from the vRO plugins.");
    }
} catch (e) {
    log.error("Failed to locate vCAC IaaS Host.",e);
}

return vcacHost;

Log output:

[] [I] [Action: getVcacHost] Locating vCAC IaaS Host...
[] [I] [Action: getVcacHost] Found vCAC IaaS host: IaaS host for Default [https://web.vra.sgroot.local/]

Discover vRealize Automation (vCACCAFE) Endpoint

If you are running a multi-tenant vRA environment but using a single vRO appliance for these tenants or have multiple tenants sharing the vRO appliance, then there will be multiple vCACCAFE endpoints, one for each tenant. The following action takes the tenant id as an input and will discover the vCACCAFE endpoint.

/*global System Server tenantId*/

/**
 * Searches for the vCACCAFE:VCACHost that is associated with the provided tenent and returns it.
 * @author Gavin Stephens <gavin.stephens@simplygeek.co.uk>
 * @version 1.1.0
 * @function getVcacCafeHost
 * @param {string} tenantId - The tenant identifier.
 * @returns {vCACCAFE:VCACHost} The vCACCAFE:VCACHost object for the tenant.
 */

function checkParams(tenantId) {
    var inputErrors = [];
    var errorMessage;
    if (!tenantId || typeof tenantId !== "string") {
        inputErrors.push(" - tenantId missing or not of type 'String'");
    }
    if (inputErrors.length > 0) {
        errorMessage = "Mandatory parameters not satisfied:\n" + inputErrors.join("\n");
        log.error(errorMessage);
    }
}

var logType = "Action";
var logName = "getVcacCafeHost";
var Logger = System.getModule("com.simplygeek.library.util").logger(logType, logName);
var log = new Logger(logType, logName);
var vcacCafeHosts = [];
var vcacCafeTenantHosts = [];
var vcacCafeHost;

try {
    checkParams(tenantId);
    log.log("Locating vCAC Cafe Host for tenant: " + tenantId);
    vcacCafeHosts = Server.findAllForType("VCACCAFE:VCACHost", tenantId);
    vcacCafeTenantHosts = vcacCafeHosts.filter(function(x){return x.tenant === tenantId;});
    if (vcacCafeTenantHosts.length > 0) {
        vcacCafeHost = vcacCafeTenantHosts[0];
    } else {
        log.error("Unable to find vCAC Cafe host for tenant: " + tenantId);
    }
    log.log("Found vCAC Cafe host: " + vcacCafeHost.name + " [" + vcacCafeHost.url + "] [" + vcacCafeHost.tenant + "]");
} catch (e) {
    log.error("Action failed when attempting to find vCACCAFE:VCACHost for the provided tenant.",e);
}

return vcacCafeHost;

Log output:

[] [I] [Action: getVcacCafeHost] Locating vCAC Cafe Host for tenant: sg
[] [I] [Action: getVcacCafeHost] Found vCAC Cafe host: Simplygeek [https://vra.sgroot.local] [sg]

I hope this has been helpful. If you discover bugs with any of my code, require some help or simply need an ad-hoc solution, then please drop me a message via the Drift app.

0 0 votes
Article Rating

Related Posts

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments