VMware Cloud Community
raptorirl
Enthusiast
Enthusiast
Jump to solution

using vCO to change the Lease time on a vRA VM

Hi there, looking for some help 🙂

Looking for an example workflow to  update the Lease on a vRA VM via vCO.

Basically, the 'Change lease' action , being unrestricted is of no use to us.. We want to ensure that the user can not extend the life of the VM beyond a specific point in time, ( be it number of days after it has been built, or not beyond a specific date) .

To that end would like to create an ASD action to attach to the VM, tht bit's fine, but it's the actual vCO workflow that I'm struggling with. I've 'googled' it and found a few references to a workflow to do this, but all the liks are to dead pages 😞 , does anyone have an example that  I could reference?

Thanks iin advance,

John.

1 Solution

Accepted Solutions
SeanKohler
Expert
Expert
Jump to solution

And to run it just from the actual workflow...

changeLease.jpg

changeLease2.jpg

changeLease3.jpg

changeLease4.jpg


View solution in original post

19 Replies
SeanKohler
Expert
Expert
Jump to solution

Heheh... I will quote myself from the other thread...

I suppose I have three ways you should be able to handle this, John.

Two use the vRA plugin service account in vRO which must have an entitlement to the builtin change lease action for machine types in the business group.

- One of these two uses the plugin API for the REST catalog-service:  (Using vCAC 6 REST APIs - Part 1 - Elastic Skies)  Part2 of this shows running an action.  I have done this with ChangeLease and it works fine.

- The other of the two uses one of the GA Library workflows: "Request a Resource Action".

In both of these you use an ASD form/workflow to capture all your relevant data to feed the request.  Some things to consider with the first is you need to capture the response of the REST call and determine if you succeeded or failed and pass that back to the calling request.

The third leverages any account entitled to the builtin change lease action for machine types in the business group and uses cloudclient. I am not 100% sure how to do this, but I am pretty sure it can be done.  Cloudclient is an execution wrapper to the REST services... and you would effectively use a Run Command capability in vRO to call out your change lease request.

I can give you very specific examples later if you need them.

Reply
0 Kudos
raptorirl
Enthusiast
Enthusiast
Jump to solution

Thanks Sean 🙂 , I did come across the Request a Resource Action, and could request the Change lease but couldn't seem to pass any properties to it?  ( prefer to avoid the Rest API if possible:-) ), so if you could expand on that option I think that'd be great!

I may also look at the CloudClient bit, (we were having some issues with non-admin users getting access to CI's that they could access via the GUI ).

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Sure... I will shoot something over in a little while.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

That should get you there...

You should look into REST more when you get some time.  It is actually easier than the API in general.

Sean

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

And to run it just from the actual workflow...

changeLease.jpg

changeLease2.jpg

changeLease3.jpg

changeLease4.jpg


raptorirl
Enthusiast
Enthusiast
Jump to solution

Many thanks Sean !

Realisezed I was looking at the wrong  workflow 🙂 ( was looking at the e'Invoke a post-provisioning action' rather than the 'Request a resource action'

This is perfect!.

     Regards,

     John,

Reply
0 Kudos
pizzle85
Expert
Expert
Jump to solution

Hey Sean. This workflow works perfectly. I'm attempting to bring it into vRA as a VM resource action with the VM as the input. I am fetching the vCACCAFE:CatalogResource object with

catalogResourceMachine = vCACCAFEEntitiesFinder.findCatalogResources(host, vm.name)[0];


that returns the catalog item properly but i don't see any operations on the item. If i just manually put the CatalogResource in the workflow attribute and run it i see all the operations. Any thoughts?

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

‌The account you use to connect the plugin in vRO to vRA (as seen in vRO inventory on the VCAC Host properties) must have an entitlement in the business group to see the actions for machine items (resources). I will link another post that shows this when I find it.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

‌>>>If i just manually put the CatalogResource in the workflow attribute and run it i see all the operations. Any thoughts?

Sorry... Using phone and missed this. I will look into it when I get back to the office.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Sorry about that... I got really busy.  I think maybe start here?  (this is the glue in the middle between conversion of your VM object to Resource object and using the Resource Operations)

Run the below workflow... and when you select the CatalogResource, expand the Actions at that time to validate Resource Operations are present.  After you select the CatalogResource, submit the workflow and validate the operations are collected into the array via syslog.

This works for me (If operations are there under Actions, they syslog).  If it doesn't work for you, there is probably an actual issue in your deployment/version.

consumerOps.jpg


Reply
0 Kudos
raptorirl
Enthusiast
Enthusiast
Jump to solution

Funnily enough, while I have the 'action' working , I'm experiencing the same problem when I try to update the lease via a workflow....

If I set the CatalogResource as an input to the workflow, it works. ( and I can drill down and see the actions on the VM in the inventory. I then used the same vCACvm to try doing it this way,, but getting different results),

If I use the following to do it, I see no Operations....

leaseDays=10;

var resources =Server.findAllForType("VCACCAFE:CatalogResource", vmName);

for each (resource in resources){

  break;

}

var VMname=resource.getName();

var VMlease=resource.getLease();

var StartD=VMlease.getStart();

var EndD=VMlease.getEnd();

//now update end of lease

EndD.setDate(StartD.getDate()+leaseDays);

var ops=resource.getOperations();    <------------- this returns null! so trying to get the 'Change Lease' action fails)

(note I do get the Start & End dates from the vCACCAFEResourceLease for this resource, so can't understand why i don't get the operations !)

PS...

As a side note, I was looking at doing it this way, because , my original thought was to

update the "Expires" property on the vCACvmEntity, and while this does update the Expire Date on the Entity, (as I can see that when query the properties after), It *does not* update what's displayed in the vRA GUI when you look at the Item. ( still shows the original lease & Expire date) . So the 'user' still thinks it's the old lease, ( and to be honest, I'm not sure which will be the actual expire date, will need to test)

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

This may fail....It will always break out on the first resource if more than one is found.

for each (resource in resources){

  break;

}

Also, at least in Java, this variable will only live in the for loop. I can't test this right now... but your "resource" might be null and not the getOperations().  Maybe not... but something to consider.

I always assign this way....

var resourceTarget;

for each (resource in resources){

     if (resource.getName()==vmName) {

          resourceTarget = resource;

          break;

     }

}

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

So... I ended up having some time.

I am seeing a similar problem.  Looking into it.  I think it has to do with getting the object through Server.findAllForType().

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

So yeah... both entitiesFinder and the Server find all for type don't get the object in the right way...

Let me know if this doesn't make sense...

// Using either Server.findAllForType or vCACCAFEEntitiesFinder.findCatalogResource doesn't get the object right

// but after getting the object, you can get the ID and then use the entities finder "getCatalogResource"

// method to get the object in the same way as supplying it as input.

var myResources = Server.findAllForType("VCACCAFE:CatalogResource",stringName);

//var myResources = vCACCAFEEntitiesFinder.findCatalogResources(cafeHost,stringName);

for each (resource in myResources){
if (resource.getName() == stringName){
  System.log(resource.getName());
  resourceTarget = vCACCAFEEntitiesFinder.getCatalogResource(cafeHost,resource.getId());
  System.log(resourceTarget.getName());
  for each (operation in resourceTarget.getOperations()){
   System.log(operation.getName());
  }
}
}

raptorirl
Enthusiast
Enthusiast
Jump to solution

Once again Sir, Thank you!

Reply
0 Kudos
raptorirl
Enthusiast
Enthusiast
Jump to solution

many thanks yet again Sean!

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

‌You're welcome. Glad you got it rolling!

Reply
0 Kudos
rszymczak
Hot Shot
Hot Shot
Jump to solution

I'll just copy & paste the answer I allready provided here trying to spread the information in as many related threads as possible so if anyone comes around here he/she might find the information.

there seems to be a bug with the vCAC Plugin for vRO anyways. Tested this with the vCACCAFE plugin version 6.2.1 and vCAC plugin version 6.2.1.

I'm using a shared session for both plugins and the plugin user has sufficient permissions. Also I'm able to see the actions listed for each item when browsing the plugin inventory.

The results I found don't make sense (yet) but seem to indicate a bug.

// This works if the vCACCAFE:CatalogResource is provided as workflow input parameter

var ops = item.getOperations(); // will return a Array containing all operations

for each (op in ops)

{

    System.log("Action: " + op.name);  // works

}

// But it fails, if the vCACCAFE:CatalogResource is dynamically collected using EntityFinder or other methods

bindingId = iaasVM.virtualMachineID;

cafeItems = vCACCAFEEntitiesFinder.getCatalogResources(cafeHost);

for each(item in cafeItems)

{

    if(item.getProviderBinding().getBindingId() == bindingId)

    {

        // The correct item is found and of type vCACCAFE:CatalogResource

        var operations = item.getOperations(); // however, this will ALWAYS return an empty Array!

    }

}

As you can see the plugin user seems to have sufficient permissions, because when calling item.getOperations() the array of operations is returned (first case). In the second case, where we dynamically search and find the item, the method will return an empty array.

Anyone at VMware has an eye on this?

As a workaround you may use somthing like this (removed exception handling for better readability) to get your operation object (took me 6 hours to find a working API call that is not bugged)

bindingId = iaasVM.virtualMachineID;

items = vCACCAFEEntitiesFinder.getCatalogResources(cafeHost);

for each(item in items)

{

    var itemBindingId = item.getProviderBinding().getBindingId();

    if(itemBindingId == bindingId)

    {

        var restClient = cafeHost.createRestClient(vCACCAFEServicesEnum.CATALOG_SERVICE);

        var response = restClient.get("consumer/resources/"+item.getId()+"/actions");

        var responseAsJSON = response.getBodyAsJson();

        for each (action in responseAsJSON.content)

        {

            if(action.bindingId === "Infrastructure.Virtual.Action.Destroy")

            {

                ressourceOperation = vCACCAFEEntitiesFinder.getCatalogResourceAction(item, action.id);

            }

        }

        break;

    }

}

Hope this helps.

Reply
0 Kudos
rkrichevskiy
Enthusiast
Enthusiast
Jump to solution

Is this still a working solution on 7.2? I get an error when using this approach:

400 BAD_REQUEST (Dynamic Script Module name : requestResourceAction#14)

Reply
0 Kudos