From 2ce9e08fac637cb6a19e5244027b118dbed708c2 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 23 Feb 2006 11:26:17 +0000 Subject: * src/libvirt.c: fixing a bug before the release of 0.0.5 * python/generator.py python/libvir.c python/libvirt-python-api.xml: also fixing the binding for getting a domain UUID * python/tests/Makefile.am python/tests/uuid.py: added a test for the new UUID API Daniel --- generator.py | 7 ++++++- libvir.c | 26 ++++++++++++++++++++++++++ libvirt-python-api.xml | 7 ++++++- tests/Makefile.am | 3 ++- tests/uuid.py | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100755 tests/uuid.py diff --git a/generator.py b/generator.py index c336f61..d9fa809 100755 --- a/generator.py +++ b/generator.py @@ -203,7 +203,9 @@ def enum(type, name, value): ####################################################################### functions_failed = [] -functions_skipped = [] +functions_skipped = [ + "virConnectListDomains" , "virDomainGetUUID" +] skipped_modules = { } @@ -259,6 +261,7 @@ foreign_encoding_args = ( skip_impl = ( 'virConnectListDomainsID', 'virDomainGetInfo', + 'virDomainGetUUID', ) def skip_function(name): @@ -568,6 +571,8 @@ def nameFixup(name, classe, type, file): func = name if func == "iD": func = "ID" + if func == "uUID": + func = "UUID" if func == "oSType": func = "OSType" if func == "xMLDesc": diff --git a/libvir.c b/libvir.c index 957f7ac..3cd2849 100644 --- a/libvir.c +++ b/libvir.c @@ -100,6 +100,31 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +PyObject * +libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + unsigned char uuid[16]; + virDomainPtr domain; + PyObject *pyobj_domain; + virDomainInfo info; + + if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain)) + return(NULL); + domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); + + if (domain == NULL) { + Py_INCREF(Py_None); + return(Py_None); + } + if (virDomainGetUUID(domain, &uuid[0]) < 0) { + Py_INCREF(Py_None); + return(Py_None); + } + py_retval = PyString_FromStringAndSize((char *) &uuid[0], 16); + + return(py_retval); +} + /************************************************************************ * * * The registration stuff * @@ -111,6 +136,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virConnectClose", libvirt_virConnectClose, METH_VARARGS, NULL}, {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL}, {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL}, + {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; diff --git a/libvirt-python-api.xml b/libvirt-python-api.xml index d90da8a..2a43280 100644 --- a/libvirt-python-api.xml +++ b/libvirt-python-api.xml @@ -6,10 +6,15 @@ - + Extract information about a domain. Note that if the connection used to get the domain is limited only a partial set of the informations can be extracted. + + Extract the UUID unique Identifier of a domain. + + + diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ab52de..fd1d5fa 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,8 @@ EXAMPLE_DIR = $(datadir)/doc/libvirt-python-$(LIBVIRT_VERSION)/examples PYTESTS= \ basic.py \ - create.py + create.py \ + uuid.py EXTRA_DIST = $(PYTESTS) diff --git a/tests/uuid.py b/tests/uuid.py new file mode 100755 index 0000000..d71d420 --- /dev/null +++ b/tests/uuid.py @@ -0,0 +1,39 @@ +#!/usr/bin/python -u +import libvirt +import sys +import os + +if not os.access("/proc/xen", os.R_OK): + print 'System is not running a Xen kernel' + sys.exit(1) + +conn = libvirt.openReadOnly(None) +if conn == None: + print 'Failed to open connection to the hypervisor' + sys.exit(1) + +ids = conn.listDomainsID() +if ids == None or len(ids) == 0: + print 'Failed to list running domains' + sys.exit(1) + +id = ids[-1] + +dom = conn.lookupByID(id) +if dom == None: + print 'Failed to find the domain %d' + sys.exit(1) + +name0 = dom.name() +uuid = dom.UUID() +print "Using domain %s" % (name0) +dom2 = conn.lookupByUUID(uuid) +if dom2 == None: + print 'Failed to lookup domain %d based on its UUID' + sys.exit(1) +if dom2.name() != name0: + print 'lookup of %s based on UUID brings a different domain %s' % ( + name0, dom2.name()) + +print "OK" +sys.exit(0) -- cgit