我使用pyVmomi在我们的vCenter上创建VM。我们有一些网络,比如“PRD-DB”。我可以使用pyVmomi将VM的网络接口更改为'PRD-DB‘。
我知道此网络地址是10.125.10.0/24。但我找不到使用pyVmomi获取此网络IP地址的方法。是什么将IP连接到网络?
编辑得更准确:如何检索可分配给虚拟机网卡的可用VLAN列表?我可以检索与这些VLAN对应的网络地址吗?
发布于 2018-11-07 12:56:14
您是否正在尝试仅获取每个虚拟机的ip地址?
如果是这样的话,您可以在vim.VirtualMachine上使用CreateContainerView通过guest对象从您的vCentre获取每个VM的IP地址。尽管您需要安装VMWare工具来收集来宾对象中的大部分信息。
serviceInstance = SmartConnect(host=host,user=user,pwd=password,port=443)
atexit.register(Disconnect, serviceInstance)
content = serviceInstance.RetrieveContent()
vm_view = content.viewManager.CreateContainerView(content.rootFolder,[vim.VirtualMachine],True)
# Loop through the vms and print the ipAddress
for vm in vm_view.view:
print(vm.guest.ipAddress)如果您正在尝试一种更高级的方法,我建议您遵循vmware github页面上提供的getvnicinfo.py示例。这实际上是通过一个更详细的视图来获取每个虚拟机的信息。尽管这似乎不能提供IP地址。
要查看主机的可用vlans,请按照以下示例操作。
hosts = content.viewManager.CreateContainerView(content.rootFolder,[vim.HostSystem],True)
for host in hosts.view:
for network in host.network:
switch = network.config.distributedVirtualSwitch
for portgroup in switch.portgroup:
print(portgroup.name) # This will print the vlan nameshttps://stackoverflow.com/questions/48386221
复制相似问题