gpt4 book ai didi

java - 如何获取虚拟机网卡的IP?

转载 作者:行者123 更新时间:2023-12-01 22:16:11 26 4
gpt4 key购买 nike

我使用的是 VSPHERE JDK JAVA 6.5。虚拟机的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));
}
}
}

最佳答案

IP 地址信息位于不同的服务中,与 NIC 信息分开。这是因为 IP 地址是通过 VMware Tools 从 guest 操作系统中提取的。

该服务称为“Guest”(在“Guest Operations”之后),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。

关于java - 如何获取虚拟机网卡的IP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58625598/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com