Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

Using the query service via java to get VM count.

$
0
0

Hi there,

 

As part of my get all orgs in host method I would like to output number of Vm's accross these organizational vDC's.

 

My only input is the host, from there I successfully query the host's organizations but then when I attempt to query vDC's that belong to my list of orgs I end up pulling a abstract decorator result which proves to have nothing inside it.

 

my code looks like this:


var vdcs = new Array();
var orgVMCount = 0;
var vcdHost = Org.getHost();

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

var resultSet = queryService.queryRecords(VclQueryRecordType.ORGVDC,params);
while (resultSet != null) {
   
    var records = resultSet.getRecords(new VclQueryResultOrgVdcRecord);
    for each (var record in records) {
        var vdcVMCount = getVdcVMCount(record.href, vcdHost);
        System.log("VDC "+record.name+" VM Count: "+vdcVMCount);
orgVMCount += vdcVMCount;
    }
   
    resultSet = resultSet.getNextPage();
}
System.log("Total Organization VM Count: "+ orgVMCount);

function getVdcVMCount(vdcHref, host){
    var vmCount = 0;
    
    var qs = host.getQueryService();
    var exp = new VclExpression(VclQueryVMField.VDC, vdcHref, VclExpressionType.EQUALS);
    var exp2 = new VclExpression(VclQueryVMField.ISVAPPTEMPLATE, false, VclExpressionType.EQUALS);
    var exps = new Array(exp,exp2);
    
    var expFilter = new VclFilter(exps,VclFilterType.AND);
    var queryParams = new VclQueryParams();
    var vmArray = new Array();
    queryParams.setFilter(expFilter);
    var rs = qs.queryRecords(VclQueryRecordType.VM,queryParams);
    while (rs != null){
        var vmRecords = rs.getRecords(new VclQueryResultVMRecord);
        vmCount += vmRecords.length;
        rs = rs.getNextPage();
    }
    return vmCount;
}

 

 

 

Any feedback would be greatly appreciated.

 

Thanks.


Viewing all articles
Browse latest Browse all 6251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>