In a recent POC the customer had a special use case which I tackled singing vRealize Orchestrator and the Event Broker Service.

So, what was the use case?

Roll out a new Windows vSphere virtual machine using a custom hostname based on the machine type (Development=’dev0001‘, Test=’tst0001′, Production=’prd0001′, etc.). The hostname has to be the next available Computer Account in the Active Directory.

For example: a user requests a new Production machine and ‘prd1021′ is the latest Computer Account in the Active Directory, the new virtual machine will get hostname ‘prd1022′.

To accomplish this, I created a vRO workflow which will be used during vRA deployment of the VM triggered by the Event Broker.

 

Custom host name vRO workflow

The vRO workflow makes use of a custom property vm.name.convention which needs to be added to vRA and can be used during request. Also an Active Directory server has to be registered with vRO.

CustomHostname-01

The workflow performers the following tasks:

  1. Get VM property information from vRA;
  2. Get the vm.name.convention custom property;
  3. Uses the custom property to search the Active Directory for the latest Computer Account;
  4. Determines the new hostname for the VM (latest Computer Account +1);
  5. Updates the initial VM hostname property used by vRA with the new hostname.

Download the workflow here and rename it to ‘EBS Host Rename.workflow’

Note: The script to search the Active Directory splits the hostname in a prefix and number. These have a fixed size in the script. In my case the prefix is 5 characters long and the number is 4 digits (total of 9). This can be changed in the script if needed.

Configure the Event Broker and create a blueprint

Start the vRO client and import the Custom Hostname workflow.

CustomHostname-02

Edit the workflow and add your vRA IaaS- and Active Directory server to the Attributes.

CustomHostname-03

Save and Close the workflow.

Login to vRA and add a new custom property definition vm.name.convention. Make it available as a dropdown value during request. Under Predefined values you can add your VM naming convention related to machine type.

CustomHostname-04

CustomHostname-05

Create a new blueprint and give it a Name.

CustomHostname-06

In the Properties tab add the Custom Property vm.name.convention and select Show in Request.

CustomHostname-07

Drag and drop a Network component and a vSphere Machine on the canvas. Edit the properties of the components according to your environment. If you want the machine to be automatically joined with the Domain, use/create a vSphere Customization specification which takes care of this.

CustomHostname-08

Save the Blueprint and publish it.

Create a new Event Subscription to trigger the Custom Hostname workflow during request. Select Machine provisioning Topic.

CustomHostname-09

Add the following Conditions:

  1. Blueprint name -> Equals -> ..yourblueprintname..
  2. Lifecycle State Name -> Equals -> VMPSMasterWorkflow32.Requested
  3. Lifecycle State Phase -> Equals -> EVENT

CustomHostname-10

Select the Custom Hostname workflow.

CustomHostname-11

Finish the Subscription and publish it.

Testing the workflow

First check your Active Directory for existing Computers Accounts.

CustomHostname-12

Go to the Catalog and request the Blueprint using the Custom Hostname.

CustomHostname-13

In my case I select Machine type Productie which determines the VM hostname prefix to be ‘wpzkh’.

The latest available Computer Account with prefix wpzkh is wpzkh1005. The new VM hostname provisioned by vRA should be ‘wpzkh1006‘. So let’s check this.

The workflow is being triggered. So the Event Subscription is working correctly.

CustomHostname-14

The new Machine name is being updated by vRO and passed on to vRA. Under Managed Machines ‘wpzkh1006′ is visible.

CustomHostname-15

Mission completed!

Note: Thanks to Adam Bohle for helping me out with the vRO piece.

 


Bio Dimitri de SwartDimitri

Dimitri is a CMP Specialist SE with VMware and therefor responsible for positioning and supporting vRealize Automation, Operations, Business and Code Stream at customers and partners.

He is a 15 year IT veteran who started as a system administrator and grew to be a senior infrastructure consultant at a large dutch hospital. He has a broad infrastructure, virtualization and VDI background and is experienced in pre-sales, consultancy, design and implementation of complex infrastructures.

Dimitri’s LinkedIn profile.



Other articles in the series vRealize Automation: