pyvomi主机硬件概要

2024-09-25 02:26:51 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我发现我们需要浏览HostHardwareSummary,但在Python中找不到任何引用/示例。https://github.com/vmware/pyvmomi


Tags: httpscom信息developersupport硬件wwwsdk
1条回答
网友
1楼 · 发布于 2024-09-25 02:26:51
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的示例,但是不需要太多的时间来修改主机系统。。你可以找到它here

相关问题 更多 >