Use the python libvirt interface function to create a Dir-type storage pool, storage volume, and delete a storage volume and storage pool

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.