Quantcast
Channel: VMware Communities : Discussion List - vSphere Client SDK
Viewing all articles
Browse latest Browse all 2218

How to fetch hosts under a cluster using QuerySpec

$
0
0

Hi,

  Using QuerySpec I am trying to fetch list of Hosts under a cluster

  I have following code

 

// create QuerySpec

    QuerySpec qs = new QuerySpec();

    qs.resourceSpec = new ResourceSpec();

    qs.resourceSpec.constraint = new Constraint();

    // HostSystem is the targetType

    qs.resourceSpec.constraint.targetType = "HostSystem";

    // request the name property

    PropertySpec pSpec = new PropertySpec();

    pSpec.propertyNames = new String[]{"name"};

    qs.resourceSpec.propertySpecs = new PropertySpec[]{pSpec};

    qs.resultSpec = new ResultSpec();

    qs.resultSpec.maxResultCount = new Integer(maxResultCount);

    // use default ordering

    qs.resultSpec.order = new OrderingCriteria();

    qs.resultSpec.order.orderingProperties = new OrderingPropertySpec[0];

    // get data from DataService

    RequestSpec requestSpec = new RequestSpec();

    requestSpec.querySpec = new QuerySpec[]{qs};

    Response response = _dataService.getData(requestSpec);

 

 

    ResultItem[] items = response.resultSet[0].items;

    if (items == null) {

       return new Object[0];

    }

    Object[] objects = new Object[items.length];

    for (int index = 0; index < items.length; ++index) {

       objects[index] = items[index].resourceObject;

    }

    return objects;

  Code is same as in ChassisRack adapter , where I can specify the cluster details so only host under cluster will get fetched .


Viewing all articles
Browse latest Browse all 2218


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