Product SiteDocumentation Site

5.5. Discovering pool sources

The sources for a storage pool's sources can be discovered by examining the pool's XML description. An example program follows that prints out a pools source description attributes.
Currently the flags parameter for the storagePoolCreateXML method should always be 0.

Example 5.5. Discover a storage pool's sources

#!/usr/bin/env python3
import sys
import libvirt
from xml.dom import minidom

poolName = 'default'

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

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

raw_xml = sp.XMLDesc(0)
xml = minidom.parseString(raw_xml)
name = xml.getElementsByTagName('name')
print('pool name: '+poolName)
spTypes = xml.getElementsByTagName('source')
for spType in spTypes:
    attr = spType.getAttribute('name')
    if attr != None:
        print('  name = '+attr)
    attr = spType.getAttribute('path')
    if attr != None:
        print('  path = '+attr)
    attr = spType.getAttribute('dir')
    if attr != None:
        print('  dir = '+attr)
    attr = spType.getAttribute('type')
    if attr != None:
        print('  type = '+attr)
    attr = spType.getAttribute('username')
    if attr != None:
        print('  username = '+attr)