Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get running domains info using python + libvirt

Tags:

python

libvirt

I'm trying to do a simple script that will get various informations about running domains on a xen host.

So far, i have :

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

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

which gives me the following error :

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

Which, according to the API (http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetInfo) should at least return me something.

Any clue ? (i'm a python newbie)

like image 237
Disco Avatar asked Jan 17 '11 15:01

Disco


2 Answers

From the documentation: 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
like image 179
Lennart Regebro Avatar answered Sep 21 '22 01:09

Lennart Regebro


To get documentations about the libvirt APIs in python, use the inline help.

Start your python interpreter (just type python in the shell).

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

This should give you a detailed documentation on libvirt.

like image 21
plasmixs Avatar answered Sep 20 '22 01:09

plasmixs