2 * libvir.c: this modules implements the main part of the glue of the
3 * libvir library and the Python interpreter. It provides the
4 * entry points where an automatically generated stub is
7 * Copyright (C) 2005, 2007-2009 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
14 /* Horrible kludge to work around even more horrible name-space pollution
15 via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
16 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
20 #include "libvirt/libvirt.h"
21 #include "libvirt/virterror.h"
22 #include "typewrappers.h"
26 extern void initlibvirtmod(void);
28 extern void initcygvirtmod(void);
31 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
32 is so common that we encapsulate it here. Now, each use is simply
33 return VIR_PY_NONE; */
34 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
35 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
36 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
38 static char *py_str(PyObject
*obj
)
40 PyObject
*str
= PyObject_Str(obj
);
46 return PyString_AsString(str
);
50 /************************************************************************
54 ************************************************************************/
57 libvirt_virDomainBlockStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
59 PyObject
*pyobj_domain
;
62 virDomainBlockStatsStruct stats
;
65 if (!PyArg_ParseTuple(args
, (char *)"Oz:virDomainBlockStats",
68 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
70 LIBVIRT_BEGIN_ALLOW_THREADS
;
71 c_retval
= virDomainBlockStats(domain
, path
, &stats
, sizeof(stats
));
72 LIBVIRT_END_ALLOW_THREADS
;
77 /* convert to a Python tuple of long objects */
78 if ((info
= PyTuple_New(5)) == NULL
)
80 PyTuple_SetItem(info
, 0, PyLong_FromLongLong(stats
.rd_req
));
81 PyTuple_SetItem(info
, 1, PyLong_FromLongLong(stats
.rd_bytes
));
82 PyTuple_SetItem(info
, 2, PyLong_FromLongLong(stats
.wr_req
));
83 PyTuple_SetItem(info
, 3, PyLong_FromLongLong(stats
.wr_bytes
));
84 PyTuple_SetItem(info
, 4, PyLong_FromLongLong(stats
.errs
));
89 libvirt_virDomainInterfaceStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
91 PyObject
*pyobj_domain
;
94 virDomainInterfaceStatsStruct stats
;
97 if (!PyArg_ParseTuple(args
, (char *)"Oz:virDomainInterfaceStats",
100 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
102 LIBVIRT_BEGIN_ALLOW_THREADS
;
103 c_retval
= virDomainInterfaceStats(domain
, path
, &stats
, sizeof(stats
));
104 LIBVIRT_END_ALLOW_THREADS
;
109 /* convert to a Python tuple of long objects */
110 if ((info
= PyTuple_New(8)) == NULL
)
112 PyTuple_SetItem(info
, 0, PyLong_FromLongLong(stats
.rx_bytes
));
113 PyTuple_SetItem(info
, 1, PyLong_FromLongLong(stats
.rx_packets
));
114 PyTuple_SetItem(info
, 2, PyLong_FromLongLong(stats
.rx_errs
));
115 PyTuple_SetItem(info
, 3, PyLong_FromLongLong(stats
.rx_drop
));
116 PyTuple_SetItem(info
, 4, PyLong_FromLongLong(stats
.tx_bytes
));
117 PyTuple_SetItem(info
, 5, PyLong_FromLongLong(stats
.tx_packets
));
118 PyTuple_SetItem(info
, 6, PyLong_FromLongLong(stats
.tx_errs
));
119 PyTuple_SetItem(info
, 7, PyLong_FromLongLong(stats
.tx_drop
));
124 libvirt_virDomainMemoryStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
126 PyObject
*pyobj_domain
;
127 unsigned int nr_stats
, i
;
128 virDomainMemoryStatStruct stats
[VIR_DOMAIN_MEMORY_STAT_NR
];
131 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainMemoryStats", &pyobj_domain
))
133 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
135 nr_stats
= virDomainMemoryStats(domain
, stats
,
136 VIR_DOMAIN_MEMORY_STAT_NR
, 0);
140 /* convert to a Python dictionary */
141 if ((info
= PyDict_New()) == NULL
)
144 for (i
= 0; i
< nr_stats
; i
++) {
145 if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_SWAP_IN
)
146 PyDict_SetItem(info
, libvirt_constcharPtrWrap("swap_in"),
147 PyLong_FromUnsignedLongLong(stats
[i
].val
));
148 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_SWAP_OUT
)
149 PyDict_SetItem(info
, libvirt_constcharPtrWrap("swap_out"),
150 PyLong_FromUnsignedLongLong(stats
[i
].val
));
151 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT
)
152 PyDict_SetItem(info
, libvirt_constcharPtrWrap("major_fault"),
153 PyLong_FromUnsignedLongLong(stats
[i
].val
));
154 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT
)
155 PyDict_SetItem(info
, libvirt_constcharPtrWrap("minor_fault"),
156 PyLong_FromUnsignedLongLong(stats
[i
].val
));
157 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_UNUSED
)
158 PyDict_SetItem(info
, libvirt_constcharPtrWrap("unused"),
159 PyLong_FromUnsignedLongLong(stats
[i
].val
));
160 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_AVAILABLE
)
161 PyDict_SetItem(info
, libvirt_constcharPtrWrap("available"),
162 PyLong_FromUnsignedLongLong(stats
[i
].val
));
168 libvirt_virDomainGetSchedulerType(PyObject
*self ATTRIBUTE_UNUSED
,
171 PyObject
*pyobj_domain
, *info
;
175 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetScedulerType",
178 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
180 LIBVIRT_BEGIN_ALLOW_THREADS
;
181 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
182 LIBVIRT_END_ALLOW_THREADS
;
183 if (c_retval
== NULL
)
186 /* convert to a Python tuple of long objects */
187 if ((info
= PyTuple_New(2)) == NULL
) {
192 PyTuple_SetItem(info
, 0, libvirt_constcharPtrWrap(c_retval
));
193 PyTuple_SetItem(info
, 1, PyInt_FromLong((long)nparams
));
199 libvirt_virDomainGetSchedulerParameters(PyObject
*self ATTRIBUTE_UNUSED
,
202 PyObject
*pyobj_domain
, *info
;
206 virSchedParameterPtr params
;
208 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetScedulerParameters",
211 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
213 LIBVIRT_BEGIN_ALLOW_THREADS
;
214 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
215 LIBVIRT_END_ALLOW_THREADS
;
217 if (c_retval
== NULL
)
221 if ((params
= malloc(sizeof(*params
)*nparams
)) == NULL
)
224 LIBVIRT_BEGIN_ALLOW_THREADS
;
225 i_retval
= virDomainGetSchedulerParameters(domain
, params
, &nparams
);
226 LIBVIRT_END_ALLOW_THREADS
;
233 /* convert to a Python tuple of long objects */
234 if ((info
= PyDict_New()) == NULL
) {
238 for (i
= 0 ; i
< nparams
; i
++) {
241 switch (params
[i
].type
) {
242 case VIR_DOMAIN_SCHED_FIELD_INT
:
243 val
= PyInt_FromLong((long)params
[i
].value
.i
);
246 case VIR_DOMAIN_SCHED_FIELD_UINT
:
247 val
= PyInt_FromLong((long)params
[i
].value
.ui
);
250 case VIR_DOMAIN_SCHED_FIELD_LLONG
:
251 val
= PyLong_FromLongLong((long long)params
[i
].value
.l
);
254 case VIR_DOMAIN_SCHED_FIELD_ULLONG
:
255 val
= PyLong_FromLongLong((long long)params
[i
].value
.ul
);
258 case VIR_DOMAIN_SCHED_FIELD_DOUBLE
:
259 val
= PyFloat_FromDouble((double)params
[i
].value
.d
);
262 case VIR_DOMAIN_SCHED_FIELD_BOOLEAN
:
263 val
= PyBool_FromLong((long)params
[i
].value
.b
);
272 key
= libvirt_constcharPtrWrap(params
[i
].field
);
273 PyDict_SetItem(info
, key
, val
);
280 libvirt_virDomainSetSchedulerParameters(PyObject
*self ATTRIBUTE_UNUSED
,
283 PyObject
*pyobj_domain
, *info
;
287 virSchedParameterPtr params
;
289 if (!PyArg_ParseTuple(args
, (char *)"OO:virDomainSetScedulerParameters",
290 &pyobj_domain
, &info
))
292 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
294 LIBVIRT_BEGIN_ALLOW_THREADS
;
295 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
296 LIBVIRT_END_ALLOW_THREADS
;
298 if (c_retval
== NULL
)
299 return VIR_PY_INT_FAIL
;
302 if ((params
= malloc(sizeof(*params
)*nparams
)) == NULL
)
303 return VIR_PY_INT_FAIL
;
305 LIBVIRT_BEGIN_ALLOW_THREADS
;
306 i_retval
= virDomainGetSchedulerParameters(domain
, params
, &nparams
);
307 LIBVIRT_END_ALLOW_THREADS
;
311 return VIR_PY_INT_FAIL
;
314 /* convert to a Python tuple of long objects */
315 for (i
= 0 ; i
< nparams
; i
++) {
317 key
= libvirt_constcharPtrWrap(params
[i
].field
);
318 val
= PyDict_GetItem(info
, key
);
324 switch (params
[i
].type
) {
325 case VIR_DOMAIN_SCHED_FIELD_INT
:
326 params
[i
].value
.i
= (int)PyInt_AS_LONG(val
);
329 case VIR_DOMAIN_SCHED_FIELD_UINT
:
330 params
[i
].value
.ui
= (unsigned int)PyInt_AS_LONG(val
);
333 case VIR_DOMAIN_SCHED_FIELD_LLONG
:
334 params
[i
].value
.l
= (long long)PyLong_AsLongLong(val
);
337 case VIR_DOMAIN_SCHED_FIELD_ULLONG
:
338 params
[i
].value
.ul
= (unsigned long long)PyLong_AsLongLong(val
);
341 case VIR_DOMAIN_SCHED_FIELD_DOUBLE
:
342 params
[i
].value
.d
= (double)PyFloat_AsDouble(val
);
345 case VIR_DOMAIN_SCHED_FIELD_BOOLEAN
:
347 /* Hack - Python's definition of Py_True breaks strict
348 * aliasing rules, so can't directly compare :-(
350 PyObject
*hacktrue
= PyBool_FromLong(1);
351 params
[i
].value
.b
= hacktrue
== val
? 1 : 0;
358 return VIR_PY_INT_FAIL
;
362 LIBVIRT_BEGIN_ALLOW_THREADS
;
363 i_retval
= virDomainSetSchedulerParameters(domain
, params
, nparams
);
364 LIBVIRT_END_ALLOW_THREADS
;
367 return VIR_PY_INT_FAIL
;
371 return VIR_PY_INT_SUCCESS
;
375 libvirt_virDomainGetVcpus(PyObject
*self ATTRIBUTE_UNUSED
,
378 PyObject
*pyobj_domain
, *pyretval
= NULL
, *pycpuinfo
= NULL
, *pycpumap
= NULL
;
379 virNodeInfo nodeinfo
;
380 virDomainInfo dominfo
;
381 virVcpuInfoPtr cpuinfo
= NULL
;
382 unsigned char *cpumap
= NULL
;
386 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetVcpus",
389 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
391 LIBVIRT_BEGIN_ALLOW_THREADS
;
392 i_retval
= virNodeGetInfo(virDomainGetConnect(domain
), &nodeinfo
);
393 LIBVIRT_END_ALLOW_THREADS
;
397 LIBVIRT_BEGIN_ALLOW_THREADS
;
398 i_retval
= virDomainGetInfo(domain
, &dominfo
);
399 LIBVIRT_END_ALLOW_THREADS
;
403 if ((cpuinfo
= malloc(sizeof(*cpuinfo
)*dominfo
.nrVirtCpu
)) == NULL
)
406 cpumaplen
= VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo
));
407 if ((cpumap
= malloc(dominfo
.nrVirtCpu
* cpumaplen
)) == NULL
)
410 LIBVIRT_BEGIN_ALLOW_THREADS
;
411 i_retval
= virDomainGetVcpus(domain
,
412 cpuinfo
, dominfo
.nrVirtCpu
,
414 LIBVIRT_END_ALLOW_THREADS
;
418 /* convert to a Python tuple of long objects */
419 if ((pyretval
= PyTuple_New(2)) == NULL
)
421 if ((pycpuinfo
= PyList_New(dominfo
.nrVirtCpu
)) == NULL
)
423 if ((pycpumap
= PyList_New(dominfo
.nrVirtCpu
)) == NULL
)
426 for (i
= 0 ; i
< dominfo
.nrVirtCpu
; i
++) {
427 PyObject
*info
= PyTuple_New(4);
430 PyTuple_SetItem(info
, 0, PyInt_FromLong((long)cpuinfo
[i
].number
));
431 PyTuple_SetItem(info
, 1, PyInt_FromLong((long)cpuinfo
[i
].state
));
432 PyTuple_SetItem(info
, 2, PyLong_FromLongLong((long long)cpuinfo
[i
].cpuTime
));
433 PyTuple_SetItem(info
, 3, PyInt_FromLong((long)cpuinfo
[i
].cpu
));
434 PyList_SetItem(pycpuinfo
, i
, info
);
436 for (i
= 0 ; i
< dominfo
.nrVirtCpu
; i
++) {
437 PyObject
*info
= PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo
));
441 for (j
= 0 ; j
< VIR_NODEINFO_MAXCPUS(nodeinfo
) ; j
++) {
442 PyTuple_SetItem(info
, j
, PyBool_FromLong(VIR_CPU_USABLE(cpumap
, cpumaplen
, i
, j
)));
444 PyList_SetItem(pycpumap
, i
, info
);
446 PyTuple_SetItem(pyretval
, 0, pycpuinfo
);
447 PyTuple_SetItem(pyretval
, 1, pycpumap
);
457 /* NB, Py_DECREF is a badly defined macro, so we require
458 * braces here to avoid 'ambiguous else' warnings from
460 * NB. this comment is true at of time of writing wrt to
461 * at least python2.5.
463 if (pyretval
) { Py_DECREF(pyretval
); }
464 if (pycpuinfo
) { Py_DECREF(pycpuinfo
); }
465 if (pycpumap
) { Py_DECREF(pycpumap
); }
471 libvirt_virDomainPinVcpu(PyObject
*self ATTRIBUTE_UNUSED
,
474 PyObject
*pyobj_domain
, *pycpumap
, *truth
;
475 virNodeInfo nodeinfo
;
476 unsigned char *cpumap
;
477 int cpumaplen
, i
, vcpu
;
480 if (!PyArg_ParseTuple(args
, (char *)"OiO:virDomainPinVcpu",
481 &pyobj_domain
, &vcpu
, &pycpumap
))
483 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
485 LIBVIRT_BEGIN_ALLOW_THREADS
;
486 i_retval
= virNodeGetInfo(virDomainGetConnect(domain
), &nodeinfo
);
487 LIBVIRT_END_ALLOW_THREADS
;
489 return VIR_PY_INT_FAIL
;
491 cpumaplen
= VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo
));
492 if ((cpumap
= malloc(cpumaplen
)) == NULL
)
493 return VIR_PY_INT_FAIL
;
494 memset(cpumap
, 0, cpumaplen
);
496 truth
= PyBool_FromLong(1);
497 for (i
= 0 ; i
< VIR_NODEINFO_MAXCPUS(nodeinfo
) ; i
++) {
498 PyObject
*flag
= PyTuple_GetItem(pycpumap
, i
);
500 VIR_USE_CPU(cpumap
, i
);
502 VIR_UNUSE_CPU(cpumap
, i
);
505 LIBVIRT_BEGIN_ALLOW_THREADS
;
506 i_retval
= virDomainPinVcpu(domain
, vcpu
, cpumap
, cpumaplen
);
507 LIBVIRT_END_ALLOW_THREADS
;
512 return VIR_PY_INT_FAIL
;
514 return VIR_PY_INT_SUCCESS
;
518 /************************************************************************
520 * Global error handler at the Python level *
522 ************************************************************************/
524 static PyObject
*libvirt_virPythonErrorFuncHandler
= NULL
;
525 static PyObject
*libvirt_virPythonErrorFuncCtxt
= NULL
;
528 libvirt_virGetLastError(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args ATTRIBUTE_UNUSED
)
533 if ((err
= virGetLastError()) == NULL
)
536 if ((info
= PyTuple_New(9)) == NULL
)
538 PyTuple_SetItem(info
, 0, PyInt_FromLong((long) err
->code
));
539 PyTuple_SetItem(info
, 1, PyInt_FromLong((long) err
->domain
));
540 PyTuple_SetItem(info
, 2, libvirt_constcharPtrWrap(err
->message
));
541 PyTuple_SetItem(info
, 3, PyInt_FromLong((long) err
->level
));
542 PyTuple_SetItem(info
, 4, libvirt_constcharPtrWrap(err
->str1
));
543 PyTuple_SetItem(info
, 5, libvirt_constcharPtrWrap(err
->str2
));
544 PyTuple_SetItem(info
, 6, libvirt_constcharPtrWrap(err
->str3
));
545 PyTuple_SetItem(info
, 7, PyInt_FromLong((long) err
->int1
));
546 PyTuple_SetItem(info
, 8, PyInt_FromLong((long) err
->int2
));
552 libvirt_virConnGetLastError(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
557 PyObject
*pyobj_conn
;
559 if (!PyArg_ParseTuple(args
, (char *)"O:virConGetLastError", &pyobj_conn
))
561 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
563 LIBVIRT_BEGIN_ALLOW_THREADS
;
564 err
= virConnGetLastError(conn
);
565 LIBVIRT_END_ALLOW_THREADS
;
569 if ((info
= PyTuple_New(9)) == NULL
)
571 PyTuple_SetItem(info
, 0, PyInt_FromLong((long) err
->code
));
572 PyTuple_SetItem(info
, 1, PyInt_FromLong((long) err
->domain
));
573 PyTuple_SetItem(info
, 2, libvirt_constcharPtrWrap(err
->message
));
574 PyTuple_SetItem(info
, 3, PyInt_FromLong((long) err
->level
));
575 PyTuple_SetItem(info
, 4, libvirt_constcharPtrWrap(err
->str1
));
576 PyTuple_SetItem(info
, 5, libvirt_constcharPtrWrap(err
->str2
));
577 PyTuple_SetItem(info
, 6, libvirt_constcharPtrWrap(err
->str3
));
578 PyTuple_SetItem(info
, 7, PyInt_FromLong((long) err
->int1
));
579 PyTuple_SetItem(info
, 8, PyInt_FromLong((long) err
->int2
));
585 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED
void *ctx
, virErrorPtr err
)
587 PyObject
*list
, *info
;
591 printf("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx
,
595 if ((err
== NULL
) || (err
->code
== VIR_ERR_OK
))
598 LIBVIRT_ENSURE_THREAD_STATE
;
600 if ((libvirt_virPythonErrorFuncHandler
== NULL
) ||
601 (libvirt_virPythonErrorFuncHandler
== Py_None
)) {
602 virDefaultErrorFunc(err
);
604 list
= PyTuple_New(2);
605 info
= PyTuple_New(9);
606 PyTuple_SetItem(list
, 0, libvirt_virPythonErrorFuncCtxt
);
607 PyTuple_SetItem(list
, 1, info
);
608 Py_XINCREF(libvirt_virPythonErrorFuncCtxt
);
609 PyTuple_SetItem(info
, 0, PyInt_FromLong((long) err
->code
));
610 PyTuple_SetItem(info
, 1, PyInt_FromLong((long) err
->domain
));
611 PyTuple_SetItem(info
, 2, libvirt_constcharPtrWrap(err
->message
));
612 PyTuple_SetItem(info
, 3, PyInt_FromLong((long) err
->level
));
613 PyTuple_SetItem(info
, 4, libvirt_constcharPtrWrap(err
->str1
));
614 PyTuple_SetItem(info
, 5, libvirt_constcharPtrWrap(err
->str2
));
615 PyTuple_SetItem(info
, 6, libvirt_constcharPtrWrap(err
->str3
));
616 PyTuple_SetItem(info
, 7, PyInt_FromLong((long) err
->int1
));
617 PyTuple_SetItem(info
, 8, PyInt_FromLong((long) err
->int2
));
618 /* TODO pass conn and dom if available */
619 result
= PyEval_CallObject(libvirt_virPythonErrorFuncHandler
, list
);
624 LIBVIRT_RELEASE_THREAD_STATE
;
628 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject
* self
,
635 if (!PyArg_ParseTuple
636 (args
, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f
,
641 printf("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx
,
645 virSetErrorFunc(NULL
, libvirt_virErrorFuncHandler
);
646 if (libvirt_virPythonErrorFuncHandler
!= NULL
) {
647 Py_XDECREF(libvirt_virPythonErrorFuncHandler
);
649 if (libvirt_virPythonErrorFuncCtxt
!= NULL
) {
650 Py_XDECREF(libvirt_virPythonErrorFuncCtxt
);
653 if ((pyobj_f
== Py_None
) && (pyobj_ctx
== Py_None
)) {
654 libvirt_virPythonErrorFuncHandler
= NULL
;
655 libvirt_virPythonErrorFuncCtxt
= NULL
;
657 Py_XINCREF(pyobj_ctx
);
660 /* TODO: check f is a function ! */
661 libvirt_virPythonErrorFuncHandler
= pyobj_f
;
662 libvirt_virPythonErrorFuncCtxt
= pyobj_ctx
;
665 py_retval
= libvirt_intWrap(1);
669 static int virConnectCredCallbackWrapper(virConnectCredentialPtr cred
,
674 PyObject
*pyauth
= (PyObject
*)cbdata
;
680 LIBVIRT_ENSURE_THREAD_STATE
;
682 pycb
= PyList_GetItem(pyauth
, 1);
683 pycbdata
= PyList_GetItem(pyauth
, 2);
685 list
= PyTuple_New(2);
686 pycred
= PyTuple_New(ncred
);
687 for (i
= 0 ; i
< ncred
; i
++) {
688 PyObject
*pycreditem
;
689 pycreditem
= PyList_New(5);
691 PyTuple_SetItem(pycred
, i
, pycreditem
);
692 PyList_SetItem(pycreditem
, 0, PyInt_FromLong((long) cred
[i
].type
));
693 PyList_SetItem(pycreditem
, 1, PyString_FromString(cred
[i
].prompt
));
694 if (cred
[i
].challenge
) {
695 PyList_SetItem(pycreditem
, 2, PyString_FromString(cred
[i
].challenge
));
698 PyList_SetItem(pycreditem
, 2, Py_None
);
700 if (cred
[i
].defresult
) {
701 PyList_SetItem(pycreditem
, 3, PyString_FromString(cred
[i
].defresult
));
704 PyList_SetItem(pycreditem
, 3, Py_None
);
706 PyList_SetItem(pycreditem
, 4, Py_None
);
709 PyTuple_SetItem(list
, 0, pycred
);
710 Py_XINCREF(pycbdata
);
711 PyTuple_SetItem(list
, 1, pycbdata
);
714 pyret
= PyEval_CallObject(pycb
, list
);
715 if (PyErr_Occurred())
718 ret
= PyLong_AsLong(pyret
);
720 for (i
= 0 ; i
< ncred
; i
++) {
721 PyObject
*pycreditem
;
724 pycreditem
= PyTuple_GetItem(pycred
, i
);
725 pyresult
= PyList_GetItem(pycreditem
, 4);
726 if (pyresult
!= Py_None
)
727 result
= PyString_AsString(pyresult
);
728 if (result
!= NULL
) {
729 cred
[i
].result
= strdup(result
);
730 cred
[i
].resultlen
= strlen(result
);
732 cred
[i
].result
= NULL
;
733 cred
[i
].resultlen
= 0;
742 LIBVIRT_RELEASE_THREAD_STATE
;
749 libvirt_virConnectOpenAuth(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
751 virConnectPtr c_retval
;
756 PyObject
*pycredtype
;
759 if (!PyArg_ParseTuple(args
, (char *)"zOi:virConnectOpenAuth", &name
, &pyauth
, &flags
))
762 pycredtype
= PyList_GetItem(pyauth
, 0);
763 pycredcb
= PyList_GetItem(pyauth
, 1);
765 auth
.ncredtype
= PyList_Size(pycredtype
);
766 if (auth
.ncredtype
) {
768 auth
.credtype
= malloc(sizeof(*auth
.credtype
) * auth
.ncredtype
);
769 if (auth
.credtype
== NULL
)
771 for (i
= 0 ; i
< auth
.ncredtype
; i
++) {
773 val
= PyList_GetItem(pycredtype
, i
);
774 auth
.credtype
[i
] = (int)PyLong_AsLong(val
);
777 auth
.cb
= pycredcb
? virConnectCredCallbackWrapper
: NULL
;
778 auth
.cbdata
= pyauth
;
780 LIBVIRT_BEGIN_ALLOW_THREADS
;
782 c_retval
= virConnectOpenAuth(name
, &auth
, flags
);
783 LIBVIRT_END_ALLOW_THREADS
;
784 py_retval
= libvirt_virConnectPtrWrap((virConnectPtr
) c_retval
);
789 /************************************************************************
791 * Wrappers for functions where generator fails *
793 ************************************************************************/
796 libvirt_virGetVersion (PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
799 unsigned long libVer
, typeVer
= 0;
802 if (!PyArg_ParseTuple (args
, (char *) "|s", &type
))
805 LIBVIRT_BEGIN_ALLOW_THREADS
;
808 c_retval
= virGetVersion (&libVer
, NULL
, NULL
);
810 c_retval
= virGetVersion (&libVer
, type
, &typeVer
);
812 LIBVIRT_END_ALLOW_THREADS
;
818 return PyInt_FromLong (libVer
);
820 return Py_BuildValue ((char *) "kk", libVer
, typeVer
);
824 libvirt_virConnectGetLibVersion (PyObject
*self ATTRIBUTE_UNUSED
,
827 unsigned long libVer
;
830 PyObject
*pyobj_conn
;
832 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectGetLibVersion",
835 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
837 LIBVIRT_BEGIN_ALLOW_THREADS
;
839 c_retval
= virConnectGetLibVersion(conn
, &libVer
);
841 LIBVIRT_END_ALLOW_THREADS
;
844 return VIR_PY_INT_FAIL
;
846 return PyInt_FromLong (libVer
);
850 libvirt_virConnectListDomainsID(PyObject
*self ATTRIBUTE_UNUSED
,
853 int ids
[500], c_retval
, i
;
855 PyObject
*pyobj_conn
;
858 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDomains", &pyobj_conn
))
860 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
862 LIBVIRT_BEGIN_ALLOW_THREADS
;
863 c_retval
= virConnectListDomains(conn
, &ids
[0], 500);
864 LIBVIRT_END_ALLOW_THREADS
;
867 py_retval
= PyList_New(c_retval
);
868 for (i
= 0;i
< c_retval
;i
++) {
869 PyList_SetItem(py_retval
, i
, libvirt_intWrap(ids
[i
]));
875 libvirt_virConnectListDefinedDomains(PyObject
*self ATTRIBUTE_UNUSED
,
881 PyObject
*pyobj_conn
;
884 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedDomains", &pyobj_conn
))
886 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
888 LIBVIRT_BEGIN_ALLOW_THREADS
;
889 c_retval
= virConnectNumOfDefinedDomains(conn
);
890 LIBVIRT_END_ALLOW_THREADS
;
895 names
= malloc(sizeof(*names
) * c_retval
);
898 LIBVIRT_BEGIN_ALLOW_THREADS
;
899 c_retval
= virConnectListDefinedDomains(conn
, names
, c_retval
);
900 LIBVIRT_END_ALLOW_THREADS
;
906 py_retval
= PyList_New(c_retval
);
909 for (i
= 0;i
< c_retval
;i
++) {
910 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
920 libvirt_virDomainGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
924 PyObject
*pyobj_domain
;
927 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetInfo", &pyobj_domain
))
929 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
931 LIBVIRT_BEGIN_ALLOW_THREADS
;
932 c_retval
= virDomainGetInfo(domain
, &info
);
933 LIBVIRT_END_ALLOW_THREADS
;
936 py_retval
= PyList_New(5);
937 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.state
));
938 PyList_SetItem(py_retval
, 1, libvirt_ulongWrap(info
.maxMem
));
939 PyList_SetItem(py_retval
, 2, libvirt_ulongWrap(info
.memory
));
940 PyList_SetItem(py_retval
, 3, libvirt_intWrap((int) info
.nrVirtCpu
));
941 PyList_SetItem(py_retval
, 4,
942 libvirt_longlongWrap((unsigned long long) info
.cpuTime
));
947 libvirt_virNodeGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
951 PyObject
*pyobj_conn
;
954 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetInfo", &pyobj_conn
))
956 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
958 LIBVIRT_BEGIN_ALLOW_THREADS
;
959 c_retval
= virNodeGetInfo(conn
, &info
);
960 LIBVIRT_END_ALLOW_THREADS
;
963 py_retval
= PyList_New(8);
964 PyList_SetItem(py_retval
, 0, libvirt_constcharPtrWrap(&info
.model
[0]));
965 PyList_SetItem(py_retval
, 1, libvirt_longWrap((long) info
.memory
>> 10));
966 PyList_SetItem(py_retval
, 2, libvirt_intWrap((int) info
.cpus
));
967 PyList_SetItem(py_retval
, 3, libvirt_intWrap((int) info
.mhz
));
968 PyList_SetItem(py_retval
, 4, libvirt_intWrap((int) info
.nodes
));
969 PyList_SetItem(py_retval
, 5, libvirt_intWrap((int) info
.sockets
));
970 PyList_SetItem(py_retval
, 6, libvirt_intWrap((int) info
.cores
));
971 PyList_SetItem(py_retval
, 7, libvirt_intWrap((int) info
.threads
));
976 libvirt_virDomainGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
978 unsigned char uuid
[VIR_UUID_BUFLEN
];
980 PyObject
*pyobj_domain
;
983 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetUUID", &pyobj_domain
))
985 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
989 LIBVIRT_BEGIN_ALLOW_THREADS
;
990 c_retval
= virDomainGetUUID(domain
, &uuid
[0]);
991 LIBVIRT_END_ALLOW_THREADS
;
995 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
1001 libvirt_virDomainGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
1003 PyObject
*py_retval
;
1004 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
1006 PyObject
*pyobj_dom
;
1009 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetUUIDString",
1012 dom
= (virDomainPtr
) PyvirDomain_Get(pyobj_dom
);
1016 LIBVIRT_BEGIN_ALLOW_THREADS
;
1017 c_retval
= virDomainGetUUIDString(dom
, &uuidstr
[0]);
1018 LIBVIRT_END_ALLOW_THREADS
;
1023 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
1028 libvirt_virDomainLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1029 PyObject
*py_retval
;
1030 virDomainPtr c_retval
;
1032 PyObject
*pyobj_conn
;
1033 unsigned char * uuid
;
1036 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virDomainLookupByUUID", &pyobj_conn
, &uuid
, &len
))
1038 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1040 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
1043 LIBVIRT_BEGIN_ALLOW_THREADS
;
1044 c_retval
= virDomainLookupByUUID(conn
, uuid
);
1045 LIBVIRT_END_ALLOW_THREADS
;
1046 py_retval
= libvirt_virDomainPtrWrap((virDomainPtr
) c_retval
);
1052 libvirt_virConnectListNetworks(PyObject
*self ATTRIBUTE_UNUSED
,
1054 PyObject
*py_retval
;
1055 char **names
= NULL
;
1058 PyObject
*pyobj_conn
;
1061 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListNetworks", &pyobj_conn
))
1063 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1065 LIBVIRT_BEGIN_ALLOW_THREADS
;
1066 c_retval
= virConnectNumOfNetworks(conn
);
1067 LIBVIRT_END_ALLOW_THREADS
;
1072 names
= malloc(sizeof(*names
) * c_retval
);
1075 LIBVIRT_BEGIN_ALLOW_THREADS
;
1076 c_retval
= virConnectListNetworks(conn
, names
, c_retval
);
1077 LIBVIRT_END_ALLOW_THREADS
;
1083 py_retval
= PyList_New(c_retval
);
1086 for (i
= 0;i
< c_retval
;i
++) {
1087 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1098 libvirt_virConnectListDefinedNetworks(PyObject
*self ATTRIBUTE_UNUSED
,
1100 PyObject
*py_retval
;
1101 char **names
= NULL
;
1104 PyObject
*pyobj_conn
;
1107 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedNetworks", &pyobj_conn
))
1109 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1111 LIBVIRT_BEGIN_ALLOW_THREADS
;
1112 c_retval
= virConnectNumOfDefinedNetworks(conn
);
1113 LIBVIRT_END_ALLOW_THREADS
;
1118 names
= malloc(sizeof(*names
) * c_retval
);
1121 LIBVIRT_BEGIN_ALLOW_THREADS
;
1122 c_retval
= virConnectListDefinedNetworks(conn
, names
, c_retval
);
1123 LIBVIRT_END_ALLOW_THREADS
;
1129 py_retval
= PyList_New(c_retval
);
1132 for (i
= 0;i
< c_retval
;i
++) {
1133 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1144 libvirt_virNetworkGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1145 PyObject
*py_retval
;
1146 unsigned char uuid
[VIR_UUID_BUFLEN
];
1147 virNetworkPtr domain
;
1148 PyObject
*pyobj_domain
;
1151 if (!PyArg_ParseTuple(args
, (char *)"O:virNetworkGetUUID", &pyobj_domain
))
1153 domain
= (virNetworkPtr
) PyvirNetwork_Get(pyobj_domain
);
1157 LIBVIRT_BEGIN_ALLOW_THREADS
;
1158 c_retval
= virNetworkGetUUID(domain
, &uuid
[0]);
1159 LIBVIRT_END_ALLOW_THREADS
;
1163 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
1169 libvirt_virNetworkGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
1171 PyObject
*py_retval
;
1172 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
1174 PyObject
*pyobj_net
;
1177 if (!PyArg_ParseTuple(args
, (char *)"O:virNetworkGetUUIDString",
1180 net
= (virNetworkPtr
) PyvirNetwork_Get(pyobj_net
);
1184 LIBVIRT_BEGIN_ALLOW_THREADS
;
1185 c_retval
= virNetworkGetUUIDString(net
, &uuidstr
[0]);
1186 LIBVIRT_END_ALLOW_THREADS
;
1191 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
1196 libvirt_virNetworkLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1197 PyObject
*py_retval
;
1198 virNetworkPtr c_retval
;
1200 PyObject
*pyobj_conn
;
1201 unsigned char * uuid
;
1204 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virNetworkLookupByUUID", &pyobj_conn
, &uuid
, &len
))
1206 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1208 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
1211 LIBVIRT_BEGIN_ALLOW_THREADS
;
1212 c_retval
= virNetworkLookupByUUID(conn
, uuid
);
1213 LIBVIRT_END_ALLOW_THREADS
;
1214 py_retval
= libvirt_virNetworkPtrWrap((virNetworkPtr
) c_retval
);
1220 libvirt_virDomainGetAutostart(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1221 PyObject
*py_retval
;
1222 int c_retval
, autostart
;
1223 virDomainPtr domain
;
1224 PyObject
*pyobj_domain
;
1226 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetAutostart", &pyobj_domain
))
1229 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1231 LIBVIRT_BEGIN_ALLOW_THREADS
;
1232 c_retval
= virDomainGetAutostart(domain
, &autostart
);
1233 LIBVIRT_END_ALLOW_THREADS
;
1236 return VIR_PY_INT_FAIL
;
1237 py_retval
= libvirt_intWrap(autostart
);
1243 libvirt_virNetworkGetAutostart(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1244 PyObject
*py_retval
;
1245 int c_retval
, autostart
;
1246 virNetworkPtr network
;
1247 PyObject
*pyobj_network
;
1249 if (!PyArg_ParseTuple(args
, (char *)"O:virNetworkGetAutostart", &pyobj_network
))
1252 network
= (virNetworkPtr
) PyvirNetwork_Get(pyobj_network
);
1254 LIBVIRT_BEGIN_ALLOW_THREADS
;
1255 c_retval
= virNetworkGetAutostart(network
, &autostart
);
1256 LIBVIRT_END_ALLOW_THREADS
;
1259 return VIR_PY_INT_FAIL
;
1260 py_retval
= libvirt_intWrap(autostart
);
1265 libvirt_virNodeGetCellsFreeMemory(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
1267 PyObject
*py_retval
;
1268 PyObject
*pyobj_conn
;
1269 int startCell
, maxCells
, c_retval
, i
;
1271 unsigned long long *freeMems
;
1273 if (!PyArg_ParseTuple(args
, (char *)"Oii:virNodeGetCellsFreeMemory", &pyobj_conn
, &startCell
, &maxCells
))
1276 if ((startCell
< 0) || (maxCells
<= 0) || (startCell
+ maxCells
> 10000))
1279 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1281 malloc(maxCells
* sizeof(*freeMems
));
1282 if (freeMems
== NULL
)
1285 LIBVIRT_BEGIN_ALLOW_THREADS
;
1286 c_retval
= virNodeGetCellsFreeMemory(conn
, freeMems
, startCell
, maxCells
);
1287 LIBVIRT_END_ALLOW_THREADS
;
1294 py_retval
= PyList_New(c_retval
);
1295 for (i
= 0;i
< c_retval
;i
++) {
1296 PyList_SetItem(py_retval
, i
,
1297 libvirt_longlongWrap((long long) freeMems
[i
]));
1305 libvirt_virConnectListStoragePools(PyObject
*self ATTRIBUTE_UNUSED
,
1307 PyObject
*py_retval
;
1308 char **names
= NULL
;
1311 PyObject
*pyobj_conn
;
1314 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListStoragePools", &pyobj_conn
))
1316 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1318 LIBVIRT_BEGIN_ALLOW_THREADS
;
1319 c_retval
= virConnectNumOfStoragePools(conn
);
1320 LIBVIRT_END_ALLOW_THREADS
;
1325 names
= malloc(sizeof(*names
) * c_retval
);
1328 LIBVIRT_BEGIN_ALLOW_THREADS
;
1329 c_retval
= virConnectListStoragePools(conn
, names
, c_retval
);
1330 LIBVIRT_END_ALLOW_THREADS
;
1336 py_retval
= PyList_New(c_retval
);
1337 if (py_retval
== NULL
) {
1339 for (i
= 0;i
< c_retval
;i
++)
1347 for (i
= 0;i
< c_retval
;i
++) {
1348 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1359 libvirt_virConnectListDefinedStoragePools(PyObject
*self ATTRIBUTE_UNUSED
,
1361 PyObject
*py_retval
;
1362 char **names
= NULL
;
1365 PyObject
*pyobj_conn
;
1368 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedStoragePools", &pyobj_conn
))
1370 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1372 LIBVIRT_BEGIN_ALLOW_THREADS
;
1373 c_retval
= virConnectNumOfDefinedStoragePools(conn
);
1374 LIBVIRT_END_ALLOW_THREADS
;
1379 names
= malloc(sizeof(*names
) * c_retval
);
1382 LIBVIRT_BEGIN_ALLOW_THREADS
;
1383 c_retval
= virConnectListDefinedStoragePools(conn
, names
, c_retval
);
1384 LIBVIRT_END_ALLOW_THREADS
;
1390 py_retval
= PyList_New(c_retval
);
1391 if (py_retval
== NULL
) {
1393 for (i
= 0;i
< c_retval
;i
++)
1401 for (i
= 0;i
< c_retval
;i
++) {
1402 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1413 libvirt_virStoragePoolListVolumes(PyObject
*self ATTRIBUTE_UNUSED
,
1415 PyObject
*py_retval
;
1416 char **names
= NULL
;
1418 virStoragePoolPtr pool
;
1419 PyObject
*pyobj_pool
;
1422 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolListVolumes", &pyobj_pool
))
1424 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
1426 LIBVIRT_BEGIN_ALLOW_THREADS
;
1427 c_retval
= virStoragePoolNumOfVolumes(pool
);
1428 LIBVIRT_END_ALLOW_THREADS
;
1433 names
= malloc(sizeof(*names
) * c_retval
);
1436 LIBVIRT_BEGIN_ALLOW_THREADS
;
1437 c_retval
= virStoragePoolListVolumes(pool
, names
, c_retval
);
1438 LIBVIRT_END_ALLOW_THREADS
;
1444 py_retval
= PyList_New(c_retval
);
1445 if (py_retval
== NULL
) {
1447 for (i
= 0;i
< c_retval
;i
++)
1455 for (i
= 0;i
< c_retval
;i
++) {
1456 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1466 libvirt_virStoragePoolGetAutostart(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1467 PyObject
*py_retval
;
1468 int c_retval
, autostart
;
1469 virStoragePoolPtr pool
;
1470 PyObject
*pyobj_pool
;
1472 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetAutostart", &pyobj_pool
))
1475 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
1477 LIBVIRT_BEGIN_ALLOW_THREADS
;
1478 c_retval
= virStoragePoolGetAutostart(pool
, &autostart
);
1479 LIBVIRT_END_ALLOW_THREADS
;
1484 py_retval
= libvirt_intWrap(autostart
);
1489 libvirt_virStoragePoolGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1490 PyObject
*py_retval
;
1492 virStoragePoolPtr pool
;
1493 PyObject
*pyobj_pool
;
1494 virStoragePoolInfo info
;
1496 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetInfo", &pyobj_pool
))
1498 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
1500 LIBVIRT_BEGIN_ALLOW_THREADS
;
1501 c_retval
= virStoragePoolGetInfo(pool
, &info
);
1502 LIBVIRT_END_ALLOW_THREADS
;
1506 if ((py_retval
= PyList_New(4)) == NULL
)
1509 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.state
));
1510 PyList_SetItem(py_retval
, 1,
1511 libvirt_longlongWrap((unsigned long long) info
.capacity
));
1512 PyList_SetItem(py_retval
, 2,
1513 libvirt_longlongWrap((unsigned long long) info
.allocation
));
1514 PyList_SetItem(py_retval
, 3,
1515 libvirt_longlongWrap((unsigned long long) info
.available
));
1521 libvirt_virStorageVolGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1522 PyObject
*py_retval
;
1524 virStorageVolPtr pool
;
1525 PyObject
*pyobj_pool
;
1526 virStorageVolInfo info
;
1528 if (!PyArg_ParseTuple(args
, (char *)"O:virStorageVolGetInfo", &pyobj_pool
))
1530 pool
= (virStorageVolPtr
) PyvirStorageVol_Get(pyobj_pool
);
1532 LIBVIRT_BEGIN_ALLOW_THREADS
;
1533 c_retval
= virStorageVolGetInfo(pool
, &info
);
1534 LIBVIRT_END_ALLOW_THREADS
;
1538 if ((py_retval
= PyList_New(3)) == NULL
)
1540 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.type
));
1541 PyList_SetItem(py_retval
, 1,
1542 libvirt_longlongWrap((unsigned long long) info
.capacity
));
1543 PyList_SetItem(py_retval
, 2,
1544 libvirt_longlongWrap((unsigned long long) info
.allocation
));
1549 libvirt_virStoragePoolGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1550 PyObject
*py_retval
;
1551 unsigned char uuid
[VIR_UUID_BUFLEN
];
1552 virStoragePoolPtr pool
;
1553 PyObject
*pyobj_pool
;
1556 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetUUID", &pyobj_pool
))
1558 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
1562 LIBVIRT_BEGIN_ALLOW_THREADS
;
1563 c_retval
= virStoragePoolGetUUID(pool
, &uuid
[0]);
1564 LIBVIRT_END_ALLOW_THREADS
;
1569 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
1575 libvirt_virStoragePoolGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
1577 PyObject
*py_retval
;
1578 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
1579 virStoragePoolPtr pool
;
1580 PyObject
*pyobj_pool
;
1583 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetUUIDString", &pyobj_pool
))
1585 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
1589 LIBVIRT_BEGIN_ALLOW_THREADS
;
1590 c_retval
= virStoragePoolGetUUIDString(pool
, &uuidstr
[0]);
1591 LIBVIRT_END_ALLOW_THREADS
;
1596 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
1601 libvirt_virStoragePoolLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1602 PyObject
*py_retval
;
1603 virStoragePoolPtr c_retval
;
1605 PyObject
*pyobj_conn
;
1606 unsigned char * uuid
;
1609 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virStoragePoolLookupByUUID", &pyobj_conn
, &uuid
, &len
))
1611 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1613 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
1616 LIBVIRT_BEGIN_ALLOW_THREADS
;
1617 c_retval
= virStoragePoolLookupByUUID(conn
, uuid
);
1618 LIBVIRT_END_ALLOW_THREADS
;
1619 py_retval
= libvirt_virStoragePoolPtrWrap((virStoragePoolPtr
) c_retval
);
1624 libvirt_virNodeListDevices(PyObject
*self ATTRIBUTE_UNUSED
,
1626 PyObject
*py_retval
;
1627 char **names
= NULL
;
1630 PyObject
*pyobj_conn
;
1634 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virNodeListDevices",
1635 &pyobj_conn
, &cap
, &flags
))
1637 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1639 LIBVIRT_BEGIN_ALLOW_THREADS
;
1640 c_retval
= virNodeNumOfDevices(conn
, cap
, flags
);
1641 LIBVIRT_END_ALLOW_THREADS
;
1646 names
= malloc(sizeof(*names
) * c_retval
);
1649 LIBVIRT_BEGIN_ALLOW_THREADS
;
1650 c_retval
= virNodeListDevices(conn
, cap
, names
, c_retval
, flags
);
1651 LIBVIRT_END_ALLOW_THREADS
;
1657 py_retval
= PyList_New(c_retval
);
1660 for (i
= 0;i
< c_retval
;i
++) {
1661 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1671 libvirt_virNodeDeviceListCaps(PyObject
*self ATTRIBUTE_UNUSED
,
1673 PyObject
*py_retval
;
1674 char **names
= NULL
;
1676 virNodeDevicePtr dev
;
1677 PyObject
*pyobj_dev
;
1679 if (!PyArg_ParseTuple(args
, (char *)"O:virNodeDeviceListCaps", &pyobj_dev
))
1681 dev
= (virNodeDevicePtr
) PyvirNodeDevice_Get(pyobj_dev
);
1683 LIBVIRT_BEGIN_ALLOW_THREADS
;
1684 c_retval
= virNodeDeviceNumOfCaps(dev
);
1685 LIBVIRT_END_ALLOW_THREADS
;
1690 names
= malloc(sizeof(*names
) * c_retval
);
1693 LIBVIRT_BEGIN_ALLOW_THREADS
;
1694 c_retval
= virNodeDeviceListCaps(dev
, names
, c_retval
);
1695 LIBVIRT_END_ALLOW_THREADS
;
1701 py_retval
= PyList_New(c_retval
);
1704 for (i
= 0;i
< c_retval
;i
++) {
1705 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1715 libvirt_virSecretGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1716 PyObject
*py_retval
;
1717 unsigned char uuid
[VIR_UUID_BUFLEN
];
1718 virSecretPtr secret
;
1719 PyObject
*pyobj_secret
;
1722 if (!PyArg_ParseTuple(args
, (char *)"O:virSecretGetUUID", &pyobj_secret
))
1724 secret
= (virSecretPtr
) PyvirSecret_Get(pyobj_secret
);
1728 LIBVIRT_BEGIN_ALLOW_THREADS
;
1729 c_retval
= virSecretGetUUID(secret
, &uuid
[0]);
1730 LIBVIRT_END_ALLOW_THREADS
;
1734 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
1740 libvirt_virSecretGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
1742 PyObject
*py_retval
;
1743 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
1745 PyObject
*pyobj_dom
;
1748 if (!PyArg_ParseTuple(args
, (char *)"O:virSecretGetUUIDString",
1751 dom
= (virSecretPtr
) PyvirSecret_Get(pyobj_dom
);
1755 LIBVIRT_BEGIN_ALLOW_THREADS
;
1756 c_retval
= virSecretGetUUIDString(dom
, &uuidstr
[0]);
1757 LIBVIRT_END_ALLOW_THREADS
;
1762 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
1767 libvirt_virSecretLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1768 PyObject
*py_retval
;
1769 virSecretPtr c_retval
;
1771 PyObject
*pyobj_conn
;
1772 unsigned char * uuid
;
1775 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virSecretLookupByUUID", &pyobj_conn
, &uuid
, &len
))
1777 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1779 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
1782 LIBVIRT_BEGIN_ALLOW_THREADS
;
1783 c_retval
= virSecretLookupByUUID(conn
, uuid
);
1784 LIBVIRT_END_ALLOW_THREADS
;
1785 py_retval
= libvirt_virSecretPtrWrap((virSecretPtr
) c_retval
);
1791 libvirt_virConnectListSecrets(PyObject
*self ATTRIBUTE_UNUSED
,
1793 PyObject
*py_retval
;
1794 char **uuids
= NULL
;
1797 PyObject
*pyobj_conn
;
1799 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListSecrets", &pyobj_conn
))
1801 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1803 LIBVIRT_BEGIN_ALLOW_THREADS
;
1804 c_retval
= virConnectNumOfSecrets(conn
);
1805 LIBVIRT_END_ALLOW_THREADS
;
1810 uuids
= malloc(sizeof(*uuids
) * c_retval
);
1813 LIBVIRT_BEGIN_ALLOW_THREADS
;
1814 c_retval
= virConnectListSecrets(conn
, uuids
, c_retval
);
1815 LIBVIRT_END_ALLOW_THREADS
;
1821 py_retval
= PyList_New(c_retval
);
1824 for (i
= 0;i
< c_retval
;i
++) {
1825 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(uuids
[i
]));
1835 libvirt_virSecretGetValue(PyObject
*self ATTRIBUTE_UNUSED
,
1837 PyObject
*py_retval
;
1838 unsigned char *c_retval
;
1840 virSecretPtr secret
;
1841 PyObject
*pyobj_secret
;
1844 if (!PyArg_ParseTuple(args
, (char *)"Oi:virSecretGetValue", &pyobj_secret
,
1847 secret
= (virSecretPtr
) PyvirSecret_Get(pyobj_secret
);
1849 LIBVIRT_BEGIN_ALLOW_THREADS
;
1850 c_retval
= virSecretGetValue(secret
, &size
, flags
);
1851 LIBVIRT_END_ALLOW_THREADS
;
1853 if (c_retval
== NULL
)
1856 py_retval
= PyString_FromStringAndSize((const char *)c_retval
, size
);
1857 memset(c_retval
, 0, size
);
1864 libvirt_virSecretSetValue(PyObject
*self ATTRIBUTE_UNUSED
,
1866 PyObject
*py_retval
;
1868 virSecretPtr secret
;
1869 PyObject
*pyobj_secret
;
1874 if (!PyArg_ParseTuple(args
, (char *)"Oz#i:virSecretSetValue", &pyobj_secret
,
1875 &value
, &size
, &flags
))
1877 secret
= (virSecretPtr
) PyvirSecret_Get(pyobj_secret
);
1879 LIBVIRT_BEGIN_ALLOW_THREADS
;
1880 c_retval
= virSecretSetValue(secret
, (const unsigned char *)value
, size
,
1882 LIBVIRT_END_ALLOW_THREADS
;
1884 py_retval
= libvirt_intWrap(c_retval
);
1889 libvirt_virConnectListInterfaces(PyObject
*self ATTRIBUTE_UNUSED
,
1891 PyObject
*py_retval
;
1892 char **names
= NULL
;
1895 PyObject
*pyobj_conn
;
1898 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListInterfaces", &pyobj_conn
))
1900 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1902 LIBVIRT_BEGIN_ALLOW_THREADS
;
1903 c_retval
= virConnectNumOfInterfaces(conn
);
1904 LIBVIRT_END_ALLOW_THREADS
;
1909 names
= malloc(sizeof(*names
) * c_retval
);
1912 LIBVIRT_BEGIN_ALLOW_THREADS
;
1913 c_retval
= virConnectListInterfaces(conn
, names
, c_retval
);
1914 LIBVIRT_END_ALLOW_THREADS
;
1920 py_retval
= PyList_New(c_retval
);
1921 if (py_retval
== NULL
) {
1923 for (i
= 0;i
< c_retval
;i
++)
1931 for (i
= 0;i
< c_retval
;i
++) {
1932 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1943 libvirt_virConnectListDefinedInterfaces(PyObject
*self ATTRIBUTE_UNUSED
,
1945 PyObject
*py_retval
;
1946 char **names
= NULL
;
1949 PyObject
*pyobj_conn
;
1952 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedInterfaces",
1955 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1957 LIBVIRT_BEGIN_ALLOW_THREADS
;
1958 c_retval
= virConnectNumOfDefinedInterfaces(conn
);
1959 LIBVIRT_END_ALLOW_THREADS
;
1964 names
= malloc(sizeof(*names
) * c_retval
);
1967 LIBVIRT_BEGIN_ALLOW_THREADS
;
1968 c_retval
= virConnectListDefinedInterfaces(conn
, names
, c_retval
);
1969 LIBVIRT_END_ALLOW_THREADS
;
1975 py_retval
= PyList_New(c_retval
);
1976 if (py_retval
== NULL
) {
1978 for (i
= 0;i
< c_retval
;i
++)
1986 for (i
= 0;i
< c_retval
;i
++) {
1987 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
1996 /*******************************************
1997 * Helper functions to avoid importing modules
1998 * for every callback
1999 *******************************************/
2000 static PyObject
*libvirt_module
= NULL
;
2001 static PyObject
*libvirt_dict
= NULL
;
2002 static PyObject
*libvirt_dom_class
= NULL
;
2005 getLibvirtModuleObject (void) {
2007 return libvirt_module
;
2009 // PyImport_ImportModule returns a new reference
2010 /* Bogus (char *) cast for RHEL-5 python API brokenness */
2011 libvirt_module
= PyImport_ImportModule((char *)"libvirt");
2012 if(!libvirt_module
) {
2014 printf("%s Error importing libvirt module\n", __FUNCTION__
);
2020 return libvirt_module
;
2024 getLibvirtDictObject (void) {
2026 return libvirt_dict
;
2028 // PyModule_GetDict returns a borrowed reference
2029 libvirt_dict
= PyModule_GetDict(getLibvirtModuleObject());
2032 printf("%s Error importing libvirt dictionary\n", __FUNCTION__
);
2038 Py_INCREF(libvirt_dict
);
2039 return libvirt_dict
;
2043 getLibvirtDomainClassObject (void) {
2044 if(libvirt_dom_class
)
2045 return libvirt_dom_class
;
2047 // PyDict_GetItemString returns a borrowed reference
2048 libvirt_dom_class
= PyDict_GetItemString(getLibvirtDictObject(),
2050 if(!libvirt_dom_class
) {
2052 printf("%s Error importing virDomain class\n", __FUNCTION__
);
2058 Py_INCREF(libvirt_dom_class
);
2059 return libvirt_dom_class
;
2061 /*******************************************
2063 *******************************************/
2066 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
2072 PyObject
*pyobj_ret
;
2074 PyObject
*pyobj_conn_inst
= (PyObject
*)opaque
;
2075 PyObject
*pyobj_dom
;
2077 PyObject
*pyobj_dom_args
;
2078 PyObject
*pyobj_dom_inst
;
2080 PyObject
*dom_class
;
2083 LIBVIRT_ENSURE_THREAD_STATE
;
2085 /* Create a python instance of this virDomainPtr */
2087 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
2088 pyobj_dom_args
= PyTuple_New(2);
2089 if(PyTuple_SetItem(pyobj_dom_args
, 0, pyobj_conn_inst
)!=0) {
2091 printf("%s error creating tuple",__FUNCTION__
);
2095 if(PyTuple_SetItem(pyobj_dom_args
, 1, pyobj_dom
)!=0) {
2097 printf("%s error creating tuple",__FUNCTION__
);
2101 Py_INCREF(pyobj_conn_inst
);
2103 dom_class
= getLibvirtDomainClassObject();
2104 if(!PyClass_Check(dom_class
)) {
2106 printf("%s dom_class is not a class!\n", __FUNCTION__
);
2111 pyobj_dom_inst
= PyInstance_New(dom_class
,
2115 Py_DECREF(pyobj_dom_args
);
2117 if(!pyobj_dom_inst
) {
2119 printf("%s Error creating a python instance of virDomain\n", __FUNCTION__
);
2125 /* Call the Callback Dispatcher */
2126 pyobj_ret
= PyObject_CallMethod(pyobj_conn_inst
,
2127 (char*)"dispatchDomainEventCallbacks",
2133 Py_DECREF(pyobj_dom_inst
);
2137 printf("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
2141 Py_DECREF(pyobj_ret
);
2147 LIBVIRT_RELEASE_THREAD_STATE
;
2152 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject
* self
,
2155 PyObject
*py_retval
; /* return value */
2156 PyObject
*pyobj_conn
; /* virConnectPtr */
2157 PyObject
*pyobj_conn_inst
; /* virConnect Python object */
2162 if (!PyArg_ParseTuple
2163 (args
, (char *) "OO:virConnectDomainEventRegister",
2164 &pyobj_conn
, &pyobj_conn_inst
)) {
2166 printf("%s failed parsing tuple\n", __FUNCTION__
);
2168 return VIR_PY_INT_FAIL
;
2172 printf("libvirt_virConnectDomainEventRegister(%p %p) called\n",
2173 pyobj_conn
, pyobj_conn_inst
);
2175 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2177 Py_INCREF(pyobj_conn_inst
);
2179 LIBVIRT_BEGIN_ALLOW_THREADS
;
2181 ret
= virConnectDomainEventRegister(conn
,
2182 libvirt_virConnectDomainEventCallback
,
2183 (void *)pyobj_conn_inst
, NULL
);
2185 LIBVIRT_END_ALLOW_THREADS
;
2187 py_retval
= libvirt_intWrap(ret
);
2192 libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject
* self
,
2195 PyObject
*py_retval
;
2196 PyObject
*pyobj_conn
;
2197 PyObject
*pyobj_conn_inst
;
2202 if (!PyArg_ParseTuple
2203 (args
, (char *) "OO:virConnectDomainEventDeregister",
2204 &pyobj_conn
, &pyobj_conn_inst
))
2208 printf("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn
);
2211 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2213 LIBVIRT_BEGIN_ALLOW_THREADS
;
2215 ret
= virConnectDomainEventDeregister(conn
, libvirt_virConnectDomainEventCallback
);
2217 LIBVIRT_END_ALLOW_THREADS
;
2219 Py_DECREF(pyobj_conn_inst
);
2220 py_retval
= libvirt_intWrap(ret
);
2224 /*******************************************
2226 *******************************************/
2227 static PyObject
*addHandleObj
= NULL
;
2228 static char *addHandleName
= NULL
;
2229 static PyObject
*updateHandleObj
= NULL
;
2230 static char *updateHandleName
= NULL
;
2231 static PyObject
*removeHandleObj
= NULL
;
2232 static char *removeHandleName
= NULL
;
2233 static PyObject
*addTimeoutObj
= NULL
;
2234 static char *addTimeoutName
= NULL
;
2235 static PyObject
*updateTimeoutObj
= NULL
;
2236 static char *updateTimeoutName
= NULL
;
2237 static PyObject
*removeTimeoutObj
= NULL
;
2238 static char *removeTimeoutName
= NULL
;
2240 #define NAME(fn) ( fn ## Name ? fn ## Name : # fn )
2243 libvirt_virEventAddHandleFunc (int fd
,
2245 virEventHandleCallback cb
,
2250 PyObject
*python_cb
;
2253 PyObject
*opaque_obj
;
2255 PyObject
*pyobj_args
;
2258 LIBVIRT_ENSURE_THREAD_STATE
;
2260 /* Lookup the python callback */
2261 python_cb
= PyDict_GetItemString(getLibvirtDictObject(),
2262 "eventInvokeHandleCallback");
2265 printf("%s: Error finding eventInvokeHandleCallback\n", __FUNCTION__
);
2271 if (!PyCallable_Check(python_cb
)) {
2273 char *name
= py_str(python_cb
);
2274 printf("%s: %s is not callable\n", __FUNCTION__
,
2275 name
? name
: "libvirt.eventInvokeHandleCallback");
2280 Py_INCREF(python_cb
);
2282 /* create tuple for cb */
2283 cb_obj
= libvirt_virEventHandleCallbackWrap(cb
);
2284 ff_obj
= libvirt_virFreeCallbackWrap(ff
);
2285 opaque_obj
= libvirt_virVoidPtrWrap(opaque
);
2287 cb_args
= PyTuple_New(3);
2288 PyTuple_SetItem(cb_args
, 0, cb_obj
);
2289 PyTuple_SetItem(cb_args
, 1, opaque_obj
);
2290 PyTuple_SetItem(cb_args
, 2, ff_obj
);
2292 pyobj_args
= PyTuple_New(4);
2293 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(fd
));
2294 PyTuple_SetItem(pyobj_args
, 1, libvirt_intWrap(event
));
2295 PyTuple_SetItem(pyobj_args
, 2, python_cb
);
2296 PyTuple_SetItem(pyobj_args
, 3, cb_args
);
2298 result
= PyEval_CallObject(addHandleObj
, pyobj_args
);
2302 } else if (!PyInt_Check(result
)) {
2304 printf("%s: %s should return an int\n", __FUNCTION__
, NAME(addHandle
));
2307 retval
= (int)PyInt_AsLong(result
);
2311 Py_DECREF(pyobj_args
);
2314 LIBVIRT_RELEASE_THREAD_STATE
;
2320 libvirt_virEventUpdateHandleFunc(int watch
, int event
)
2323 PyObject
*pyobj_args
;
2325 LIBVIRT_ENSURE_THREAD_STATE
;
2327 pyobj_args
= PyTuple_New(2);
2328 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(watch
));
2329 PyTuple_SetItem(pyobj_args
, 1, libvirt_intWrap(event
));
2331 result
= PyEval_CallObject(updateHandleObj
, pyobj_args
);
2338 Py_DECREF(pyobj_args
);
2340 LIBVIRT_RELEASE_THREAD_STATE
;
2345 libvirt_virEventRemoveHandleFunc(int watch
)
2348 PyObject
*pyobj_args
;
2352 virFreeCallback cff
;
2354 LIBVIRT_ENSURE_THREAD_STATE
;
2356 pyobj_args
= PyTuple_New(1);
2357 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(watch
));
2359 result
= PyEval_CallObject(removeHandleObj
, pyobj_args
);
2363 } else if (!PyTuple_Check(result
) || PyTuple_Size(result
) != 3) {
2365 printf("%s: %s must return opaque obj registered with %s"
2366 "to avoid leaking libvirt memory\n",
2367 __FUNCTION__
, NAME(removeHandle
), NAME(addHandle
));
2370 opaque
= PyTuple_GetItem(result
, 1);
2371 ff
= PyTuple_GetItem(result
, 2);
2372 cff
= PyvirFreeCallback_Get(ff
);
2374 (*cff
)(PyvirVoidPtr_Get(opaque
));
2379 Py_DECREF(pyobj_args
);
2381 LIBVIRT_RELEASE_THREAD_STATE
;
2387 libvirt_virEventAddTimeoutFunc(int timeout
,
2388 virEventTimeoutCallback cb
,
2394 PyObject
*python_cb
;
2398 PyObject
*opaque_obj
;
2400 PyObject
*pyobj_args
;
2403 LIBVIRT_ENSURE_THREAD_STATE
;
2405 /* Lookup the python callback */
2406 python_cb
= PyDict_GetItemString(getLibvirtDictObject(),
2407 "eventInvokeTimeoutCallback");
2410 printf("%s: Error finding eventInvokeTimeoutCallback\n", __FUNCTION__
);
2416 if (!PyCallable_Check(python_cb
)) {
2418 char *name
= py_str(python_cb
);
2419 printf("%s: %s is not callable\n", __FUNCTION__
,
2420 name
? name
: "libvirt.eventInvokeTimeoutCallback");
2425 Py_INCREF(python_cb
);
2427 /* create tuple for cb */
2428 cb_obj
= libvirt_virEventTimeoutCallbackWrap(cb
);
2429 ff_obj
= libvirt_virFreeCallbackWrap(ff
);
2430 opaque_obj
= libvirt_virVoidPtrWrap(opaque
);
2432 cb_args
= PyTuple_New(3);
2433 PyTuple_SetItem(cb_args
, 0, cb_obj
);
2434 PyTuple_SetItem(cb_args
, 1, opaque_obj
);
2435 PyTuple_SetItem(cb_args
, 2, ff_obj
);
2437 pyobj_args
= PyTuple_New(3);
2439 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(timeout
));
2440 PyTuple_SetItem(pyobj_args
, 1, python_cb
);
2441 PyTuple_SetItem(pyobj_args
, 2, cb_args
);
2443 result
= PyEval_CallObject(addTimeoutObj
, pyobj_args
);
2447 } else if (!PyInt_Check(result
)) {
2449 printf("%s: %s should return an int\n", __FUNCTION__
, NAME(addTimeout
));
2452 retval
= (int)PyInt_AsLong(result
);
2456 Py_DECREF(pyobj_args
);
2459 LIBVIRT_RELEASE_THREAD_STATE
;
2464 libvirt_virEventUpdateTimeoutFunc(int timer
, int timeout
)
2466 PyObject
*result
= NULL
;
2467 PyObject
*pyobj_args
;
2469 LIBVIRT_ENSURE_THREAD_STATE
;
2471 pyobj_args
= PyTuple_New(2);
2472 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(timer
));
2473 PyTuple_SetItem(pyobj_args
, 1, libvirt_intWrap(timeout
));
2475 result
= PyEval_CallObject(updateTimeoutObj
, pyobj_args
);
2482 Py_DECREF(pyobj_args
);
2484 LIBVIRT_RELEASE_THREAD_STATE
;
2488 libvirt_virEventRemoveTimeoutFunc(int timer
)
2490 PyObject
*result
= NULL
;
2491 PyObject
*pyobj_args
;
2495 virFreeCallback cff
;
2497 LIBVIRT_ENSURE_THREAD_STATE
;
2499 pyobj_args
= PyTuple_New(1);
2500 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(timer
));
2502 result
= PyEval_CallObject(removeTimeoutObj
, pyobj_args
);
2506 } else if (!PyTuple_Check(result
) || PyTuple_Size(result
) != 3) {
2508 printf("%s: %s must return opaque obj registered with %s"
2509 "to avoid leaking libvirt memory\n",
2510 __FUNCTION__
, NAME(removeTimeout
), NAME(addTimeout
));
2513 opaque
= PyTuple_GetItem(result
, 1);
2514 ff
= PyTuple_GetItem(result
, 2);
2515 cff
= PyvirFreeCallback_Get(ff
);
2517 (*cff
)(PyvirVoidPtr_Get(opaque
));
2522 Py_DECREF(pyobj_args
);
2524 LIBVIRT_RELEASE_THREAD_STATE
;
2530 libvirt_virEventRegisterImpl(ATTRIBUTE_UNUSED PyObject
* self
,
2533 /* Unref the previously-registered impl (if any) */
2534 Py_XDECREF(addHandleObj
);
2535 free(addHandleName
);
2536 Py_XDECREF(updateHandleObj
);
2537 free(updateHandleName
);
2538 Py_XDECREF(removeHandleObj
);
2539 free(removeHandleName
);
2540 Py_XDECREF(addTimeoutObj
);
2541 free(addTimeoutName
);
2542 Py_XDECREF(updateTimeoutObj
);
2543 free(updateTimeoutName
);
2544 Py_XDECREF(removeTimeoutObj
);
2545 free(removeTimeoutName
);
2547 /* Parse and check arguments */
2548 if (!PyArg_ParseTuple(args
, (char *) "OOOOOO:virEventRegisterImpl",
2549 &addHandleObj
, &updateHandleObj
,
2550 &removeHandleObj
, &addTimeoutObj
,
2551 &updateTimeoutObj
, &removeTimeoutObj
) ||
2552 !PyCallable_Check(addHandleObj
) ||
2553 !PyCallable_Check(updateHandleObj
) ||
2554 !PyCallable_Check(removeHandleObj
) ||
2555 !PyCallable_Check(addTimeoutObj
) ||
2556 !PyCallable_Check(updateTimeoutObj
) ||
2557 !PyCallable_Check(removeTimeoutObj
))
2558 return VIR_PY_INT_FAIL
;
2560 /* Get argument string representations (for error reporting) */
2561 addHandleName
= py_str(addTimeoutObj
);
2562 updateHandleName
= py_str(updateHandleObj
);
2563 removeHandleName
= py_str(removeHandleObj
);
2564 addTimeoutName
= py_str(addTimeoutObj
);
2565 updateTimeoutName
= py_str(updateTimeoutObj
);
2566 removeTimeoutName
= py_str(removeTimeoutObj
);
2568 /* Inc refs since we're holding onto these objects until
2569 * the next call (if any) to this function.
2571 Py_INCREF(addHandleObj
);
2572 Py_INCREF(updateHandleObj
);
2573 Py_INCREF(removeHandleObj
);
2574 Py_INCREF(addTimeoutObj
);
2575 Py_INCREF(updateTimeoutObj
);
2576 Py_INCREF(removeTimeoutObj
);
2578 LIBVIRT_BEGIN_ALLOW_THREADS
;
2580 /* Now register our C EventImpl, which will dispatch
2581 * to the Python callbacks passed in as args.
2583 virEventRegisterImpl(libvirt_virEventAddHandleFunc
,
2584 libvirt_virEventUpdateHandleFunc
,
2585 libvirt_virEventRemoveHandleFunc
,
2586 libvirt_virEventAddTimeoutFunc
,
2587 libvirt_virEventUpdateTimeoutFunc
,
2588 libvirt_virEventRemoveTimeoutFunc
);
2590 LIBVIRT_END_ALLOW_THREADS
;
2592 return VIR_PY_INT_SUCCESS
;
2596 libvirt_virEventInvokeHandleCallback(PyObject
*self ATTRIBUTE_UNUSED
,
2599 int watch
, fd
, event
;
2601 PyObject
*py_opaque
;
2602 virEventHandleCallback cb
;
2605 if (!PyArg_ParseTuple
2606 (args
, (char *) "iiiOO:virEventInvokeHandleCallback",
2607 &watch
, &fd
, &event
, &py_f
, &py_opaque
2609 return VIR_PY_INT_FAIL
;
2611 cb
= (virEventHandleCallback
) PyvirEventHandleCallback_Get(py_f
);
2612 opaque
= (void *) PyvirVoidPtr_Get(py_opaque
);
2615 LIBVIRT_BEGIN_ALLOW_THREADS
;
2616 cb (watch
, fd
, event
, opaque
);
2617 LIBVIRT_END_ALLOW_THREADS
;
2620 return VIR_PY_INT_SUCCESS
;
2624 libvirt_virEventInvokeTimeoutCallback(PyObject
*self ATTRIBUTE_UNUSED
,
2629 PyObject
*py_opaque
;
2630 virEventTimeoutCallback cb
;
2633 if (!PyArg_ParseTuple
2634 (args
, (char *) "iOO:virEventInvokeTimeoutCallback",
2635 &timer
, &py_f
, &py_opaque
2637 return VIR_PY_INT_FAIL
;
2639 cb
= (virEventTimeoutCallback
) PyvirEventTimeoutCallback_Get(py_f
);
2640 opaque
= (void *) PyvirVoidPtr_Get(py_opaque
);
2642 LIBVIRT_BEGIN_ALLOW_THREADS
;
2644 LIBVIRT_END_ALLOW_THREADS
;
2647 return VIR_PY_INT_SUCCESS
;
2650 /************************************************************************
2652 * The registration stuff *
2654 ************************************************************************/
2655 static PyMethodDef libvirtMethods
[] = {
2656 #include "libvirt-export.c"
2657 {(char *) "virGetVersion", libvirt_virGetVersion
, METH_VARARGS
, NULL
},
2658 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion
, METH_VARARGS
, NULL
},
2659 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth
, METH_VARARGS
, NULL
},
2660 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID
, METH_VARARGS
, NULL
},
2661 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains
, METH_VARARGS
, NULL
},
2662 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister
, METH_VARARGS
, NULL
},
2663 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister
, METH_VARARGS
, NULL
},
2664 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo
, METH_VARARGS
, NULL
},
2665 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo
, METH_VARARGS
, NULL
},
2666 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID
, METH_VARARGS
, NULL
},
2667 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString
, METH_VARARGS
, NULL
},
2668 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID
, METH_VARARGS
, NULL
},
2669 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler
, METH_VARARGS
, NULL
},
2670 {(char *) "virGetLastError", libvirt_virGetLastError
, METH_VARARGS
, NULL
},
2671 {(char *) "virConnGetLastError", libvirt_virConnGetLastError
, METH_VARARGS
, NULL
},
2672 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks
, METH_VARARGS
, NULL
},
2673 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks
, METH_VARARGS
, NULL
},
2674 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID
, METH_VARARGS
, NULL
},
2675 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString
, METH_VARARGS
, NULL
},
2676 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID
, METH_VARARGS
, NULL
},
2677 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart
, METH_VARARGS
, NULL
},
2678 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart
, METH_VARARGS
, NULL
},
2679 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats
, METH_VARARGS
, NULL
},
2680 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats
, METH_VARARGS
, NULL
},
2681 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats
, METH_VARARGS
, NULL
},
2682 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory
, METH_VARARGS
, NULL
},
2683 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType
, METH_VARARGS
, NULL
},
2684 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters
, METH_VARARGS
, NULL
},
2685 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters
, METH_VARARGS
, NULL
},
2686 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus
, METH_VARARGS
, NULL
},
2687 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu
, METH_VARARGS
, NULL
},
2688 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools
, METH_VARARGS
, NULL
},
2689 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools
, METH_VARARGS
, NULL
},
2690 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart
, METH_VARARGS
, NULL
},
2691 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes
, METH_VARARGS
, NULL
},
2692 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo
, METH_VARARGS
, NULL
},
2693 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo
, METH_VARARGS
, NULL
},
2694 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID
, METH_VARARGS
, NULL
},
2695 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString
, METH_VARARGS
, NULL
},
2696 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID
, METH_VARARGS
, NULL
},
2697 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl
, METH_VARARGS
, NULL
},
2698 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback
, METH_VARARGS
, NULL
},
2699 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback
, METH_VARARGS
, NULL
},
2700 {(char *) "virNodeListDevices", libvirt_virNodeListDevices
, METH_VARARGS
, NULL
},
2701 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps
, METH_VARARGS
, NULL
},
2702 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID
, METH_VARARGS
, NULL
},
2703 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString
, METH_VARARGS
, NULL
},
2704 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID
, METH_VARARGS
, NULL
},
2705 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets
, METH_VARARGS
, NULL
},
2706 {(char *) "virSecretGetValue", libvirt_virSecretGetValue
, METH_VARARGS
, NULL
},
2707 {(char *) "virSecretSetValue", libvirt_virSecretSetValue
, METH_VARARGS
, NULL
},
2708 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces
, METH_VARARGS
, NULL
},
2709 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces
, METH_VARARGS
, NULL
},
2710 {NULL
, NULL
, 0, NULL
}
2721 static int initialized
= 0;
2723 if (initialized
!= 0)
2728 /* initialize the python extension module */
2729 Py_InitModule((char *)