【问题标题】:HostHardwareSummary in pyvomipyvmomi 中的主机硬件摘要
【发布时间】:2016-03-22 08:02:24
【问题描述】:

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

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

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

【问题讨论】:

    标签: python vmware pyvmomi


    【解决方案1】:
    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 2019-08-27
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      相关资源
      最近更新 更多