virStoragePool
class. The following example program features a number of the methods which describe some attributes of a pool.
Example 5.2. Show the usage of some storage pool methods
# Example-2.py #!/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) pool = conn.storagePoolLookupByName('default') if pool == None: print('Failed to locate any StoragePool objects.', file=sys.stderr) exit(1) info = pool.info() print('Pool: '+pool.name()) print(' UUID: '+pool.UUIDString()) print(' Autostart: '+str(pool.autostart())) print(' Is active: '+str(pool.isActive())) print(' Is persistent: '+str(pool.isPersistent())) print(' Num volumes: '+str(pool.numOfVolumes())) print(' Pool state: '+str(info[0])) print(' Capacity: '+str(info[1])) print(' Allocation: '+str(info[2])) print(' Available: '+str(info[3])) conn.close() exit(0)
autostart
flag is set then when the user connects to the storage pool libvirt will automatically make the storage pool available if it is not on a local file system e.g. an NFS mount. Storage pools on local file systems also need to be started if the autostart
is not set.
isActive
method indicates whether or not the user must activate the storage pool in some way. The create
method can activate a storage pool.
isPersistent
method indicates whether or not a storage pool needs to be activated using create
method. A value of 1 indicates that the storage pool is persistent and will remain on the file system after it is released.
VIR_STORAGE_XML_INACTIVE |
Example 5.3. Get the XML description of a storage pool
# Example-3.py #!/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) pool = conn.storagePoolLookupByName('default') if pool == None: print('Failed to locate any StoragePool objects.', file=sys.stderr) exit(1) xml = pool.XMLDesc(0) print(xml) conn.close() exit(0)