7 Replies Latest reply on Jun 11, 2014 12:33 PM by tmalaher Branched from an earlier discussion.

    Query vCloud VDC Object from vCO

    ihryamzik Novice

      Is it possible to get VDC by name as well?

        • 1. Re: Query vCloud VDC Object from vCO
          Burke- Virtuoso
          VMware Employees

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



          vdcName (string)

          vcdHost (vCloud:Host)


          Return: Array/vCloud:Vdc

          • 2. Re: Query vCloud VDC Object from vCO
            cdecanini_ Virtuoso
            VMware Employees

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

            • 3. Re: Query vCloud VDC Object from vCO
              esstokes1 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.

              • 4. Re: Query vCloud VDC Object from vCO
                cdecanini_ Virtuoso
                VMware Employees

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

                • 5. Re: Query vCloud VDC Object from vCO
                  ceastman Novice

                  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

                  • 6. Re: Query vCloud VDC Object from vCO
                    Burke- Virtuoso
                    VMware Employees

                    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.

                    • 7. Re: Query vCloud VDC Object from vCO
                      tmalaher Novice

                      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?