How to use Compute allocation & Network configure subscription to change the IP address and Rename of VM in VRA 8

As we talk about the automation in VM provisioning , One of the crucial step is to get the IP address from external source.

Recently I was working on used case where we want to provide the IP addresses at the time of submitting the provisioning.

There are multiple ways to do it in VRA and VRO . I am using VRA ABX Python action to achieve it.

Used Case: I want to submit more than one machine at time and provide the IP addresses at same time. For my example I am using 2 Machines here.

Subscription Used:

  • Compute Allocation
  • Network Configure

First Lets take a look at Blueprint’s Yaml where we define all custom properties.

formatVersion: 1
    type: string
    title: NewVMName1
    type: string
    title: NewVMName2
    type: string
    title: VM-1-IP
    title: VM-2-IP
    type: string
    type: Cloud.Machine
      firstVM: '${input.firstVM}'
      SecondVM: '${input.SecondVM}'
      VM1IP: '${input.VM1IP}'
      VM2IP: '${input.VM2IP}'
      abxaction: 'yes'
      count: 2
      image: VMwareCode-CentOS
      flavor: VMwareCode-small
        - network: '${}'
          assignment: static
    type: Cloud.vSphere.Network
      networkType: existing
        - tag: 'vsphere:network'

  • As we see above , I am using 4 Inputs as 2 VM names and 2 IP addresses in line 19-22
  • Line 23 we will use for condition in subscription
  • Also I am using static assignment in line 28-29
  • Line 35 is to Target the Network Profile where I have defined the Range

Once we are done with Blueprint, that is how it will look like when we click on Deploy

Since I am changing the name of VM and assigning the IP , I would need 2 ABX action
Below is the action is to change the VM Name as per Input

Below is the action Code in Python
def handler(context, inputs):
    firstVM = inputs['customProperties']['firstVM']
    secondVM = inputs['customProperties']['SecondVM']
    returnobj = inputs
    returnobj['resourceNames'][0] = firstVM
    returnobj['resourceNames'][1] = secondVM
    return returnobj

Here is the action for Assigning the IP addresses to correspond VMs.

Below is the python code for same
def handler(context, inputs):
    firstVMIP = inputs['customProperties']['VM1IP']
    SecondVMIP = inputs['customProperties']['VM2IP']
    outputs = {}
    addresses = [[]]
    outputs["addresses"] = addresses
    return outputs

If you have followed the article without missing any step, means you are done Python and Yaml code stuff.
Now all is left is Creation of the subscription If already not exist and Map to above created ABX python action.

To create the new Subscription follow below
Click on Cloud Assembly => Click Extensibility => Subscription = > Click New Subscription

Provide Name, enable Subscription and on Event Topic Choose Compute Allocation

If you noticed in YAML line number 23 I have specified the condition abxaction: yes

      abxaction: 'yes'

In subscription we are using that as condition to run and in action/workflow choose abx and above created action.

Click Save and we are done with Rename subscription.

Click New subscription once again and this time we will choose Network Configure subscription and network action , Rest all settings will be same.

so we have done all the coding and configuration , Now it is time to submit the VM provisioning request .

Once we submit this , You can check the outcome in action result or once vm allocation is done.

As we see the name as we submitted during provisioning, lets check the IP of each .

Both VMs got renamed and static IP which we entered has been applied to VMs.

Disclaimer: Indexing issue for multi Dimensional array has been fixed in 8.4.1, which was getting interchanged in 8.3 and 8.4

How to rename the VM during the Deployment in VRA/VRO7.6(vRealize Automation 7.x)

Often there are situations where we want to automate the name generation of the VMs and There are multiple ways to do that in VRA.

We can use Machine Prefix feature which is inbuilt in VRA . we can navigate to Portal by below
Infrastructure => Compute Resources => Machine Prefixes

Another way is to use the VRO , As we all know we can Integrate anything in VRO , all we need is plugin. Another used case we can do is to Integrate with naming server then pass the value to VRA for VM Name or if we want to specify on runtime.

Recently I was working on used case , where I want to provide the VM name at the time of submitting the request , that is what we are covering on this Post .

Here is my request/ Custom form look like.

Before start the VRO part lets complete the pre-requisite for VRA /VRO configuration .

  • Click on Blueprint and click on custom property tab and add the below properties as in the screenshot .
  • Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Requested value must be * .
  • VMNewName value must be blank .
  • Down the package from above and unzip the package .
  • Open VRO legacy Client .

Once VRO client is open , Change the view to Design and Import Package.

Choose the File which we download from above step.

Click open and Import the package certificate .

Select All files while importing.

  • Click Import selected elements
  • Once done we should be able to see the VMwareCode folder and Rename VM workflow.
  • Click on Rename VM workflow and click on edit
  • Click on Not SET for Host which is highlighted and choose the IAAS host from VRA plugin.
  • Click Select and Save and close and continue anyway — This step is required to get the value of VM and update the value
  • VRO configuration is done , Now lets configure the subscription in VRA.
  • To Configure the subscription login to vra and click on Administrator => Events => Subscription.
  • Click on New Subscription and choose the Machine Provisioning.
  • Click Next and Choose based on condition.
  • Click Next and Choose the workflow which we created in above step.
  • Click Next and choose the option for priority and blocking , Blocking means If workflow fails it will stop there and build will mark as failed.
  • Now Last step is left to create/edit the custom form for blueprint .
  • Go to the blueprint and click on custom form .
  • We will see the NewVMName field under the vSphere Machine section.

Once Done we are good to Test with provisioning
Note: I have choose HOST option also in my form which may not be available for you as this require separate configuration.

Here is the result of test provisioning.