sdeva
Contributor
Contributor

Update Lease date for a deployed VM from VRO

Jump to solution

I am trying to update the VRA Lease data (Expires) from the VcAC using VRO.  I am able to fetch the virtual machine entity and list all attributes, and I am using "add update from virtual machine entity" to update the Expires , workflow completes successfully but the value is not updated.

[2018-05-21 21:58:56.979] [I] Found existing property Expires

[2018-05-21 21:58:56.981] [I] Update entity id 89570 with property Expires : 2018-10-31T16:15:00.000-0700 on virtualMachine entity testvm

Can some one help me on how to update the Lease for a deployed VM using VRO

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
sdeva
Contributor
Contributor

Really Sorry for the delayed response, It worked fine after adding the entitlement.   Thanks for your help

View solution in original post

0 Kudos
6 Replies
Hejahida82
VMware Employee
VMware Employee

The way I do it is to use the Change Lease operation on the deployment object in vRA, which sets the expiry date for all objects in the deployment. In my case I do this at the end of provisioning requests to allow predefined lease options to be presented in a drop down on the request form for a single blueprint.

To get the Change Lease operation I use the following code where:

//deploymentCatalogResource is a vCACCAFE:CatalogResource object set to the deployment I want to update.

//operationName is a string set to 'Change Lease'

//inputs is a Properties object containing the inputs for the Change Lease operation

//newLeaseDate is a Date object representing the new expiration date I want to set

var myvCACCAFEDateTimeLiteral = new vCACCAFEDateTimeLiteral(newLeaseDate) ;

//Get all the operations that are available on the deployment

var operations = deploymentCatalogResource.getOperations();

//Locate the deployment change lease operation and store it

for each (operation in operations)

{

  System.log(workflow.currentWorkflow.name + ": " + operation.getName() + " operation is available on this catalog resource")

  if (operation.getName().toLowerCase() == operationName.toLowerCase())

  {

  System.log(workflow.currentWorkflow.name + ": " + operation.getName() + " operation identified and selected");

  break;

  }

}

var inputs = new Properties();

inputs.put("provider-ExpirationDate", myvCACCAFEDateTimeLiteral);

xpirationDate", myvCACCAFEDateTimeLiteral);

I then use the action (com.vmware.library.vcaccafe.request) requestResourceAction and pass in the operation and input variables. This initiates the Change Lease operation, I have a loop to check the status of this action to check whether it is still in progress or if it failed/succeeded with the option to retry it if it failed.

0 Kudos
sdeva
Contributor
Contributor

I am using the below code, For deploymentCatalogResource I am using vCACCAFE:CatalogResource  and passing the deployment. But I still have issues in updating the lease value.

var numberOfDaysToAdd = 30;
var leaseEndDate = "2019 -08-15T00:00:00.000Z";

var newLeaseDate = new Date();
newLeaseDate.setDate(newLeaseDate.getDate() + numberOfDaysToAdd);
System.log("new date:" + newLeaseDate);
var myvCACCAFEDateTimeLiteral = new vCACCAFEDateTimeLiteral(newLeaseDate) ; 
System.log("new date11:" + myvCACCAFEDateTimeLiteral);

var operations = deploymentCatalogResource.getOperations();  
System.log("operation value:" + operations);
for each (operation in operations) 

System.log(workflow.currentWorkflow.name + ": " + operation.getName() + " operation is available on this catalog resource") 
if (operation.getName().toLowerCase() == operationName.toLowerCase()) 

System.log(workflow.currentWorkflow.name + ": " + operation.getName() + " operation identified and selected"); 
break; 



var inputs = new Properties(); 
inputs.put("provider-ExpirationDate", myvCACCAFEDateTimeLiteral); 
System.log("operation value:" + operation);
System.getModule("com.vmware.library.vcaccafe.request").requestResourceAction(operation,inputs);

0 Kudos
Hejahida82
VMware Employee
VMware Employee

Hi sdeva​. I've copied and pasted your code into a test workflow in my lab and executed it against an existing deployment containing one network item and one Windows VM. It completed successfully, and the lease was updated on the deployment so there is nothing wrong with the code you are trying to use.

Can you clarify a few things so we can figure out why you are experiencing problems:

  • How are you trying to execute the workflow. Are you using it in an event broker subsciption, or just running it as a day 2 operation on an existing deployment
  • What error message if any are you getting when trying to run this
  • Do you see the change lease request submitted in vRA
  • What level of access to the target deployment does the account you have used for your vRA connection in vRO if using a Shared Session on the vRA connection have, does it have permissions to use the change lease action in vRA on that deployment. Iif using per user session on your vRA connection then what permissions does the account you are running the workflow as have.
0 Kudos
sdeva
Contributor
Contributor

I am trying on an existing deployment.

I don't see any errors workflow completes successfully, but when I log on to VRA and look for the expiry date it is not modified.

I don't see a request generated on the VRA.

0 Kudos
Hejahida82
VMware Employee
VMware Employee

Ok you should be seeing a change lease request in vRA. Obviously depending on the credentials you are using for the vRA connection it might not show up as being submitted by your account, so make sure you have the drop down in the top right set to All Groups I Manage. I assume you see the entry in the workflow log saying the request was sent like this:

[2018-05-26 11:27:15.852] [I] Update Lease: Change Lease operation is available on this catalog resource

[2018-05-26 11:27:15.867] [I] Update Lease: Change Lease operation identified and selected

[2018-05-26 11:27:15.873] [I] operation value:DynamicWrapper (Instance) : [vCACCAFEConsumerResourceOperation]-[class com.vmware.vcac.catalog.rest.stubs.ConsumerResourceOperation] -- VALUE : com.vmware.vcac.catalog.rest.stubs.ConsumerResourceOperation@47098c4f

[2018-05-26 11:27:15.914] [I] Getting resource action 'Change Lease' request form...

[2018-05-26 11:27:16.186] [I] Accepted inputs:

[2018-05-26 11:27:16.189] [I]  - provider-ExpirationDate

[2018-05-26 11:27:16.191] [I] Filling in resource action request...

[2018-05-26 11:27:16.193] [I] Sending resource action request...

[2018-05-26 11:27:16.939] [I] Resource action request '26e30e41-720f-4aa5-9ef7-bedc35b6e195' sent!

Try updating the workflow to log the status of the request. Replace the line

System.getModule("com.vmware.library.vcaccafe.request").requestResourceAction(operation,inputs);

with the following line

var leaseActionRequest = System.getModule("com.vmware.library.vcaccafe.request").requestResourceAction(operation,inputs);

Then add these lines

//Get the action request again to have the latest status

//cafeHost is the vCACCAFE:VCACHOST that the deployment resides on

var latestActionRequest = vCACCAFEEntitiesFinder.getResourceActionRequest(cafeHost, leaseActionRequest.getId());

//Extract the status of the action request

var stateName = latestActionRequest.getStateName();

System.log("Change Lease Request is currently in state: " + stateName);

That will print out the status of the request. I have a loop in my workflow which checks if the stateName value is Submitted or In Progress, waits for 10 seconds and then checks again. It repeats this until the status changes to a different value indicating it has completed.

0 Kudos
sdeva
Contributor
Contributor

Really Sorry for the delayed response, It worked fine after adding the entitlement.   Thanks for your help

View solution in original post

0 Kudos