Quantcast
Channel: VMware Communities : Unanswered Discussions - Sample Exchange
Viewing all articles
Browse latest Browse all 70

Looking for java code to retrieve virtual disk info on a VM.

$
0
0

 

Hi,

 

 

I am looking for some sample code to retrieve virtual disk info on a VM.

I need to list total capacity of the virtual disk and free (or used) capacity of the disk.

 

 

I have gotten far enough to get total capacity of virtual disk but I can't seem to find how much of it is used (or free).

Below is part of my code.

Any help will be appreciated.

Thank you,

Robert

 

 

ManagedObjectReference[] datastores;

 

 

String[][] typeinfo = new String[][] { new String[] { "HostSystem","name" }, };

 

 

ObjectContent[] arrayMor = getMOR(typeinfo);

 

 

HostConnectInfo info = _service.queryHostConnectionInfo(objMor);

 

 

HostListSummary hostInfo = info.getHost();

 

 

HostConfigSummary hostSummary = hostInfo.getConfig();

 

 

System.out

 

 

.println("----


");

 

 

System.out.println("Host = " + hostSummary.getName());

 

 

VirtualMachineSummary vmarray[] = info.getVm();

 

 

 

 

 

for (int k = 0; k < vmarray.length; k++) {

 

 

VirtualMachineSummary vminfo = vmarray[k];

 

 

VirtualMachineConfigSummary vmSummary = vminfo.getConfig();

 

 

VirtualMachineConfigSummary vmConfig = vminfo.getConfig();

 

 

ManagedObjectReference vmMOR = vminfo.getVm();

 

 

// HostConnectInfo vmor_info =

 

 

// _service.queryHostConnectionInfo(vmMOR);

 

 

HostDatastoreConnectInfo[] datastore = info.getDatastore();

 

 

if (vmName.equalsIgnoreCase(vmSummary.getName())) {

 

 

System.out.println("== VM name: " + vmSummary.getName());

 

 

System.out.println("\t\t # of Virtual Disks = "+ vmSummary.getNumVirtualDisks());

 

 

Object configObj = getDynamicProperty(vmMOR, "config.hardware.device");

 

 

if (configObj != null)

 

 

{

 

 

VirtualDevice vdAry[] = (VirtualDevice[])configObj;

 

 

if (vdAry != null&& vdAry.length > 0) {

 

 

for (int l = 0; l < vdAry.length; l++) {

 

 

VirtualDevice vdevice = vdAry[l];

 

 

System.out.println("vdevice "+vdevice.getClass().toString());

 

 

if (vdevice.getClass().toString().contains("VirtualDisk")) {

 

 

VirtualDisk vd = (VirtualDisk)vdAry[l];

 

 

Description desc = vd.getDeviceInfo();

 

 

System.out.println(desc.getLabel()" Capacity = "desc.getSummary());

 

 

//Integer shares = vd.getShares().getShares();

 

 

}

 

 

}

 

 

}

 

 

}

 

 


Viewing all articles
Browse latest Browse all 70

Trending Articles



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