Search code examples
javaweb-servicesvmwarevsphere

vSphere WebServervice API get VirtualMachine Details


I need to get some details about a VirtualMachine like the VM Name, the DNS Name, the Resourcepool and the Host via the vShpere API.

I found a way to search for the VM but I don't know how I can get this details.

Has anyone done this?

Thanke you

Stephan


Solution

  •     //    you can find this code to get some ResourcePool infomation 
    
              ComputeResource cresource = (ComputeResource) host.getParent();
                        ResourcePool[] resourcepools = cresource.getResourcePool().getResourcePools();
    
    
       // if you find a way to search one vm .so  you can write below code. 
        ServiceInstance si = null;
        si = new ServiceInstance(new URL(
                                "https://"+hostVal+"/sdk"), usernameVal,
                                passwordVal, true);
        VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
                                        si.getRootFolder()).searchManagedEntity(
                                        "VirtualMachine", VM_NAME);