我想检索 ESXi 信息(型号和硬件BIOS标识)
我发现我们需要浏览HostHardwareSummary,但在 Python 中找不到任何参考/示例。https://github.com/vmware/pyvmomi
我想检索 ESXi 信息(型号和硬件BIOS标识)
我发现我们需要浏览HostHardwareSummary,但在 Python 中找不到任何参考/示例。https://github.com/vmware/pyvmomi
import ssl
import requests
# this will disable the warnings from requests
requests.packages.urllib3.disable_warnings()
from pyVmomi import vim
from pyVim import connect
# this will only work if you have 2.7.9 or newer
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_NONE
service_instance = connect.SmartConnect(host="your host", user="your user", pwd="password", sslContext=context)
search_index = service_instance.content.searchIndex
root_folder = service_instance.content.rootFolder
# below is one of several ways to find a host.. this is one of the worst ways but it is quick for the purpose of this example
view_ref = service_instance.content.viewManager.CreateContainerView(container=root_folder,type=[vim.HostSystem], recursive=True)
host = view_ref.view[0]
print host.name
print host.summary.hardware.uuid
print host.summary.hardware.model
view_ref.Destroy
我希望这个例子有帮助。如果您需要为很多主机获取此信息,您应该真正使用属性收集器。我为虚拟机编写了一个示例,但对 HostSystems 进行修改并不需要太多时间。你可以在这里找到它