2011-01-17 10 views
4

Ich versuche, ein einfaches Skript, das verschiedene Informationen über das Ausführen von Domänen auf einem Xen-Host erhalten wird.erhalten Sie Domänen Informationen mit Python + libvirt

Bisher habe ich:

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

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

, die mir die folgende Störung gibt:

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

, die nach dem API (http://www.libvirt.org/html/ libvirt-libvirt.html # virDomainGetInfo) sollte mir zumindest etwas zurückgeben.

Irgendwelche Hinweise? (Ich bin ein Python-Neuling)

Antwort

5

Aus der Dokumentation: 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 
+2

Das bedeutet, dass 'infos = libvirt.virDomainGetInfo (dom)' stattdessen 'infos = dom.info()' sein muss. –

+0

ok, ging da etwas zu schnell. :) – Disco

4

Dokumentationen Um über die libvirt APIs in Python, verwenden Sie die Inline-Hilfe.

Starten Sie Ihren Python-Interpreter (geben Sie einfach python in die Shell ein).

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

Dies sollte Ihnen eine detaillierte Dokumentation über libvirt geben.

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') 
Verwandte Themen