VMWarevRAvRO

Change Lease Date – Day2 Operation in vRA

Overview

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:

 

/**
* This is Day-2 Operation part of the vRA Entitlements action.
* @param {vc:VirtualMachine} vcVm – The virtaul machine of vCenter.
*/

 

System.log(“\n================================”);
System.log(“\n START: Lease Day Configuration.”);
System.log(“\n================================”);

//var machine=payload.get(“machine”);
//System.log(“VM name: “+machine.get(“name”));
//System.log(“VM MoRef: “+machine.get(“externalReference”));
//vmName = machine.get(“name”);
vmName = vcVm.name;

// Number days to Add (Lease days).
var numberOfDaysToAdd = 10;
var myResources = Server.findAllForType(“VCACCAFE:CatalogResource”, vmName);

for each (resource in myResources){
if (resource.getName() == vmName){
catalogResourceName = vCACCAFEEntitiesFinder.getCatalogResource(cafeHost,resource.getId());
catalogResourceMachine = catalogResourceName = vCACCAFEEntitiesFinder.getCatalogResource(cafeHost, catalogResourceName.parentResourceRef.getId());
System.log(“catalogResourceMachine = ” +catalogResourceMachine);
}
}

var operations = catalogResourceMachine.getOperations();

for each (op in operations){
System.log(op.getName());
if (String(op.getName()) == “Change Lease”){
System.log(op.getName());
operation = op;
System.log(“operation = ” +operation);
}
}

//System.log (operation.getName() + ” for machine resource ” + catalogResourceMachine.getName() + ” was selected.”);

var newLeaseDate = new Date();
newLeaseDate.setDate(newLeaseDate.getDate() + numberOfDaysToAdd);
System.log(“Setting new lease date to ” + newLeaseDate);

var myvCACCAFEDateTimeLiteral = new vCACCAFEDateTimeLiteral(newLeaseDate);

var inputs = new Properties();
inputs.put(“provider-ExpirationDate”, myvCACCAFEDateTimeLiteral);

//var result = System.getModule(“vra.nus.action”).requestResourceAction(operation,inputs);
var result = System.getModule(“com.vmware.library.vcaccafe.request”).requestResourceAction(operation,inputs);

System.log(“result =” +result);
System.log(“\n==============================”);
System.log(“\n END: Lease Day Configuration.”);

System.log(“\n==============================”);

Tags

Related Articles

Leave a Reply

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

Close