[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] libver-python fix & test script



On Tue, Feb 07, 2006 at 04:21:08PM +0000, Angus Thomas wrote:
> Against the current CVS version, the python method libvir.open() is 
> failing because it requires "name" as a parameter, but in src/libvir.c, 
> virConnectOpen returns NULL if name is set. Very simple patch attached.

  I prefer the current behaviour as I expect name to be significant in the
future and NULL (or None from python) to mean local Xen access.

> Also attached is a simple script to test reporting of domain state via 
> the python bindings. Hopefully useful as a test of the python 
> bindings/simple example of how to use them. It generates output like this:

  Okay I had something similar but less complete in my tree. I need to
incorporate more examples, I started with a C file but I will need to add
python examples too.

> [root chaka ~]# ./libver-python-test
> Attached to a hypervisor of type - Xen
> There are currently 2 domains running
> 
> Domain ID 0 is named Domain-0
>        State is Running
>        maxMem is -4
  this is a bit bizarre, that how the hypervisor direct call report 
'unlimited' maxMem. If you run the same as an user the information 
extracted from xend will usually be equal to the 'memory' value.

>        memory is 262224
>        nrVirtCpu is 1
>        cpuTime is 2294771524162

  running as root allow direct hypercall, and hence the maximum precision
provided by the Xen hypervisor for time consumption

> Domain ID 2 is named guest1
>        State is Blocked
>        maxMem is 131072
>        memory is 131052
>        nrVirtCpu is 1
>        cpuTime is 34682760385
> 

[...]

> #!/usr/bin/env python
> #
> # Simple script to test libver-python reporting
> #
> # Copyright 2005-2006  Red Hat, Inc.
> # Angus Thomas <athomas redhat com>
> #
> # This software may be freely redistributed under the terms of the GNU
> # general public license.
> #
> # You should have received a copy of the GNU General Public License
> # along with this program; if not, write to the Free Software
> # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> 
> domain_states="No State", "Running", "Blocked", "Paused", "Shutdown", "Shutoff", "Crashed"
> 
> import libvir

   Now 'import libvirt' with 0.0.4
you can do something like

try:
    import libvirt
except:
    import libvir
    libvirt = libvir

if you want to be able to still use both

> virt=libvir.open("Xen");

   Use libvirt.open(None)
 And the ; separator at the end of line is C, though legal in Python it
looks a bit strange :-)

> print ("Attached to a hypervisor of type - %s" % (virt.getType()));
> 
> print ("There are currently %s domains running" % (virt.numOfDomains()));
> 
> id_list=virt.listDomainsID();
> for dom_id in id_list:
> 	dom=virt.lookupByID(dom_id);
> 	print ("\nDomain ID %s is named %s" % (dom_id, dom.name()));
> 	dom_info=dom.info();
> #	print ("\tState is %s" % (dom_info[0]));
> 	print ("\tState is %s" % (domain_states[dom_info[0]]));
> 	print ("\tmaxMem is %s" % (dom_info[1]));
> 	print ("\tmemory is %s" % (dom_info[2]));
> 	print ("\tnrVirtCpu is %s" % (dom_info[3]));
> 	print ("\tcpuTime is %s" % (dom_info[4]));

  thanks, and sorry for the delay when answering !

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]