Skip to content

Instantly share code, notes, and snippets.

@DavesCodeMusings
Created May 1, 2022 19:24
Show Gist options
  • Select an option

  • Save DavesCodeMusings/fd72c11ed8b97fc3601fa47bebc7d2fa to your computer and use it in GitHub Desktop.

Select an option

Save DavesCodeMusings/fd72c11ed8b97fc3601fa47bebc7d2fa to your computer and use it in GitHub Desktop.
List storage pools using python-libvirt
#!/usr/bin/env python3
import sys
import libvirt
conn = None
try:
conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
print(repr(e), file=sys.stderr)
exit(1)
pools = conn.listAllStoragePools(0)
if pools == None:
print('Failed to locate any StoragePool objects.', file=sys.stderr)
exit(1)
for pool in pools:
print(pool.UUIDString(), "A" if pool.isActive() else "I", pool.name())
conn.close()
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment