The libvirt Storage section is studied. A simple example is used for test and verification:
Import lib1_conn = libvirt. open ('qemu: // system') # conn = libvirt. open ('qemu: // system ') xmldesc = ''' <pool type = "dir"> <Name> test </Name> <target> <path>/var/images_test </path> </Target> </pool> ''' # storage_pool.connect () storage_pool = Conn. storagepooldefinexml (xmldesc, 0) # print storage_pool.name () print Conn. isalive () storage_pool.build (0) # create storage_pool.create (0) # enable storage storage_pool.isactive () xmldesd_vol = ''' <volume type = "file"> <Name> qcow2.img </Name> <allocation unit = "M"> 10 </allocation> <capacity unit = "m & quot;> 1000 </capacity> <target> <format type = "qcow2"/> </Target> </volume> ''' print storage_pool.createxml (xmldesd_vol, 0) # virstoragevol Class Object print storage_pool.listvolumes () print storage_pool.isactive ()
Output result:
virttest1<libvirt.virStorageVol instance at 0x7faa5fa55518>['qcow2.img']1
Delete storage volumes and storage pools
Import lib1_conn = libvirt. open ('qemu: // system') # conn = libvirt. open ('qemu: // system ') ''' Delete pool vol ''' storage _ pool = Conn. storagepoollookupbyname ("test") # storage_pool.create (0) # enable the storage pool S_v = storage_pool.storagevollookupbyname ('qcow2. IMG ') print s_vprint s_v.delete (0) print storage_pool.destroy () # Stop the storage print storage_pool.delete (0) # Delete the storage. before deleting the storage, ensure that no vol is printed in the storage pool () # deleting a storage Definition