【问题标题】:How to retrieve the list of all storage adapters on an ESXi host using pyvmomi?如何使用 pyvmomi 检索 ESXi 主机上所有存储适配器的列表?
【发布时间】:2023-04-07 10:33:02
【问题描述】:

我最近开始使用 pyvmomi 来自动化一些任务。

我需要使用 pyvmomi 检索存储适配器列表。 但是,我没有找到示例或 API。

【问题讨论】:

    标签: pyvmomi


    【解决方案1】:

    我编写了一个名为vmwc 的python 包来为Python 提供一个简单的VMWare SDK 客户端(它基本上包装了具有高级功能的pyvmomi)。

    以下 sn-p 来自它的源代码。此函数枚举 ESXi 的数据存储 + 磁盘信息 (source)

    def get_datastores(self):
    
        # Search for all ESXi hosts
        objview = self._content.viewManager.CreateContainerView(self._content.rootFolder, [vim.HostSystem], True)
        esxi_hosts = objview.view
        objview.Destroy()
    
        for esxi_host in esxi_hosts:
    
            # All Filesystems on ESXi host
            storage_system = esxi_host.configManager.storageSystem
            host_file_sys_vol_mount_info = storage_system.fileSystemVolumeInfo.mountInfo
    
            for host_mount_info in host_file_sys_vol_mount_info:
    
                # Extract only VMFS volumes
                if host_mount_info.volume.type != "VMFS":
                    continue
    
                datastore = {
                    'name': host_mount_info.volume.name,
                    'disks': [item.diskName for item in host_mount_info.volume.extent],
                    'uuid': host_mount_info.volume.uuid,
                    'capacity': host_mount_info.volume.capacity,
                    'vmfs_version': host_mount_info.volume.version,
                    'local': host_mount_info.volume.local,
                    'ssd': host_mount_info.volume.ssd
                }
    
                yield datastore
    

    顺便说一句,这就是您使用 vmwc 执行此操作的方式

    #!/usr/bin/env python
    
    from vmwc import VMWareClient
    
    
    def main():
        host = '192.168.1.1'
        username = '<username>'
        password = '<password>'
    
        with VMWareClient(host, username, password) as client:
            for datastore in client.get_datastores():
                print (datastore)
    
    
    if __name__ == '__main__':
        main()
    

    【讨论】:

    • 首先恭喜Python包实现!我已经尝试运行上面的代码,因为我也在调查检索数据存储的 LUN ID,但是从我看到的某些属性可能没有正确填充:File "/usr/local/lib/python3.9/site-packages/vmwc/__init__.py", line 166, in get_datastores host_file_sys_vol_mount_info = storage_system.fileSystemVolumeInfo.mountInfo AttributeError: 'NoneType' object has no attribute 'mountInfo' 关于如何解决这个问题的任何想法?
    猜你喜欢
    • 2019-08-27
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 2019-09-27
    • 2012-02-01
    • 2020-10-20
    相关资源
    最近更新 更多