我终于找到并回答了我的问题,所以我把解决方案贴在这里,以防有人碰到同样的问题。在
libvirt connection对象可以使用存储池。在
从libvirt.org网站:“存储池是管理员(通常是专门的存储管理员)留出的供虚拟机使用的存储量。存储池由存储管理员或系统管理员划分为存储卷,并将这些卷作为块设备分配给虚拟机。“
基本上,卷就是quemu-img create创建的。一旦您在同一目录中创建了一个存储池,其中包含所有.img(使用qemu-img创建的)文件;使用qemu-img创建的文件将被视为卷。在
下面的代码将列出所有现有卷,包括使用qemu-img创建的卷conn = libvirt.open()
pools = conn.listAllStoragePools(0)
for pool in pools:
#check if pool is active
if pool.isActive() == 0:
#activate pool
pool.create()
stgvols = pool.listVolumes()
print('Storage pool: '+pool.name())
for stgvol in stgvols :
print(' Storage vol: '+stgvol)
创建存储池:
^{pr2}$
创建卷:def createStoragePoolVolume(pool, name):
stpVolXml = """
"""+name+""".img
0
10
/path/to/guest_images/"""+name+""".img
107
107
0744
virt_image_t
"""
stpVol = pool.createXML(stpVolXml, 0)
return stpVol
|