qc4vmware
Virtuoso
Virtuoso

vRA 8 Extend a lease to it's max end date via API

I'm hoping there is an easy way to extend a lease to it's maximum possible date easily via a second day action.  We want to be able to create a one click lease extension where you don't need to figure it out.  Just max it based on your lease policy rules.  We're trying to setup an environment where there is a blanked policy that sets max lease time to a year but at anytime a user should be able to pop in and extend it and we pretty much always just want to max it and let them know the new end lease date.

0 Kudos
3 Replies
Dlally1
Contributor
Contributor

So we're setting lease based on user input, I know it's not what you asked.  But this is just an idea and you can probably modify it how you'd like. 

 

 

var leasedays = customProperties.get("leasedays")
var myCurrentDate=new Date();
var myFutureDate=new Date(myCurrentDate);
    myFutureDate.setDate(myFutureDate.getDate()+ leasedays);

System.log(myFutureDate);


var leaseDateFormatted = System.formatDate(myFutureDate,"yyyy-MM-dd'T'HH:mm:ss'.000Z'")
var leasedatestr = leaseDateFormatted.toString();
System.log(leaseDateFormatted);

var object = {
  "actionId": "Deployment.ChangeLease",
  "targetId": deploymentId,
  "inputs": {"Lease Expiration Date": leasedatestr}
}

var content = JSON.stringify(object);

var restClient = host.createRestClient();
var request = restClient.createRequest("POST",'/deployment/api/deployments/'+deploymentId+'/requests', content);
var keys = inputHeaders.keys;
for(var key in keys){
    request.setHeader(keys[key], inputHeaders.get(keys[key]));
    System.log("Value for key: "+keys[key] +" is: "+inputHeaders.get(keys[key]));
}
var response = restClient.execute(request);
qc4vmware
Virtuoso
Virtuoso

Thanks for the example and I think I've got a handle on changing the lease what I need to know is what are the rules of the current policy.  I could probably hard code this for now since we have only one lease policy in place but if there were more than one I'd need to set it to within the boundaries of the maximum runtime allowed.  So I guess I need to know how to get that "applied policy" information on the deployment via the api.  The policy api's look pretty sparse but I haven't dug into them so maybe what I'm looking for is in there?

0 Kudos
qc4vmware
Virtuoso
Virtuoso

So I think I found what I was looking for.  If pull the deployment action detail it lists all of the relevant information.  I can use the formatMaximum property and that should work!  I accidentally submitted a request with no expiration date and sure enough it used the default value of a year.  Not sure where that default came from but maybe it's always a year?

 

{

  "id": "Deployment.ChangeLease",

  "name": "ChangeLease",

  "displayName": "Change Lease",

  "description": "Set a deployment's expiration date",

  "schema": {

    "type": "object",

    "properties": {

      "Deployment expires in": {

        "type": "string",

        "title": "Deployment expires in",

        "readOnly": true,

        "default": "449d 20h 21m"

      },

      "Lease Expiration Date": {

        "type": "string",

        "title": "Lease Expiration Date",

        "description": "The lease can be extended by up to 0d 3h 38m",

        "format": "date-time",

        "formatMinimum": "2022-06-09T22:39:00Z",

        "formatMaximum": "2023-09-02T22:39:00Z",

        "default": "2023-09-02T19:01:00Z"

      }

    },

    "required": [

      "Lease Expiration Date"

    ]

  },

  "valid": true,

  "actionType": "RESOURCE_ACTION"

}

0 Kudos