VMware {code} Community
sarav1186
Contributor
Contributor

how to obtain the esxserver datastore name ,capacity and free space of that?

Hi All

I need to obtain the datastore name,capacity of that and free space as its gets displayed in the VI for a particular esxserver using SDK.

Thanks in Advance

0 Kudos
3 Replies
njain
Expert
Expert

The "HostSystem" managed object has a property "datastore" which is an array of MOR to the available datastores to the ESX. Accessing the "summary.name", "summary.capacity" and "summary.freeSpace" properties will give you the desired values.

  <br /><br/>
ManagedObjectReference[] ds = (ManagedObjectReference[])cb.getServiceUtil().getDynamicProperty(obj.hostMOR, "datastore");<br/><br/>
for (int i = 0; i &lt; ds.length; i++) {<br/><br/>
  DatastoreSummary dsSummary = (DatastoreSummary)cb.getServiceUtil().getDynamicProperty(ds[i], "summary");<br/><br/>
  System.out.println("\n Datastore Name: " + dsSummary.getName() +<br/><br/>
                     "\n Capacity (in bytes): " + dsSummary.getCapacity() +<br/><br/>
                     "\n Free Space (in bytes): " + dsSummary.getFreeSpace() +<br/><br/>
                     "\n");<br/><br/>
}

</p>

0 Kudos
sarav1186
Contributor
Contributor

Thanks for the code snippet.It works perfect.

0 Kudos
Steve_Jin
Expert
Expert

VI Java API version looks easier to read:

Datastore[] ds = host.getDatastore();

for (int i = 0; i &lt; ds.length; i++) {

DatastoreSummary dsSummary = (DatastoreSummary)ds[i].getSummary();

System.out.println("\n Datastore Name: " + dsSummary.getName()

+ "\n Capacity (in bytes): " + dsSummary.getCapacity()

+ "\n Free Space (in bytes): " + dsSummary.getFreeSpace() + "\n");

}

Steve JIN, VMware Engineering

Creator of VI Java API:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos