VMware Aria Automation Blog

from Stefan Schnell

Source code for any runtime environment of Aria Automation can also be used independently from the appliance. This allows us to create scripts that runs inside of and outside from Aria Automation. So it could be necessary to detect whether the source code is executed in Aria Automation or not.

Detect if Script is Executing in Aria Automation


JavaScript

The Rhino engine is used in the JavaScript runtime environment of Aria Automation. It works directly on the orchestration appliance. That is why the environment variables of Aria Automation can be read and this is very interesting. When the command printenv is entered in a terminal window, many fewer environment variables are displayed than when the same command is executed in an action.

/**
 * This approach works until release 8.16.2
 */

var command = new Command("printenv");
command.execute(true);

var commandOutput = command.output;
System.log(commandOutput);

When the code above is executed, many environment variables were displayed that were specific to Aria Automation. Here a selection:

/**
 * ABX_SERVICE_PORT
 * ABX_SERVICE_SERVICE_HOST
 * ORCHESTRATION_UI_PORT
 * ORCHESTRATION_UI_SERVICE_HOST
 * TENANT_MANAGEMENT_UI_PORT
 * TENANT_MANAGEMENT_UI_SERCICE_HOST
 * VCO_CONTROLCENTER_SERVICE_PORT
 * VCO_CONTROLCENTER_SERVICE_SERVICE_HOST
 * VCO_SERVICE_PORT
 * VCO_SERVICE_SERVICE_HOST
 */

So I tested the following tiny snippet:

var VcoControlcenterServicePort = 
  java.lang.System.getenv("VCO_CONTROLCENTER_SERVICE_PORT");

if (VcoControlcenterServicePort === null) {
  System.log("VcoControlcenterServicePort not set");
} else {
  System.log(VcoControlcenterServicePort);
}

vmware aria automation action to detect environment with result
It delivers in the context of Aria Automation a result, and in the context of a simulation null.

linux terminal with script to detect environment with result
This seems to be a valid approach to differentiate whether a program is executed in the context of the JavaScript runtime environment of Aria Automation or not.

Python

The Python runtime environment of Aria Automation is executed in a container. To detect whether the script is executed in Aria Automation it is first checked whether the code runs in a Linux environment. If this is the case, it is checked whether it is a VMware Photon OS. If this is also the case, it is checked whether the host name begins with vco-app-, this identifies the orchestration appliance.

import os
import platform
import subprocess

def isAriaAutomation():

    ariaAutomationFlag = False

    try:

        if (platform.system().lower() == "linux"):

            stdout = b""
            stderr = b""

            command = ["cat", "/etc/photon-release"]
            cmd = subprocess.Popen(
                command,
                stdout = subprocess.PIPE,
                stderr = subprocess.PIPE
            )
            stdout, stderr = cmd.communicate()

            if "vmware photon os" in stdout.decode("utf-8").lower():

                hostName = os.environ["HOSTNAME"]
                if (hostName):
                    if (hostName.startswith("vco-app-")):
                        ariaAutomationFlag = True

    except:
        pass

    return ariaAutomationFlag