4

virt-manager中,查看连接详细信息下的存储选项卡时,有一个“使用者”列,显示使用每个卷的域:

在此处输入图像描述

如何使用 API(python 绑定)确定相同的信息,即使用给定卷的域?

我浏览了API 文档dir()在 libvirt、libvirt.virConnect、libvirt.virStoragePool 和 libvirt.virStorageVol 上运行,但我仍然对此一无所知。

4

1 回答 1

3

这是我现在找到的解决方案。使用虚拟机域的名称,它返回域使用的卷的绝对路径。

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
于 2014-01-25T23:33:17.313 回答