vRA 7 – Getting more information in workflows from the vRO ExecutionContext object

When a vRO workflow or action is called from vRA, additional input parameters (in addition to those specified as the workflow/action inputs) are provided in the Execution Context object. These can be very useful as they contain additional data that can be used inside the workflows. A couple of good examples would be the user that requested the resource or the name of the tenant.

Here is a list of parameters provided inside the Execution Context (those without a description I’m still trying to figure out):

 Parameter Name  Description
__asd_catalogRequestId
__asd_correlationId  The Request ID
__asd_requestInstanceId
__asd_requestInstanceTimestamp Request Date & Time
__asd_requestInstanceTypeId The lifecycle ID
__asd_requestTraceId
__asd_requestedBy The UPN of the user who made the request
__asd_requestedFor The UPN of the user the request was on behalf of
__asd_targetResourceId
__asd_targetResourceProviderId
__asd_targetResourceProviderTypeId com.vmware.csp.iaas.blueprint.service
__asd_targetResourceTypeId Type ID, i.e. ‘machine’
__asd_tenantRef The friendly name of the tenant (i.e. vsphere.local)

Wait, where is ‘__asd_subtenantRef’? More on that in my post here (soon).

You can also see these in the variables tab for the workflow run:

List all parameters

The parameters and their values in the execution context object can be retrieved using the System scripting class. There is a method called ‘getContext()‘, which returns an object called ‘ExecutionContext‘. The ExecutionContext object has the following methods:

boolean contains(String name)
Object getParameter(String name)
Array parameterNames(String name)

Insert the following code into a scripting task in your workflow to list all the parameters and their values:

Retrieve the value for a specific parameter

To retrieve a value for a specified parameter the following example can be used:

Retrieves the tenant name and sets it to a variable/attribute.

If anyone can shed some light on what the other parameters do then please comment and I’ll update the page.

Resolve vRA/vCAC VM to vCenter VM

If you want to perform configuration tasks against a VM during the deployment process or even for Day 2 operations then you will need to resolve the vRA managed VM to a vCenter VM of type VC:VirtualMachine in your vRO workflows. I initially required this when applying tags to a VM during the BuildingMachine LifeCycle POST state, which involved using the VAPI endpoint.

vRO with the vRA plugin installed will make available two modules with some pre-defined actions .

  • com.vmware.vcac.asd.mappings
  • com.vmware.vcac.asd

findvcvmbyuuid

The two actions that we are interested in are ‘mapToVCVM‘ and ‘findVcVmByUuid‘. Let’s take a look at these two actions.

mapToVCVM

Inputs: VMProperties(Properties)
Return type: VC:VirtualMachine

This action has an input ‘VMProperties‘ of type ‘Properties‘, which is passed to it by the calling workflow or action. If you don’t know what this is, it is the vRA payload sent to vRO by the Event Broker Service (EBS). I’ll post another article at a later date on how I am doing this if you’re not sure. The first line of the script extracts the custom property ‘VirtualMachine.Admin.UUID’, which returns the unique UUID of the virtual machine (in previous versions of this action, the MoRef was used which is not unique across multiple vCenter Servers) and stores the value in ‘vmUuid‘.

The second line returns the result of ‘System.getModule(“com.vmware.vcac.asd”).findVcVmByUuid(vmUuid)’ of type VC:VirtualMachine. This code calls another module/action and passes ‘vmUuid‘ as an input (refer to the previous image if you’re unsure what is happening here and it should make sense). The result of this is returned to the original calling workflow/action as a VC:VirtualMachine type, which will be the vCenter managed VM object.

findVcVmByUuid

Inputs: VmUuid(String)
Return type: VC:VirtualMachine

This action has an input ‘VmUuid‘ of type ‘String‘. As you saw from the ‘mapToVCVM‘ action, this string is passed over with the value of the UUID for the virtual machine. The action then discovers the configured vCenter endpoints and performs a search on each for the VM until a result is found and returns it.

At this point you have probably worked out that you don’t need to use ‘mapToVCVM‘ at all and we could simply extract the UUID ourselves and then make a call to the ‘findVcVmByUuid‘ action.

Continue reading