6

我正在尝试做一个简单的脚本,它将获取有关在 xen 主机上运行域的各种信息。

到目前为止,我有:

import libvirt
import pprint
conn = libvirt.open('xen:///')

for id in conn.listDomainsID():
    dom = conn.lookupByID(id)
    infos = libvirt.virDomainGetInfo(dom)

这给了我以下错误:

AttributeError: 'module' object has no attribute 'virDomainGetInfo'

其中,根据 API(http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetInfo)至少应该给我一些回报。

有什么线索吗?(我是蟒蛇新手)

4

3 回答 3

6

从文档:http ://www.libvirt.org/python.html

There is a couple of function who don't map directly to their C counterparts due to specificities in their argument conversions:

    * virConnectListDomains is replaced by virDomain::listDomainsID(self) which returns a list of the integer ID for the currently running domains
    * virDomainGetInfo is replaced by virDomain::info() which returns a list of
         1. state: one of the state values (virDomainState)
         2. maxMemory: the maximum memory used by the domain
         3. memory: the current amount of memory used by the domain
         4. nbVirtCPU: the number of virtual CPU
         5. cpuTime: the time used by the domain in nanoseconds
于 2011-01-17T16:05:24.717 回答
4

要获取有关 python 中 libvirt API 的文档,请使用内联帮助。

启动你的 python 解释器(只需输入pythonshell)。

>>> import libvirt
>>> help(libvirt)

这应该为您提供有关 libvirt 的详细文档。

于 2013-10-23T10:39:44.577 回答
0
import libvirt
import xml.etree.ElementTree as ET
conn = libvirt.open(name)
domain = conn.lookupByName(domain_name)
domain_config = ET.fromstring(domain.XMLDesc())
domain_disks = domain_config.findall('//disk')
于 2016-12-12T16:41:42.907 回答