From fd21f1b3ec43888cd22c8fd7a2c8be7c4eb37626 Mon Sep 17 00:00:00 2001
From: Daniel Veillard <veillard@redhat.com>
Date: Fri, 24 Feb 2006 12:26:56 +0000
Subject: [PATCH] * python/generator.py python/libvir.c
 python/libvirt-python-api.xml:   UUID strings can contain zeroes, so the
 autogenerated conversion   functions don't work. Daniel

---
 ChangeLog                     |  6 ++++++
 python/generator.py           |  3 ++-
 python/libvir.c               | 24 ++++++++++++++++++++++++
 python/libvirt-python-api.xml |  6 ++++++
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 6968673f8a..c460f66018 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Feb 24 13:25:36 CET 2006 Daniel Veillard <veillard@redhat.com>
+
+	* python/generator.py python/libvir.c python/libvirt-python-api.xml:
+	  UUID strings can contain zeroes, so the autogenerated conversion
+	  functions don't work.
+
 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
diff --git a/python/generator.py b/python/generator.py
index d9fa809146..005ac07f44 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -204,7 +204,7 @@ def enum(type, name, value):
 
 functions_failed = []
 functions_skipped = [
-    "virConnectListDomains" , "virDomainGetUUID"
+    "virConnectListDomains"
 ]
 
 skipped_modules = {
@@ -262,6 +262,7 @@ skip_impl = (
     'virConnectListDomainsID',
     'virDomainGetInfo',
     'virDomainGetUUID',
+    'virDomainLookupByUUID',
 )
 
 def skip_function(name):
diff --git a/python/libvir.c b/python/libvir.c
index 3cd28490ef..2a43142f16 100644
--- a/python/libvir.c
+++ b/python/libvir.c
@@ -125,6 +125,29 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
     return(py_retval);
 }
 
+PyObject *
+libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+    PyObject *py_retval;
+    virDomainPtr c_retval;
+    virConnectPtr conn;
+    PyObject *pyobj_conn;
+    unsigned char * uuid;
+    int len;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID", &pyobj_conn, &uuid, &len))
+        return(NULL);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    if ((uuid == NULL) || (len != 16)) {
+        Py_INCREF(Py_None);
+	return(Py_None);
+    }
+
+    c_retval = virDomainLookupByUUID(conn, uuid);
+    py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
+    return(py_retval);
+}
+
 /************************************************************************
  *									*
  *			The registration stuff				*
@@ -137,6 +160,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
     {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
     {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
+    {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
diff --git a/python/libvirt-python-api.xml b/python/libvirt-python-api.xml
index 2a4328010f..3b75525665 100644
--- a/python/libvirt-python-api.xml
+++ b/python/libvirt-python-api.xml
@@ -6,6 +6,12 @@
       <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='virDomainLookupByUUID' file='python'>
+      <info>Try to lookup a domain on the given hypervisor based on its UUID.</info>
+      <return type='virDomainPtr' info='a new domain object or NULL in case of failure'/>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <arg name='uuid' type='const unsigned char *' info='the UUID string for the domain, must be 16 bytes'/>
+    </function>
     <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'/>