When it comes to automation and further customization of the vRA managed VMs we can’t overlook the vRA 7.x Event Broker. It gives us the opportunity to trigger a vRO workflow when one or multiple conditions are met. In most use cases the information regarding the object that triggers the workflow needs to be used in the vRO workflow. This article aims to explore how to pass basic and custom properties from vRA to vRO.
Event subscription
For the purpose of this example we will create a new subscription which will trigger a workflow after VM provisioning.
First step would be to prepare the vRO workflow. In this case we only need one input parameter of type Properties.
We will work with and print the received information from vRA via one Scriptable task.
Make sure to add the Properties parameter to the IN section of the Scriptable task in order to have access to it.
Now we are ready to create our subscription.
- From vRA select Administration -> Events -> Subscriptions and select the green plus icon to add new.
- Select an event topic. On the left hand side are listed the available options to select and on the right side there are details about the selected topic. The information carried by this event is shown under the Schema.
Select Machine Provisioning and click Next. - As mentioned above, we want to trigger a workflow after VM provisioning. To achieve that, on the Conditions tab select the following:
Property Operator Value Data > Machine > Machine type Equals Constant > Virtual Machine Data > Lifecycle state > Lifecycle state name Equals Constant > VMPSMasterWorkflow32.MachineProvisioned Data > Lifecycle state > State phase Equals Constant > POST
Once ready, click Next. - On the Workflow tab browse to the workflow you want to be executed. On the right side you’ll see a brief summary of the workflow.
Select the desired workflow and click Next. - Specify name and description for the new subscription on the Details tab and click Finish. The rest of the fields in this tab are beyond the scope of this article.
- Don’t forget to Publish the subscription after it’s ready.
At this point we have created our subscription which will trigger specific workflow after VM Provisioning. Let’s move on with reading the information passed from vRA Event Broker to vRO.
Basic properties
Based on the Schema of the carried info from vRA showed above, here is an example of reading two of the basic machine properties – Name and MoRef (Managed Object Reference).
First, let’s add the following code to the Scriptable task:
var machine=payload.get("machine"); System.log("VM name: "+machine.get("name")); System.log("VM MoRef: "+machine.get("externalReference"));
Once new VM is provisioned from vRA the result from the workflow should look like this:
Custom properties
Below is expanded view of part of the Schema shown in the Event Subscription section.
By default, the data in machine -> properties is not carried out. To do so, we need to add a custom property to the blueprint.
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.MachineProvisioned
For the value we can use either:
- * – to pass all data
- Property name – to pass only specific property
In addition, I have prepared two custom properties with predefined list of values and assigned them to the blueprint. The final Properties tab looks as follows:
Next we need to edit the Scriptable task in the vRO workflow and add the following code:
var vmProperties = machine.get("properties"); for each (var key in vmProperties.keys) { System.log("Key: "+key+" Value: "+vmProperties.get(key)); } System.log("Selected purpose: "+vmProperties.get("Purpose")); System.log("Selected team: "+vmProperties.get("Team"));
The for each cycle will print all properties and their values.
The last two lines will print only the specified properties.
Now, let’s request new VM from this blueprint, selecting values for the custom properties:
Once the VM is provisioned, we can check the workflow results:
As you can see, besides the custom added properties, there are multiple built in. It’s recommended to use specific prefix for the custom properties to avoid overlapping.
Having access to additional VM information can help you to further automate your VM provisioning activities.
Your ideas and comments are always welcome!
Ivaylo Ivanov
Latest posts by Ivaylo Ivanov (see all)
- Runecast Analyzer plugin for vRO - September 11, 2017
- Unattended Deployment and Configuration of OVA - August 8, 2017
- Point to vAPI Endpoint with JavaScript in vRO - February 15, 2017
Thanks Mate! as I finally started to play with vRA recently, was looking for the way how to execute command on the remote ssh host with some variables. Was surprised this isn’t there out of the box.
Excellent.
Is it possible to edit/update the values of keys in the payload in one EBS workflow so that the next EBS workflow gets an updated value?