1

I recently started using pyvmomi to automate few tasks.

I need to retrieve the list of storage adapters using pyvmomi. However, I did not find examples or APIs.

Tejaswi
  • 264
  • 1
  • 10

1 Answers1

1

I've wrote a python package called vmwc to provide a simple VMWare SDK client for Python (it basically wraps pyvmomi with high level functionality).

The following snippet is from it's source code. This function enumerates the ESXi's datastores + disk information (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

BTW, this is how you would do this using 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()
Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129
  • First of all, congrats on the Python package implementation! I've tried running the above code as I was also investigating on retrieving LUN IDs for datastores, however from what I see some of the attributes might not be properly populated: ```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'``` Any ideas on how to fix this one? – Alexandru Sandu Jan 21 '22 at 11:05