]> xenbits.xensource.com Git - libvirt.git/commitdiff
* src/libvirt.c: fixing a bug before the release of 0.0.5
authorDaniel Veillard <veillard@redhat.com>
Thu, 23 Feb 2006 11:26:17 +0000 (11:26 +0000)
committerDaniel Veillard <veillard@redhat.com>
Thu, 23 Feb 2006 11:26:17 +0000 (11:26 +0000)
* 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

ChangeLog
docs/examples/examples.xml
python/generator.py
python/libvir.c
python/libvirt-python-api.xml
python/tests/Makefile.am
python/tests/uuid.py [new file with mode: 0755]
src/libvirt.c

index 93b5c46b013935ad185c2f0f3e6dfa1ff7102e7e..6968673f8a5a3808b8b355d912e6ab0d0531d501 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Feb 23 06:24:46 EST 2006 Daniel Veillard <veillard@redhat.com>
+
+       * 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
+
 Thu Feb 23 11:41:06 CET 2006 Daniel Veillard <veillard@redhat.com>
 
        * NEWS configure.in docs/libvir.html docs/news.html: preparing the
index 84dbfe25f427ee80f860d896f4f020a157f02157..5e54567843625422dffd3075dad9a94403eda618 100644 (file)
     <includes>
     </includes>
     <uses>
-      <function line='30' file='libvirt' name='virDomainGetInfo'/>
-      <function line='110' file='libvirt' name='virConnectListDomains'/>
-      <function line='92' file='libvirt' name='virDomainFree'/>
-      <function line='72' file='libvirt' name='virDomainResume'/>
-      <function line='49' file='libvirt' name='virDomainLookupByID'/>
-      <function line='131' file='libvirt' name='virConnectClose'/>
-      <struct line='27' file='libvirt' name='virDomainInfo'/>
-      <function line='61' file='libvirt' name='virDomainSuspend'/>
-      <function line='99' file='libvirt' name='virConnectOpenReadOnly'/>
+      <function line='31' file='libvirt' name='virDomainGetInfo'/>
+      <function line='111' file='libvirt' name='virConnectListDomains'/>
+      <function line='93' file='libvirt' name='virDomainFree'/>
+      <function line='73' file='libvirt' name='virDomainResume'/>
+      <function line='50' file='libvirt' name='virDomainLookupByID'/>
+      <function line='132' file='libvirt' name='virConnectClose'/>
+      <struct line='28' file='libvirt' name='virDomainInfo'/>
+      <function line='62' file='libvirt' name='virDomainSuspend'/>
+      <function line='100' file='libvirt' name='virConnectOpenReadOnly'/>
     </uses>
   </example>
   <symbols>
index c336f6114359139d1e0f5305873e29bc9d880ea8..d9fa809146dfbe96dd5610a3369660bd958abe24 100755 (executable)
@@ -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":
index 957f7ac11a11e169f1a94b167e4173903be57a10..3cd28490efb90ae1445de7cb846c5621e740e395 100644 (file)
@@ -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}
 };
 
index d90da8a27a4adec6702faf0e7d92688496dd23d8..2a4328010fa0efc21f5088f973d1550c28ac888b 100644 (file)
@@ -6,10 +6,15 @@
       <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
       <return type='int *' info="the list of ID or None in case of error"/>
     </function>
-    <function name='virDomainGetInfo' file='libvir' module='libvir'>
+    <function name='virDomainGetInfo' file='libvir' module='python'>
       <info>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.</info>
       <return type='int *' info='the list of informations or None in case of error'/>
       <arg name='domain' type='virDomainPtr' info='a domain object'/>
     </function>
+    <function name='virDomainGetUUID' file='libvir' module='python'>
+      <info>Extract the UUID unique Identifier of a domain.</info>
+      <return type='char *' info='the 16 bytes string or None in case of error'/>
+      <arg name='domain' type='virDomainPtr' info='a domain object'/>
+    </function>
   </symbols>
 </api>
index 8ab52ded901540e14e540416ea1638dd2aa195da..fd1d5fa8f67b9f6357ccb5aff388607aff94a2fd 100644 (file)
@@ -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/python/tests/uuid.py b/python/tests/uuid.py
new file mode 100755 (executable)
index 0000000..d71d420
--- /dev/null
@@ -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)
index 489599a5d3ee87550f8c8d3acfc7b6f512dfd13a..6c4596da54e2bc4fc91cacac3bb1f722fd37305d 100644 (file)
@@ -103,6 +103,7 @@ virConnectOpen(const char *name) {
     ret = (virConnectPtr) malloc(sizeof(virConnect));
     if (ret == NULL)
         goto failed;
+    memset(ret, 0, sizeof(virConnect));
     ret->magic = VIR_CONNECT_MAGIC;
     ret->handle = handle;
     ret->xshandle = xshandle;
@@ -158,6 +159,7 @@ virConnectOpenReadOnly(const char *name) {
     ret = (virConnectPtr) malloc(sizeof(virConnect));
     if (ret == NULL)
         goto failed;
+    memset(ret, 0, sizeof(virConnect));
     ret->magic = VIR_CONNECT_MAGIC;
     ret->handle = handle;
     ret->xshandle = xshandle;
@@ -644,6 +646,7 @@ virDomainLookupByID(virConnectPtr conn, int id) {
     if (ret == NULL) {
         goto error;
     }
+    memset(ret, 0, sizeof(virDomain));
     ret->magic = VIR_DOMAIN_MAGIC;
     ret->conn = conn;
     ret->handle = id;
@@ -719,10 +722,12 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
            free(name);
        return(NULL);
     }
+    memset(ret, 0, sizeof(virDomain));
     ret->magic = VIR_DOMAIN_MAGIC;
     ret->conn = conn;
     ret->handle = id;
     ret->name = name;
+    ret->path = 0;
     memcpy(ret->uuid, uuid, 16);
 
     return(ret);
@@ -794,6 +799,7 @@ do_found:
        ret = (virDomainPtr) malloc(sizeof(virDomain));
        if (ret == NULL)
            goto done;
+       memset(ret, 0, sizeof(virDomain));
        ret->magic = VIR_DOMAIN_MAGIC;
        ret->conn = conn;
        ret->handle = id;