vmwarevspherevmware-tools

How to get all volumes attached with vm in vphere in java api?


image of vm description, I can see 2 hard disk is being used by VM

How can I get list of all volumes attached with VM in vSphere using java api.


Solution

  • In the mean time, I found the answer. All courtesy to Deadline

        VirtualMachine vm = getVM(); // get the vm object
    
        List<VirtualDisk> virtualDiskList = new ArrayList<VirtualDisk>();
        VirtualMachineConfigInfo vmConfig = vm.getConfig();
        VirtualDevice[] vds = vmConfig.getHardware().getDevice();
        for(VirtualDevice vd : vds){
            if(vd instanceof VirtualDisk){
                virtualDiskList.add((VirtualDisk)vd);
            }
        }
    

    Now virtualDiskList contains all virtual disks(volumes) attached with the given instance.