Created
May 1, 2022 19:24
-
-
Save DavesCodeMusings/fd72c11ed8b97fc3601fa47bebc7d2fa to your computer and use it in GitHub Desktop.
List storage pools using python-libvirt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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