Product SiteDocumentation Site

5.8. Listing volumes

The following example program demonstrates how to list all the storage volumes contained by the "default" storage pool.

Example 5.7. Demonstrate listing the storage volumes

# Example-7.py
#!/usr/bin/env python3
import sys
import libvirt
from xml.dom import minidom

poolName = 'default'

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

sp = conn.storagePoolLookupByName(poolName)
if sp == None:
    print('Failed to find storage pool '+poolName, file=sys.stderr)
    exit(1)

stgvols = sp.listVolumes()
print('Storage pool: '+poolName)
for stgvol in stgvols :
    print('  Storage vol: '+stgvol)

conn.close()
exit(0)