Configuring a lower lease time for a vRealize Automation deployment

20161114-1Recently a customer I was working with had the need to ensure that deployments of a certain service category had a lower lease time than others. So all blueprints would have no maximum lease time configured, but if a customer chose a “DevTest” catalog item, then the lease time is set to seven days.

One way to achieve this would be to have a separate blueprint just for the DevTest environment. However I wanted to avoid blueprint sprawl, and this was explicitly not want the customer wanted. I also knew this was entirely achievable using vRealize Orchestrator.

High Level

The aim will be to change the lease time “in flight”, or during deployment. To do this, we will need the request ID, from which we will correlate to the deployment ID. Once we have that, we will list the available operations on that deployment, find the one to change the lease, and execute it.

To get the request ID we will use the System.getContent() method to retrieve the __asd_correlationId parameter. We will then use the vCACCAFEHost createCatalogClient() method to create an instance of the vCACCAFECatalogConsumerRequestService to retrieve a list of resources that correlate to the request ID.

From that, a list of resources will come back associated with that deployment. No matter how many there are, luckily the last one is always the deployment name and ID. From this we can find the CatalogResource, which will return a list of operations available on the deployment. Changing the lease will be one of them.

The conceptional workflow will look something like this:

Getting Started

Create a new workflow with the following attributes:

  • attDeploymentCatalogResource
  • attNumDays
  • attOperationName
  • attRequestId
  • attResourceId
  • attVcacCafeHost

attDeploymentCatalogResource should be of type vCACCAFE:CatalogResource, attNumDays of type number and attVcacCafeHost of type vCACCAFE:VCACHost. The remainder will be of type String. There will be no input or output parameters.

Enter a value of 7 for attNumDays, Change Lease for attOperationName and select your vRA host for attVcacCafeHost:

Select the Schema tab and drag a scriptable item onto the canvass. Rename it Get Request ID, and drag the attRequestId attribute across to make it an output:

Click on the scripting tab and paste in the following code:

//Get the request ID

attRequestId = System.getContext().getParameter("__asd_correlationId");

System.log("Request ID is: " + attRequestId);

Drag another scriptable task on and call it Get Resource ID. Drag attRequestId and attVcacCafeHost attributes in as inputs, and attResourceId as an output:

Paste in the following code:

//Create an instance of vCACCAFECatalogClient
var client = attVcacCafeHost.createCatalogClient();

//Create an instance of vCACCAFECatalogConsumerRequestService
var requestService = client.getCatalogConsumerRequestService();

//getResourcesProvisionedByRequest returns type vCACCAFEPagedResources .getContent() will return an array of vCACCAFECatalogResource
var resources = requestService.getResourcesProvisionedByRequest(attRequestId, null).getContent();

//Loop through results and set the resource ID
for (var i = 0; i < resources.length; i++) {
	if (i == resources.length -1) {
		attResourceId = resources[i].id;

Add another scriptable task called Get Catalog Resource, set attResourceId and attVcacCafeHost as inputs and attDeploymentCatalogResource as an output:

We will use the following code to get the catalog resource request:

//Get the catalog resource based on the ID
attDeploymentCatalogResource = vCACCAFEEntitiesFinder.getCatalogResource(attVcacCafeHost, attResourceId);
System.log("The catalog resource is: " +;

Now we need to add another piece of code to let the workflow pause for a couple of minutes while the deployments finishes.

This task needs no inputs or outputs, just the following code:


Finally, add the last scriptable task to the canvass. Call it Change Lease and drag attDeploymentCatalogResource, attNumDays and attOperationName in. No outputs are needed.

Paste in the following code:

//Set the new lease date
var newLeaseDate = new Date();
newLeaseDate.setDate(newLeaseDate.getDate() + attNumDays);
var myvCACCAFEDateTimeLiteral = new vCACCAFEDateTimeLiteral(newLeaseDate) ;

//Get all the operations that are available on the deployment
var operations = attDeploymentCatalogResource.getOperations();

//Get the change lease operation
for each (operation in operations) {
	System.log( + ": " + operation.getName() + " operation is available on this catalog resource")
	if (operation.getName().toLowerCase() == attOperationName.toLowerCase()) {
		System.log( + ": " + operation.getName() + " operation identified and selected");

//Change the lease
var inputs = new Properties();
inputs.put("provider-ExpirationDate", myvCACCAFEDateTimeLiteral);

Save and validate the workflow, confirming there are no errors.

vRealize Automation

The last task is to create a vRealize Automation Event Broker subscription to trigger the workflow. I would suggest using the VMPSMasterWorkflow32.MachineProvisioned lifecycle state.

Don’t forget to publish the subscription!

Once that has been configured, deploy a workload. All being well it should provision, then after a slight pause the lease should change:


Changing lease

All done!

Note: Another way to achieve this would be to pass the payload to vRO, and from that the machine properties. Once you have that, you could get the parent deployment. But hey, there’s more than one way to skin a cat…

One thought on “Configuring a lower lease time for a vRealize Automation deployment

  1. You could also do this at catalog item request completed ebs event and run it not blocking. That way it will work also and run once for multi VM deployments as well as single VM deployments.
    I usually run a loop with a 15 second sleep untill the deployment status is successful and then continue in the workflow.


Leave a Reply

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

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

Facebook photo

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

Connecting to %s

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