VMware Cloud Community
Aristizabal
Enthusiast
Enthusiast
Jump to solution

Query vCloud vApp by name from vCO

Hello,

I have been using the following discussion as a reference to query a vCloud vApp object from vCO using a name string.

http://communities.vmware.com/thread/391401

My code looks like:

var queryService = vcloudServer.getQueryService()
var expression = new VclExpression(VclQueryVAppField.NAME, vAppName, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);
var vApp = new Array();
var resultSet = queryService.queryRecords(VclQueryRecordType.VAPP, params);
while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultVAppRecord());
    System.log(records.length + " records found");
    for each (var record in records) {
        if (record.vdc == vdc.getReference().href) {
            var vAppRef = new VclReference();
            vAppRef.href = record.href;
            vAppRef.name = record.name;
            vAppRef.type = record.type;
            vAppRef.push(vdc.getHost().getEntityByReference(VclEntityType.VAPP, vAppRef));
            }
        }
    resultSet = resultSet.getNextPage();
}
System.log("vApp(s) found:"+vApp.length)

Where vcloudServer is of the type vCloud:Host and vAppName is the name of the vApp I am looking for (string type).

The workflow runs but it never finds anything.

Any clue what is the problem here?

(vCO 5.1, vCloud director 5.1)

Thanks,

Juan.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Try :

var vcloudServer = vdc.getHost();
var queryService = vcloudServer.getQueryService()
var expression = new VclExpression(VclQueryVAppField.NAME, vAppName, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);
var vApps = new Array();
var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVAPP, params);
while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultAdminVAppRecord());
    System.log(records.length + " records found");
    for each (var record in records) {
        if (record.vdc == vdc.getReference().href) {
            var vAppRef = new VclReference();
            vAppRef.href = record.href;
            vAppRef.name = record.name;
            vAppRef.type = record.type;
            vApps.push(vdc.getHost().getEntityByReference(VclFinderType.VAPP, vAppRef));
            }
        }
    resultSet = resultSet.getNextPage();
}
System.log("vApp(s) found:"+vApps.length);

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

0 Kudos
7 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Replace VclEntityType by VclFindertype.

If your plug-in is configured for the system org, replace VclQueryRecordType.VAPP by VclQueryRecordType.ADMINVAPP

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
0 Kudos
Aristizabal
Enthusiast
Enthusiast
Jump to solution

Hi Christophe,

I did what you suggested but I still get an empty query, my vCloud pluggin is  configured  for the system org so it has access to all the organizations.

The modified code is this:

var queryService = vcloudServer.getQueryService()
var expression = new VclExpression(VclQueryVAppField.NAME, vAppName, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);
var vApp = new Array();
var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVAPP, params);
while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultVAppRecord());
    System.log(records.length + " records found");
    for each (var record in records) {
        if (record.vdc == vdc.getReference().href) {
            var vAppRef = new VclReference();
            vAppRef.href = record.href;
            vAppRef.name = record.name;
            vAppRef.type = record.type;
            vAppRef.push(vdc.getHost().getEntityByReference(VclFinderType.VAPP, vAppRef));
            }
        }
    resultSet = resultSet.getNextPage();
}
System.log("vApp(s) found:"+vApp.length)

Thanks,

Juan.

0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Try :

var vcloudServer = vdc.getHost();
var queryService = vcloudServer.getQueryService()
var expression = new VclExpression(VclQueryVAppField.NAME, vAppName, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);
var vApps = new Array();
var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVAPP, params);
while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultAdminVAppRecord());
    System.log(records.length + " records found");
    for each (var record in records) {
        if (record.vdc == vdc.getReference().href) {
            var vAppRef = new VclReference();
            vAppRef.href = record.href;
            vAppRef.name = record.name;
            vAppRef.type = record.type;
            vApps.push(vdc.getHost().getEntityByReference(VclFinderType.VAPP, vAppRef));
            }
        }
    resultSet = resultSet.getNextPage();
}
System.log("vApp(s) found:"+vApps.length);

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
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

BTW are you intending to search the vApps by name only for a given 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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
Aristizabal
Enthusiast
Enthusiast
Jump to solution

My idea is to search by vApp name on the entire vCloud director inventory, since the deployment is done through vCAC I can guarantee that every vApp name is unique by using a common machine prefix for all the organizations.

Thanks a lot for the help, I got it to work by a slightly modification of  your code under the section where the vApp object is saved on the array. Here is the last version:

var queryService = vcloudServer.getQueryService()
var expression = new VclExpression(VclQueryVAppField.NAME, vAppName, VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);
var vApp = new Array();
var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVAPP, params);
while (resultSet != null)  {
    var records = resultSet.getRecords(new VclQueryResultAdminVAppRecord());
    System.log(records.length + " records found");
    for each (var record in records) {
        var vAppRef = new VclReference();
        vAppRef.href = record.href;
        vAppRef.name = record.name;
        vAppRef.type = record.type;
        var vAppItem = (vcloudServer.getEntityByReference(VclFinderType.VAPP, vAppRef));
        vApp.push(vAppItem);
    }
    resultSet = resultSet.getNextPage();
}
System.log("vApp(s) found:"+vApp.length)

0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

I was wondering if you where filtering for a particular VDC.

I took this opportunity to make the code work for any org and uploaded it here : http://communities.vmware.com/docs/DOC-22250

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
0 Kudos
Aristizabal
Enthusiast
Enthusiast
Jump to solution

Great, I just tried it and it works perfectly. Thanks.

0 Kudos