Java vSphere WebServervice API获取虚拟机详细信息

Java vSphere WebServervice API获取虚拟机详细信息,java,web-services,vmware,vsphere,Java,Web Services,Vmware,Vsphere,我需要通过vShpere API获得有关虚拟机的一些详细信息,如VM名称、DNS名称、资源池和主机 我找到了一种搜索虚拟机的方法,但我不知道如何获得这些详细信息 有人这样做过吗 谢谢 Stephan您可以通过以下方法获取虚拟机信息 // you can find this code to get some ResourcePool infomation ComputeResource cresource = (ComputeResource) host.ge

我需要通过vShpere API获得有关虚拟机的一些详细信息,如VM名称、DNS名称、资源池和主机

我找到了一种搜索虚拟机的方法,但我不知道如何获得这些详细信息

有人这样做过吗

谢谢


Stephan

您可以通过以下方法获取虚拟机信息

    //    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);
  • 获取服务实例
  • 从服务实例获取根文件夹
  • 在根文件夹中使用vmname搜索虚拟机
  • Folder rootFolder=serviceInstance.getRootFolder();
    InventoryNavigator InventoryNavigator=新的InventoryNavigator(根文件夹);
    vm=(VirtualMachine)inventoryNavigator.SearchManageIdentity(VirtualMachine.class.getSimpleName(),vmName)