VMware Cloud Community
ihryamzik
Contributor
Contributor

Query vCloud VDC Object from vCO

Is it possible to get VDC by name as well?

Reply
0 Kudos
7 Replies
Burke-
VMware Employee
VMware Employee

Sure, using Christophe's code:

var queryService = vcdHost.getQueryService();
var expression = new VclExpression(VclQueryOrgVdcField.NAME, vdcName, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);


var ovdcs = new Array();
var resultSet = queryService.queryRecords(VclQueryRecordType.ORGVDC, params);


while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultOrgVdcRecord());
    System.log(records.length + " oVDC record found");
    for each (var record in records) {
        var ovdcRef = new VclReference();
        ovdcRef.href = record.href;
        ovdcRef.name = record.name;
        ovdcRef.type = record.type;
       ovdcs.push(vcdHost.getEntityByReference(VclEntityType.VDC, ovdcRef)); // for use with vCD 1.5.x

       //ovdcs.push(vcdHost.getEntityByReference(VclFinderType.VDC,ovdcRef)); // uncomment for use with vCD 5.x

    }
    resultSet = resultSet.getNextPage();
}

return ovdcs;

Inputs:

vdcName (string)

vcdHost (vCloud:Host)

Return: Array/vCloud:Vdc

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee

With the vCD 5.1 plug-ib replace VclEntityType by VclFinderType.

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
esstokes1
Enthusiast
Enthusiast

The API shows that getEntityByReference return type is Object so how do you cast that object to vCloud:Vdc?  We are using the same code but cannot use any of the objects on the array to instantiate a vApp.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee

It will return an object of the type you specified (at least if it can with the reference you provided).

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
ceastman
Contributor
Contributor

Where can I find the package that supplies the method you mention?

var vAppTemplates = System.getModule("com.vmware.pso.library.vcloud.qs").getVAppTemplatesByName(vdc.getHost(), name); 


specificaly getVAppTemplatesByName

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee

Ceastman - this action is not mentioned in this thread - it seems you have replied to the wrong thread here. In any case, that action is likely in one of Christophe's packages found on the "Documents" tab of this community... I'm unsure which one at the moment since this message is not with the original reference.

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
tmalaher
Contributor
Contributor

For me, (and apparently for a poster in the original thread) querying on ORGVDC gets no results (no errors, just an empty ResultSet no matter what query is made).

You have to search for ADMINVDC instead. But strangely, you don't use the AdminQueryService for this, instead you use the regular query service.

Also, when I do a similar query for edge gateways in our production environment, the getEntityByReference takes ~10 seconds per entry, so actually making a list of all 60 edge gateways takes 566 seconds!

So, three points/questions:

1) why can't we search for ORGVDC?

2) How do I know which query service to use for which object type? I would have thought that searching for an AdminVdc would use the AdminQueryService.

3) Beware doing getEntityByReference inside a loop when stepping through a query resultset. If your query returns more than one result, you may take a huge performance hit.

and bonus:

4) Wow. getEntityByReference is a dog. I can understand that there might be some overhead to retrieve the details for the entity and update VCO's cache, but it seems that this is very non-linear. In my Development environment where we have 9 Gateways, doing getEntityByReference takes ~2 seconds, so retrieving all 9 takes 21 seconds. In production, at two seconds apiece this would take ~120 seconds, which is a long time, but nowhere near 566 seconds.

Naturally it should take longer to run through a longer list, but each lookup is also taking longer, so the result is exponential. Why shouldn't it take constant-time to retrieve update a single entry in the cache?

Reply
0 Kudos