Set Deployment Name to VM Name

By | 7. July 2021

The most common use case implemented with vRealize Automation is classic Infrastructure-as-a-Service for VMs. vRealize Automation has the concept of a Deployment that can contain multiple objects incl. network, security and multiple VMs. Although this is the target architecture most of our customers are planning to reach, for many of them their first use case is deployment of a single VM. VRealize Automation requires the “Deployment Name” as a mandatory field to fill and most of the consumers have challenges to put the right value. In this case where there is a 1:1 relationship between Deployment and VM, IT departments often would like to use the same name for Deployment as for the virtual machine for easier navigation. Often this should be enhanced by a time stamp or ID.

This is no OOTB functionality in vRealize Automation but it can be achieved by the following procedure.

Get RefreshToken from vRA

See the documentation here how to get a refresh token.

If you prefer using Postman, you can use below command to get the refresh token as well:

 

Create ABX Constant/Secret

CloudAssembly: Go to Extensibility à Actions à Action Constants

Create an Action Constant that contains the api RefreshToken from previous step:

Create ABX Action

Cloud Assembly: Go to Extensibility à Actions à New Action

Specify Action Name, assign it to the right project and create the action

Insert below code and modify the yellow marked part based on your environment details:

import requests
import json

def handler(context, inputs):

    refreshtoken = context.getSecret(inputs["RefreshToken"])
    vrahost = "vra801.space.local"

# Request Bearer Token
    requesturl = "https://" + vrahost + "/iaas/api/login"
    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }

    requestbody = {
        'refreshToken': refreshtoken
    }   

    response = requests.post(url=requesturl, data=json.dumps(requestbody),headers=headers,verify=False)
   
responseJson = response.json()
    bearer = responseJson["token"]
    print(bearer)

# Modify Depoyment Name
    requesturl = "https://" + vrahost + "/deployment/api/deployments/" + inputs["deploymentId"]

    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer
    }

    requestbody = {
        'name': inputs["resourceNames"][0]
    }

    response = requests.patch(url=requesturl, data=json.dumps(requestbody),headers=headers,verify=False)
    print(response.json())

 

Add action constant and dependency as shown in below screenshot:

Save the action.

Create Subscription

Follow below screenshots and save the subscription:

 

Feel free to enable it for all projects.

Modify custom form (optional)

When all processes described before are in place, the user will have to provide a deployment name on blueprint request. Whatever he puts in will automatically be overwritten. However, this might be confusing for the user as he doesn’t know which purpose this field is for and what he must enter.

Therefore, several customers decide to hide that field/make it read only and/or add a default value. This can be achieved by following modifications in custom forms:

Be aware that if a constant default value is set it will prevent multiple requests for the same blueprint until the rewrite of the deployment name has happened. You might want to use an external source/Orchestrator Action instead. The Orchestrator Action could dynamically populate the default value and make sure that it is unique per request – e.g. by adding an ID or timestamp. I’ll not cover the related workflow in this blog post.

Have fun!

print
Christian Ferber
Latest posts by Christian Ferber (see all)
Category: Aria Automation Cloud Management Tags: , , ,

About Christian Ferber

Christian ist seit Juli 2015 bei VMware als Senior Systems Engineer für Enterprise Management tätig. Durch die Arbeit in diversen Cloud-Projekten auch in seinen vergangenen Tätigkeiten hat er Erfahrung im Bereich Rechenzentrumsthemen wie Server, Storage, Networking und Cloud-Management aufgebaut. Heute liegt sein Schwerpunkt im Bereich Automatisierung, Betriebsmonitoring bzw. Analyse und Verrechnung. Er betreut die vRealize Produktfamilie für Enterprise-Kunden in Deutschland.

4 thoughts on “Set Deployment Name to VM Name

  1. Robert

    Hi Christian,
    thank you for the post, thats a good way to archive the same computername and deploymentname.
    But wouldn’t it be easier to make the Computername to the Deploymentname? So you don’t need the Action, only the Custom Form.
    Br, Robert

    Reply
    1. Christian Ferber Post author

      Hi Robert,
      thanks for the feedback!
      Many customers do want to define their computer name by other means (e.g. external sources), so in my opinion it’s more efficient to set deployment name based on computername.
      Also deployment name can contain e.g. spaces which would need to be taken care of.
      Anyway there’s multiple ways achieving the goal. This blog shows what I have seen at customers so far.
      Regards,
      Christian

      Reply
  2. Damion

    Hi. I just tried using your example in vRA 8.10 and I’m getting that import request is not an available module.

    I was wondering if there was a simpler method to renaming a VM, for example, to lower a linux VM/hostname I use
    old_name = inputs[“resourceNames”][0]
    new_name = old_name.lower()

    outputs = {}
    outputs[“resourceNames”] = inputs[“resourceNames”]
    outputs[“resourceNames”][0] = new_name

    print(“Setting machine name from {0} to {1}”.format(old_name, new_name))

    return outputs

    So is there a way to set the deploymentName this way as well? Or is it required to update the deploymentName through the API?

    Reply
    1. Christian Ferber Post author

      Hi,
      the deployment name is an Aria Automation object and is independent to the VM name. To change the deployment name the only way is through Aria Automation API.
      So your code would just change the VM machine name, but it won’t do any changes to the deployment name.
      On the requests library:
      Make sure you name it as “requests” not “request” and also make sure you add it as dependency in the action properties (see screenshot in the blog). This will require that your Aria Automation has internet access.
      Hope, this helps.

      Regards,

      Christian

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.