如何使用pyvmomi检索ESXi主机上所有存储适配器的列表?

时间:2019-02-01 06:51:29

标签: pyvmomi

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

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

1 个答案:

答案 0 :(得分:0)

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

以下代码段来自其源代码。此函数枚举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()