vRealize (vCAC) and vCenter Orchestrator workflow to change the machine name before building the machine

This workflow allows you to change the machine name for a vRealize Automation Virtual Machine during the build process. It is based on the articles series on the VMware Blog created by Ted Sprinks. (link) That series of three articles is very good, but it might be a bit lengthy if you just need this one single workflow. Also I use this article during my vRealize Automation Training when students would like to run  an additional example workflow in their lab environment.

The workflow is available as a downloadable package: BuildingMachineChangeHostname.zip

After importing the package in vRealize Orchestartor follow the steps in this article to assign the workflow to a blueprint as a state change workflow.

But first here is the contents of this workflow. It is actually just one scriptable task:

vRA VM Change Hostname

The contents of the scriptable task is in the image below and the script's source is also added. The input  and output for the script is the virtualMachineEntity, which is of the vCAC:Entity variable type.

vRA VM Change Hostname

Here is the script for your reference:

//Get the properties of the vCAC VM Entity object (different than vCAC custom properties)
var vmEntityProps = virtualMachineEntity.getProperties();

//set the new hostname, change this to your needs, add your own logic
//this example just adds a VM- prefix
var oldname = vmEntityProps.get('VirtualMachineName')
var newname = "VM-" + oldname;

//remove the log entry when everything works and you don't need this for debugging and troubleshooting
System.log("Updating VirtualMachineName to '" + newname + "'.");

//Change the VirtualMachineName property by deleting it and re-adding it
vmEntityProps.put('VirtualMachineName', newname);

//Update the Entity object to save the change
var hostId = virtualMachineEntity.hostId;
var modelName = virtualMachineEntity.modelName;
var entitySetName = virtualMachineEntity.entitySetName;
var entityIdString = virtualMachineEntity.keyString;
var actionResult = System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId,modelName,entitySetName,entityIdString,vmEntityProps,null,null);

//remove the log entry when everything works and you don't need this for debugging and troubleshooting
System.log("Update of VirtualMachineName finished.");

Adding the workflow to a Blueprint

To execute the workflow when you build a new machine assign the workflow to a blueprint with the default workflow that exists if you have the vRealize Automation Plug-in installed in vRealize Orchestrator. It is in the library under vCloud Automation Center in v6.x or in vRealize Automation for v7.

vRA VM Change Hostname

Make sure to select the BuildingMachine workflow stub to enable because we want to change the host name before the provisioning takes place.

vRA VM Change Hostname

Following the wizard you will next select one or more blueprints to assign this workflow to.

vRA VM Change Hostname

In the next step select the BuidlingMachineChangeHostname workflow as the workflow that will be added to the blueprint's properties.


vRA VM Change Hostname

Now if you request a machine from the blueprint the vRealize Orchestrator workflow will be executed and the hostname being used in the provisioning process is updated.


vRealize Orchestrator Articles on this website

Follow us on LinkedIn




Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer