Python 3.x python列出vsphere上具有ip的所有vm
我正在尝试从vsphere服务器获取vm名称和ip,目前我只有vm的名称。如何获得ipPython 3.x python列出vsphere上具有ip的所有vm,python-3.x,vmware,vsphere,pyvmomi,Python 3.x,Vmware,Vsphere,Pyvmomi,我正在尝试从vsphere服务器获取vm名称和ip,目前我只有vm的名称。如何获得ip #! /usr/bin/env python from pyVim.connect import SmartConnect, SmartConnectNoSSL, Disconnect from pyVmomi import vim import json from pyVim.connect import SmartConnect from pyVmomi import vim import ssl #
#! /usr/bin/env python
from pyVim.connect import SmartConnect, SmartConnectNoSSL, Disconnect
from pyVmomi import vim
import json
from pyVim.connect import SmartConnect
from pyVmomi import vim
import ssl
# Get all the Vms from vCenter server inventory and print its name
# Below is Python 2.7.x code, which can be easily converted to python 3.x version
s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode=ssl.CERT_NONE
si= SmartConnectNoSSL(host="192.168.1.2", user="titi@gege.com", pwd="my_pass")
content=si.content
# Method that populates objects of type vimtype
def get_all_objs(content, vimtype):
obj = {}
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
for managed_object_ref in container.view:
obj.update({managed_object_ref: managed_object_ref.name})
return obj
#Calling above method
getAllVms=get_all_objs(content, [vim.VirtualMachine])
#Iterating each vm object and printing its name
for vm in getAllVms:
print (vm.name)
每个VM的IP地址信息位于对象中,可在以下位置获得:
VM.guestinfo.ipaddress
注意,返回的IP地址来源于VMware工具,因此请确保这些工具已安装并正在运行。cam i是如何实现的?语言改进