如何获得虚拟机网卡的IP?

时间:2019-10-30 12:39:37

标签: java automation sdk vsphere

我正在使用VSPHERE JDK JAVA 6.5。 VM的IP隐藏在哪里?我得到了带有一些信息的vmNics(),但是IP并不是其中的一部分。

我必须使用哪个班级? 谢谢

VMTypes.Info vmInfo = vcVAPIConnect.getVM(vapiStub, vmID);
if (vmInfo != null) {
    System.out.println("VM Detail Id   = " + vmID);
    System.out.println("VM Detail Name = " + vmInfo.getName());

    Set<String> fldList = vmInfo._getDynamicFieldNames();
    System.out.println("VM Dyn. Fieldlist (Size): " + fldList.size());
    for (String fldValue: fldList) {
        System.out.println("VM Detail Name = " + fldValue + " / " + vmInfo._getDynamicField(fldValue));
    }

    System.out.println("VM Detail Hardware Version   = " + vmInfo.getHardware().getVersion());

    System.out.println("VM Detail CPU CoresPerSocket = " + vmInfo.getCpu().getCoresPerSocket());
    System.out.println("VM Detail CPU Count          = " + vmInfo.getCpu().getCount());
    System.out.println("VM Detail CPU CannonialName  = " + vmInfo.getCpu()._getCanonicalName());

    System.out.println("VM Detail RAM Size           = " + vmInfo.getMemory().getSizeMiB());
    System.out.println("VM Detail RAM CannonialName  = " + vmInfo.getMemory()._getCanonicalName());

    Map<String, EthernetTypes.Info> vmNics = vmInfo.getNics();
    System.out.println("VM Detail NIC Size           = " + vmNics.size());
    for (String nicKey: vmNics.keySet()) {
        System.out.println("VM Detail NIC Key            = " + nicKey);
        System.out.println("VM Detail NIC CannonialName  = " + vmNics.get(nicKey)._getCanonicalName());
        System.out.println("VM Detail NIC MacAddr        = " + vmNics.get(nicKey).getMacAddress());
        System.out.println("VM Detail NIC MacType        = " + vmNics.get(nicKey).getMacType().toString());
        System.out.println("VM Detail NIC Label          = " + vmNics.get(nicKey).getLabel());
        System.out.println("VM Detail NIC PCI Slot       = " + vmNics.get(nicKey).getPciSlotNumber());
        System.out.println("VM Detail NIC Backing Name   = " + vmNics.get(nicKey).getBacking().getNetworkName());
        System.out.println("VM Detail NIC Backing Net    = " + vmNics.get(nicKey).getBacking().getNetwork());
        System.out.println("VM Detail NIC Backing Host   = " + vmNics.get(nicKey).getBacking().getHostDevice());

        fldList = vmNics.get(nicKey)._getDynamicFieldNames();
        System.out.println("VM Detail NIC Dyn. Fieldlist (Size):    " + fldList.size());
        for (String fldValue: fldList) {
            System.out.println("VM Detail NIC = " + fldValue + " / " + vmInfo._getDynamicField(fldValue));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

IP地址信息与NIC信息位于不同的服务中。这是因为IP地址是通过VMware Tools从来宾OS提取的。

该服务称为来宾(在来宾操作之后),并且可以在以下位置找到IP地址以及其他属性:https://code.vmware.com/apis/366/vsphere-automation/VMware-vSphere-Automation-SDK-REST-6.7.0/docs/apidocs/operations/com/vmware/vcenter/vm/guest/identity.get-operation.html

一个值得注意的问题,提出这项服务时我并不乐观。我知道它不在vSphere 6.5发行版中,但可能已经在以后的某个时候添加了。我确实知道它在vSphere 6.7中,但是由于您使用的是6.5 SDK,这可能无济于事。