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.
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:
[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
memory is 262224
nrVirtCpu is 1
cpuTime is 2294771524162
Domain ID 2 is named guest1
State is Blocked
maxMem is 131072
memory is 131052
nrVirtCpu is 1
cpuTime is 34682760385
--- libvir-pristine/src/libvir.c 2006-01-27 08:59:42.000000000 +0000
+++ libvir-0.0.2/src/libvir.c 2006-02-07 12:59:17.000000000 +0000
@@ -89,8 +89,8 @@
struct xs_handle *xshandle = NULL;
/* we can only talk to the local Xen supervisor ATM */
- if (name != NULL)
- return(NULL);
+/* if (name != NULL)
+ return(NULL); */
handle = xenHypervisorOpen();
if (handle == -1)
#!/usr/bin/env python
#
# Simple script to test libver-python reporting
#
# Copyright 2005-2006 Red Hat, Inc.
# Angus Thomas <athomas(a)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
virt=libvir.open("Xen");
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]));