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

Best approach to fetch the hostSystem name and names of VMs on the host

$
0
0

Hi There,

 

My requirement is to fetch the name property of the host and the names of all VMs on that host.

 

I trying following code, but unable to fetch "vm.name" property. Am i missing something here.

 

QuerySpec qs = new QuerySpec();

  qs.resourceSpec = new ResourceSpec();

qs.resourceSpec.constraint.targetType = HOST_TYPE;

  // request the name property

  PropertySpec pSpec = new PropertySpec();

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

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

  qs.resultSpec = new ResultSpec();

  qs.resultSpec.maxResultCount = 1;

  // use default ordering

  qs.resultSpec.order = new OrderingCriteria();

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

  // get data from DataService

  RequestSpec qsSpec = new RequestSpec();

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

 

Response response = _dataService.getData(qsSpec);

 

 

Thanks


Viewing all articles
Browse latest Browse all 2218

Trending Articles