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)によると、少なくとも何かが返されるはずです。

どんな手掛かり ?(私はPython初心者です)

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のlibvirtAPIに関するドキュメントを入手するには、インラインヘルプを使用してください。

Pythonインタープリターを起動します(pythonシェルに入力するだけです)。

>>> 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 に答える