pyvmomi - 如何使用 pyvmomi 检索 ESXi 主机上所有存储适配器的列表?
问题描述
我最近开始使用 pyvmomi 来自动化一些任务。
我需要使用 pyvmomi 检索存储适配器列表。但是,我没有找到示例或 API。
解决方案
我编写了一个名为vmwc的 python 包来为 Python 提供一个简单的 VMWare SDK 客户端(它基本上包装了具有高级功能的 pyvmomi)。
以下片段来自它的源代码。此函数枚举 ESXi 的数据存储 + 磁盘信息(来源)
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()
推荐阅读
- mysql - 我们可以将多个存储过程连接在一起吗?
- java - 如何创建正确的 JPA 多对多关系
- python - 如何使用 Python 提高从 2 到 N 的数字查找 N 是否为 Coprime 的时间复杂度?
- keras - Coremltools 无法成功将输出更改为图像
- javascript - 如何在 Eclipse 2020-06 中更改 Javascript 的语法着色
- react-testing-library - 如何使用 react-testing-library 测试反应列表项的移动
- java - 如何像种子一样通过全球互联网发送数据?
- javascript - 需要为过滤器再添加一列“姓氏”。如果在下面的代码中的数据源中可用。角度数据表
- sparql - 如何从 WikiData 的 SPARQL 端点获取关系标签?
- docker - 连接失败:连接关闭(代码:1000)