pyvomi 中的 HostHardwareSummary

HostHardwareSummary in pyvomi

我要检索ESXi信息(型号和硬件BIOS标识)

https://www.vmware.com/support/developer/vc-sdk/visdk2xpubs/ReferenceGuide/vim.host.Summary.HardwareSummary.html

我发现我们需要浏览 HostHardwareSummary,但在 Python 中找不到任何 reference/example。 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

希望这个例子对您有所帮助。如果您需要为很多主机获取此信息,您应该真正使用 属性 收集器。我写了一个用于 VM 的示例,但不需要为 HostSystems 修改它。您可以找到它 here