VMware Cloud Community
michael_stefani
Enthusiast
Enthusiast
Jump to solution

Can't set lease with ASD

I've seen the property "provider-VirtualMachine.LeaseDays" documented on various blogs as a way to set the lease if requesting through REST or ASD.  I'm using ASD and calling the RequestCatalogItem through a custom blueprint.  Using the command below "VirtualMachine.LeaseDays" does get set as a custom property for the machine, but it doesn't seem to be enforced correctly.  Whatever the lease is for the base blueprint that's what gets set on the VM.  Anyone found a workaround for this?

inputs.put("provider-VirtualMachine.LeaseDays", new vCACCAFEIntegerLiteral(14).getValue());

Reply
0 Kudos
1 Solution

Accepted Solutions
SeanKohler
Expert
Expert
Jump to solution

Well... it is an example workflow and the script is documented.

It would run in either case... but you will want to understand and tailor the script to do what you want.

Basically, there is a workflow in the VCAC portion of the Library workflows that allows you to perform a resource operation request on a catalogresource.  You can literally just run it and supply the values... if you see the Operation for Change Lease, then your service account for the plugin to vRA is configured properly in your BusinessGroup to see the ChangeLease Action.  (it can be the only one that sees it if you want)

Then you can BOTH create a new CUSTOM Resource Action (provided you have ASD... which you do in your case), for change Lease (with date constraints that are missing in the current out of the box action), AND use it as part of your provisioning workflow if you so desire.

In either case you would want to supply the proper inputs to the provided Library workflow which includes the CatalogResource (virtual machine), the Operation(Change Lease), and the property values for the Operation.  (in this case, a valid datetime)

With the ResourceAction method, the user makes a request for your custom change lease, and then the service account makes a request for the actual change lease passing through the values you allowed in the initial workflow if valid.  So you will see two requests in history.  One as the user.  One as the service account.

View solution in original post

Reply
0 Kudos
18 Replies
gmuleshkov
VMware Employee
VMware Employee
Jump to solution

I am not really sure what could be the reason for this behavior but a workaround could be to the vRA REST client directly.

The scripting should be something like this:

var json = {

    "@type": "CatalogItemRequest",

    "catalogItemRef": {

        "id": ".............."

    },

    "organization": {

        "tenantRef": ".......",

        "subtenantRef": ".................."

    },

    "requestedFor": ".........",

    "state": "SUBMITTED",

    "requestNumber": ...,

    "requestData": {

        "entries": [

            {

.............................

                }

            }

        ]

    }

};

var catalogClient = host.createCatalogClient();

catalogClient.post("consumer/requests/" , JSON.stringify(json));

In order to get the correct json firebug or something similar could be used from the browser. Then the json should be transfer to the scripting and the lease days value could be changed inside the scripting task.

Hope this helps.

Regards,

Georgi

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Hey Michael....

Maybe this workflow will help you...

The service account used for plugin registration needs to be entitled to change lease on the item.  (needs to be part of the business group)

If you are interested in doing it through CloudClient... it is pretty easy to do that way too.

Reply
0 Kudos
michael_stefani
Enthusiast
Enthusiast
Jump to solution

So are you running that as a custom action available for a VM or as part of the initial provisioning of the VM?

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Well... it is an example workflow and the script is documented.

It would run in either case... but you will want to understand and tailor the script to do what you want.

Basically, there is a workflow in the VCAC portion of the Library workflows that allows you to perform a resource operation request on a catalogresource.  You can literally just run it and supply the values... if you see the Operation for Change Lease, then your service account for the plugin to vRA is configured properly in your BusinessGroup to see the ChangeLease Action.  (it can be the only one that sees it if you want)

Then you can BOTH create a new CUSTOM Resource Action (provided you have ASD... which you do in your case), for change Lease (with date constraints that are missing in the current out of the box action), AND use it as part of your provisioning workflow if you so desire.

In either case you would want to supply the proper inputs to the provided Library workflow which includes the CatalogResource (virtual machine), the Operation(Change Lease), and the property values for the Operation.  (in this case, a valid datetime)

With the ResourceAction method, the user makes a request for your custom change lease, and then the service account makes a request for the actual change lease passing through the values you allowed in the initial workflow if valid.  So you will see two requests in history.  One as the user.  One as the service account.

Reply
0 Kudos
michael_stefani
Enthusiast
Enthusiast
Jump to solution

Sean, can you point me in the right direction for something?  So I was thinking about invoking the Request a Resource Action in our BuildingMachine stub, but it looks like it wants a vCACCAFE:CatalogResource input type.  Is there some way to extract that from the vCAC:VirtualMachine or vCAC:Entity properties that are available to me within the WF stubs?

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

>> vCAC:VirtualMachine or vCAC:Entity

With either you can get the name...

With the name, you can do either what rszymczak‌ posted in page two of this thread... or what I posted shortly afterward...

VM Creation with ASD -- Need advice

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()); 

  } 

The first part gets the resource based on string name, but it is the first value in an Array.  So you loop through the array and assign the array object to a single variable.  Then you have to use the ID of that object to get the object again using getCatalogResource(host,ID).  (appears to be a bug, but this method supplies the object correctly... and then use the resource object accordingly in your script.  In the case above, I am also grabbing all the resource operations available (entitled) to the Service Account on that resource.

This is all just an example of getting objects and syslogging them.  Of course, you would need to modify to meet your needs.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Oh... and commit that Server.findAllForType(TYPE, stringPluginFilterIfAvailable) to memory. That is a very useful way to get an array of ANY object in the vRO Inventory.  From what I have found... if it exists in vRO, you can get it that way.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Hi... this may help you.

Constrained Change Lease - Freebee

Reply
0 Kudos
michael_stefani
Enthusiast
Enthusiast
Jump to solution

Sean, we were playing around with the workflow and got everything working in test for an existing VM.  The problem we're running into now is that the vCACCAFE:CatalogResource doesn't seem like it gets created until the the entire build process is complete.  So running this in a STUB workflow doesn't work since there is not CatalogResource until after the WF is complete.  Does that make sense?

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Yeah... I had a faulty understanding of when the Inventory item was created.  I verified on my end, and I agree this will not work during Machine Provisioned.  The Resource is created after the stubs run.  If I figure something else out, I will let you know. I am creating machines from ASD request forms and setting lease... but through cloud client.

I suspect you are using Request Catalog Item?

Reply
0 Kudos
michael_stefani
Enthusiast
Enthusiast
Jump to solution

Yeah, we're running the ASD requests through the Request Catalog Item.  Appreciate all the replies.  Is there anyway to have a workflow kick off a separate workflow (not within itself)?  I've never seen that done, but if that's possible we could have the last step of Machine Provisoined kick off another workflow, wait 2 minutes, and then the item would be available.  Just a thought, no idea how feasible that is though.  Thanks again,

Mike

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Yeah... great minds think alike... Smiley Happy

There may be a way through Async workflow... but I don't know yet if the "called" workflow has to finish before the parent finishes.  I know it is async within the workflow.  Would need to test it out...

You could, instead of waiting for time, wait for the object... with some timeout period.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Well I can duplicate your problem entirely...

I can track the integer value all the way into the form right up until submittal through the requests helper method.  It doesn't supply the value to the request... and provider-VirtualMachine.LeaseDays is the right field.

vCACCAFERequestsHelper.requestCatalogItem(item, form);

We could submit bug fix requests in for it through support, I suppose.  At a minimum, maybe support can give us an answer of how to set Lease using that Library workflow... or the workflow actions... or even the methods... because it fails entirely.

I tried both request and request on behalf of... to no avail...

properties = new Properties();

var longInt = new vCACCAFEIntegerLiteral(10);
properties.put("provider-VirtualMachine.LeaseDays", longInt.getValue());

System.log(longInt.getValue());
System.log(properties.keys);
System.log(properties.get("provider-VirtualMachine.LeaseDays"));

System.getModule("com.vmware.library.vcaccafe.util").validateObject(item, "Catalog item");
System.log("Getting catalog item '" + item.getName() + "' request form...");
var form = vCACCAFERequestsHelper.getRequestFormForCatalogItem(item);

System.log("Accepted inputs:");
var fields = vCACCAFERequestsHelper.getFormKeys(form);
for (var i = 0; i < fields.length; i++) {
System.log(" - " + fields[i]);
}

form = vCACCAFERequestsHelper.setFormValues(form, properties);
var literalMap = form.getValues();
System.log(literalMap.get("provider-VirtualMachine.LeaseDays"));
//VALUE IS GOOD HERE... PART OF THE FORM

throw "**********break break break break**************";

System.log("Sending catalog item request...");
var request = vCACCAFERequestsHelper.requestCatalogItem(item, form);

//On Behalf
//var request = vCACCAFERequestsHelper.requestCatalogItemOnBehalfOf(item, form, "myID");
System.log("Catalog item request '" + request.getId() + "' sent!");
System.log( request);


Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

So with regard to your other idea...

I think it might actually work.  It would be a secondary request for Lease Extension... but it gets around the Initial Request Issue.

async.jpg

async2.jpg

async3.jpg

Or you could just switch to cloud client... create an ASD workflow that does an SSH to a script host to make the request itself.  The response is the request ID... then you can track the request ID and do other things post machine completion.  That looks like this...

CloudClient>vra catalog request submit --id "Centos6" --groupid "BusinessGroup" --reason "Thermonuclear War" --description "Tic-Tac-Toe" --requestedFor "user@domain.com" --properties "VirtualMachine.CPU.Count=2,VirtualMachine.Memory.Size=8192,provider-Cafe.Shim.VirtualMachine.NumberOfInstances=1,LeaseDays=10,provider-OtherProperties=many"

(and yes, it is just LeaseDays... even CloudClient falls over with provider-VirtualMachine.LeaseDays... they should have just made the damn value a string and not had all these type conversion problems)  Smiley Happy

Reply
0 Kudos
michael_stefani
Enthusiast
Enthusiast
Jump to solution

Going to give it a try this morning.  Thanks for all the info.  Never heard of that cloudclient, but I'm going to check it out after I wrap this up. 

Mike

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

>>>Going to give it a try this morning.

The Async?  Please do share if it works out for you.  I am very interested in this possibility.  (I may test later as well if your outcomes look positive.)

Reply
0 Kudos
michael_stefani
Enthusiast
Enthusiast
Jump to solution

Yep, tested out the Async and it worked like a charm.  I just made the Async workflow call the last thing in my MachineProvisioned stub WF and put a 120sec timeout at the beginning of the ChangeLease WF.  Decent workaround for the built-in lease not working for Request a catalog Item.  Thanks again for all the help Sean.

Mike

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Wow... That is so cool.  Nice job!

Reply
0 Kudos