VMware Cloud Community
milson
Enthusiast
Enthusiast
Jump to solution

Challenges working with blueprints in vco vcac plugin

Hi,

Working with the latest VCAC plugin for VCO release (5.2 and 5.5 respectively), I was intending to put a simple set of script element wrappers in front of the "Provision a virtual machine from a blueprint" workflow, such that (for starters) the provisioning group and blueprint inputs could be sent in as simple name strings, rather than expecting complex objects (as provided), to allow for simpler REST API consumption (not through the presentation layer btw, which was using the inventory tree to lookup and provide said input objects interactively).  I found no provided actions letting me do simple object retrievals by name, and decided to start by grabbing a full array of the objects and do string matching against it...

That turned out to be quite simple for provisioning groups and is working well - namely because of the provided method "host.findAllChildProvisioningGroups()", whether using it directly or through the "getAvailableProvisioningGroups" action.

Blueprints are turning out to be a different story.  I did find the "getBlueprints" action, which appears to be leveraged by the presentation layer when the workflow is run interactively, taking a provisioningGroup object as input (which I had already retrieved above).  It wasn't working when used in a script element, though.  Upon reviewing the backing action, I found it was relying on a property of the provisioning group object, rather than a method (there isn't a useful method available).  Adding some debugging confirmed the expected array was never populating when referenced (group.virtualMachineTemplates).  I'm not sure if it's broken, or if I should only expect it would work via presentation, or if I was just using it incorrectly - but I started looking for alternatives.

I looked around in the API browser and other samples, including the extensibility package and reviewed all the provided actions, but they always seem to expect the VCAC:Blueprint input type.  I did find getBlueprintsForProperty and it's close to what I need, though it runs far too slowly when pulling a large blueprint list (almost a second per object).  I know linqpad can dump all blueprints in VCAC (via ODATA) much faster.

In the end, I'm just looking for a way to easily get all blueprints for a provisioning group (or, even a host if it's fast enough), returned in an array of type VCAC:Blueprint I can iterate through - or even more simply, to retrieve blueprint objects directly based on a known displayName and get my object.  I'm aware of the full VCAC entity mechanism added in the latest plugin, but concerned that what I get back won't match the input type..it appears some properties don't match the VCO type and others aren't part of a blueprint entity at all.  Frankly I was hoping to not get that familiar with the innards of the existing VCAC API, and would rather not have to recreate a blueprint object from its requisite entity parts.

If you're still with me, thanks! - and, any ideas?  I'd love to hear I'm missing something painfully simple here...

-Milson

1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

OK spent some more time on this with starting to implement a piece of javascript to get directly a vCAC inventory object from its entity. Instead of iterating all objects of the same type it is getting the object directly by ID.

var entityKeyProperties = entity.entityKey;

var entityIdKey = entityKeyProperties.keys[0];

var entityIdValue = entityKeyProperties.get(entityIdKey);

System.log("Found key " + entityIdKey + " : " + entityIdValue);

switch(entity.entitySetName) {

    case "VirtualMachines" :

        inventoryObject = Server.findForType("vCAC:VirtualMachine", entity.hostId + "/" + entityIdValue);

        break;

 

    case "VirtualMachineTemplates" :

        inventoryObject = Server.findForType("vCAC:BluePrint", entity.hostId + "/" + entityIdValue);

        break;

 

    default : throw "No inventory object for entity type " + entity.entitySetName;

I was working with older release of the plug-in and then decided to test with the latest release of the plug-in (5.2) and made a nice discovery.

Engineering simplified our life with implementing entity.getInventoryObject();

So basically:

var entity = vCACinventoryObject.getEntity(); // convert an inventory object to an entity

inventoryObject = entity.getInventoryObject(); // convert an entity to an inventory object

So in your case the code to search quickly for a blueprint by name would be:

if (vcacHost == null) return null;

var model = "ManagementModelEntities.svc";

var entitySetName = "VirtualMachineTemplates";

var property = new Properties();

property.put("VirtualMachineTemplateName",name);

var entities = vCACEntityManager.readModelEntitiesByCustomFilter(vcacHost.id, model, entitySetName, property, null);

var blueprints = new Array();

for each (var entity in entities) {

    blueprints.push(entity.getInventoryObject());

}

return blueprints;

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

Reply
0 Kudos
10 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

You can get all the blueprints with Server.findAllForType("vCAC:BluePrint");

And iterate through these to filter them by name,

vCACEntityManager.readModelEntitiesByCustomFilter should be a lot faster to find a virtualMachineTemplate entity by name and getting his ID but unfortunately you would still have to call Server.findAllForType("vCAC:BluePrint") to get the matching Blueprint object since there is not method I know to convert an entity to a vCO inventory object in this plug-in.

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
milson
Enthusiast
Enthusiast
Jump to solution

Thanks Christope!

That is working well enough for now..since I had to get full list anyway, it was moot to pull the entities first.  Thanks for the tip, I hadn't worked much with inventory objects directly in script tasks.  It's still much faster this way than using one of the existing actions that had a number of nested loops.

Regards

Milson

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

OK spent some more time on this with starting to implement a piece of javascript to get directly a vCAC inventory object from its entity. Instead of iterating all objects of the same type it is getting the object directly by ID.

var entityKeyProperties = entity.entityKey;

var entityIdKey = entityKeyProperties.keys[0];

var entityIdValue = entityKeyProperties.get(entityIdKey);

System.log("Found key " + entityIdKey + " : " + entityIdValue);

switch(entity.entitySetName) {

    case "VirtualMachines" :

        inventoryObject = Server.findForType("vCAC:VirtualMachine", entity.hostId + "/" + entityIdValue);

        break;

 

    case "VirtualMachineTemplates" :

        inventoryObject = Server.findForType("vCAC:BluePrint", entity.hostId + "/" + entityIdValue);

        break;

 

    default : throw "No inventory object for entity type " + entity.entitySetName;

I was working with older release of the plug-in and then decided to test with the latest release of the plug-in (5.2) and made a nice discovery.

Engineering simplified our life with implementing entity.getInventoryObject();

So basically:

var entity = vCACinventoryObject.getEntity(); // convert an inventory object to an entity

inventoryObject = entity.getInventoryObject(); // convert an entity to an inventory object

So in your case the code to search quickly for a blueprint by name would be:

if (vcacHost == null) return null;

var model = "ManagementModelEntities.svc";

var entitySetName = "VirtualMachineTemplates";

var property = new Properties();

property.put("VirtualMachineTemplateName",name);

var entities = vCACEntityManager.readModelEntitiesByCustomFilter(vcacHost.id, model, entitySetName, property, null);

var blueprints = new Array();

for each (var entity in entities) {

    blueprints.push(entity.getInventoryObject());

}

return blueprints;

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
milson
Enthusiast
Enthusiast
Jump to solution

Very handy, thanks!

milson
Enthusiast
Enthusiast
Jump to solution

And as a quick followup, with that in place as an action (works great, by the way) it reduced the API call time for workflow submission from >3s to <400ms in my case.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Glad this helped. How many blueprints do you have ?

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
milson
Enthusiast
Enthusiast
Jump to solution

Looks like around 200 blueprints.  Just for more trivia...in the original workflow, prompting based on presentation element 'GetAction("com.vmware.library.vcac","getBlueprints").call(#provisioningGroup)' it would take upwards of two minutes for the UI to display the full list interactively.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

I am confused by the getBlueprints action. The iteration is useless and is certainly a left over meant for a System.log.

You could use return group.virtualMachineTemplates right away and it should be faster.

As for my code commenting the "property.put("VirtualMachineTemplateName",name); " line should return all the blueprints.


Then you can benchmark both to see which one is faster Smiley Happy

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
spmsaj
Contributor
Contributor
Jump to solution

Old post, but same problem. GetBlueprints work, but it only gets the blueprint specifically created or allocated to the Provisioning group. It doesnt return Global blueprints that gets allocated to the group

Reply
0 Kudos
spmsaj
Contributor
Contributor
Jump to solution

How to find only those blueprints that are associated with a provisioning group including global shared BPs? Even a simple OData query only returns the blueprints specifically owned by the group. It doesnt return the global blueprints that are shared for the group. The task I have at hand is to find all blueprints that a user is allowed to use, and not able to figure that out in the API when it comes to Global blueprints. Any suggestions?

Reply
0 Kudos