summaryrefslogtreecommitdiffstats
path: root/libvir.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2006-11-07 23:18:56 +0000
committerDaniel P. Berrange <berrange@redhat.com>2006-11-07 23:18:56 +0000
commit945919ffff7f4e856d17d2b5a6b48cab5417d92f (patch)
tree3305085c6fb2534b0e4bc607eb1c6f30eb67e8fd /libvir.c
parent54db0825da704d121264647798fdd829a3ade6e2 (diff)
downloadlibvirt-python-v6-945919ffff7f4e856d17d2b5a6b48cab5417d92f.tar.gz
libvirt-python-v6-945919ffff7f4e856d17d2b5a6b48cab5417d92f.tar.xz
libvirt-python-v6-945919ffff7f4e856d17d2b5a6b48cab5417d92f.zip
Propagate libvirt errors back with python exceptions
Diffstat (limited to 'libvir.c')
-rw-r--r--libvir.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libvir.c b/libvir.c
index 3d580e5..a7b98dc 100644
--- a/libvir.c
+++ b/libvir.c
@@ -18,6 +18,8 @@
void initlibvirmod(void);
PyObject *libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
+PyObject *libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
+PyObject *libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
/************************************************************************
@@ -29,6 +31,62 @@ PyObject *libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *ar
static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
+PyObject *
+libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED)
+{
+ virError err;
+ PyObject *info;
+
+ if (virCopyLastError(&err) <= 0) {
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+
+ info = PyTuple_New(9);
+ PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code));
+ PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain));
+ PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message));
+ PyTuple_SetItem(info, 3, PyInt_FromLong((long) err.level));
+ PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err.str1));
+ PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err.str2));
+ PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err.str3));
+ PyTuple_SetItem(info, 7, PyInt_FromLong((long) err.int1));
+ PyTuple_SetItem(info, 8, PyInt_FromLong((long) err.int2));
+
+ return info;
+}
+
+PyObject *
+libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
+{
+ virError err;
+ PyObject *info;
+ virConnectPtr conn;
+ PyObject *pyobj_conn;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virConGetLastError", &pyobj_conn))
+ return(NULL);
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ if (virConnCopyLastError(conn, &err) <= 0) {
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+
+ info = PyTuple_New(9);
+ PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code));
+ PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain));
+ PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message));
+ PyTuple_SetItem(info, 3, PyInt_FromLong((long) err.level));
+ PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err.str1));
+ PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err.str2));
+ PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err.str3));
+ PyTuple_SetItem(info, 7, PyInt_FromLong((long) err.int1));
+ PyTuple_SetItem(info, 8, PyInt_FromLong((long) err.int2));
+
+ return info;
+}
+
static void
libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err)
{
@@ -311,6 +369,8 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
{(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
{(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
+ {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
+ {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};