Tun Lin Aung Tun Lin Aung - 2 months ago 9
Java Question

Is there any ways to get drive information of each vmware in Vmware ESX via Vsphere SDK with Java?

In my vmware esx server, I have four vmware such as Window 7, Window XP, Window Server 2008 and Window Server 2012. And drive information for each vmware:


  • Window 7 -> drive C
    - Used 2GB, Free 2GB, Total 4GB

  • Window XP -> drive C
    - Used 2GB, Free 2GB, Total 4GB

  • Window Server 2008 -> drive C
    - Used 2GB, Free 2GB, Total 4GB
    -> drive D
    - Used 2GB, Free 2GB, Total 4GB

  • Window Server 2012 -> drive C
    - Used 2GB, Free 2GB, Total 4GB
    -> drive D
    - Used 2GB, Free 2GB, Total 4GB



My question is:

How do I get drive detail information (for example, Drive C, used space and free space of Window 7) by vsphere sdk? And also drive information of another 3 vmware.

Answer

Answer:

GuestInfo info = vm.getGuest(); //(vm means VirtualMachine object.)
GuestDiskInfo[] dInfos = info.getDisk();
if (dInfos != null) {
  System.out.println("Disk Info");
  for (GuestDiskInfo dInfo : dInfos) {
    System.out.println(" Capacity(GB):"+dInfo.getCapacity()/1024/1024/1024);
    System.out.println(" Free(GB):"+dInfo.getFreeSpace()/1024/1024/1024);
    System.out.println(" Disk Path:"+dInfo.getDiskPath());
    System.out.println("============");
  }
}

**Important: Firstly need to install vmware tools on each guest os machine. From this question, guest os are Window 7, Window Xp, Window Server 2008 and Window server 2012.