How to provide VM lease date during the submission of VM build in VRA8 using ABX flow

Recently I was on working on scenario where we want to provide the lease date of VM at the time of submission. It is well known feature in 7.x which we get .


In VRA 8.x we can play with lease only with Day 2 actions.

With the help of extensibility you can provide the lease time during submission and use extensibility to trigger abx flow/ workflow as day 2.

The flow looks like below .

Here is my Yaml looks like.

formatVersion: 1
inputs:
  leaseDate:
    type: string
    title: Lease Date
    format: date-time
resources:
  Cloud_Network_1:
    type: Cloud.Network
    properties:
      constraints:
        - tag: 'vsphere:network'
      networkType: existing
  Cloud_vSphere_Machine_1:
    type: Cloud.vSphere.Machine
    properties:
      image: Images
      abxaction: 'yes'
      leaseDate: '${input.leaseDate}'
      cpuCount: 1
      totalMemoryMB: 1024
      awaitIp: false
      customizeGuestOs: false
      storage:
        constraints:
          - tag: 'vsphere:ds'
      constraints:
        - tag: 'vsphere:cluster'
      networks:
        - network: '${resource.Cloud_Network_1.id}'

Here us my Catalog log request will look like.

It is simple blueprint and catalog request where I am using date-time as format in input and will be using for my ABX flow .

Here is the quick look of both abx action in flow
1. VRAtoken
2. Extend Lesse

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def handler(context, inputs):
    vrafqdn = inputs['vrafqdn']
    username = inputs['username']
    password = inputs['password']
    refreshtokenurl = f"https://{vrafqdn}/csp/gateway/am/api/login?access_token"
    iaasUrl = f"https://{vrafqdn}/iaas/api/login"
    headers = {
        'accept': "application/json",
        'content-type': "application/json"
    }
    payload = f'{{"username":"{username}","password":"{password}"}}'
    apioutput = requests.post(refreshtokenurl, data=payload, verify=False, headers=headers)
    refreshtoken = apioutput.json()['refresh_token']
    iaasPayload = f'{{"refreshToken": "{refreshtoken}"}}'
    iaasApiOutput = requests.post(iaasUrl, data=iaasPayload, headers=headers, verify=False).json()['token']
    bearerToken = "Bearer " + iaasApiOutput
    print(bearerToken)
    outputs = {}
    outputs['vratoken'] = bearerToken
    return outputs
Here is another action of setting the lease.
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def handler(context, inputs):
    token = inputs['vratoken']
    vrafqdn = inputs['vrafqdn']
    deploymentid = inputs['deploymentId']
    print(token)
    print(deploymentid)
    leasedate = inputs['requestInputs']['leaseDate']
    url = f'https://{vrafqdn}/deployment/api/deployments/{deploymentid}/requests'
    headers = {
        'accept': "application/json",
        'content-type': "application/json",
        'authorization': token
        }
    data = {
        "actionId": "Deployment.ChangeLease",
        "inputs": {
            'Lease Expiration Date': leasedate
            }
        }
    jdata = json.dumps(data)
    apioutput = requests.post(url, headers=headers,data=jdata, verify=False)
    print(apioutput)
    print(apioutput.json())

Once we are done with creating the ABX action , we can create ABX Flow .

Here is the quick look for ABX flow

Once we are done with setting the flow , Last Part which is left is configuring the subscription.

Here is the quick look how my subscription looks like , we will be setting this on Deployment completed.

Disclaimer : My VRA lab has internet connectivity , so I can use any module online , you may need to make the action as module and zip it ,before you use as ABX action/flow . If you are using VRA Cloud then we can use as it is without any change.
Also This flow will trigger twice once ,One time failure is expected .

One thought on “How to provide VM lease date during the submission of VM build in VRA8 using ABX flow

  1. Pingback: Newsletter: 28 August 2021 – Notes from MWhite

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s