在 virt-manager
中,当查看连接详细信息下的存储选项卡时,有一个“使用者”列显示使用每个卷的域:
如何使用 API(python 绑定(bind))确定相同的信息,即使用给定卷的域?
我浏览了 API documentation并在 libvirt、libvirt.virConnect、libvirt.virStoragePool 和 libvirt.virStorageVol 上运行了 dir()
,但我仍然对此一头雾水。
最佳答案
这是我目前找到的解决方案。使用虚拟机域的名称,它返回域使用的卷的绝对路径。
import libvirt
from xml.etree import ElementTree as ET
URI = "qemu:///system"
VM = "truffles"
# Get the virDomain object
conn = libvirt.open(URI)
domain_object = conn.lookupByName(VM)
# Get the XML description of the VM
vm_xml = domain_object.XMLDesc(0)
# Get the volume in use from the element tree
root = ET.fromstring(vm_xml)
disk_source = root.find('./devices/disk/source')
volume_in_use = disk_source.get('file')
print volume_in_use
关于python - libvirt - 通过 API 确定域使用的卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21342079/