Release of libvirt-2.4.0
[libvirt-python/ericb.git] / libvirt-override.c
blobfa3e2cab9b941bc3d489afa40ec8db4d434add81
1 /*
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
5 * unpractical
7 * Copyright (C) 2005, 2007-2015 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
12 /* Horrible kludge to work around even more horrible name-space pollution
13 via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
14 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
15 #undef HAVE_PTHREAD_H
17 /* We want to see *_LAST enums. */
18 #define VIR_ENUM_SENTINELS
20 #include <Python.h>
21 #include <libvirt/libvirt.h>
22 #include <libvirt/virterror.h>
23 #include <stddef.h>
24 #include "typewrappers.h"
25 #include "build/libvirt.h"
26 #include "libvirt-utils.h"
28 #if PY_MAJOR_VERSION > 2
29 # ifndef __CYGWIN__
30 extern PyObject *PyInit_libvirtmod(void);
31 # else
32 extern PyObject *PyInit_cygvirtmod(void);
33 # endif
34 #else
35 # ifndef __CYGWIN__
36 extern void initlibvirtmod(void);
37 # else
38 extern void initcygvirtmod(void);
39 # endif
40 #endif
42 #if 0
43 # define DEBUG_ERROR 1
44 #endif
46 #if DEBUG_ERROR
47 # define DEBUG(fmt, ...) \
48 printf(fmt, __VA_ARGS__)
49 #else
50 # define DEBUG(fmt, ...) \
51 do {} while (0)
52 #endif
56 * Utility function to retrieve the number of node CPUs present.
57 * It first tries virNodeGetCPUMap, which will return the
58 * number reliably, if available.
59 * As a fallback and for compatibility with backlevel libvirt
60 * versions virNodeGetInfo will be called to calculate the
61 * CPU number, which has the potential to return a too small
62 * number if some host CPUs are offline.
64 static int
65 getPyNodeCPUCount(virConnectPtr conn)
67 int i_retval;
69 #if LIBVIR_CHECK_VERSION(1, 0, 0)
70 LIBVIRT_BEGIN_ALLOW_THREADS;
71 i_retval = virNodeGetCPUMap(conn, NULL, NULL, 0);
72 LIBVIRT_END_ALLOW_THREADS;
73 #else /* fallback: use nodeinfo */
74 virNodeInfo nodeinfo;
76 LIBVIRT_BEGIN_ALLOW_THREADS;
77 i_retval = virNodeGetInfo(conn, &nodeinfo);
78 LIBVIRT_END_ALLOW_THREADS;
80 if (i_retval >= 0)
81 i_retval = VIR_NODEINFO_MAXCPUS(nodeinfo);
82 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
84 return i_retval;
87 /************************************************************************
88 * *
89 * Statistics *
90 * *
91 ************************************************************************/
93 static PyObject *
94 libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED,
95 PyObject *args)
97 virDomainPtr domain;
98 PyObject *pyobj_domain;
99 char * path;
100 int c_retval;
101 virDomainBlockStatsStruct stats;
102 PyObject *info;
104 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats",
105 &pyobj_domain, &path))
106 return NULL;
107 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
109 LIBVIRT_BEGIN_ALLOW_THREADS;
110 c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats));
111 LIBVIRT_END_ALLOW_THREADS;
113 if (c_retval < 0)
114 return VIR_PY_NONE;
116 /* convert to a Python tuple of long objects */
117 if ((info = PyTuple_New(5)) == NULL)
118 return NULL;
120 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_longlongWrap(stats.rd_req), error);
121 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_longlongWrap(stats.rd_bytes), error);
122 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_longlongWrap(stats.wr_req), error);
123 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_longlongWrap(stats.wr_bytes), error);
124 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_longlongWrap(stats.errs), error);
126 return info;
128 error:
129 Py_DECREF(info);
130 return NULL;
133 static PyObject *
134 libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED,
135 PyObject *args)
137 virDomainPtr domain;
138 PyObject *pyobj_domain;
139 PyObject *ret = NULL;
140 int i_retval;
141 int nparams = 0;
142 unsigned int flags;
143 virTypedParameterPtr params;
144 const char *path;
146 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainBlockStatsFlags",
147 &pyobj_domain, &path, &flags))
148 return NULL;
149 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
151 LIBVIRT_BEGIN_ALLOW_THREADS;
152 i_retval = virDomainBlockStatsFlags(domain, path, NULL, &nparams, flags);
153 LIBVIRT_END_ALLOW_THREADS;
155 if (i_retval < 0)
156 return VIR_PY_NONE;
158 if (!nparams)
159 return PyDict_New();
161 if (VIR_ALLOC_N(params, nparams) < 0)
162 return PyErr_NoMemory();
164 LIBVIRT_BEGIN_ALLOW_THREADS;
165 i_retval = virDomainBlockStatsFlags(domain, path, params, &nparams, flags);
166 LIBVIRT_END_ALLOW_THREADS;
168 if (i_retval < 0) {
169 ret = VIR_PY_NONE;
170 goto cleanup;
173 ret = getPyVirTypedParameter(params, nparams);
175 cleanup:
176 virTypedParamsFree(params, nparams);
177 return ret;
180 static PyObject *
181 libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED,
182 PyObject *args)
184 virDomainPtr domain;
185 PyObject *pyobj_domain, *totalbool;
186 PyObject *ret = NULL;
187 PyObject *error = NULL;
188 int ncpus = -1, start_cpu = 0;
189 int sumparams = 0, nparams = -1;
190 size_t i;
191 int i_retval;
192 unsigned int flags;
193 bool totalflag;
194 virTypedParameterPtr params = NULL, cpuparams;
196 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainGetCPUStats",
197 &pyobj_domain, &totalbool, &flags))
198 return NULL;
199 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
201 if (libvirt_boolUnwrap(totalbool, &totalflag) < 0)
202 return NULL;
204 if ((ret = PyList_New(0)) == NULL)
205 return NULL;
207 if (!totalflag) {
208 LIBVIRT_BEGIN_ALLOW_THREADS;
209 ncpus = virDomainGetCPUStats(domain, NULL, 0, 0, 0, flags);
210 LIBVIRT_END_ALLOW_THREADS;
212 if (ncpus < 0) {
213 error = VIR_PY_NONE;
214 goto error;
217 LIBVIRT_BEGIN_ALLOW_THREADS;
218 nparams = virDomainGetCPUStats(domain, NULL, 0, 0, 1, flags);
219 LIBVIRT_END_ALLOW_THREADS;
221 if (nparams < 0) {
222 error = VIR_PY_NONE;
223 goto error;
226 sumparams = nparams * MIN(ncpus, 128);
228 if (VIR_ALLOC_N(params, sumparams) < 0) {
229 error = PyErr_NoMemory();
230 goto error;
233 while (ncpus) {
234 int queried_ncpus = MIN(ncpus, 128);
235 if (nparams) {
237 LIBVIRT_BEGIN_ALLOW_THREADS;
238 i_retval = virDomainGetCPUStats(domain, params,
239 nparams, start_cpu,
240 queried_ncpus, flags);
241 LIBVIRT_END_ALLOW_THREADS;
243 if (i_retval < 0) {
244 error = VIR_PY_NONE;
245 goto error;
247 } else {
248 i_retval = 0;
251 for (i = 0; i < queried_ncpus; i++) {
252 cpuparams = &params[i * nparams];
253 VIR_PY_LIST_APPEND_GOTO(ret,
254 getPyVirTypedParameter(cpuparams,
255 i_retval),
256 error);
259 start_cpu += queried_ncpus;
260 ncpus -= queried_ncpus;
261 virTypedParamsClear(params, sumparams);
263 } else {
264 LIBVIRT_BEGIN_ALLOW_THREADS;
265 nparams = virDomainGetCPUStats(domain, NULL, 0, -1, 1, flags);
266 LIBVIRT_END_ALLOW_THREADS;
268 if (nparams < 0) {
269 error = VIR_PY_NONE;
270 goto error;
273 if (nparams) {
274 sumparams = nparams;
276 if (VIR_ALLOC_N(params, nparams) < 0) {
277 error = PyErr_NoMemory();
278 goto error;
281 LIBVIRT_BEGIN_ALLOW_THREADS;
282 i_retval = virDomainGetCPUStats(domain, params, nparams,
283 -1, 1, flags);
284 LIBVIRT_END_ALLOW_THREADS;
286 if (i_retval < 0) {
287 error = VIR_PY_NONE;
288 goto error;
290 } else {
291 i_retval = 0;
294 VIR_PY_LIST_APPEND_GOTO(ret, getPyVirTypedParameter(params, i_retval),
295 error);
298 virTypedParamsFree(params, sumparams);
299 return ret;
301 error:
302 virTypedParamsFree(params, sumparams);
303 Py_DECREF(ret);
304 return error;
307 static PyObject *
308 libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED,
309 PyObject *args)
311 virDomainPtr domain;
312 PyObject *pyobj_domain;
313 char * path;
314 int c_retval;
315 virDomainInterfaceStatsStruct stats;
316 PyObject *info;
318 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainInterfaceStats",
319 &pyobj_domain, &path))
320 return NULL;
321 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
323 LIBVIRT_BEGIN_ALLOW_THREADS;
324 c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats));
325 LIBVIRT_END_ALLOW_THREADS;
327 if (c_retval < 0)
328 return VIR_PY_NONE;
330 /* convert to a Python tuple of long objects */
331 if ((info = PyTuple_New(8)) == NULL)
332 return NULL;
334 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_longlongWrap(stats.rx_bytes), error);
335 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_longlongWrap(stats.rx_packets), error);
336 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_longlongWrap(stats.rx_errs), error);
337 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_longlongWrap(stats.rx_drop), error);
338 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_longlongWrap(stats.tx_bytes), error);
339 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_longlongWrap(stats.tx_packets), error);
340 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_longlongWrap(stats.tx_errs), error);
341 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_longlongWrap(stats.tx_drop), error);
343 return info;
345 error:
346 Py_DECREF(info);
347 return NULL;
350 static PyObject *
351 libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED,
352 PyObject *args)
354 virDomainPtr domain;
355 PyObject *pyobj_domain;
356 unsigned int nr_stats;
357 size_t i;
358 virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
359 PyObject *info;
360 PyObject *key = NULL, *val = NULL;
362 if (!PyArg_ParseTuple(args, (char *)"O:virDomainMemoryStats", &pyobj_domain))
363 return NULL;
364 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
366 nr_stats = virDomainMemoryStats(domain, stats,
367 VIR_DOMAIN_MEMORY_STAT_NR, 0);
368 if (nr_stats == -1)
369 return VIR_PY_NONE;
371 /* convert to a Python dictionary */
372 if ((info = PyDict_New()) == NULL)
373 return NULL;
375 for (i = 0; i < nr_stats; i++) {
376 switch (stats[i].tag) {
377 case VIR_DOMAIN_MEMORY_STAT_SWAP_IN:
378 key = libvirt_constcharPtrWrap("swap_in");
379 break;
380 case VIR_DOMAIN_MEMORY_STAT_SWAP_OUT:
381 key = libvirt_constcharPtrWrap("swap_out");
382 break;
383 case VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT:
384 key = libvirt_constcharPtrWrap("major_fault");
385 break;
386 case VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT:
387 key = libvirt_constcharPtrWrap("minor_fault");
388 break;
389 case VIR_DOMAIN_MEMORY_STAT_UNUSED:
390 key = libvirt_constcharPtrWrap("unused");
391 break;
392 case VIR_DOMAIN_MEMORY_STAT_AVAILABLE:
393 key = libvirt_constcharPtrWrap("available");
394 break;
395 case VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON:
396 key = libvirt_constcharPtrWrap("actual");
397 break;
398 case VIR_DOMAIN_MEMORY_STAT_RSS:
399 key = libvirt_constcharPtrWrap("rss");
400 break;
401 default:
402 continue;
404 val = libvirt_ulonglongWrap(stats[i].val);
406 VIR_PY_DICT_SET_GOTO(info, key, val, error);
409 return info;
411 error:
412 Py_DECREF(info);
413 return NULL;
416 static PyObject *
417 libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
418 PyObject *args)
420 virDomainPtr domain;
421 PyObject *pyobj_domain, *info;
422 char *c_retval;
423 int nparams;
425 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerType",
426 &pyobj_domain))
427 return NULL;
428 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
430 LIBVIRT_BEGIN_ALLOW_THREADS;
431 c_retval = virDomainGetSchedulerType(domain, &nparams);
432 LIBVIRT_END_ALLOW_THREADS;
433 if (c_retval == NULL)
434 return VIR_PY_NONE;
436 /* convert to a Python tuple of long objects */
437 if ((info = PyTuple_New(2)) == NULL)
438 goto cleanup;
440 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_constcharPtrWrap(c_retval), error);
441 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)nparams), error);
443 cleanup:
444 VIR_FREE(c_retval);
445 return info;
447 error:
448 Py_CLEAR(info);
449 goto cleanup;
453 static PyObject *
454 libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
455 PyObject *args)
457 virDomainPtr domain;
458 PyObject *pyobj_domain;
459 PyObject *ret = NULL;
460 char *c_retval;
461 int i_retval;
462 int nparams = 0;
463 virTypedParameterPtr params;
465 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerParameters",
466 &pyobj_domain))
467 return NULL;
468 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
470 LIBVIRT_BEGIN_ALLOW_THREADS;
471 c_retval = virDomainGetSchedulerType(domain, &nparams);
472 LIBVIRT_END_ALLOW_THREADS;
474 if (c_retval == NULL)
475 return VIR_PY_NONE;
476 VIR_FREE(c_retval);
478 if (!nparams)
479 return PyDict_New();
481 if (VIR_ALLOC_N(params, nparams) < 0)
482 return PyErr_NoMemory();
484 LIBVIRT_BEGIN_ALLOW_THREADS;
485 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
486 LIBVIRT_END_ALLOW_THREADS;
488 if (i_retval < 0) {
489 ret = VIR_PY_NONE;
490 goto cleanup;
493 ret = getPyVirTypedParameter(params, nparams);
495 cleanup:
496 virTypedParamsFree(params, nparams);
497 return ret;
500 static PyObject *
501 libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
502 PyObject *args)
504 virDomainPtr domain;
505 PyObject *pyobj_domain;
506 PyObject *ret = NULL;
507 char *c_retval;
508 int i_retval;
509 int nparams = 0;
510 unsigned int flags;
511 virTypedParameterPtr params;
513 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetScedulerParametersFlags",
514 &pyobj_domain, &flags))
515 return NULL;
516 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
518 LIBVIRT_BEGIN_ALLOW_THREADS;
519 c_retval = virDomainGetSchedulerType(domain, &nparams);
520 LIBVIRT_END_ALLOW_THREADS;
522 if (c_retval == NULL)
523 return VIR_PY_NONE;
524 VIR_FREE(c_retval);
526 if (!nparams)
527 return PyDict_New();
529 if (VIR_ALLOC_N(params, nparams) < 0)
530 return PyErr_NoMemory();
532 LIBVIRT_BEGIN_ALLOW_THREADS;
533 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams,
534 flags);
535 LIBVIRT_END_ALLOW_THREADS;
537 if (i_retval < 0) {
538 ret = VIR_PY_NONE;
539 goto cleanup;
542 ret = getPyVirTypedParameter(params, nparams);
544 cleanup:
545 virTypedParamsFree(params, nparams);
546 return ret;
549 static PyObject *
550 libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
551 PyObject *args)
553 virDomainPtr domain;
554 PyObject *pyobj_domain, *info;
555 PyObject *ret = NULL;
556 char *c_retval;
557 int i_retval;
558 int nparams = 0;
559 Py_ssize_t size = 0;
560 virTypedParameterPtr params = NULL, new_params = NULL;
562 if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetScedulerParameters",
563 &pyobj_domain, &info))
564 return NULL;
565 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
567 if ((size = PyDict_Size(info)) < 0)
568 return NULL;
570 if (size == 0) {
571 PyErr_Format(PyExc_LookupError,
572 "Need non-empty dictionary to set attributes");
573 return NULL;
576 LIBVIRT_BEGIN_ALLOW_THREADS;
577 c_retval = virDomainGetSchedulerType(domain, &nparams);
578 LIBVIRT_END_ALLOW_THREADS;
580 if (c_retval == NULL)
581 return VIR_PY_INT_FAIL;
582 VIR_FREE(c_retval);
584 if (nparams == 0) {
585 PyErr_Format(PyExc_LookupError,
586 "Domain has no settable attributes");
587 return NULL;
590 if (VIR_ALLOC_N(params, nparams) < 0)
591 return PyErr_NoMemory();
593 LIBVIRT_BEGIN_ALLOW_THREADS;
594 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
595 LIBVIRT_END_ALLOW_THREADS;
597 if (i_retval < 0) {
598 ret = VIR_PY_INT_FAIL;
599 goto cleanup;
602 new_params = setPyVirTypedParameter(info, params, nparams);
603 if (!new_params)
604 goto cleanup;
606 LIBVIRT_BEGIN_ALLOW_THREADS;
607 i_retval = virDomainSetSchedulerParameters(domain, new_params, size);
608 LIBVIRT_END_ALLOW_THREADS;
610 if (i_retval < 0) {
611 ret = VIR_PY_INT_FAIL;
612 goto cleanup;
615 ret = VIR_PY_INT_SUCCESS;
617 cleanup:
618 virTypedParamsFree(params, nparams);
619 virTypedParamsFree(new_params, size);
620 return ret;
623 static PyObject *
624 libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
625 PyObject *args)
627 virDomainPtr domain;
628 PyObject *pyobj_domain, *info;
629 PyObject *ret = NULL;
630 char *c_retval;
631 int i_retval;
632 int nparams = 0;
633 Py_ssize_t size = 0;
634 unsigned int flags;
635 virTypedParameterPtr params, new_params = NULL;
637 if (!PyArg_ParseTuple(args,
638 (char *)"OOI:virDomainSetScedulerParametersFlags",
639 &pyobj_domain, &info, &flags))
640 return NULL;
641 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
643 if ((size = PyDict_Size(info)) < 0)
644 return NULL;
646 if (size == 0) {
647 PyErr_Format(PyExc_LookupError,
648 "Need non-empty dictionary to set attributes");
649 return NULL;
652 LIBVIRT_BEGIN_ALLOW_THREADS;
653 c_retval = virDomainGetSchedulerType(domain, &nparams);
654 LIBVIRT_END_ALLOW_THREADS;
656 if (c_retval == NULL)
657 return VIR_PY_INT_FAIL;
658 VIR_FREE(c_retval);
660 if (nparams == 0) {
661 PyErr_Format(PyExc_LookupError,
662 "Domain has no settable attributes");
663 return NULL;
666 if (VIR_ALLOC_N(params, nparams) < 0)
667 return PyErr_NoMemory();
669 LIBVIRT_BEGIN_ALLOW_THREADS;
670 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams,
671 flags);
672 LIBVIRT_END_ALLOW_THREADS;
674 if (i_retval < 0) {
675 ret = VIR_PY_INT_FAIL;
676 goto cleanup;
679 new_params = setPyVirTypedParameter(info, params, nparams);
680 if (!new_params)
681 goto cleanup;
683 LIBVIRT_BEGIN_ALLOW_THREADS;
684 i_retval = virDomainSetSchedulerParametersFlags(domain, new_params, size,
685 flags);
686 LIBVIRT_END_ALLOW_THREADS;
688 if (i_retval < 0) {
689 ret = VIR_PY_INT_FAIL;
690 goto cleanup;
693 ret = VIR_PY_INT_SUCCESS;
695 cleanup:
696 virTypedParamsFree(params, nparams);
697 virTypedParamsFree(new_params, nparams);
698 return ret;
701 static PyObject *
702 libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
703 PyObject *args)
705 virDomainPtr domain;
706 PyObject *pyobj_domain, *info;
707 PyObject *ret = NULL;
708 int i_retval;
709 int nparams = 0;
710 Py_ssize_t size = 0;
711 unsigned int flags;
712 virTypedParameterPtr params = NULL, new_params = NULL;
714 if (!PyArg_ParseTuple(args,
715 (char *)"OOI:virDomainSetBlkioParameters",
716 &pyobj_domain, &info, &flags))
717 return NULL;
718 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
720 if ((size = PyDict_Size(info)) < 0)
721 return NULL;
723 if (size == 0) {
724 PyErr_Format(PyExc_LookupError,
725 "Need non-empty dictionary to set attributes");
726 return NULL;
729 LIBVIRT_BEGIN_ALLOW_THREADS;
730 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
731 LIBVIRT_END_ALLOW_THREADS;
733 if (i_retval < 0)
734 return VIR_PY_INT_FAIL;
736 if (nparams == 0) {
737 PyErr_Format(PyExc_LookupError,
738 "Domain has no settable attributes");
739 return NULL;
742 if (VIR_ALLOC_N(params, nparams) < 0)
743 return PyErr_NoMemory();
745 LIBVIRT_BEGIN_ALLOW_THREADS;
746 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
747 LIBVIRT_END_ALLOW_THREADS;
749 if (i_retval < 0) {
750 ret = VIR_PY_INT_FAIL;
751 goto cleanup;
754 new_params = setPyVirTypedParameter(info, params, nparams);
755 if (!new_params)
756 goto cleanup;
758 LIBVIRT_BEGIN_ALLOW_THREADS;
759 i_retval = virDomainSetBlkioParameters(domain, new_params, size, flags);
760 LIBVIRT_END_ALLOW_THREADS;
762 if (i_retval < 0) {
763 ret = VIR_PY_INT_FAIL;
764 goto cleanup;
767 ret = VIR_PY_INT_SUCCESS;
769 cleanup:
770 virTypedParamsFree(params, nparams);
771 virTypedParamsFree(new_params, size);
772 return ret;
775 static PyObject *
776 libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
777 PyObject *args)
779 virDomainPtr domain;
780 PyObject *pyobj_domain;
781 PyObject *ret = NULL;
782 int i_retval;
783 int nparams = 0;
784 unsigned int flags;
785 virTypedParameterPtr params;
787 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetBlkioParameters",
788 &pyobj_domain, &flags))
789 return NULL;
790 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
792 LIBVIRT_BEGIN_ALLOW_THREADS;
793 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
794 LIBVIRT_END_ALLOW_THREADS;
796 if (i_retval < 0)
797 return VIR_PY_NONE;
799 if (!nparams)
800 return PyDict_New();
802 if (VIR_ALLOC_N(params, nparams) < 0)
803 return PyErr_NoMemory();
805 LIBVIRT_BEGIN_ALLOW_THREADS;
806 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
807 LIBVIRT_END_ALLOW_THREADS;
809 if (i_retval < 0) {
810 ret = VIR_PY_NONE;
811 goto cleanup;
814 ret = getPyVirTypedParameter(params, nparams);
816 cleanup:
817 virTypedParamsFree(params, nparams);
818 return ret;
821 static PyObject *
822 libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
823 PyObject *args)
825 virDomainPtr domain;
826 PyObject *pyobj_domain, *info;
827 PyObject *ret = NULL;
828 int i_retval;
829 int nparams = 0;
830 Py_ssize_t size = 0;
831 unsigned int flags;
832 virTypedParameterPtr params = NULL, new_params = NULL;
834 if (!PyArg_ParseTuple(args,
835 (char *)"OOI:virDomainSetMemoryParameters",
836 &pyobj_domain, &info, &flags))
837 return NULL;
838 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
840 if ((size = PyDict_Size(info)) < 0)
841 return NULL;
843 if (size == 0) {
844 PyErr_Format(PyExc_LookupError,
845 "Need non-empty dictionary to set attributes");
846 return NULL;
849 LIBVIRT_BEGIN_ALLOW_THREADS;
850 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
851 LIBVIRT_END_ALLOW_THREADS;
853 if (i_retval < 0)
854 return VIR_PY_INT_FAIL;
856 if (nparams == 0) {
857 PyErr_Format(PyExc_LookupError,
858 "Domain has no settable attributes");
859 return NULL;
862 if (VIR_ALLOC_N(params, nparams) < 0)
863 return PyErr_NoMemory();
865 LIBVIRT_BEGIN_ALLOW_THREADS;
866 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
867 LIBVIRT_END_ALLOW_THREADS;
869 if (i_retval < 0) {
870 ret = VIR_PY_INT_FAIL;
871 goto cleanup;
874 new_params = setPyVirTypedParameter(info, params, nparams);
875 if (!new_params)
876 goto cleanup;
878 LIBVIRT_BEGIN_ALLOW_THREADS;
879 i_retval = virDomainSetMemoryParameters(domain, new_params, size, flags);
880 LIBVIRT_END_ALLOW_THREADS;
882 if (i_retval < 0) {
883 ret = VIR_PY_INT_FAIL;
884 goto cleanup;
887 ret = VIR_PY_INT_SUCCESS;
889 cleanup:
890 virTypedParamsFree(params, nparams);
891 virTypedParamsFree(new_params, size);
892 return ret;
895 static PyObject *
896 libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
897 PyObject *args)
899 virDomainPtr domain;
900 PyObject *pyobj_domain;
901 PyObject *ret = NULL;
902 int i_retval;
903 int nparams = 0;
904 unsigned int flags;
905 virTypedParameterPtr params;
907 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetMemoryParameters",
908 &pyobj_domain, &flags))
909 return NULL;
910 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
912 LIBVIRT_BEGIN_ALLOW_THREADS;
913 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
914 LIBVIRT_END_ALLOW_THREADS;
916 if (i_retval < 0)
917 return VIR_PY_NONE;
919 if (!nparams)
920 return PyDict_New();
922 if (VIR_ALLOC_N(params, nparams) < 0)
923 return PyErr_NoMemory();
925 LIBVIRT_BEGIN_ALLOW_THREADS;
926 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
927 LIBVIRT_END_ALLOW_THREADS;
929 if (i_retval < 0) {
930 ret = VIR_PY_NONE;
931 goto cleanup;
934 ret = getPyVirTypedParameter(params, nparams);
936 cleanup:
937 virTypedParamsFree(params, nparams);
938 return ret;
941 static PyObject *
942 libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
943 PyObject *args)
945 virDomainPtr domain;
946 PyObject *pyobj_domain, *info;
947 PyObject *ret = NULL;
948 int i_retval;
949 int nparams = 0;
950 Py_ssize_t size = 0;
951 unsigned int flags;
952 virTypedParameterPtr params = NULL, new_params = NULL;
954 if (!PyArg_ParseTuple(args,
955 (char *)"OOI:virDomainSetNumaParameters",
956 &pyobj_domain, &info, &flags))
957 return NULL;
958 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
960 if ((size = PyDict_Size(info)) < 0)
961 return NULL;
963 if (size == 0) {
964 PyErr_Format(PyExc_LookupError,
965 "Need non-empty dictionary to set attributes");
966 return NULL;
969 LIBVIRT_BEGIN_ALLOW_THREADS;
970 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
971 LIBVIRT_END_ALLOW_THREADS;
973 if (i_retval < 0)
974 return VIR_PY_INT_FAIL;
976 if (nparams == 0) {
977 PyErr_Format(PyExc_LookupError,
978 "Domain has no settable attributes");
979 return NULL;
982 if (VIR_ALLOC_N(params, nparams) < 0)
983 return PyErr_NoMemory();
985 LIBVIRT_BEGIN_ALLOW_THREADS;
986 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
987 LIBVIRT_END_ALLOW_THREADS;
989 if (i_retval < 0) {
990 ret = VIR_PY_INT_FAIL;
991 goto cleanup;
994 new_params = setPyVirTypedParameter(info, params, nparams);
995 if (!new_params)
996 goto cleanup;
998 LIBVIRT_BEGIN_ALLOW_THREADS;
999 i_retval = virDomainSetNumaParameters(domain, new_params, size, flags);
1000 LIBVIRT_END_ALLOW_THREADS;
1002 if (i_retval < 0) {
1003 ret = VIR_PY_INT_FAIL;
1004 goto cleanup;
1007 ret = VIR_PY_INT_SUCCESS;
1009 cleanup:
1010 virTypedParamsFree(params, nparams);
1011 virTypedParamsFree(new_params, size);
1012 return ret;
1015 static PyObject *
1016 libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1017 PyObject *args)
1019 virDomainPtr domain;
1020 PyObject *pyobj_domain;
1021 PyObject *ret = NULL;
1022 int i_retval;
1023 int nparams = 0;
1024 unsigned int flags;
1025 virTypedParameterPtr params;
1027 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetNumaParameters",
1028 &pyobj_domain, &flags))
1029 return NULL;
1030 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1032 LIBVIRT_BEGIN_ALLOW_THREADS;
1033 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1034 LIBVIRT_END_ALLOW_THREADS;
1036 if (i_retval < 0)
1037 return VIR_PY_NONE;
1039 if (!nparams)
1040 return PyDict_New();
1042 if (VIR_ALLOC_N(params, nparams) < 0)
1043 return PyErr_NoMemory();
1045 LIBVIRT_BEGIN_ALLOW_THREADS;
1046 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1047 LIBVIRT_END_ALLOW_THREADS;
1049 if (i_retval < 0) {
1050 ret = VIR_PY_NONE;
1051 goto cleanup;
1054 ret = getPyVirTypedParameter(params, nparams);
1056 cleanup:
1057 virTypedParamsFree(params, nparams);
1058 return ret;
1061 static PyObject *
1062 libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1063 PyObject *args)
1065 virDomainPtr domain;
1066 PyObject *pyobj_domain, *info;
1067 PyObject *ret = NULL;
1068 int i_retval;
1069 int nparams = 0;
1070 Py_ssize_t size = 0;
1071 unsigned int flags;
1072 const char *device = NULL;
1073 virTypedParameterPtr params = NULL, new_params = NULL;
1075 if (!PyArg_ParseTuple(args,
1076 (char *)"OzOI:virDomainSetInterfaceParameters",
1077 &pyobj_domain, &device, &info, &flags))
1078 return NULL;
1079 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1081 if ((size = PyDict_Size(info)) < 0)
1082 return NULL;
1084 if (size == 0) {
1085 PyErr_Format(PyExc_LookupError,
1086 "Need non-empty dictionary to set attributes");
1087 return NULL;
1090 LIBVIRT_BEGIN_ALLOW_THREADS;
1091 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams,
1092 flags);
1093 LIBVIRT_END_ALLOW_THREADS;
1095 if (i_retval < 0)
1096 return VIR_PY_INT_FAIL;
1098 if (nparams == 0) {
1099 PyErr_Format(PyExc_LookupError,
1100 "Domain has no settable attributes");
1101 return NULL;
1104 if (VIR_ALLOC_N(params, nparams) < 0)
1105 return PyErr_NoMemory();
1107 LIBVIRT_BEGIN_ALLOW_THREADS;
1108 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams,
1109 flags);
1110 LIBVIRT_END_ALLOW_THREADS;
1112 if (i_retval < 0) {
1113 ret = VIR_PY_INT_FAIL;
1114 goto cleanup;
1117 new_params = setPyVirTypedParameter(info, params, nparams);
1118 if (!new_params)
1119 goto cleanup;
1121 LIBVIRT_BEGIN_ALLOW_THREADS;
1122 i_retval = virDomainSetInterfaceParameters(domain, device, new_params, size,
1123 flags);
1124 LIBVIRT_END_ALLOW_THREADS;
1126 if (i_retval < 0) {
1127 ret = VIR_PY_INT_FAIL;
1128 goto cleanup;
1131 ret = VIR_PY_INT_SUCCESS;
1133 cleanup:
1134 virTypedParamsFree(params, nparams);
1135 virTypedParamsFree(new_params, size);
1136 return ret;
1139 static PyObject *
1140 libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1141 PyObject *args)
1143 virDomainPtr domain;
1144 PyObject *pyobj_domain;
1145 PyObject *ret = NULL;
1146 int i_retval;
1147 int nparams = 0;
1148 unsigned int flags;
1149 const char *device = NULL;
1150 virTypedParameterPtr params;
1152 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetInterfaceParameters",
1153 &pyobj_domain, &device, &flags))
1154 return NULL;
1155 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1157 LIBVIRT_BEGIN_ALLOW_THREADS;
1158 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams,
1159 flags);
1160 LIBVIRT_END_ALLOW_THREADS;
1162 if (i_retval < 0)
1163 return VIR_PY_NONE;
1165 if (!nparams)
1166 return PyDict_New();
1168 if (VIR_ALLOC_N(params, nparams) < 0)
1169 return PyErr_NoMemory();
1171 LIBVIRT_BEGIN_ALLOW_THREADS;
1172 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams,
1173 flags);
1174 LIBVIRT_END_ALLOW_THREADS;
1176 if (i_retval < 0) {
1177 ret = VIR_PY_NONE;
1178 goto cleanup;
1181 ret = getPyVirTypedParameter(params, nparams);
1183 cleanup:
1184 virTypedParamsFree(params, nparams);
1185 return ret;
1188 static PyObject *
1189 libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
1190 PyObject *args)
1192 virDomainPtr domain;
1193 PyObject *pyobj_domain, *pyretval = NULL;
1194 PyObject *pycpuinfo = NULL, *pycpumap = NULL;
1195 PyObject *error = NULL;
1196 virDomainInfo dominfo;
1197 virVcpuInfoPtr cpuinfo = NULL;
1198 unsigned char *cpumap = NULL;
1199 size_t cpumaplen, i;
1200 int i_retval, cpunum;
1202 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
1203 &pyobj_domain))
1204 return NULL;
1205 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1207 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1208 return VIR_PY_NONE;
1210 LIBVIRT_BEGIN_ALLOW_THREADS;
1211 i_retval = virDomainGetInfo(domain, &dominfo);
1212 LIBVIRT_END_ALLOW_THREADS;
1213 if (i_retval < 0)
1214 return VIR_PY_NONE;
1216 if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0)
1217 return PyErr_NoMemory();
1219 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1220 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1221 VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) {
1222 error = PyErr_NoMemory();
1223 goto cleanup;
1226 LIBVIRT_BEGIN_ALLOW_THREADS;
1227 i_retval = virDomainGetVcpus(domain,
1228 cpuinfo, dominfo.nrVirtCpu,
1229 cpumap, cpumaplen);
1230 LIBVIRT_END_ALLOW_THREADS;
1231 if (i_retval < 0) {
1232 error = VIR_PY_NONE;
1233 goto cleanup;
1236 /* convert to a Python tuple of long objects */
1237 if ((pyretval = PyTuple_New(2)) == NULL)
1238 goto cleanup;
1239 if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
1240 goto cleanup;
1242 VIR_PY_TUPLE_SET_GOTO(pyretval, 0, pycpuinfo, cleanup);
1244 if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
1245 goto cleanup;
1247 VIR_PY_TUPLE_SET_GOTO(pyretval, 1, pycpumap, cleanup);
1249 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1250 PyObject *info = PyTuple_New(4);
1252 if (info == NULL)
1253 goto cleanup;
1255 VIR_PY_LIST_SET_GOTO(pycpuinfo, i, info, cleanup);
1257 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)cpuinfo[i].number),
1258 cleanup);
1259 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)cpuinfo[i].state),
1260 cleanup);
1261 VIR_PY_TUPLE_SET_GOTO(info, 2,
1262 libvirt_ulonglongWrap((long)cpuinfo[i].cpuTime),
1263 cleanup);
1264 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)cpuinfo[i].cpu),
1265 cleanup);
1267 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1268 PyObject *info = PyTuple_New(cpunum);
1269 size_t j;
1270 if (info == NULL)
1271 goto cleanup;
1273 VIR_PY_LIST_SET_GOTO(pycpumap, i, info, cleanup);
1275 for (j = 0; j < cpunum; j++) {
1276 VIR_PY_TUPLE_SET_GOTO(info, j,
1277 PyBool_FromLong(VIR_CPU_USABLE(cpumap,
1278 cpumaplen,
1279 i, j)),
1280 cleanup);
1284 VIR_FREE(cpuinfo);
1285 VIR_FREE(cpumap);
1287 return pyretval;
1289 cleanup:
1290 VIR_FREE(cpuinfo);
1291 VIR_FREE(cpumap);
1292 Py_XDECREF(pyretval);
1293 return error;
1297 static PyObject *
1298 libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
1299 PyObject *args)
1301 virDomainPtr domain;
1302 PyObject *pyobj_domain, *pycpumap;
1303 PyObject *ret = NULL;
1304 unsigned char *cpumap;
1305 int cpumaplen, vcpu, tuple_size, cpunum;
1306 size_t i;
1307 int i_retval;
1309 if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu",
1310 &pyobj_domain, &vcpu, &pycpumap))
1311 return NULL;
1312 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1314 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1315 return VIR_PY_INT_FAIL;
1317 if (PyTuple_Check(pycpumap)) {
1318 tuple_size = PyTuple_Size(pycpumap);
1319 if (tuple_size == -1)
1320 return ret;
1321 } else {
1322 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1323 return ret;
1326 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1327 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1328 return PyErr_NoMemory();
1330 for (i = 0; i < tuple_size; i++) {
1331 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1332 bool b;
1334 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1335 goto cleanup;
1337 if (b)
1338 VIR_USE_CPU(cpumap, i);
1339 else
1340 VIR_UNUSE_CPU(cpumap, i);
1343 for (; i < cpunum; i++)
1344 VIR_UNUSE_CPU(cpumap, i);
1346 LIBVIRT_BEGIN_ALLOW_THREADS;
1347 i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen);
1348 LIBVIRT_END_ALLOW_THREADS;
1350 if (i_retval < 0) {
1351 ret = VIR_PY_INT_FAIL;
1352 goto cleanup;
1354 ret = VIR_PY_INT_SUCCESS;
1356 cleanup:
1357 VIR_FREE(cpumap);
1358 return ret;
1361 static PyObject *
1362 libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED,
1363 PyObject *args)
1365 virDomainPtr domain;
1366 PyObject *pyobj_domain, *pycpumap;
1367 PyObject *ret = NULL;
1368 unsigned char *cpumap;
1369 int cpumaplen, vcpu, tuple_size, cpunum;
1370 size_t i;
1371 unsigned int flags;
1372 int i_retval;
1374 if (!PyArg_ParseTuple(args, (char *)"OiOI:virDomainPinVcpuFlags",
1375 &pyobj_domain, &vcpu, &pycpumap, &flags))
1376 return NULL;
1377 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1379 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1380 return VIR_PY_INT_FAIL;
1382 if (PyTuple_Check(pycpumap)) {
1383 tuple_size = PyTuple_Size(pycpumap);
1384 if (tuple_size == -1)
1385 return ret;
1386 } else {
1387 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1388 return ret;
1391 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1392 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1393 return PyErr_NoMemory();
1395 for (i = 0; i < tuple_size; i++) {
1396 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1397 bool b;
1399 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1400 goto cleanup;
1402 if (b)
1403 VIR_USE_CPU(cpumap, i);
1404 else
1405 VIR_UNUSE_CPU(cpumap, i);
1408 for (; i < cpunum; i++)
1409 VIR_UNUSE_CPU(cpumap, i);
1411 LIBVIRT_BEGIN_ALLOW_THREADS;
1412 i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags);
1413 LIBVIRT_END_ALLOW_THREADS;
1414 if (i_retval < 0) {
1415 ret = VIR_PY_INT_FAIL;
1416 goto cleanup;
1418 ret = VIR_PY_INT_SUCCESS;
1420 cleanup:
1421 VIR_FREE(cpumap);
1422 return ret;
1425 static PyObject *
1426 libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1427 PyObject *args)
1429 virDomainPtr domain;
1430 PyObject *pyobj_domain, *pycpumaps = NULL, *error = NULL;
1431 virDomainInfo dominfo;
1432 unsigned char *cpumaps = NULL;
1433 size_t cpumaplen, vcpu, pcpu;
1434 unsigned int flags;
1435 int i_retval, cpunum;
1437 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetVcpuPinInfo",
1438 &pyobj_domain, &flags))
1439 return NULL;
1440 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1442 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1443 return VIR_PY_NONE;
1445 LIBVIRT_BEGIN_ALLOW_THREADS;
1446 i_retval = virDomainGetInfo(domain, &dominfo);
1447 LIBVIRT_END_ALLOW_THREADS;
1448 if (i_retval < 0)
1449 return VIR_PY_NONE;
1451 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1452 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1453 VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0)
1454 goto cleanup;
1456 LIBVIRT_BEGIN_ALLOW_THREADS;
1457 i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu,
1458 cpumaps, cpumaplen, flags);
1459 LIBVIRT_END_ALLOW_THREADS;
1461 if (i_retval < 0) {
1462 error = VIR_PY_NONE;
1463 goto cleanup;
1466 if ((pycpumaps = PyList_New(dominfo.nrVirtCpu)) == NULL)
1467 goto cleanup;
1469 for (vcpu = 0; vcpu < dominfo.nrVirtCpu; vcpu++) {
1470 PyObject *mapinfo = PyTuple_New(cpunum);
1471 if (mapinfo == NULL)
1472 goto cleanup;
1474 VIR_PY_LIST_SET_GOTO(pycpumaps, vcpu, mapinfo, cleanup);
1476 for (pcpu = 0; pcpu < cpunum; pcpu++) {
1477 VIR_PY_TUPLE_SET_GOTO(mapinfo,
1478 pcpu,
1479 PyBool_FromLong(VIR_CPU_USABLE(cpumaps,
1480 cpumaplen,
1481 vcpu,
1482 pcpu)),
1483 cleanup);
1487 VIR_FREE(cpumaps);
1489 return pycpumaps;
1491 cleanup:
1492 VIR_FREE(cpumaps);
1494 Py_XDECREF(pycpumaps);
1496 return error;
1500 #if LIBVIR_CHECK_VERSION(0, 10, 0)
1501 static PyObject *
1502 libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED,
1503 PyObject *args)
1505 virDomainPtr domain;
1506 PyObject *pyobj_domain, *pycpumap;
1507 unsigned char *cpumap = NULL;
1508 int cpumaplen, tuple_size, cpunum;
1509 size_t i;
1510 int i_retval;
1511 unsigned int flags;
1513 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainPinEmulator",
1514 &pyobj_domain, &pycpumap, &flags))
1515 return NULL;
1517 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1519 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1520 return VIR_PY_INT_FAIL;
1522 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1524 if (!PyTuple_Check(pycpumap)) {
1525 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1526 return NULL;
1529 if ((tuple_size = PyTuple_Size(pycpumap)) == -1)
1530 return NULL;
1532 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1533 return PyErr_NoMemory();
1535 for (i = 0; i < tuple_size; i++) {
1536 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1537 bool b;
1539 if (!flag || libvirt_boolUnwrap(flag, &b) < 0) {
1540 VIR_FREE(cpumap);
1541 return NULL;
1544 if (b)
1545 VIR_USE_CPU(cpumap, i);
1546 else
1547 VIR_UNUSE_CPU(cpumap, i);
1550 for (; i < cpunum; i++)
1551 VIR_UNUSE_CPU(cpumap, i);
1553 LIBVIRT_BEGIN_ALLOW_THREADS;
1554 i_retval = virDomainPinEmulator(domain, cpumap, cpumaplen, flags);
1555 LIBVIRT_END_ALLOW_THREADS;
1557 VIR_FREE(cpumap);
1559 if (i_retval < 0)
1560 return VIR_PY_INT_FAIL;
1562 return VIR_PY_INT_SUCCESS;
1566 static PyObject *
1567 libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1568 PyObject *args)
1570 virDomainPtr domain;
1571 PyObject *pyobj_domain;
1572 PyObject *pycpumap;
1573 unsigned char *cpumap;
1574 size_t cpumaplen;
1575 size_t pcpu;
1576 unsigned int flags;
1577 int ret;
1578 int cpunum;
1580 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetEmulatorPinInfo",
1581 &pyobj_domain, &flags))
1582 return NULL;
1584 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1586 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1587 return VIR_PY_NONE;
1589 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1591 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1592 return PyErr_NoMemory();
1594 LIBVIRT_BEGIN_ALLOW_THREADS;
1595 ret = virDomainGetEmulatorPinInfo(domain, cpumap, cpumaplen, flags);
1596 LIBVIRT_END_ALLOW_THREADS;
1597 if (ret < 0) {
1598 VIR_FREE(cpumap);
1599 return VIR_PY_NONE;
1602 if (!(pycpumap = PyTuple_New(cpunum))) {
1603 VIR_FREE(cpumap);
1604 return NULL;
1607 for (pcpu = 0; pcpu < cpunum; pcpu++) {
1608 VIR_PY_TUPLE_SET_GOTO(pycpumap,
1609 pcpu,
1610 PyBool_FromLong(VIR_CPU_USABLE(cpumap,
1611 cpumaplen,
1613 pcpu)),
1614 error);
1617 cleanup:
1618 VIR_FREE(cpumap);
1619 return pycpumap;
1621 error:
1622 Py_CLEAR(pycpumap);
1623 goto cleanup;
1625 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
1627 #if LIBVIR_CHECK_VERSION(1, 2, 14)
1628 static PyObject *
1629 libvirt_virDomainGetIOThreadInfo(PyObject *self ATTRIBUTE_UNUSED,
1630 PyObject *args)
1632 virDomainPtr domain;
1633 PyObject *pyobj_domain;
1634 PyObject *py_retval = NULL;
1635 PyObject *py_iothrinfo = NULL;
1636 virDomainIOThreadInfoPtr *iothrinfo = NULL;
1637 unsigned int flags;
1638 size_t pcpu, i;
1639 int niothreads, cpunum;
1641 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetIOThreadInfo",
1642 &pyobj_domain, &flags))
1643 return NULL;
1644 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1646 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1647 return VIR_PY_NONE;
1649 LIBVIRT_BEGIN_ALLOW_THREADS;
1650 niothreads = virDomainGetIOThreadInfo(domain, &iothrinfo, flags);
1651 LIBVIRT_END_ALLOW_THREADS;
1653 if (niothreads < 0) {
1654 py_retval = VIR_PY_NONE;
1655 goto cleanup;
1658 /* convert to a Python list */
1659 if ((py_iothrinfo = PyList_New(niothreads)) == NULL)
1660 goto cleanup;
1662 /* NOTE: If there are zero IOThreads we will return an empty list */
1663 for (i = 0; i < niothreads; i++) {
1664 PyObject *iothrtpl = NULL;
1665 PyObject *iothrmap = NULL;
1666 virDomainIOThreadInfoPtr iothr = iothrinfo[i];
1668 if (iothr == NULL) {
1669 py_retval = VIR_PY_NONE;
1670 goto cleanup;
1673 if ((iothrtpl = PyTuple_New(2)) == NULL)
1674 goto cleanup;
1676 VIR_PY_LIST_SET_GOTO(py_iothrinfo, i, iothrtpl, cleanup);
1678 /* 0: IOThread ID */
1679 VIR_PY_TUPLE_SET_GOTO(iothrtpl, 0, libvirt_uintWrap(iothr->iothread_id),
1680 cleanup);
1682 /* 1: CPU map */
1683 if ((iothrmap = PyList_New(cpunum)) == NULL)
1684 goto cleanup;
1686 VIR_PY_TUPLE_SET_GOTO(iothrtpl, 1, iothrmap, cleanup);
1688 for (pcpu = 0; pcpu < cpunum; pcpu++)
1689 VIR_PY_LIST_SET_GOTO(iothrmap, pcpu,
1690 PyBool_FromLong(VIR_CPU_USED(iothr->cpumap,
1691 pcpu)),
1692 cleanup);
1695 py_retval = py_iothrinfo;
1696 py_iothrinfo = NULL;
1698 cleanup:
1699 if (niothreads > 0) {
1700 for (i = 0; i < niothreads; i++)
1701 virDomainIOThreadInfoFree(iothrinfo[i]);
1703 VIR_FREE(iothrinfo);
1704 Py_XDECREF(py_iothrinfo);
1705 return py_retval;
1708 static PyObject *
1709 libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED,
1710 PyObject *args)
1712 virDomainPtr domain;
1713 PyObject *pyobj_domain, *pycpumap;
1714 PyObject *ret = NULL;
1715 unsigned char *cpumap;
1716 int cpumaplen, iothread_val, tuple_size, cpunum;
1717 size_t i;
1718 unsigned int flags;
1719 int i_retval;
1721 if (!PyArg_ParseTuple(args, (char *)"OiOI:virDomainPinIOThread",
1722 &pyobj_domain, &iothread_val, &pycpumap, &flags))
1723 return NULL;
1724 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1726 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1727 return VIR_PY_INT_FAIL;
1729 if (PyTuple_Check(pycpumap)) {
1730 if ((tuple_size = PyTuple_Size(pycpumap)) == -1)
1731 return ret;
1732 } else {
1733 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1734 return ret;
1737 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1738 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1739 return PyErr_NoMemory();
1741 for (i = 0; i < tuple_size; i++) {
1742 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1743 bool b;
1745 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1746 goto cleanup;
1748 if (b)
1749 VIR_USE_CPU(cpumap, i);
1750 else
1751 VIR_UNUSE_CPU(cpumap, i);
1754 for (; i < cpunum; i++)
1755 VIR_UNUSE_CPU(cpumap, i);
1757 LIBVIRT_BEGIN_ALLOW_THREADS;
1758 i_retval = virDomainPinIOThread(domain, iothread_val,
1759 cpumap, cpumaplen, flags);
1760 LIBVIRT_END_ALLOW_THREADS;
1761 if (i_retval < 0) {
1762 ret = VIR_PY_INT_FAIL;
1763 goto cleanup;
1765 ret = VIR_PY_INT_SUCCESS;
1767 cleanup:
1768 VIR_FREE(cpumap);
1769 return ret;
1772 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
1774 /************************************************************************
1776 * Global error handler at the Python level *
1778 ************************************************************************/
1780 static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
1781 static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
1783 static PyObject *
1784 libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED,
1785 PyObject *args ATTRIBUTE_UNUSED)
1787 virError *err;
1788 PyObject *info;
1790 if ((err = virGetLastError()) == NULL)
1791 return VIR_PY_NONE;
1793 if ((info = PyTuple_New(9)) == NULL)
1794 return NULL;
1796 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), error);
1797 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), error);
1798 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), error);
1799 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), error);
1800 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), error);
1801 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), error);
1802 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), error);
1803 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), error);
1804 VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), error);
1806 return info;
1808 error:
1809 Py_XDECREF(info);
1810 return NULL;
1813 static PyObject *
1814 libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED,
1815 PyObject *args)
1817 virError *err;
1818 PyObject *info;
1819 virConnectPtr conn;
1820 PyObject *pyobj_conn;
1822 if (!PyArg_ParseTuple(args, (char *)"O:virConGetLastError", &pyobj_conn))
1823 return NULL;
1824 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1826 LIBVIRT_BEGIN_ALLOW_THREADS;
1827 err = virConnGetLastError(conn);
1828 LIBVIRT_END_ALLOW_THREADS;
1829 if (err == NULL)
1830 return VIR_PY_NONE;
1832 if ((info = PyTuple_New(9)) == NULL)
1833 return NULL;
1835 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), error);
1836 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), error);
1837 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), error);
1838 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), error);
1839 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), error);
1840 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), error);
1841 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), error);
1842 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), error);
1843 VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), error);
1845 return info;
1847 error:
1848 Py_XDECREF(info);
1849 return NULL;
1852 static void
1853 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx,
1854 virErrorPtr err)
1856 PyObject *list = NULL, *info = NULL;
1857 PyObject *result;
1859 DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
1860 err->message);
1862 if ((err == NULL) || (err->code == VIR_ERR_OK))
1863 return;
1865 LIBVIRT_ENSURE_THREAD_STATE;
1867 if ((libvirt_virPythonErrorFuncHandler == NULL) ||
1868 (libvirt_virPythonErrorFuncHandler == Py_None)) {
1869 virDefaultErrorFunc(err);
1870 } else {
1871 if ((list = PyTuple_New(2)) == NULL)
1872 goto cleanup;
1874 Py_XINCREF(libvirt_virPythonErrorFuncCtxt);
1875 VIR_PY_TUPLE_SET_GOTO(list, 0, libvirt_virPythonErrorFuncCtxt, cleanup);
1877 if ((info = PyTuple_New(9)) == NULL)
1878 goto cleanup;
1880 VIR_PY_TUPLE_SET_GOTO(list, 1, info, cleanup);
1882 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), cleanup);
1883 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), cleanup);
1884 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), cleanup);
1885 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), cleanup);
1886 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), cleanup);
1887 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), cleanup);
1888 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), cleanup);
1889 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), cleanup);
1890 VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), cleanup);
1892 /* TODO pass conn and dom if available */
1893 result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
1894 Py_XDECREF(result);
1897 cleanup:
1898 Py_XDECREF(list);
1899 LIBVIRT_RELEASE_THREAD_STATE;
1902 static PyObject *
1903 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject *self,
1904 PyObject *args)
1906 PyObject *py_retval;
1907 PyObject *pyobj_f;
1908 PyObject *pyobj_ctx;
1910 if (!PyArg_ParseTuple(args, (char *) "OO:virRegisterErrorHandler",
1911 &pyobj_f, &pyobj_ctx))
1912 return NULL;
1914 DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
1915 pyobj_f);
1917 virSetErrorFunc(NULL, libvirt_virErrorFuncHandler);
1919 Py_XDECREF(libvirt_virPythonErrorFuncHandler);
1920 Py_XDECREF(libvirt_virPythonErrorFuncCtxt);
1922 if ((pyobj_f == Py_None) && (pyobj_ctx == Py_None)) {
1923 libvirt_virPythonErrorFuncHandler = NULL;
1924 libvirt_virPythonErrorFuncCtxt = NULL;
1925 } else {
1926 Py_XINCREF(pyobj_ctx);
1927 Py_XINCREF(pyobj_f);
1929 /* TODO: check f is a function ! */
1930 libvirt_virPythonErrorFuncHandler = pyobj_f;
1931 libvirt_virPythonErrorFuncCtxt = pyobj_ctx;
1934 py_retval = libvirt_intWrap(1);
1935 return py_retval;
1938 static int
1939 virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
1940 unsigned int ncred,
1941 void *cbdata)
1943 PyObject *list = NULL;
1944 PyObject *pycred;
1945 PyObject *pyauth = (PyObject *)cbdata;
1946 PyObject *pycbdata;
1947 PyObject *pycb;
1948 PyObject *pyret = NULL;
1949 int ret = -1;
1950 size_t i;
1952 LIBVIRT_ENSURE_THREAD_STATE;
1954 pycb = PyList_GetItem(pyauth, 1);
1955 pycbdata = PyList_GetItem(pyauth, 2);
1957 if ((list = PyTuple_New(2)) == NULL)
1958 goto cleanup;
1960 if ((pycred = PyTuple_New(ncred)) == NULL)
1961 goto cleanup;
1963 VIR_PY_TUPLE_SET_GOTO(list, 0, pycred, cleanup);
1965 for (i = 0; i < ncred; i++) {
1966 PyObject *pycreditem;
1967 if ((pycreditem = PyList_New(5)) == NULL)
1968 goto cleanup;
1970 VIR_PY_TUPLE_SET_GOTO(pycred, i, pycreditem, cleanup);
1972 VIR_PY_LIST_SET_GOTO(pycreditem, 0,
1973 libvirt_intWrap((long)cred[i].type), cleanup);
1974 VIR_PY_LIST_SET_GOTO(pycreditem, 1,
1975 libvirt_constcharPtrWrap(cred[i].prompt), cleanup);
1977 if (cred[i].challenge) {
1978 VIR_PY_LIST_SET_GOTO(pycreditem, 2,
1979 libvirt_constcharPtrWrap(cred[i].challenge),
1980 cleanup);
1981 } else {
1982 VIR_PY_LIST_SET_GOTO(pycreditem, 2, VIR_PY_NONE, cleanup);
1984 if (cred[i].defresult) {
1985 VIR_PY_LIST_SET_GOTO(pycreditem, 3,
1986 libvirt_constcharPtrWrap(cred[i].defresult),
1987 cleanup);
1988 } else {
1989 VIR_PY_LIST_SET_GOTO(pycreditem, 3, VIR_PY_NONE, cleanup);
1991 VIR_PY_LIST_SET_GOTO(pycreditem, 4, VIR_PY_NONE, cleanup);
1994 Py_XINCREF(pycbdata);
1995 VIR_PY_TUPLE_SET_GOTO(list, 1, pycbdata, cleanup);
1997 PyErr_Clear();
1998 pyret = PyEval_CallObject(pycb, list);
1999 if (PyErr_Occurred()) {
2000 PyErr_Print();
2001 goto cleanup;
2004 ret = PyLong_AsLong(pyret);
2005 if (ret == 0) {
2006 for (i = 0; i < ncred; i++) {
2007 PyObject *pycreditem;
2008 PyObject *pyresult;
2009 char *result = NULL;
2010 pycreditem = PyTuple_GetItem(pycred, i);
2011 pyresult = PyList_GetItem(pycreditem, 4);
2012 if (pyresult != Py_None)
2013 libvirt_charPtrUnwrap(pyresult, &result);
2014 if (result != NULL) {
2015 cred[i].result = result;
2016 cred[i].resultlen = strlen(result);
2017 } else {
2018 cred[i].result = NULL;
2019 cred[i].resultlen = 0;
2024 cleanup:
2025 Py_XDECREF(list);
2026 Py_XDECREF(pyret);
2028 LIBVIRT_RELEASE_THREAD_STATE;
2030 return ret;
2034 static PyObject *
2035 libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED,
2036 PyObject *args)
2038 PyObject *py_retval;
2039 virConnectPtr c_retval;
2040 char * name;
2041 unsigned int flags;
2042 PyObject *pyauth;
2043 PyObject *pycredcb;
2044 PyObject *pycredtype;
2045 virConnectAuth auth;
2047 memset(&auth, 0, sizeof(auth));
2048 if (!PyArg_ParseTuple(args, (char *)"zOI:virConnectOpenAuth",
2049 &name, &pyauth, &flags))
2050 return NULL;
2052 pycredtype = PyList_GetItem(pyauth, 0);
2053 pycredcb = PyList_GetItem(pyauth, 1);
2055 auth.ncredtype = PyList_Size(pycredtype);
2056 if (auth.ncredtype) {
2057 size_t i;
2058 if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0)
2059 return PyErr_NoMemory();
2060 for (i = 0; i < auth.ncredtype; i++) {
2061 PyObject *val;
2062 val = PyList_GetItem(pycredtype, i);
2063 auth.credtype[i] = (int)PyLong_AsLong(val);
2066 if (pycredcb && pycredcb != Py_None)
2067 auth.cb = virConnectCredCallbackWrapper;
2068 auth.cbdata = pyauth;
2070 LIBVIRT_BEGIN_ALLOW_THREADS;
2072 c_retval = virConnectOpenAuth(name, &auth, flags);
2073 LIBVIRT_END_ALLOW_THREADS;
2074 VIR_FREE(auth.credtype);
2075 py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval);
2076 return py_retval;
2080 /************************************************************************
2082 * Wrappers for functions where generator fails *
2084 ************************************************************************/
2086 static PyObject *
2087 libvirt_virGetVersion(PyObject *self ATTRIBUTE_UNUSED,
2088 PyObject *args)
2090 char *type = NULL;
2091 unsigned long libVer, typeVer = 0;
2092 int c_retval;
2094 if (!PyArg_ParseTuple(args, (char *) "|s:virGetVersion", &type))
2095 return NULL;
2097 LIBVIRT_BEGIN_ALLOW_THREADS;
2099 if (type == NULL)
2100 c_retval = virGetVersion(&libVer, NULL, NULL);
2101 else
2102 c_retval = virGetVersion(&libVer, type, &typeVer);
2104 LIBVIRT_END_ALLOW_THREADS;
2106 if (c_retval == -1)
2107 return VIR_PY_NONE;
2109 if (type == NULL)
2110 return libvirt_intWrap(libVer);
2111 else
2112 return Py_BuildValue((char *) "kk", libVer, typeVer);
2115 static PyObject *
2116 libvirt_virConnectGetVersion(PyObject *self ATTRIBUTE_UNUSED,
2117 PyObject *args)
2119 unsigned long hvVersion;
2120 int c_retval;
2121 virConnectPtr conn;
2122 PyObject *pyobj_conn;
2124 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetVersion",
2125 &pyobj_conn))
2126 return NULL;
2127 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2129 LIBVIRT_BEGIN_ALLOW_THREADS;
2131 c_retval = virConnectGetVersion(conn, &hvVersion);
2133 LIBVIRT_END_ALLOW_THREADS;
2135 if (c_retval == -1)
2136 return VIR_PY_INT_FAIL;
2138 return libvirt_intWrap(hvVersion);
2141 #if LIBVIR_CHECK_VERSION(1, 1, 3)
2142 static PyObject *
2143 libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED,
2144 PyObject *args)
2146 int c_retval;
2147 virConnectPtr conn;
2148 PyObject *rv = NULL, *pyobj_conn;
2149 char **models = NULL;
2150 size_t i;
2151 unsigned int flags = 0;
2152 const char *arch = NULL;
2154 if (!PyArg_ParseTuple(args, (char *)"OsI:virConnectGetCPUModelNames",
2155 &pyobj_conn, &arch, &flags))
2156 return NULL;
2157 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2159 LIBVIRT_BEGIN_ALLOW_THREADS;
2161 c_retval = virConnectGetCPUModelNames(conn, arch, &models, flags);
2163 LIBVIRT_END_ALLOW_THREADS;
2165 if (c_retval == -1)
2166 return VIR_PY_NONE;
2168 if ((rv = PyList_New(c_retval)) == NULL)
2169 goto error;
2171 for (i = 0; i < c_retval; i++)
2172 VIR_PY_LIST_SET_GOTO(rv, i, libvirt_constcharPtrWrap(models[i]), error);
2174 done:
2175 if (models) {
2176 for (i = 0; i < c_retval; i++)
2177 VIR_FREE(models[i]);
2178 VIR_FREE(models);
2181 return rv;
2183 error:
2184 Py_CLEAR(rv);
2185 goto done;
2187 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
2189 static PyObject *
2190 libvirt_virConnectGetLibVersion(PyObject *self ATTRIBUTE_UNUSED,
2191 PyObject *args)
2193 unsigned long libVer;
2194 int c_retval;
2195 virConnectPtr conn;
2196 PyObject *pyobj_conn;
2198 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetLibVersion",
2199 &pyobj_conn))
2200 return NULL;
2201 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2203 LIBVIRT_BEGIN_ALLOW_THREADS;
2205 c_retval = virConnectGetLibVersion(conn, &libVer);
2207 LIBVIRT_END_ALLOW_THREADS;
2209 if (c_retval == -1)
2210 return VIR_PY_INT_FAIL;
2212 return libvirt_intWrap(libVer);
2215 static PyObject *
2216 libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
2217 PyObject *args)
2219 PyObject *py_retval;
2220 int *ids = NULL, c_retval;
2221 size_t i;
2222 virConnectPtr conn;
2223 PyObject *pyobj_conn;
2226 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDomains", &pyobj_conn))
2227 return NULL;
2228 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2230 LIBVIRT_BEGIN_ALLOW_THREADS;
2231 c_retval = virConnectNumOfDomains(conn);
2232 LIBVIRT_END_ALLOW_THREADS;
2233 if (c_retval < 0)
2234 return VIR_PY_NONE;
2236 if (c_retval) {
2237 if (VIR_ALLOC_N(ids, c_retval) < 0)
2238 return PyErr_NoMemory();
2240 LIBVIRT_BEGIN_ALLOW_THREADS;
2241 c_retval = virConnectListDomains(conn, ids, c_retval);
2242 LIBVIRT_END_ALLOW_THREADS;
2243 if (c_retval < 0) {
2244 py_retval = VIR_PY_NONE;
2245 goto cleanup;
2249 if ((py_retval = PyList_New(c_retval)) == NULL)
2250 goto cleanup;
2252 if (ids)
2253 for (i = 0; i < c_retval; i++)
2254 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_intWrap(ids[i]), error);
2256 cleanup:
2257 VIR_FREE(ids);
2258 return py_retval;
2260 error:
2261 VIR_FREE(ids);
2262 Py_XDECREF(py_retval);
2263 return NULL;
2266 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2267 static PyObject *
2268 libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
2269 PyObject *args)
2271 PyObject *pyobj_conn;
2272 PyObject *py_retval = NULL;
2273 virConnectPtr conn;
2274 virDomainPtr *doms = NULL;
2275 int c_retval = 0;
2276 size_t i;
2277 unsigned int flags;
2279 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllDomains",
2280 &pyobj_conn, &flags))
2281 return NULL;
2282 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2284 LIBVIRT_BEGIN_ALLOW_THREADS;
2285 c_retval = virConnectListAllDomains(conn, &doms, flags);
2286 LIBVIRT_END_ALLOW_THREADS;
2287 if (c_retval < 0)
2288 return VIR_PY_NONE;
2290 if (!(py_retval = PyList_New(c_retval)))
2291 goto cleanup;
2293 for (i = 0; i < c_retval; i++) {
2294 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_virDomainPtrWrap(doms[i]), error);
2295 /* python steals the pointer */
2296 doms[i] = NULL;
2299 cleanup:
2300 for (i = 0; i < c_retval; i++)
2301 if (doms[i])
2302 virDomainFree(doms[i]);
2303 VIR_FREE(doms);
2304 return py_retval;
2306 error:
2307 Py_CLEAR(py_retval);
2308 goto cleanup;
2310 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2312 static PyObject *
2313 libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
2314 PyObject *args)
2316 PyObject *py_retval;
2317 char **names = NULL;
2318 int c_retval;
2319 size_t i;
2320 virConnectPtr conn;
2321 PyObject *pyobj_conn;
2324 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedDomains",
2325 &pyobj_conn))
2326 return NULL;
2327 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2329 LIBVIRT_BEGIN_ALLOW_THREADS;
2330 c_retval = virConnectNumOfDefinedDomains(conn);
2331 LIBVIRT_END_ALLOW_THREADS;
2332 if (c_retval < 0)
2333 return VIR_PY_NONE;
2335 if (c_retval) {
2336 if (VIR_ALLOC_N(names, c_retval) < 0)
2337 return PyErr_NoMemory();
2338 LIBVIRT_BEGIN_ALLOW_THREADS;
2339 c_retval = virConnectListDefinedDomains(conn, names, c_retval);
2340 LIBVIRT_END_ALLOW_THREADS;
2341 if (c_retval < 0) {
2342 py_retval = VIR_PY_NONE;
2343 goto cleanup;
2347 if ((py_retval = PyList_New(c_retval)) == NULL)
2348 goto cleanup;
2350 if (names) {
2351 for (i = 0; i < c_retval; i++)
2352 VIR_PY_LIST_SET_GOTO(py_retval, i,
2353 libvirt_constcharPtrWrap(names[i]), error);
2356 cleanup:
2357 if (c_retval > 0)
2358 for (i = 0; i < c_retval; i++)
2359 VIR_FREE(names[i]);
2360 VIR_FREE(names);
2361 return py_retval;
2363 error:
2364 Py_CLEAR(py_retval);
2365 goto cleanup;
2368 static PyObject *
2369 libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
2370 PyObject *args)
2372 PyObject *py_retval;
2373 char **names = NULL;
2374 int c_retval;
2375 size_t i;
2376 virDomainPtr dom;
2377 PyObject *pyobj_dom;
2378 unsigned int flags;
2380 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListNames",
2381 &pyobj_dom, &flags))
2382 return NULL;
2383 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2385 LIBVIRT_BEGIN_ALLOW_THREADS;
2386 c_retval = virDomainSnapshotNum(dom, flags);
2387 LIBVIRT_END_ALLOW_THREADS;
2388 if (c_retval < 0)
2389 return VIR_PY_NONE;
2391 if (c_retval) {
2392 if (VIR_ALLOC_N(names, c_retval) < 0)
2393 return PyErr_NoMemory();
2394 LIBVIRT_BEGIN_ALLOW_THREADS;
2395 c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
2396 LIBVIRT_END_ALLOW_THREADS;
2397 if (c_retval < 0) {
2398 py_retval = VIR_PY_NONE;
2399 goto cleanup;
2402 py_retval = PyList_New(c_retval);
2403 if (!py_retval)
2404 goto cleanup;
2406 for (i = 0; i < c_retval; i++)
2407 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_constcharPtrWrap(names[i]), error);
2409 cleanup:
2410 if (c_retval > 0)
2411 for (i = 0; i < c_retval; i++)
2412 VIR_FREE(names[i]);
2413 VIR_FREE(names);
2414 return py_retval;
2416 error:
2417 Py_CLEAR(py_retval);
2418 goto cleanup;
2421 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2422 static PyObject *
2423 libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
2424 PyObject *args)
2426 PyObject *py_retval = NULL;
2427 virDomainSnapshotPtr *snaps = NULL;
2428 int c_retval;
2429 size_t i;
2430 virDomainPtr dom;
2431 PyObject *pyobj_dom;
2432 unsigned int flags;
2434 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainListAllSnapshots",
2435 &pyobj_dom, &flags))
2436 return NULL;
2437 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2439 LIBVIRT_BEGIN_ALLOW_THREADS;
2440 c_retval = virDomainListAllSnapshots(dom, &snaps, flags);
2441 LIBVIRT_END_ALLOW_THREADS;
2442 if (c_retval < 0)
2443 return VIR_PY_NONE;
2445 if (!(py_retval = PyList_New(c_retval)))
2446 goto cleanup;
2448 for (i = 0; i < c_retval; i++) {
2449 VIR_PY_LIST_SET_GOTO(py_retval, i,
2450 libvirt_virDomainSnapshotPtrWrap(snaps[i]), error);
2451 snaps[i] = NULL;
2454 cleanup:
2455 for (i = 0; i < c_retval; i++)
2456 if (snaps[i])
2457 virDomainSnapshotFree(snaps[i]);
2458 VIR_FREE(snaps);
2459 return py_retval;
2461 error:
2462 Py_CLEAR(py_retval);
2463 goto cleanup;
2465 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2467 static PyObject *
2468 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
2469 PyObject *args)
2471 PyObject *py_retval;
2472 char **names = NULL;
2473 int c_retval;
2474 size_t i;
2475 virDomainSnapshotPtr snap;
2476 PyObject *pyobj_snap;
2477 unsigned int flags;
2479 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListChildrenNames",
2480 &pyobj_snap, &flags))
2481 return NULL;
2482 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2484 LIBVIRT_BEGIN_ALLOW_THREADS;
2485 c_retval = virDomainSnapshotNumChildren(snap, flags);
2486 LIBVIRT_END_ALLOW_THREADS;
2487 if (c_retval < 0)
2488 return VIR_PY_NONE;
2490 if (c_retval) {
2491 if (VIR_ALLOC_N(names, c_retval) < 0)
2492 return PyErr_NoMemory();
2493 LIBVIRT_BEGIN_ALLOW_THREADS;
2494 c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
2495 flags);
2496 LIBVIRT_END_ALLOW_THREADS;
2497 if (c_retval < 0) {
2498 py_retval = VIR_PY_NONE;
2499 goto cleanup;
2503 if ((py_retval = PyList_New(c_retval)) == NULL)
2504 goto cleanup;
2506 for (i = 0; i < c_retval; i++)
2507 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_constcharPtrWrap(names[i]), error);
2509 cleanup:
2510 if (c_retval > 0)
2511 for (i = 0; i < c_retval; i++)
2512 VIR_FREE(names[i]);
2513 VIR_FREE(names);
2514 return py_retval;
2516 error:
2517 Py_CLEAR(py_retval);
2518 goto cleanup;
2521 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2522 static PyObject *
2523 libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2524 PyObject *args)
2526 PyObject *py_retval = NULL;
2527 virDomainSnapshotPtr *snaps = NULL;
2528 int c_retval;
2529 size_t i;
2530 virDomainSnapshotPtr parent;
2531 PyObject *pyobj_parent;
2532 unsigned int flags;
2534 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListAllChildren",
2535 &pyobj_parent, &flags))
2536 return NULL;
2537 parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
2539 LIBVIRT_BEGIN_ALLOW_THREADS;
2540 c_retval = virDomainSnapshotListAllChildren(parent, &snaps, flags);
2541 LIBVIRT_END_ALLOW_THREADS;
2542 if (c_retval < 0)
2543 return VIR_PY_NONE;
2545 if (!(py_retval = PyList_New(c_retval)))
2546 goto cleanup;
2548 for (i = 0; i < c_retval; i++) {
2549 VIR_PY_LIST_SET_GOTO(py_retval, i,
2550 libvirt_virDomainSnapshotPtrWrap(snaps[i]), error);
2551 snaps[i] = NULL;
2554 cleanup:
2555 for (i = 0; i < c_retval; i++)
2556 if (snaps[i])
2557 virDomainSnapshotFree(snaps[i]);
2558 VIR_FREE(snaps);
2559 return py_retval;
2561 error:
2562 Py_CLEAR(py_retval);
2563 goto cleanup;
2565 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2567 static PyObject *
2568 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
2569 PyObject *args)
2571 int c_retval;
2572 virDomainSnapshotPtr snap;
2573 PyObject *pyobj_snap;
2574 PyObject *pyobj_dom;
2575 unsigned int flags;
2577 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainRevertToSnapshot",
2578 &pyobj_dom, &pyobj_snap, &flags))
2579 return NULL;
2580 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2582 LIBVIRT_BEGIN_ALLOW_THREADS;
2583 c_retval = virDomainRevertToSnapshot(snap, flags);
2584 LIBVIRT_END_ALLOW_THREADS;
2585 if (c_retval < 0)
2586 return VIR_PY_INT_FAIL;
2588 return libvirt_intWrap(c_retval);
2591 static PyObject *
2592 libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED,
2593 PyObject *args)
2595 PyObject *py_retval;
2596 int c_retval;
2597 virDomainPtr domain;
2598 PyObject *pyobj_domain;
2599 virDomainInfo info;
2601 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_domain))
2602 return NULL;
2603 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2605 LIBVIRT_BEGIN_ALLOW_THREADS;
2606 c_retval = virDomainGetInfo(domain, &info);
2607 LIBVIRT_END_ALLOW_THREADS;
2608 if (c_retval < 0)
2609 return VIR_PY_NONE;
2611 if ((py_retval = PyList_New(5)) == NULL)
2612 return NULL;
2614 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap((int) info.state), error);
2615 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_ulongWrap(info.maxMem), error);
2616 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_ulongWrap(info.memory), error);
2617 VIR_PY_LIST_SET_GOTO(py_retval, 3,
2618 libvirt_intWrap((int) info.nrVirtCpu), error);
2619 VIR_PY_LIST_SET_GOTO(py_retval, 4,
2620 libvirt_ulonglongWrap(info.cpuTime), error);
2622 return py_retval;
2624 error:
2625 Py_XDECREF(py_retval);
2626 return NULL;
2629 static PyObject *
2630 libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED,
2631 PyObject *args)
2633 PyObject *py_retval;
2634 int c_retval;
2635 virDomainPtr domain;
2636 PyObject *pyobj_domain;
2637 int state;
2638 int reason;
2639 unsigned int flags;
2641 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetState",
2642 &pyobj_domain, &flags))
2643 return NULL;
2645 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2647 LIBVIRT_BEGIN_ALLOW_THREADS;
2648 c_retval = virDomainGetState(domain, &state, &reason, flags);
2649 LIBVIRT_END_ALLOW_THREADS;
2650 if (c_retval < 0)
2651 return VIR_PY_NONE;
2653 if ((py_retval = PyList_New(2)) == NULL)
2654 return NULL;
2656 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap(state), error);
2657 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_intWrap(reason), error);
2659 return py_retval;
2661 error:
2662 Py_XDECREF(py_retval);
2663 return NULL;
2666 static PyObject *
2667 libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED,
2668 PyObject *args)
2670 PyObject *py_retval;
2671 int c_retval;
2672 virDomainPtr domain;
2673 PyObject *pyobj_domain;
2674 virDomainControlInfo info;
2675 unsigned int flags;
2677 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetControlInfo",
2678 &pyobj_domain, &flags))
2679 return NULL;
2680 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2682 LIBVIRT_BEGIN_ALLOW_THREADS;
2683 c_retval = virDomainGetControlInfo(domain, &info, flags);
2684 LIBVIRT_END_ALLOW_THREADS;
2685 if (c_retval < 0)
2686 return VIR_PY_NONE;
2688 if ((py_retval = PyList_New(3)) == NULL)
2689 return NULL;
2691 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap(info.state), error);
2692 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_intWrap(info.details), error);
2693 VIR_PY_LIST_SET_GOTO(py_retval, 2,
2694 libvirt_ulonglongWrap(info.stateTime), error);
2696 return py_retval;
2698 error:
2699 Py_XDECREF(py_retval);
2700 return NULL;
2703 static PyObject *
2704 libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED,
2705 PyObject *args)
2707 PyObject *py_retval;
2708 int c_retval;
2709 virDomainPtr domain;
2710 PyObject *pyobj_domain;
2711 virDomainBlockInfo info;
2712 const char *path;
2713 unsigned int flags;
2715 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockInfo",
2716 &pyobj_domain, &path, &flags))
2717 return NULL;
2718 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2720 LIBVIRT_BEGIN_ALLOW_THREADS;
2721 c_retval = virDomainGetBlockInfo(domain, path, &info, flags);
2722 LIBVIRT_END_ALLOW_THREADS;
2723 if (c_retval < 0)
2724 return VIR_PY_NONE;
2726 if ((py_retval = PyList_New(3)) == NULL)
2727 return NULL;
2729 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2730 libvirt_ulonglongWrap(info.capacity), error);
2731 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2732 libvirt_ulonglongWrap(info.allocation), error);
2733 VIR_PY_LIST_SET_GOTO(py_retval, 2,
2734 libvirt_ulonglongWrap(info.physical), error);
2736 return py_retval;
2738 error:
2739 Py_XDECREF(py_retval);
2740 return NULL;
2743 static PyObject *
2744 libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED,
2745 PyObject *args)
2747 PyObject *py_retval;
2748 int c_retval;
2749 virConnectPtr conn;
2750 PyObject *pyobj_conn;
2751 virNodeInfo info;
2753 if (!PyArg_ParseTuple(args, (char *)"O:virNodeGetInfo", &pyobj_conn))
2754 return NULL;
2755 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2757 LIBVIRT_BEGIN_ALLOW_THREADS;
2758 c_retval = virNodeGetInfo(conn, &info);
2759 LIBVIRT_END_ALLOW_THREADS;
2760 if (c_retval < 0)
2761 return VIR_PY_NONE;
2763 if ((py_retval = PyList_New(8)) == NULL)
2764 return NULL;
2766 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2767 libvirt_constcharPtrWrap(&info.model[0]), error);
2768 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2769 libvirt_longWrap((long) info.memory >> 10), error);
2770 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_intWrap((int) info.cpus), error);
2771 VIR_PY_LIST_SET_GOTO(py_retval, 3, libvirt_intWrap((int) info.mhz), error);
2772 VIR_PY_LIST_SET_GOTO(py_retval, 4, libvirt_intWrap((int) info.nodes), error);
2773 VIR_PY_LIST_SET_GOTO(py_retval, 5, libvirt_intWrap((int) info.sockets), error);
2774 VIR_PY_LIST_SET_GOTO(py_retval, 6, libvirt_intWrap((int) info.cores), error);
2775 VIR_PY_LIST_SET_GOTO(py_retval, 7, libvirt_intWrap((int) info.threads), error);
2777 return py_retval;
2779 error:
2780 Py_XDECREF(py_retval);
2781 return NULL;
2784 static PyObject *
2785 libvirt_virNodeGetSecurityModel(PyObject *self ATTRIBUTE_UNUSED,
2786 PyObject *args)
2788 PyObject *py_retval;
2789 int c_retval;
2790 virConnectPtr conn;
2791 PyObject *pyobj_conn;
2792 virSecurityModel model;
2794 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityModel",
2795 &pyobj_conn))
2796 return NULL;
2797 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2799 LIBVIRT_BEGIN_ALLOW_THREADS;
2800 c_retval = virNodeGetSecurityModel(conn, &model);
2801 LIBVIRT_END_ALLOW_THREADS;
2802 if (c_retval < 0)
2803 return VIR_PY_NONE;
2805 if ((py_retval = PyList_New(2)) == NULL)
2806 return NULL;
2808 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2809 libvirt_constcharPtrWrap(&model.model[0]), error);
2810 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2811 libvirt_constcharPtrWrap(&model.doi[0]), error);
2813 return py_retval;
2815 error:
2816 Py_XDECREF(py_retval);
2817 return NULL;
2820 static PyObject *
2821 libvirt_virDomainGetSecurityLabel(PyObject *self ATTRIBUTE_UNUSED,
2822 PyObject *args)
2824 PyObject *py_retval;
2825 int c_retval;
2826 virDomainPtr dom;
2827 PyObject *pyobj_dom;
2828 virSecurityLabel label;
2830 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabel",
2831 &pyobj_dom))
2832 return NULL;
2833 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2835 LIBVIRT_BEGIN_ALLOW_THREADS;
2836 c_retval = virDomainGetSecurityLabel(dom, &label);
2837 LIBVIRT_END_ALLOW_THREADS;
2838 if (c_retval < 0)
2839 return VIR_PY_NONE;
2841 if ((py_retval = PyList_New(2)) == NULL)
2842 return NULL;
2844 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2845 libvirt_constcharPtrWrap(&label.label[0]), error);
2846 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2847 libvirt_boolWrap(label.enforcing), error);
2849 return py_retval;
2851 error:
2852 Py_XDECREF(py_retval);
2853 return NULL;
2856 #if LIBVIR_CHECK_VERSION(0, 10, 0)
2857 static PyObject *
2858 libvirt_virDomainGetSecurityLabelList(PyObject *self ATTRIBUTE_UNUSED,
2859 PyObject *args)
2861 PyObject *py_retval;
2862 int c_retval;
2863 virDomainPtr dom;
2864 PyObject *pyobj_dom;
2865 virSecurityLabel *labels = NULL;
2866 size_t i;
2868 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabelList",
2869 &pyobj_dom))
2870 return NULL;
2872 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2874 LIBVIRT_BEGIN_ALLOW_THREADS;
2875 c_retval = virDomainGetSecurityLabelList(dom, &labels);
2876 LIBVIRT_END_ALLOW_THREADS;
2878 if (c_retval < 0)
2879 return VIR_PY_NONE;
2881 if (!(py_retval = PyList_New(0)))
2882 goto error;
2884 for (i = 0 ; i < c_retval ; i++) {
2885 PyObject *entry;
2887 if (!(entry = PyList_New(2)))
2888 goto error;
2890 VIR_PY_LIST_APPEND_GOTO(py_retval, entry, error);
2892 VIR_PY_LIST_SET_GOTO(entry, 0,
2893 libvirt_constcharPtrWrap(&labels[i].label[0]),
2894 error);
2895 VIR_PY_LIST_SET_GOTO(entry, 1,
2896 libvirt_boolWrap(labels[i].enforcing), error);
2899 cleanup:
2900 VIR_FREE(labels);
2901 return py_retval;
2903 error:
2904 Py_CLEAR(py_retval);
2905 goto cleanup;
2907 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
2909 static PyObject *
2910 libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED,
2911 PyObject *args)
2913 unsigned char uuid[VIR_UUID_BUFLEN];
2914 virDomainPtr domain;
2915 PyObject *pyobj_domain;
2916 int c_retval;
2918 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
2919 return NULL;
2920 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2922 if (domain == NULL)
2923 return VIR_PY_NONE;
2924 LIBVIRT_BEGIN_ALLOW_THREADS;
2925 c_retval = virDomainGetUUID(domain, &uuid[0]);
2926 LIBVIRT_END_ALLOW_THREADS;
2928 if (c_retval < 0)
2929 return VIR_PY_NONE;
2931 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
2934 static PyObject *
2935 libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
2936 PyObject *args)
2938 char uuidstr[VIR_UUID_STRING_BUFLEN];
2939 virDomainPtr dom;
2940 PyObject *pyobj_dom;
2941 int c_retval;
2943 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString",
2944 &pyobj_dom))
2945 return NULL;
2946 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2948 if (dom == NULL)
2949 return VIR_PY_NONE;
2950 LIBVIRT_BEGIN_ALLOW_THREADS;
2951 c_retval = virDomainGetUUIDString(dom, &uuidstr[0]);
2952 LIBVIRT_END_ALLOW_THREADS;
2954 if (c_retval < 0)
2955 return VIR_PY_NONE;
2957 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
2960 static PyObject *
2961 libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
2962 PyObject *args)
2964 virDomainPtr c_retval;
2965 virConnectPtr conn;
2966 PyObject *pyobj_conn;
2967 unsigned char * uuid;
2968 int len;
2970 if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID",
2971 &pyobj_conn, &uuid, &len))
2972 return NULL;
2973 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2975 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
2976 return VIR_PY_NONE;
2978 LIBVIRT_BEGIN_ALLOW_THREADS;
2979 c_retval = virDomainLookupByUUID(conn, uuid);
2980 LIBVIRT_END_ALLOW_THREADS;
2982 return libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
2986 static PyObject *
2987 libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
2988 PyObject *args)
2990 PyObject *py_retval;
2991 char **names = NULL;
2992 int c_retval;
2993 size_t i;
2994 virConnectPtr conn;
2995 PyObject *pyobj_conn;
2998 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks",
2999 &pyobj_conn))
3000 return NULL;
3001 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3003 LIBVIRT_BEGIN_ALLOW_THREADS;
3004 c_retval = virConnectNumOfNetworks(conn);
3005 LIBVIRT_END_ALLOW_THREADS;
3006 if (c_retval < 0)
3007 return VIR_PY_NONE;
3009 if (c_retval) {
3010 if (VIR_ALLOC_N(names, c_retval) < 0)
3011 return PyErr_NoMemory();
3012 LIBVIRT_BEGIN_ALLOW_THREADS;
3013 c_retval = virConnectListNetworks(conn, names, c_retval);
3014 LIBVIRT_END_ALLOW_THREADS;
3015 if (c_retval < 0) {
3016 py_retval = VIR_PY_NONE;
3017 goto cleanup;
3021 if ((py_retval = PyList_New(c_retval)) == NULL)
3022 goto cleanup;
3024 if (names)
3025 for (i = 0; i < c_retval; i++)
3026 VIR_PY_LIST_SET_GOTO(py_retval, i,
3027 libvirt_constcharPtrWrap(names[i]), error);
3029 cleanup:
3030 if (c_retval > 0)
3031 for (i = 0; i < c_retval; i++)
3032 VIR_FREE(names[i]);
3033 VIR_FREE(names);
3034 return py_retval;
3036 error:
3037 Py_CLEAR(py_retval);
3038 goto cleanup;
3042 static PyObject *
3043 libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
3044 PyObject *args)
3046 PyObject *py_retval;
3047 char **names = NULL;
3048 int c_retval;
3049 size_t i;
3050 virConnectPtr conn;
3051 PyObject *pyobj_conn;
3054 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks",
3055 &pyobj_conn))
3056 return NULL;
3057 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3059 LIBVIRT_BEGIN_ALLOW_THREADS;
3060 c_retval = virConnectNumOfDefinedNetworks(conn);
3061 LIBVIRT_END_ALLOW_THREADS;
3062 if (c_retval < 0)
3063 return VIR_PY_NONE;
3065 if (c_retval) {
3066 if (VIR_ALLOC_N(names, c_retval) < 0)
3067 return PyErr_NoMemory();
3068 LIBVIRT_BEGIN_ALLOW_THREADS;
3069 c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
3070 LIBVIRT_END_ALLOW_THREADS;
3071 if (c_retval < 0) {
3072 py_retval = VIR_PY_NONE;
3073 goto cleanup;
3077 if ((py_retval = PyList_New(c_retval)) == NULL)
3078 goto cleanup;
3080 for (i = 0; i < c_retval; i++)
3081 VIR_PY_LIST_SET_GOTO(py_retval, i,
3082 libvirt_constcharPtrWrap(names[i]), error);
3084 cleanup:
3085 if (c_retval > 0)
3086 for (i = 0; i < c_retval; i++)
3087 VIR_FREE(names[i]);
3088 VIR_FREE(names);
3089 return py_retval;
3091 error:
3092 Py_CLEAR(py_retval);
3093 goto cleanup;
3096 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3097 static PyObject *
3098 libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
3099 PyObject *args)
3101 PyObject *pyobj_conn;
3102 PyObject *py_retval = NULL;
3103 virConnectPtr conn;
3104 virNetworkPtr *nets = NULL;
3105 int c_retval = 0;
3106 size_t i;
3107 unsigned int flags;
3109 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNetworks",
3110 &pyobj_conn, &flags))
3111 return NULL;
3112 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3114 LIBVIRT_BEGIN_ALLOW_THREADS;
3115 c_retval = virConnectListAllNetworks(conn, &nets, flags);
3116 LIBVIRT_END_ALLOW_THREADS;
3117 if (c_retval < 0)
3118 return VIR_PY_NONE;
3120 if (!(py_retval = PyList_New(c_retval)))
3121 goto cleanup;
3123 for (i = 0; i < c_retval; i++) {
3124 VIR_PY_LIST_SET_GOTO(py_retval, i,
3125 libvirt_virNetworkPtrWrap(nets[i]), error);
3126 nets[i] = NULL;
3129 cleanup:
3130 for (i = 0; i < c_retval; i++)
3131 if (nets[i])
3132 virNetworkFree(nets[i]);
3133 VIR_FREE(nets);
3134 return py_retval;
3136 error:
3137 Py_CLEAR(py_retval);
3138 goto cleanup;
3140 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3143 static PyObject *
3144 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED,
3145 PyObject *args)
3147 unsigned char uuid[VIR_UUID_BUFLEN];
3148 virNetworkPtr domain;
3149 PyObject *pyobj_domain;
3150 int c_retval;
3152 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain))
3153 return NULL;
3154 domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
3156 if (domain == NULL)
3157 return VIR_PY_NONE;
3158 LIBVIRT_BEGIN_ALLOW_THREADS;
3159 c_retval = virNetworkGetUUID(domain, &uuid[0]);
3160 LIBVIRT_END_ALLOW_THREADS;
3162 if (c_retval < 0)
3163 return VIR_PY_NONE;
3165 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3168 static PyObject *
3169 libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3170 PyObject *args)
3172 char uuidstr[VIR_UUID_STRING_BUFLEN];
3173 virNetworkPtr net;
3174 PyObject *pyobj_net;
3175 int c_retval;
3177 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString",
3178 &pyobj_net))
3179 return NULL;
3180 net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net);
3182 if (net == NULL)
3183 return VIR_PY_NONE;
3184 LIBVIRT_BEGIN_ALLOW_THREADS;
3185 c_retval = virNetworkGetUUIDString(net, &uuidstr[0]);
3186 LIBVIRT_END_ALLOW_THREADS;
3188 if (c_retval < 0)
3189 return VIR_PY_NONE;
3191 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3194 static PyObject *
3195 libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3196 PyObject *args)
3198 virNetworkPtr c_retval;
3199 virConnectPtr conn;
3200 PyObject *pyobj_conn;
3201 unsigned char * uuid;
3202 int len;
3204 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID",
3205 &pyobj_conn, &uuid, &len))
3206 return NULL;
3207 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3209 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3210 return VIR_PY_NONE;
3212 LIBVIRT_BEGIN_ALLOW_THREADS;
3213 c_retval = virNetworkLookupByUUID(conn, uuid);
3214 LIBVIRT_END_ALLOW_THREADS;
3216 return libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval);
3220 static PyObject *
3221 libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3222 PyObject *args)
3224 int c_retval, autostart;
3225 virDomainPtr domain;
3226 PyObject *pyobj_domain;
3228 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetAutostart",
3229 &pyobj_domain))
3230 return NULL;
3232 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
3234 LIBVIRT_BEGIN_ALLOW_THREADS;
3235 c_retval = virDomainGetAutostart(domain, &autostart);
3236 LIBVIRT_END_ALLOW_THREADS;
3238 if (c_retval < 0)
3239 return VIR_PY_INT_FAIL;
3241 return libvirt_intWrap(autostart);
3245 static PyObject *
3246 libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3247 PyObject *args)
3249 int c_retval, autostart;
3250 virNetworkPtr network;
3251 PyObject *pyobj_network;
3253 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetAutostart",
3254 &pyobj_network))
3255 return NULL;
3257 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
3259 LIBVIRT_BEGIN_ALLOW_THREADS;
3260 c_retval = virNetworkGetAutostart(network, &autostart);
3261 LIBVIRT_END_ALLOW_THREADS;
3263 if (c_retval < 0)
3264 return VIR_PY_INT_FAIL;
3266 return libvirt_intWrap(autostart);
3269 static PyObject *
3270 libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
3271 PyObject *args)
3273 PyObject *py_retval;
3274 PyObject *pyobj_conn;
3275 int startCell, maxCells, c_retval;
3276 size_t i;
3277 virConnectPtr conn;
3278 unsigned long long *freeMems;
3280 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory",
3281 &pyobj_conn, &startCell, &maxCells))
3282 return NULL;
3284 if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
3285 return VIR_PY_NONE;
3287 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3288 if (VIR_ALLOC_N(freeMems, maxCells) < 0)
3289 return PyErr_NoMemory();
3291 LIBVIRT_BEGIN_ALLOW_THREADS;
3292 c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
3293 LIBVIRT_END_ALLOW_THREADS;
3295 if (c_retval < 0) {
3296 py_retval = VIR_PY_NONE;
3297 goto cleanup;
3300 if ((py_retval = PyList_New(c_retval)) == NULL)
3301 goto cleanup;
3303 for (i = 0; i < c_retval; i++)
3304 VIR_PY_LIST_SET_GOTO(py_retval, i,
3305 libvirt_ulonglongWrap(freeMems[i]), error);
3307 cleanup:
3308 VIR_FREE(freeMems);
3309 return py_retval;
3311 error:
3312 Py_CLEAR(py_retval);
3313 goto cleanup;
3316 static PyObject *
3317 libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED,
3318 PyObject *args)
3320 PyObject *ret = NULL;
3321 PyObject *key = NULL;
3322 PyObject *val = NULL;
3323 PyObject *pyobj_conn;
3324 virConnectPtr conn;
3325 unsigned int flags;
3326 int cpuNum, c_retval;
3327 size_t i;
3328 int nparams = 0;
3329 virNodeCPUStatsPtr stats = NULL;
3331 if (!PyArg_ParseTuple(args, (char *)"OiI:virNodeGetCPUStats",
3332 &pyobj_conn, &cpuNum, &flags))
3333 return ret;
3334 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3336 LIBVIRT_BEGIN_ALLOW_THREADS;
3337 c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
3338 LIBVIRT_END_ALLOW_THREADS;
3339 if (c_retval < 0)
3340 return VIR_PY_NONE;
3342 if (nparams) {
3343 if (VIR_ALLOC_N(stats, nparams) < 0)
3344 return PyErr_NoMemory();
3346 LIBVIRT_BEGIN_ALLOW_THREADS;
3347 c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
3348 LIBVIRT_END_ALLOW_THREADS;
3349 if (c_retval < 0) {
3350 VIR_FREE(stats);
3351 return VIR_PY_NONE;
3355 if (!(ret = PyDict_New()))
3356 goto error;
3358 for (i = 0; i < nparams; i++) {
3359 key = libvirt_constcharPtrWrap(stats[i].field);
3360 val = libvirt_ulonglongWrap(stats[i].value);
3362 VIR_PY_DICT_SET_GOTO(ret, key, val, error);
3365 cleanup:
3366 VIR_FREE(stats);
3367 return ret;
3369 error:
3370 Py_CLEAR(ret);
3371 goto cleanup;
3374 static PyObject *
3375 libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED,
3376 PyObject *args)
3378 PyObject *ret = NULL;
3379 PyObject *key = NULL;
3380 PyObject *val = NULL;
3381 PyObject *pyobj_conn;
3382 virConnectPtr conn;
3383 unsigned int flags;
3384 int cellNum, c_retval;
3385 size_t i;
3386 int nparams = 0;
3387 virNodeMemoryStatsPtr stats = NULL;
3389 if (!PyArg_ParseTuple(args, (char *)"OiI:virNodeGetMemoryStats",
3390 &pyobj_conn, &cellNum, &flags))
3391 return NULL;
3392 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3394 LIBVIRT_BEGIN_ALLOW_THREADS;
3395 c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
3396 LIBVIRT_END_ALLOW_THREADS;
3397 if (c_retval < 0)
3398 return VIR_PY_NONE;
3400 if (nparams) {
3401 if (VIR_ALLOC_N(stats, nparams) < 0)
3402 return PyErr_NoMemory();
3404 LIBVIRT_BEGIN_ALLOW_THREADS;
3405 c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
3406 LIBVIRT_END_ALLOW_THREADS;
3407 if (c_retval < 0) {
3408 VIR_FREE(stats);
3409 return VIR_PY_NONE;
3413 if (!(ret = PyDict_New()))
3414 goto error;
3416 for (i = 0; i < nparams; i++) {
3417 key = libvirt_constcharPtrWrap(stats[i].field);
3418 val = libvirt_ulonglongWrap(stats[i].value);
3420 VIR_PY_DICT_SET_GOTO(ret, key, val, error);
3423 cleanup:
3424 VIR_FREE(stats);
3425 return ret;
3427 error:
3428 Py_CLEAR(ret);
3429 goto cleanup;
3432 static PyObject *
3433 libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3434 PyObject *args)
3436 PyObject *py_retval;
3437 char **names = NULL;
3438 int c_retval;
3439 size_t i;
3440 virConnectPtr conn;
3441 PyObject *pyobj_conn;
3443 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListStoragePools",
3444 &pyobj_conn))
3445 return NULL;
3446 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3448 LIBVIRT_BEGIN_ALLOW_THREADS;
3449 c_retval = virConnectNumOfStoragePools(conn);
3450 LIBVIRT_END_ALLOW_THREADS;
3451 if (c_retval < 0)
3452 return VIR_PY_NONE;
3454 if (c_retval) {
3455 if (VIR_ALLOC_N(names, c_retval) < 0)
3456 return PyErr_NoMemory();
3457 LIBVIRT_BEGIN_ALLOW_THREADS;
3458 c_retval = virConnectListStoragePools(conn, names, c_retval);
3459 LIBVIRT_END_ALLOW_THREADS;
3460 if (c_retval < 0) {
3461 py_retval = VIR_PY_NONE;
3462 goto cleanup;
3466 if ((py_retval = PyList_New(c_retval)) == NULL)
3467 goto cleanup;
3469 for (i = 0; i < c_retval; i++)
3470 VIR_PY_LIST_SET_GOTO(py_retval, i,
3471 libvirt_constcharPtrWrap(names[i]), error);
3473 cleanup:
3474 if (c_retval > 0)
3475 for (i = 0; i < c_retval; i++)
3476 VIR_FREE(names[i]);
3477 VIR_FREE(names);
3478 return py_retval;
3480 error:
3481 Py_CLEAR(py_retval);
3482 goto cleanup;
3486 static PyObject *
3487 libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3488 PyObject *args)
3490 PyObject *py_retval;
3491 char **names = NULL;
3492 int c_retval;
3493 size_t i;
3494 virConnectPtr conn;
3495 PyObject *pyobj_conn;
3497 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedStoragePools",
3498 &pyobj_conn))
3499 return NULL;
3500 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3502 LIBVIRT_BEGIN_ALLOW_THREADS;
3503 c_retval = virConnectNumOfDefinedStoragePools(conn);
3504 LIBVIRT_END_ALLOW_THREADS;
3505 if (c_retval < 0)
3506 return VIR_PY_NONE;
3508 if (c_retval) {
3509 if (VIR_ALLOC_N(names, c_retval) < 0)
3510 return PyErr_NoMemory();
3511 LIBVIRT_BEGIN_ALLOW_THREADS;
3512 c_retval = virConnectListDefinedStoragePools(conn, names, c_retval);
3513 LIBVIRT_END_ALLOW_THREADS;
3514 if (c_retval < 0) {
3515 py_retval = VIR_PY_NONE;
3516 goto cleanup;
3520 if ((py_retval = PyList_New(c_retval)) == NULL)
3521 goto cleanup;
3523 if (names) {
3524 for (i = 0; i < c_retval; i++)
3525 VIR_PY_LIST_SET_GOTO(py_retval, i,
3526 libvirt_constcharPtrWrap(names[i]), error);
3529 cleanup:
3530 if (c_retval > 0)
3531 for (i = 0; i < c_retval; i++)
3532 VIR_FREE(names[i]);
3533 VIR_FREE(names);
3534 return py_retval;
3536 error:
3537 Py_CLEAR(py_retval);
3538 goto cleanup;
3541 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3542 static PyObject *
3543 libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3544 PyObject *args)
3546 PyObject *pyobj_conn;
3547 PyObject *py_retval = NULL;
3548 virConnectPtr conn;
3549 virStoragePoolPtr *pools = NULL;
3550 int c_retval = 0;
3551 size_t i;
3552 unsigned int flags;
3554 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllStoragePools",
3555 &pyobj_conn, &flags))
3556 return NULL;
3557 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3559 LIBVIRT_BEGIN_ALLOW_THREADS;
3560 c_retval = virConnectListAllStoragePools(conn, &pools, flags);
3561 LIBVIRT_END_ALLOW_THREADS;
3562 if (c_retval < 0)
3563 return VIR_PY_NONE;
3565 if (!(py_retval = PyList_New(c_retval)))
3566 goto cleanup;
3568 for (i = 0; i < c_retval; i++) {
3569 VIR_PY_LIST_SET_GOTO(py_retval, i,
3570 libvirt_virStoragePoolPtrWrap(pools[i]), error);
3571 /* python steals the pointer */
3572 pools[i] = NULL;
3575 cleanup:
3576 for (i = 0; i < c_retval; i++)
3577 if (pools[i])
3578 virStoragePoolFree(pools[i]);
3579 VIR_FREE(pools);
3580 return py_retval;
3582 error:
3583 Py_CLEAR(py_retval);
3584 goto cleanup;
3586 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3588 static PyObject *
3589 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
3590 PyObject *args)
3592 PyObject *py_retval;
3593 char **names = NULL;
3594 int c_retval;
3595 size_t i;
3596 virStoragePoolPtr pool;
3597 PyObject *pyobj_pool;
3599 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolListVolumes",
3600 &pyobj_pool))
3601 return NULL;
3602 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3604 LIBVIRT_BEGIN_ALLOW_THREADS;
3605 c_retval = virStoragePoolNumOfVolumes(pool);
3606 LIBVIRT_END_ALLOW_THREADS;
3607 if (c_retval < 0)
3608 return VIR_PY_NONE;
3610 if (c_retval) {
3611 if (VIR_ALLOC_N(names, c_retval) < 0)
3612 return PyErr_NoMemory();
3614 LIBVIRT_BEGIN_ALLOW_THREADS;
3615 c_retval = virStoragePoolListVolumes(pool, names, c_retval);
3616 LIBVIRT_END_ALLOW_THREADS;
3617 if (c_retval < 0) {
3618 py_retval = VIR_PY_NONE;
3619 goto cleanup;
3623 if ((py_retval = PyList_New(c_retval)) == NULL)
3624 goto cleanup;
3626 if (names)
3627 for (i = 0; i < c_retval; i++)
3628 VIR_PY_LIST_SET_GOTO(py_retval, i,
3629 libvirt_constcharPtrWrap(names[i]), error);
3631 cleanup:
3632 if (c_retval > 0)
3633 for (i = 0; i < c_retval; i++)
3634 VIR_FREE(names[i]);
3635 VIR_FREE(names);
3636 return py_retval;
3638 error:
3639 Py_CLEAR(py_retval);
3640 goto cleanup;
3643 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3644 static PyObject *
3645 libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
3646 PyObject *args)
3648 PyObject *py_retval = NULL;
3649 virStoragePoolPtr pool;
3650 virStorageVolPtr *vols = NULL;
3651 int c_retval = 0;
3652 size_t i;
3653 unsigned int flags;
3654 PyObject *pyobj_pool;
3656 if (!PyArg_ParseTuple(args, (char *)"OI:virStoragePoolListAllVolumes",
3657 &pyobj_pool, &flags))
3658 return NULL;
3660 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3662 LIBVIRT_BEGIN_ALLOW_THREADS;
3663 c_retval = virStoragePoolListAllVolumes(pool, &vols, flags);
3664 LIBVIRT_END_ALLOW_THREADS;
3665 if (c_retval < 0)
3666 return VIR_PY_NONE;
3668 if (!(py_retval = PyList_New(c_retval)))
3669 goto cleanup;
3671 for (i = 0; i < c_retval; i++) {
3672 VIR_PY_LIST_SET_GOTO(py_retval, i,
3673 libvirt_virStorageVolPtrWrap(vols[i]), error);
3674 /* python steals the pointer */
3675 vols[i] = NULL;
3678 cleanup:
3679 for (i = 0; i < c_retval; i++)
3680 if (vols[i])
3681 virStorageVolFree(vols[i]);
3682 VIR_FREE(vols);
3683 return py_retval;
3685 error:
3686 Py_CLEAR(py_retval);
3687 goto cleanup;
3689 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3692 static PyObject *
3693 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3694 PyObject *args)
3696 int c_retval, autostart;
3697 virStoragePoolPtr pool;
3698 PyObject *pyobj_pool;
3700 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetAutostart",
3701 &pyobj_pool))
3702 return NULL;
3704 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3706 LIBVIRT_BEGIN_ALLOW_THREADS;
3707 c_retval = virStoragePoolGetAutostart(pool, &autostart);
3708 LIBVIRT_END_ALLOW_THREADS;
3710 if (c_retval < 0)
3711 return VIR_PY_INT_FAIL;
3713 return libvirt_intWrap(autostart);
3716 static PyObject *
3717 libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED,
3718 PyObject *args)
3720 PyObject *py_retval;
3721 int c_retval;
3722 virStoragePoolPtr pool;
3723 PyObject *pyobj_pool;
3724 virStoragePoolInfo info;
3726 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetInfo", &pyobj_pool))
3727 return NULL;
3728 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3730 LIBVIRT_BEGIN_ALLOW_THREADS;
3731 c_retval = virStoragePoolGetInfo(pool, &info);
3732 LIBVIRT_END_ALLOW_THREADS;
3733 if (c_retval < 0)
3734 return VIR_PY_NONE;
3736 if ((py_retval = PyList_New(4)) == NULL)
3737 return NULL;
3739 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3740 libvirt_intWrap((int) info.state), error);
3741 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3742 libvirt_ulonglongWrap(info.capacity), error);
3743 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3744 libvirt_ulonglongWrap(info.allocation), error);
3745 VIR_PY_LIST_SET_GOTO(py_retval, 3,
3746 libvirt_ulonglongWrap(info.available), error);
3748 return py_retval;
3750 error:
3751 Py_XDECREF(py_retval);
3752 return NULL;
3756 static PyObject *
3757 libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED,
3758 PyObject *args)
3760 PyObject *py_retval;
3761 int c_retval;
3762 virStorageVolPtr pool;
3763 PyObject *pyobj_pool;
3764 virStorageVolInfo info;
3766 if (!PyArg_ParseTuple(args, (char *)"O:virStorageVolGetInfo", &pyobj_pool))
3767 return NULL;
3768 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3770 LIBVIRT_BEGIN_ALLOW_THREADS;
3771 c_retval = virStorageVolGetInfo(pool, &info);
3772 LIBVIRT_END_ALLOW_THREADS;
3773 if (c_retval < 0)
3774 return VIR_PY_NONE;
3776 if ((py_retval = PyList_New(3)) == NULL)
3777 return NULL;
3779 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3780 libvirt_intWrap((int) info.type), error);
3781 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3782 libvirt_ulonglongWrap(info.capacity), error);
3783 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3784 libvirt_ulonglongWrap(info.allocation), error);
3786 return py_retval;
3788 error:
3789 Py_DECREF(py_retval);
3790 return NULL;
3793 static PyObject *
3794 libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED,
3795 PyObject *args)
3797 unsigned char uuid[VIR_UUID_BUFLEN];
3798 virStoragePoolPtr pool;
3799 PyObject *pyobj_pool;
3800 int c_retval;
3802 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUID", &pyobj_pool))
3803 return NULL;
3804 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3806 if (pool == NULL)
3807 return VIR_PY_NONE;
3808 LIBVIRT_BEGIN_ALLOW_THREADS;
3809 c_retval = virStoragePoolGetUUID(pool, &uuid[0]);
3810 LIBVIRT_END_ALLOW_THREADS;
3812 if (c_retval < 0)
3813 return VIR_PY_NONE;
3815 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3818 static PyObject *
3819 libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3820 PyObject *args)
3822 char uuidstr[VIR_UUID_STRING_BUFLEN];
3823 virStoragePoolPtr pool;
3824 PyObject *pyobj_pool;
3825 int c_retval;
3827 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString",
3828 &pyobj_pool))
3829 return NULL;
3830 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3832 if (pool == NULL)
3833 return VIR_PY_NONE;
3834 LIBVIRT_BEGIN_ALLOW_THREADS;
3835 c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]);
3836 LIBVIRT_END_ALLOW_THREADS;
3838 if (c_retval < 0)
3839 return VIR_PY_NONE;
3841 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3844 static PyObject *
3845 libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3846 PyObject *args)
3848 virStoragePoolPtr c_retval;
3849 virConnectPtr conn;
3850 PyObject *pyobj_conn;
3851 unsigned char * uuid;
3852 int len;
3854 if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID",
3855 &pyobj_conn, &uuid, &len))
3856 return NULL;
3857 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3859 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3860 return VIR_PY_NONE;
3862 LIBVIRT_BEGIN_ALLOW_THREADS;
3863 c_retval = virStoragePoolLookupByUUID(conn, uuid);
3864 LIBVIRT_END_ALLOW_THREADS;
3866 return libvirt_virStoragePoolPtrWrap((virStoragePoolPtr) c_retval);
3869 static PyObject *
3870 libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
3871 PyObject *args)
3873 PyObject *py_retval;
3874 char **names = NULL;
3875 int c_retval;
3876 size_t i;
3877 virConnectPtr conn;
3878 PyObject *pyobj_conn;
3879 char *cap;
3880 unsigned int flags;
3882 if (!PyArg_ParseTuple(args, (char *)"OzI:virNodeListDevices",
3883 &pyobj_conn, &cap, &flags))
3884 return NULL;
3885 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3887 LIBVIRT_BEGIN_ALLOW_THREADS;
3888 c_retval = virNodeNumOfDevices(conn, cap, flags);
3889 LIBVIRT_END_ALLOW_THREADS;
3890 if (c_retval < 0)
3891 return VIR_PY_NONE;
3893 if (c_retval) {
3894 if (VIR_ALLOC_N(names, c_retval) < 0)
3895 return PyErr_NoMemory();
3897 LIBVIRT_BEGIN_ALLOW_THREADS;
3898 c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
3899 LIBVIRT_END_ALLOW_THREADS;
3901 if (c_retval < 0) {
3902 py_retval = VIR_PY_NONE;
3903 goto cleanup;
3907 if ((py_retval = PyList_New(c_retval)) == NULL)
3908 goto cleanup;
3910 if (names)
3911 for (i = 0; i < c_retval; i++)
3912 VIR_PY_LIST_SET_GOTO(py_retval, i,
3913 libvirt_constcharPtrWrap(names[i]), error);
3915 cleanup:
3916 if (c_retval > 0)
3917 for (i = 0; i < c_retval; i++)
3918 VIR_FREE(names[i]);
3919 VIR_FREE(names);
3920 return py_retval;
3922 error:
3923 Py_CLEAR(py_retval);
3924 goto cleanup;
3927 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3928 static PyObject *
3929 libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
3930 PyObject *args)
3932 PyObject *pyobj_conn;
3933 PyObject *py_retval = NULL;
3934 virConnectPtr conn;
3935 virNodeDevicePtr *devices = NULL;
3936 int c_retval = 0;
3937 size_t i;
3938 unsigned int flags;
3940 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNodeDevices",
3941 &pyobj_conn, &flags))
3942 return NULL;
3943 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3945 LIBVIRT_BEGIN_ALLOW_THREADS;
3946 c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
3947 LIBVIRT_END_ALLOW_THREADS;
3948 if (c_retval < 0)
3949 return VIR_PY_NONE;
3951 if (!(py_retval = PyList_New(c_retval)))
3952 goto cleanup;
3954 for (i = 0; i < c_retval; i++) {
3955 VIR_PY_LIST_SET_GOTO(py_retval, i,
3956 libvirt_virNodeDevicePtrWrap(devices[i]), error);
3957 /* python steals the pointer */
3958 devices[i] = NULL;
3961 cleanup:
3962 for (i = 0; i < c_retval; i++)
3963 if (devices[i])
3964 virNodeDeviceFree(devices[i]);
3965 VIR_FREE(devices);
3966 return py_retval;
3968 error:
3969 Py_CLEAR(py_retval);
3970 goto cleanup;
3972 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3974 static PyObject *
3975 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
3976 PyObject *args)
3978 PyObject *py_retval;
3979 char **names = NULL;
3980 int c_retval;
3981 size_t i;
3982 virNodeDevicePtr dev;
3983 PyObject *pyobj_dev;
3985 if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
3986 return NULL;
3987 dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
3989 LIBVIRT_BEGIN_ALLOW_THREADS;
3990 c_retval = virNodeDeviceNumOfCaps(dev);
3991 LIBVIRT_END_ALLOW_THREADS;
3992 if (c_retval < 0)
3993 return VIR_PY_NONE;
3995 if (c_retval) {
3996 if (VIR_ALLOC_N(names, c_retval) < 0)
3997 return PyErr_NoMemory();
3998 LIBVIRT_BEGIN_ALLOW_THREADS;
3999 c_retval = virNodeDeviceListCaps(dev, names, c_retval);
4000 LIBVIRT_END_ALLOW_THREADS;
4001 if (c_retval < 0) {
4002 py_retval = VIR_PY_NONE;
4003 goto cleanup;
4007 if ((py_retval = PyList_New(c_retval)) == NULL)
4008 goto cleanup;
4010 if (names)
4011 for (i = 0; i < c_retval; i++)
4012 VIR_PY_LIST_SET_GOTO(py_retval, i,
4013 libvirt_constcharPtrWrap(names[i]), error);
4015 cleanup:
4016 if (c_retval > 0)
4017 for (i = 0; i < c_retval; i++)
4018 VIR_FREE(names[i]);
4019 VIR_FREE(names);
4020 return py_retval;
4022 error:
4023 Py_CLEAR(py_retval);
4024 goto cleanup;
4027 static PyObject *
4028 libvirt_virSecretGetUUID(PyObject *self ATTRIBUTE_UNUSED,
4029 PyObject *args)
4031 unsigned char uuid[VIR_UUID_BUFLEN];
4032 virSecretPtr secret;
4033 PyObject *pyobj_secret;
4034 int c_retval;
4036 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUID", &pyobj_secret))
4037 return NULL;
4038 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4040 if (secret == NULL)
4041 return VIR_PY_NONE;
4042 LIBVIRT_BEGIN_ALLOW_THREADS;
4043 c_retval = virSecretGetUUID(secret, &uuid[0]);
4044 LIBVIRT_END_ALLOW_THREADS;
4046 if (c_retval < 0)
4047 return VIR_PY_NONE;
4049 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4052 static PyObject *
4053 libvirt_virSecretGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4054 PyObject *args)
4056 char uuidstr[VIR_UUID_STRING_BUFLEN];
4057 virSecretPtr dom;
4058 PyObject *pyobj_dom;
4059 int c_retval;
4061 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUIDString",
4062 &pyobj_dom))
4063 return NULL;
4064 dom = (virSecretPtr) PyvirSecret_Get(pyobj_dom);
4066 if (dom == NULL)
4067 return VIR_PY_NONE;
4068 LIBVIRT_BEGIN_ALLOW_THREADS;
4069 c_retval = virSecretGetUUIDString(dom, &uuidstr[0]);
4070 LIBVIRT_END_ALLOW_THREADS;
4072 if (c_retval < 0)
4073 return VIR_PY_NONE;
4075 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4078 static PyObject *
4079 libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
4080 PyObject *args)
4082 virSecretPtr c_retval;
4083 virConnectPtr conn;
4084 PyObject *pyobj_conn;
4085 unsigned char * uuid;
4086 int len;
4088 if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID",
4089 &pyobj_conn, &uuid, &len))
4090 return NULL;
4091 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4093 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4094 return VIR_PY_NONE;
4096 LIBVIRT_BEGIN_ALLOW_THREADS;
4097 c_retval = virSecretLookupByUUID(conn, uuid);
4098 LIBVIRT_END_ALLOW_THREADS;
4100 return libvirt_virSecretPtrWrap((virSecretPtr) c_retval);
4104 static PyObject *
4105 libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
4106 PyObject *args)
4108 PyObject *py_retval;
4109 char **uuids = NULL;
4110 virConnectPtr conn;
4111 int c_retval;
4112 size_t i;
4113 PyObject *pyobj_conn;
4115 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
4116 return NULL;
4117 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4119 LIBVIRT_BEGIN_ALLOW_THREADS;
4120 c_retval = virConnectNumOfSecrets(conn);
4121 LIBVIRT_END_ALLOW_THREADS;
4122 if (c_retval < 0)
4123 return VIR_PY_NONE;
4125 if (c_retval) {
4126 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4127 return PyErr_NoMemory();
4128 LIBVIRT_BEGIN_ALLOW_THREADS;
4129 c_retval = virConnectListSecrets(conn, uuids, c_retval);
4130 LIBVIRT_END_ALLOW_THREADS;
4131 if (c_retval < 0) {
4132 py_retval = VIR_PY_NONE;
4133 goto cleanup;
4137 if ((py_retval = PyList_New(c_retval)) == NULL)
4138 goto cleanup;
4140 if (uuids) {
4141 for (i = 0; i < c_retval; i++)
4142 VIR_PY_LIST_SET_GOTO(py_retval, i,
4143 libvirt_constcharPtrWrap(uuids[i]), error);
4146 cleanup:
4147 if (c_retval > 0)
4148 for (i = 0; i < c_retval; i++)
4149 VIR_FREE(uuids[i]);
4150 VIR_FREE(uuids);
4151 return py_retval;
4153 error:
4154 Py_CLEAR(py_retval);
4155 goto cleanup;
4158 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4159 static PyObject *
4160 libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
4161 PyObject *args)
4163 PyObject *pyobj_conn;
4164 PyObject *py_retval = NULL;
4165 virConnectPtr conn;
4166 virSecretPtr *secrets = NULL;
4167 int c_retval = 0;
4168 size_t i;
4169 unsigned int flags;
4171 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllSecrets",
4172 &pyobj_conn, &flags))
4173 return NULL;
4174 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4176 LIBVIRT_BEGIN_ALLOW_THREADS;
4177 c_retval = virConnectListAllSecrets(conn, &secrets, flags);
4178 LIBVIRT_END_ALLOW_THREADS;
4179 if (c_retval < 0)
4180 return VIR_PY_NONE;
4182 if (!(py_retval = PyList_New(c_retval)))
4183 goto cleanup;
4185 for (i = 0; i < c_retval; i++) {
4186 VIR_PY_LIST_SET_GOTO(py_retval, i,
4187 libvirt_virSecretPtrWrap(secrets[i]), error);
4188 /* python steals the pointer */
4189 secrets[i] = NULL;
4192 cleanup:
4193 for (i = 0; i < c_retval; i++)
4194 if (secrets[i])
4195 virSecretFree(secrets[i]);
4196 VIR_FREE(secrets);
4197 return py_retval;
4199 error:
4200 Py_CLEAR(py_retval);
4201 goto cleanup;
4203 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4205 static PyObject *
4206 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
4207 PyObject *args)
4209 PyObject *py_retval;
4210 unsigned char *c_retval;
4211 size_t size;
4212 virSecretPtr secret;
4213 PyObject *pyobj_secret;
4214 unsigned int flags;
4216 if (!PyArg_ParseTuple(args, (char *)"OI:virSecretGetValue", &pyobj_secret,
4217 &flags))
4218 return NULL;
4219 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4221 LIBVIRT_BEGIN_ALLOW_THREADS;
4222 c_retval = virSecretGetValue(secret, &size, flags);
4223 LIBVIRT_END_ALLOW_THREADS;
4225 if (c_retval == NULL)
4226 return VIR_PY_NONE;
4228 py_retval = libvirt_charPtrSizeWrap((char*)c_retval, size);
4229 VIR_FREE(c_retval);
4231 return py_retval;
4234 static PyObject *
4235 libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
4236 PyObject *args)
4238 int c_retval;
4239 virSecretPtr secret;
4240 PyObject *pyobj_secret;
4241 const char *value;
4242 int size;
4243 unsigned int flags;
4245 if (!PyArg_ParseTuple(args, (char *)"Oz#I:virSecretSetValue", &pyobj_secret,
4246 &value, &size, &flags))
4247 return NULL;
4248 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4250 LIBVIRT_BEGIN_ALLOW_THREADS;
4251 c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
4252 flags);
4253 LIBVIRT_END_ALLOW_THREADS;
4255 return libvirt_intWrap(c_retval);
4258 static PyObject *
4259 libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED,
4260 PyObject *args)
4262 unsigned char uuid[VIR_UUID_BUFLEN];
4263 virNWFilterPtr nwfilter;
4264 PyObject *pyobj_nwfilter;
4265 int c_retval;
4267 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID",
4268 &pyobj_nwfilter))
4269 return NULL;
4270 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4272 if (nwfilter == NULL)
4273 return VIR_PY_NONE;
4274 LIBVIRT_BEGIN_ALLOW_THREADS;
4275 c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
4276 LIBVIRT_END_ALLOW_THREADS;
4278 if (c_retval < 0)
4279 return VIR_PY_NONE;
4281 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4284 static PyObject *
4285 libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4286 PyObject *args)
4288 char uuidstr[VIR_UUID_STRING_BUFLEN];
4289 virNWFilterPtr nwfilter;
4290 PyObject *pyobj_nwfilter;
4291 int c_retval;
4293 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
4294 &pyobj_nwfilter))
4295 return NULL;
4296 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4298 if (nwfilter == NULL)
4299 return VIR_PY_NONE;
4300 LIBVIRT_BEGIN_ALLOW_THREADS;
4301 c_retval = virNWFilterGetUUIDString(nwfilter, &uuidstr[0]);
4302 LIBVIRT_END_ALLOW_THREADS;
4304 if (c_retval < 0)
4305 return VIR_PY_NONE;
4307 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4310 static PyObject *
4311 libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
4312 PyObject *args)
4314 virNWFilterPtr c_retval;
4315 virConnectPtr conn;
4316 PyObject *pyobj_conn;
4317 unsigned char * uuid;
4318 int len;
4320 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID",
4321 &pyobj_conn, &uuid, &len))
4322 return NULL;
4323 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4325 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4326 return VIR_PY_NONE;
4328 LIBVIRT_BEGIN_ALLOW_THREADS;
4329 c_retval = virNWFilterLookupByUUID(conn, uuid);
4330 LIBVIRT_END_ALLOW_THREADS;
4332 return libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
4336 static PyObject *
4337 libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4338 PyObject *args)
4340 PyObject *py_retval;
4341 char **uuids = NULL;
4342 virConnectPtr conn;
4343 int c_retval;
4344 size_t i;
4345 PyObject *pyobj_conn;
4347 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters",
4348 &pyobj_conn))
4349 return NULL;
4350 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4352 LIBVIRT_BEGIN_ALLOW_THREADS;
4353 c_retval = virConnectNumOfNWFilters(conn);
4354 LIBVIRT_END_ALLOW_THREADS;
4355 if (c_retval < 0)
4356 return VIR_PY_NONE;
4358 if (c_retval) {
4359 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4360 return PyErr_NoMemory();
4362 LIBVIRT_BEGIN_ALLOW_THREADS;
4363 c_retval = virConnectListNWFilters(conn, uuids, c_retval);
4364 LIBVIRT_END_ALLOW_THREADS;
4365 if (c_retval < 0) {
4366 py_retval = VIR_PY_NONE;
4367 goto cleanup;
4371 if ((py_retval = PyList_New(c_retval)) == NULL)
4372 goto cleanup;
4374 if (uuids)
4375 for (i = 0; i < c_retval; i++)
4376 VIR_PY_LIST_SET_GOTO(py_retval, i,
4377 libvirt_constcharPtrWrap(uuids[i]), error);
4379 cleanup:
4380 if (c_retval > 0)
4381 for (i = 0; i < c_retval; i++)
4382 VIR_FREE(uuids[i]);
4383 VIR_FREE(uuids);
4384 return py_retval;
4386 error:
4387 Py_CLEAR(py_retval);
4388 goto cleanup;
4391 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4392 static PyObject *
4393 libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4394 PyObject *args)
4396 PyObject *pyobj_conn;
4397 PyObject *py_retval = NULL;
4398 virConnectPtr conn;
4399 virNWFilterPtr *filters = NULL;
4400 int c_retval = 0;
4401 size_t i;
4402 unsigned int flags;
4404 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNWFilters",
4405 &pyobj_conn, &flags))
4406 return NULL;
4407 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4409 LIBVIRT_BEGIN_ALLOW_THREADS;
4410 c_retval = virConnectListAllNWFilters(conn, &filters, flags);
4411 LIBVIRT_END_ALLOW_THREADS;
4412 if (c_retval < 0)
4413 return VIR_PY_NONE;
4415 if (!(py_retval = PyList_New(c_retval)))
4416 goto cleanup;
4418 for (i = 0; i < c_retval; i++) {
4419 VIR_PY_LIST_SET_GOTO(py_retval, i,
4420 libvirt_virNWFilterPtrWrap(filters[i]), error);
4421 /* python steals the pointer */
4422 filters[i] = NULL;
4425 cleanup:
4426 for (i = 0; i < c_retval; i++)
4427 if (filters[i])
4428 virNWFilterFree(filters[i]);
4429 VIR_FREE(filters);
4430 return py_retval;
4432 error:
4433 Py_CLEAR(py_retval);
4434 goto cleanup;
4436 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4438 static PyObject *
4439 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4440 PyObject *args)
4442 PyObject *py_retval;
4443 char **names = NULL;
4444 int c_retval;
4445 size_t i;
4446 virConnectPtr conn;
4447 PyObject *pyobj_conn;
4450 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListInterfaces",
4451 &pyobj_conn))
4452 return NULL;
4453 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4455 LIBVIRT_BEGIN_ALLOW_THREADS;
4456 c_retval = virConnectNumOfInterfaces(conn);
4457 LIBVIRT_END_ALLOW_THREADS;
4458 if (c_retval < 0)
4459 return VIR_PY_NONE;
4461 if (c_retval) {
4462 if (VIR_ALLOC_N(names, c_retval) < 0)
4463 return PyErr_NoMemory();
4465 LIBVIRT_BEGIN_ALLOW_THREADS;
4466 c_retval = virConnectListInterfaces(conn, names, c_retval);
4467 LIBVIRT_END_ALLOW_THREADS;
4468 if (c_retval < 0) {
4469 py_retval = VIR_PY_NONE;
4470 goto cleanup;
4474 if ((py_retval = PyList_New(c_retval)) == NULL)
4475 goto cleanup;
4477 if (names)
4478 for (i = 0; i < c_retval; i++)
4479 VIR_PY_LIST_SET_GOTO(py_retval, i,
4480 libvirt_constcharPtrWrap(names[i]), error);
4482 cleanup:
4483 if (c_retval > 0)
4484 for (i = 0; i < c_retval; i++)
4485 VIR_FREE(names[i]);
4486 VIR_FREE(names);
4487 return py_retval;
4489 error:
4490 Py_CLEAR(py_retval);
4491 goto cleanup;
4495 static PyObject *
4496 libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4497 PyObject *args)
4499 PyObject *py_retval;
4500 char **names = NULL;
4501 int c_retval;
4502 size_t i;
4503 virConnectPtr conn;
4504 PyObject *pyobj_conn;
4507 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedInterfaces",
4508 &pyobj_conn))
4509 return NULL;
4510 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4512 LIBVIRT_BEGIN_ALLOW_THREADS;
4513 c_retval = virConnectNumOfDefinedInterfaces(conn);
4514 LIBVIRT_END_ALLOW_THREADS;
4515 if (c_retval < 0)
4516 return VIR_PY_NONE;
4518 if (c_retval) {
4519 if (VIR_ALLOC_N(names, c_retval) < 0)
4520 return PyErr_NoMemory();
4522 LIBVIRT_BEGIN_ALLOW_THREADS;
4523 c_retval = virConnectListDefinedInterfaces(conn, names, c_retval);
4524 LIBVIRT_END_ALLOW_THREADS;
4525 if (c_retval < 0) {
4526 py_retval = VIR_PY_NONE;
4527 goto cleanup;
4531 if ((py_retval = PyList_New(c_retval)) == NULL)
4532 goto cleanup;
4534 if (names) {
4535 for (i = 0; i < c_retval; i++)
4536 VIR_PY_LIST_SET_GOTO(py_retval, i,
4537 libvirt_constcharPtrWrap(names[i]), error);
4540 cleanup:
4541 if (c_retval > 0)
4542 for (i = 0; i < c_retval; i++)
4543 VIR_FREE(names[i]);
4544 VIR_FREE(names);
4545 return py_retval;
4547 error:
4548 Py_CLEAR(py_retval);
4549 goto cleanup;
4553 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4554 static PyObject *
4555 libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4556 PyObject *args)
4558 PyObject *pyobj_conn;
4559 PyObject *py_retval = NULL;
4560 virConnectPtr conn;
4561 virInterfacePtr *ifaces = NULL;
4562 int c_retval = 0;
4563 size_t i;
4564 unsigned int flags;
4566 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllInterfaces",
4567 &pyobj_conn, &flags))
4568 return NULL;
4569 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4571 LIBVIRT_BEGIN_ALLOW_THREADS;
4572 c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
4573 LIBVIRT_END_ALLOW_THREADS;
4574 if (c_retval < 0)
4575 return VIR_PY_NONE;
4577 if (!(py_retval = PyList_New(c_retval)))
4578 goto cleanup;
4580 for (i = 0; i < c_retval; i++) {
4581 VIR_PY_LIST_SET_GOTO(py_retval, i,
4582 libvirt_virInterfacePtrWrap(ifaces[i]), error);
4583 /* python steals the pointer */
4584 ifaces[i] = NULL;
4587 cleanup:
4588 for (i = 0; i < c_retval; i++)
4589 if (ifaces[i])
4590 virInterfaceFree(ifaces[i]);
4591 VIR_FREE(ifaces);
4592 return py_retval;
4594 error:
4595 Py_CLEAR(py_retval);
4596 goto cleanup;
4598 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4600 static PyObject *
4601 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
4602 PyObject *args)
4604 PyObject *pyobj_conn;
4605 PyObject *list;
4606 virConnectPtr conn;
4607 unsigned int flags;
4608 char **xmlcpus = NULL;
4609 int ncpus = 0;
4610 char *base_cpu;
4611 PyObject *pybase_cpu;
4612 size_t i, j;
4614 if (!PyArg_ParseTuple(args, (char *)"OOI:virConnectBaselineCPU",
4615 &pyobj_conn, &list, &flags))
4616 return NULL;
4617 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4619 if (PyList_Check(list)) {
4620 ncpus = PyList_Size(list);
4621 if (VIR_ALLOC_N(xmlcpus, ncpus) < 0)
4622 return PyErr_NoMemory();
4624 for (i = 0; i < ncpus; i++) {
4625 if (libvirt_charPtrUnwrap(PyList_GetItem(list, i),
4626 &(xmlcpus[i])) < 0 ||
4627 xmlcpus[i] == NULL) {
4628 for (j = 0 ; j < i ; j++)
4629 VIR_FREE(xmlcpus[j]);
4630 VIR_FREE(xmlcpus);
4631 return NULL;
4636 LIBVIRT_BEGIN_ALLOW_THREADS;
4637 base_cpu = virConnectBaselineCPU(conn, (const char **)xmlcpus, ncpus, flags);
4638 LIBVIRT_END_ALLOW_THREADS;
4640 for (i = 0 ; i < ncpus ; i++)
4641 VIR_FREE(xmlcpus[i]);
4642 VIR_FREE(xmlcpus);
4644 if (base_cpu == NULL)
4645 return VIR_PY_NONE;
4647 pybase_cpu = libvirt_constcharPtrWrap(base_cpu);
4648 VIR_FREE(base_cpu);
4650 return pybase_cpu;
4654 static PyObject *
4655 libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4656 PyObject *args)
4658 PyObject *py_retval;
4659 int c_retval;
4660 virDomainPtr domain;
4661 PyObject *pyobj_domain;
4662 virDomainJobInfo info;
4664 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetJobInfo", &pyobj_domain))
4665 return NULL;
4666 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4668 LIBVIRT_BEGIN_ALLOW_THREADS;
4669 c_retval = virDomainGetJobInfo(domain, &info);
4670 LIBVIRT_END_ALLOW_THREADS;
4671 if (c_retval < 0)
4672 return VIR_PY_NONE;
4674 if ((py_retval = PyList_New(12)) == NULL)
4675 return NULL;
4677 VIR_PY_LIST_SET_GOTO(py_retval, 0,
4678 libvirt_intWrap((int) info.type), error);
4679 VIR_PY_LIST_SET_GOTO(py_retval, 1,
4680 libvirt_ulonglongWrap(info.timeElapsed), error);
4681 VIR_PY_LIST_SET_GOTO(py_retval, 2,
4682 libvirt_ulonglongWrap(info.timeRemaining), error);
4683 VIR_PY_LIST_SET_GOTO(py_retval, 3,
4684 libvirt_ulonglongWrap(info.dataTotal), error);
4685 VIR_PY_LIST_SET_GOTO(py_retval, 4,
4686 libvirt_ulonglongWrap(info.dataProcessed), error);
4687 VIR_PY_LIST_SET_GOTO(py_retval, 5,
4688 libvirt_ulonglongWrap(info.dataRemaining), error);
4689 VIR_PY_LIST_SET_GOTO(py_retval, 6,
4690 libvirt_ulonglongWrap(info.memTotal), error);
4691 VIR_PY_LIST_SET_GOTO(py_retval, 7,
4692 libvirt_ulonglongWrap(info.memProcessed), error);
4693 VIR_PY_LIST_SET_GOTO(py_retval, 8,
4694 libvirt_ulonglongWrap(info.memRemaining), error);
4695 VIR_PY_LIST_SET_GOTO(py_retval, 9,
4696 libvirt_ulonglongWrap(info.fileTotal), error);
4697 VIR_PY_LIST_SET_GOTO(py_retval, 10,
4698 libvirt_ulonglongWrap(info.fileProcessed), error);
4699 VIR_PY_LIST_SET_GOTO(py_retval, 11,
4700 libvirt_ulonglongWrap(info.fileRemaining), error);
4702 return py_retval;
4704 error:
4705 Py_DECREF(py_retval);
4706 return NULL;
4709 #if LIBVIR_CHECK_VERSION(1, 0, 3)
4710 static PyObject *
4711 libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED,
4712 PyObject *args)
4714 PyObject *pyobj_domain;
4715 virDomainPtr domain;
4716 unsigned int flags;
4717 virTypedParameterPtr params = NULL;
4718 int nparams = 0;
4719 int type;
4720 PyObject *dict = NULL;
4721 int rc;
4723 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetJobStats",
4724 &pyobj_domain, &flags))
4725 return NULL;
4726 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4728 LIBVIRT_BEGIN_ALLOW_THREADS;
4729 rc = virDomainGetJobStats(domain, &type, &params, &nparams, flags);
4730 LIBVIRT_END_ALLOW_THREADS;
4731 if (rc < 0)
4732 return VIR_PY_NONE;
4734 if (!(dict = getPyVirTypedParameter(params, nparams)))
4735 goto cleanup;
4737 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("type"),
4738 libvirt_intWrap(type), error);
4740 cleanup:
4741 virTypedParamsFree(params, nparams);
4742 return dict;
4744 error:
4745 Py_CLEAR(dict);
4746 goto cleanup;
4748 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
4750 static PyObject *
4751 libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4752 PyObject *args)
4754 virDomainPtr domain;
4755 PyObject *pyobj_domain;
4756 const char *path;
4757 unsigned int flags;
4758 virDomainBlockJobInfo info;
4759 int c_ret;
4760 PyObject *dict;
4762 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockJobInfo",
4763 &pyobj_domain, &path, &flags))
4764 return NULL;
4765 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4767 LIBVIRT_BEGIN_ALLOW_THREADS;
4768 c_ret = virDomainGetBlockJobInfo(domain, path, &info, flags);
4769 LIBVIRT_END_ALLOW_THREADS;
4771 if (c_ret < 0)
4772 return VIR_PY_NONE;
4774 if ((dict = PyDict_New()) == NULL)
4775 return NULL;
4777 if (c_ret == 0)
4778 return dict;
4780 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("type"),
4781 libvirt_intWrap(info.type), error);
4782 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("bandwidth"),
4783 libvirt_ulongWrap(info.bandwidth), error);
4784 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("cur"),
4785 libvirt_ulonglongWrap(info.cur), error);
4786 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("end"),
4787 libvirt_ulonglongWrap(info.end), error);
4789 return dict;
4791 error:
4792 Py_DECREF(dict);
4793 return NULL;
4796 static PyObject *
4797 libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4798 PyObject *args)
4800 virDomainPtr domain;
4801 PyObject *pyobj_domain, *info;
4802 PyObject *ret = NULL;
4803 int i_retval;
4804 int nparams = 0;
4805 Py_ssize_t size = 0;
4806 const char *disk;
4807 unsigned int flags;
4808 virTypedParameterPtr params = NULL, new_params = NULL;
4810 if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainSetBlockIoTune",
4811 &pyobj_domain, &disk, &info, &flags))
4812 return NULL;
4813 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4815 if ((size = PyDict_Size(info)) < 0)
4816 return NULL;
4818 if (size == 0) {
4819 PyErr_Format(PyExc_LookupError,
4820 "Need non-empty dictionary to set attributes");
4821 return NULL;
4824 LIBVIRT_BEGIN_ALLOW_THREADS;
4825 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4826 LIBVIRT_END_ALLOW_THREADS;
4828 if (i_retval < 0)
4829 return VIR_PY_INT_FAIL;
4831 if (nparams == 0) {
4832 PyErr_Format(PyExc_LookupError,
4833 "Domain has no settable attributes");
4834 return NULL;
4837 if (VIR_ALLOC_N(params, nparams) < 0)
4838 return PyErr_NoMemory();
4840 LIBVIRT_BEGIN_ALLOW_THREADS;
4841 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4842 LIBVIRT_END_ALLOW_THREADS;
4844 if (i_retval < 0) {
4845 ret = VIR_PY_INT_FAIL;
4846 goto cleanup;
4849 new_params = setPyVirTypedParameter(info, params, nparams);
4850 if (!new_params)
4851 goto cleanup;
4853 LIBVIRT_BEGIN_ALLOW_THREADS;
4854 i_retval = virDomainSetBlockIoTune(domain, disk, new_params, size, flags);
4855 LIBVIRT_END_ALLOW_THREADS;
4857 if (i_retval < 0) {
4858 ret = VIR_PY_INT_FAIL;
4859 goto cleanup;
4862 ret = VIR_PY_INT_SUCCESS;
4864 cleanup:
4865 virTypedParamsFree(params, nparams);
4866 virTypedParamsFree(new_params, size);
4867 return ret;
4870 static PyObject *
4871 libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4872 PyObject *args)
4874 virDomainPtr domain;
4875 PyObject *pyobj_domain;
4876 PyObject *ret = NULL;
4877 int i_retval;
4878 int nparams = 0;
4879 const char *disk;
4880 unsigned int flags;
4881 virTypedParameterPtr params;
4883 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockIoTune",
4884 &pyobj_domain, &disk, &flags))
4885 return NULL;
4886 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4888 LIBVIRT_BEGIN_ALLOW_THREADS;
4889 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4890 LIBVIRT_END_ALLOW_THREADS;
4892 if (i_retval < 0)
4893 return VIR_PY_NONE;
4895 if (!nparams)
4896 return PyDict_New();
4898 if (VIR_ALLOC_N(params, nparams) < 0)
4899 return PyErr_NoMemory();
4901 LIBVIRT_BEGIN_ALLOW_THREADS;
4902 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4903 LIBVIRT_END_ALLOW_THREADS;
4905 if (i_retval < 0) {
4906 ret = VIR_PY_NONE;
4907 goto cleanup;
4910 ret = getPyVirTypedParameter(params, nparams);
4912 cleanup:
4913 virTypedParamsFree(params, nparams);
4914 return ret;
4917 static PyObject *
4918 libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED,
4919 PyObject *args)
4921 PyObject *py_retval = VIR_PY_NONE;
4922 virDomainPtr domain;
4923 PyObject *pyobj_domain;
4924 unsigned int flags;
4925 virDomainDiskErrorPtr disks = NULL;
4926 unsigned int ndisks;
4927 int count;
4928 size_t i;
4930 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetDiskErrors",
4931 &pyobj_domain, &flags))
4932 return NULL;
4934 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4936 if ((count = virDomainGetDiskErrors(domain, NULL, 0, 0)) < 0)
4937 return VIR_PY_NONE;
4938 ndisks = count;
4940 if (ndisks) {
4941 if (VIR_ALLOC_N(disks, ndisks) < 0)
4942 return PyErr_NoMemory();
4944 LIBVIRT_BEGIN_ALLOW_THREADS;
4945 count = virDomainGetDiskErrors(domain, disks, ndisks, 0);
4946 LIBVIRT_END_ALLOW_THREADS;
4948 if (count < 0) {
4949 py_retval = VIR_PY_NONE;
4950 goto cleanup;
4954 if (!(py_retval = PyDict_New()))
4955 goto cleanup;
4957 for (i = 0; i < count; i++) {
4958 VIR_PY_DICT_SET_GOTO(py_retval,
4959 libvirt_constcharPtrWrap(disks[i].disk),
4960 libvirt_intWrap(disks[i].error),
4961 error);
4964 cleanup:
4965 if (count > 0)
4966 for (i = 0; i < count; i++)
4967 VIR_FREE(disks[i].disk);
4968 VIR_FREE(disks);
4969 return py_retval;
4971 error:
4972 Py_CLEAR(py_retval);
4973 goto cleanup;
4977 #if LIBVIR_CHECK_VERSION(1, 2, 14)
4978 static PyObject *
4979 libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED,
4980 PyObject *args)
4982 PyObject *py_retval = VIR_PY_NONE;
4983 PyObject *pyobj_domain;
4984 virDomainPtr domain;
4985 virDomainInterfacePtr *ifaces = NULL;
4986 unsigned int source;
4987 unsigned int flags;
4988 int ifaces_count = 0;
4989 size_t i, j;
4991 if (!PyArg_ParseTuple(args, (char *) "OII:virDomainInterfaceAddresses",
4992 &pyobj_domain, &source, &flags))
4993 return NULL;
4995 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4997 LIBVIRT_BEGIN_ALLOW_THREADS;
4998 ifaces_count = virDomainInterfaceAddresses(domain, &ifaces, source, flags);
4999 LIBVIRT_END_ALLOW_THREADS;
5001 if (ifaces_count < 0)
5002 goto cleanup;
5004 if (!(py_retval = PyDict_New()))
5005 goto error;
5007 for (i = 0; i < ifaces_count; i++) {
5008 virDomainInterfacePtr iface = ifaces[i];
5009 PyObject *py_addrs = NULL;
5010 PyObject *py_iface = NULL;
5012 if (!(py_iface = PyDict_New()))
5013 goto error;
5015 VIR_PY_DICT_SET_GOTO(py_retval, libvirt_charPtrWrap(iface->name),
5016 py_iface, error);
5018 if (iface->naddrs) {
5019 if (!(py_addrs = PyList_New(iface->naddrs))) {
5020 goto error;
5022 } else {
5023 py_addrs = VIR_PY_NONE;
5026 VIR_PY_DICT_SET_GOTO(py_iface, libvirt_constcharPtrWrap("addrs"),
5027 py_addrs, error);
5029 VIR_PY_DICT_SET_GOTO(py_iface, libvirt_constcharPtrWrap("hwaddr"),
5030 libvirt_constcharPtrWrap(iface->hwaddr), error);
5032 for (j = 0; j < iface->naddrs; j++) {
5033 virDomainIPAddressPtr addr = &(iface->addrs[j]);
5034 PyObject *py_addr = PyDict_New();
5036 if (!py_addr)
5037 goto error;
5039 VIR_PY_LIST_SET_GOTO(py_addrs, j, py_addr, error);
5041 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("addr"),
5042 libvirt_constcharPtrWrap(addr->addr), error);
5043 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("prefix"),
5044 libvirt_uintWrap(addr->prefix), error);
5045 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("type"),
5046 libvirt_intWrap(addr->type), error);
5050 cleanup:
5051 if (ifaces && ifaces_count > 0) {
5052 for (i = 0; i < ifaces_count; i++) {
5053 virDomainInterfaceFree(ifaces[i]);
5056 VIR_FREE(ifaces);
5058 return py_retval;
5060 error:
5061 Py_CLEAR(py_retval);
5062 goto cleanup;
5064 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
5067 /*******************************************
5068 * Helper functions to avoid importing modules
5069 * for every callback
5070 *******************************************/
5071 static PyObject *libvirt_module = NULL;
5072 static PyObject *libvirt_dict = NULL;
5074 static PyObject *
5075 getLibvirtModuleObject(void)
5077 if (libvirt_module)
5078 return libvirt_module;
5080 // PyImport_ImportModule returns a new reference
5081 /* Bogus (char *) cast for RHEL-5 python API brokenness */
5082 libvirt_module = PyImport_ImportModule((char *)"libvirt");
5083 if (!libvirt_module) {
5084 DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
5085 PyErr_Print();
5086 return NULL;
5089 return libvirt_module;
5092 static PyObject *
5093 getLibvirtDictObject(void)
5095 if (libvirt_dict)
5096 return libvirt_dict;
5098 // PyModule_GetDict returns a borrowed reference
5099 libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
5100 if (!libvirt_dict) {
5101 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
5102 PyErr_Print();
5103 return NULL;
5106 Py_INCREF(libvirt_dict);
5107 return libvirt_dict;
5111 static PyObject *
5112 libvirt_lookupPythonFunc(const char *funcname)
5114 PyObject *python_cb;
5116 /* Lookup the python callback */
5117 python_cb = PyDict_GetItemString(getLibvirtDictObject(), funcname);
5119 if (!python_cb) {
5120 DEBUG("%s: Error finding %s\n", __FUNCTION__, funcname);
5121 PyErr_Print();
5122 PyErr_Clear();
5123 return NULL;
5126 if (!PyCallable_Check(python_cb)) {
5127 DEBUG("%s: %s is not callable\n", __FUNCTION__, funcname);
5128 return NULL;
5131 return python_cb;
5134 /*******************************************
5135 * Domain Events
5136 *******************************************/
5138 static int
5139 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5140 virDomainPtr dom,
5141 int event,
5142 int detail,
5143 void *opaque)
5145 PyObject *pyobj_ret = NULL;
5147 PyObject *pyobj_conn = (PyObject*)opaque;
5148 PyObject *pyobj_dom;
5150 int ret = -1;
5152 LIBVIRT_ENSURE_THREAD_STATE;
5154 /* Create a python instance of this virDomainPtr */
5155 virDomainRef(dom);
5156 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5157 virDomainFree(dom);
5158 goto cleanup;
5161 /* Call the Callback Dispatcher */
5162 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5163 (char*)"_dispatchDomainEventCallbacks",
5164 (char*)"Oii",
5165 pyobj_dom,
5166 event, detail);
5168 Py_DECREF(pyobj_dom);
5170 cleanup:
5171 if (!pyobj_ret) {
5172 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5173 PyErr_Print();
5174 } else {
5175 Py_DECREF(pyobj_ret);
5176 ret = 0;
5179 LIBVIRT_RELEASE_THREAD_STATE;
5180 return ret;
5183 static PyObject *
5184 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject *self,
5185 PyObject *args)
5187 PyObject *pyobj_conn; /* virConnectPtr */
5188 PyObject *pyobj_conn_inst; /* virConnect Python object */
5190 virConnectPtr conn;
5191 int ret = 0;
5193 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectDomainEventRegister",
5194 &pyobj_conn, &pyobj_conn_inst))
5195 return NULL;
5197 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
5198 pyobj_conn, pyobj_conn_inst);
5199 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5201 Py_INCREF(pyobj_conn_inst);
5203 LIBVIRT_BEGIN_ALLOW_THREADS;
5205 ret = virConnectDomainEventRegister(conn,
5206 libvirt_virConnectDomainEventCallback,
5207 pyobj_conn_inst, NULL);
5209 LIBVIRT_END_ALLOW_THREADS;
5211 return libvirt_intWrap(ret);
5214 static PyObject *
5215 libvirt_virConnectDomainEventDeregister(PyObject *self ATTRIBUTE_UNUSED,
5216 PyObject *args)
5218 PyObject *pyobj_conn;
5219 PyObject *pyobj_conn_inst;
5221 virConnectPtr conn;
5222 int ret = 0;
5224 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectDomainEventDeregister",
5225 &pyobj_conn, &pyobj_conn_inst))
5226 return NULL;
5228 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
5230 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5232 LIBVIRT_BEGIN_ALLOW_THREADS;
5234 ret = virConnectDomainEventDeregister(conn, libvirt_virConnectDomainEventCallback);
5236 LIBVIRT_END_ALLOW_THREADS;
5238 Py_DECREF(pyobj_conn_inst);
5239 return libvirt_intWrap(ret);
5242 /*******************************************
5243 * Event Impl
5244 *******************************************/
5245 static PyObject *addHandleObj;
5246 static char *addHandleName;
5247 static PyObject *updateHandleObj;
5248 static char *updateHandleName;
5249 static PyObject *removeHandleObj;
5250 static char *removeHandleName;
5251 static PyObject *addTimeoutObj;
5252 static char *addTimeoutName;
5253 static PyObject *updateTimeoutObj;
5254 static char *updateTimeoutName;
5255 static PyObject *removeTimeoutObj;
5256 static char *removeTimeoutName;
5258 #define NAME(fn) ( fn ## Name ? fn ## Name : # fn )
5260 static int
5261 libvirt_virEventAddHandleFunc(int fd,
5262 int event,
5263 virEventHandleCallback cb,
5264 void *opaque,
5265 virFreeCallback ff)
5267 PyObject *result;
5268 PyObject *python_cb = NULL;
5269 PyObject *cb_args = NULL;
5270 PyObject *pyobj_args = NULL;
5271 int retval = -1;
5273 LIBVIRT_ENSURE_THREAD_STATE;
5275 if ((pyobj_args = PyTuple_New(4)) == NULL)
5276 goto cleanup;
5278 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(fd), cleanup);
5279 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
5281 /* Lookup the python callback */
5282 python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
5283 if (!python_cb) {
5284 goto cleanup;
5286 Py_INCREF(python_cb);
5288 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, python_cb, cleanup);
5290 if ((cb_args = PyTuple_New(3)) == NULL)
5291 goto cleanup;
5293 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 3, cb_args, cleanup);
5295 VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventHandleCallbackWrap(cb), cleanup);
5296 VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
5297 VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
5299 result = PyEval_CallObject(addHandleObj, pyobj_args);
5300 if (!result) {
5301 PyErr_Print();
5302 PyErr_Clear();
5303 } else {
5304 libvirt_intUnwrap(result, &retval);
5307 Py_XDECREF(result);
5309 cleanup:
5310 Py_XDECREF(pyobj_args);
5312 LIBVIRT_RELEASE_THREAD_STATE;
5314 return retval;
5317 static void
5318 libvirt_virEventUpdateHandleFunc(int watch,
5319 int event)
5321 PyObject *result = NULL;
5322 PyObject *pyobj_args;
5324 LIBVIRT_ENSURE_THREAD_STATE;
5326 if ((pyobj_args = PyTuple_New(2)) == NULL)
5327 goto cleanup;
5329 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
5330 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
5332 result = PyEval_CallObject(updateHandleObj, pyobj_args);
5333 if (!result) {
5334 PyErr_Print();
5335 PyErr_Clear();
5338 cleanup:
5339 Py_XDECREF(result);
5340 Py_XDECREF(pyobj_args);
5342 LIBVIRT_RELEASE_THREAD_STATE;
5346 static int
5347 libvirt_virEventRemoveHandleFunc(int watch)
5349 PyObject *result = NULL;
5350 PyObject *pyobj_args;
5351 PyObject *opaque;
5352 PyObject *ff;
5353 int retval = -1;
5354 virFreeCallback cff;
5356 LIBVIRT_ENSURE_THREAD_STATE;
5358 if ((pyobj_args = PyTuple_New(1)) == NULL)
5359 goto cleanup;
5361 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
5363 result = PyEval_CallObject(removeHandleObj, pyobj_args);
5364 if (!result) {
5365 PyErr_Print();
5366 PyErr_Clear();
5367 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
5368 DEBUG("%s: %s must return opaque obj registered with %s"
5369 "to avoid leaking libvirt memory\n",
5370 __FUNCTION__, NAME(removeHandle), NAME(addHandle));
5371 } else {
5372 opaque = PyTuple_GetItem(result, 1);
5373 ff = PyTuple_GetItem(result, 2);
5374 cff = PyvirFreeCallback_Get(ff);
5375 if (cff)
5376 (*cff)(PyvirVoidPtr_Get(opaque));
5377 retval = 0;
5380 cleanup:
5381 Py_XDECREF(result);
5382 Py_XDECREF(pyobj_args);
5384 LIBVIRT_RELEASE_THREAD_STATE;
5386 return retval;
5390 static int
5391 libvirt_virEventAddTimeoutFunc(int timeout,
5392 virEventTimeoutCallback cb,
5393 void *opaque,
5394 virFreeCallback ff)
5396 PyObject *result = NULL;
5397 PyObject *python_cb = NULL;
5398 PyObject *cb_args = NULL;
5399 PyObject *pyobj_args = NULL;
5400 int retval = -1;
5402 LIBVIRT_ENSURE_THREAD_STATE;
5404 if ((pyobj_args = PyTuple_New(3)) == NULL)
5405 goto cleanup;
5407 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timeout), cleanup);
5409 /* Lookup the python callback */
5410 python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
5411 if (!python_cb) {
5412 goto cleanup;
5414 Py_INCREF(python_cb);
5415 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, python_cb, cleanup);
5417 if ((cb_args = PyTuple_New(3)) == NULL)
5418 goto cleanup;
5420 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, cb_args, cleanup);
5422 VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventTimeoutCallbackWrap(cb), cleanup);
5423 VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
5424 VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
5426 result = PyEval_CallObject(addTimeoutObj, pyobj_args);
5427 if (!result) {
5428 PyErr_Print();
5429 PyErr_Clear();
5430 } else {
5431 libvirt_intUnwrap(result, &retval);
5434 cleanup:
5435 Py_XDECREF(result);
5436 Py_XDECREF(pyobj_args);
5438 LIBVIRT_RELEASE_THREAD_STATE;
5439 return retval;
5442 static void
5443 libvirt_virEventUpdateTimeoutFunc(int timer,
5444 int timeout)
5446 PyObject *result = NULL;
5447 PyObject *pyobj_args;
5449 LIBVIRT_ENSURE_THREAD_STATE;
5451 if ((pyobj_args = PyTuple_New(2)) == NULL)
5452 goto cleanup;
5454 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
5455 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(timeout), cleanup);
5457 result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
5458 if (!result) {
5459 PyErr_Print();
5460 PyErr_Clear();
5463 cleanup:
5464 Py_XDECREF(result);
5465 Py_XDECREF(pyobj_args);
5467 LIBVIRT_RELEASE_THREAD_STATE;
5470 static int
5471 libvirt_virEventRemoveTimeoutFunc(int timer)
5473 PyObject *result = NULL;
5474 PyObject *pyobj_args;
5475 PyObject *opaque;
5476 PyObject *ff;
5477 int retval = -1;
5478 virFreeCallback cff;
5480 LIBVIRT_ENSURE_THREAD_STATE;
5482 if ((pyobj_args = PyTuple_New(1)) == NULL)
5483 goto cleanup;
5485 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
5487 result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
5488 if (!result) {
5489 PyErr_Print();
5490 PyErr_Clear();
5491 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
5492 DEBUG("%s: %s must return opaque obj registered with %s"
5493 "to avoid leaking libvirt memory\n",
5494 __FUNCTION__, NAME(removeTimeout), NAME(addTimeout));
5495 } else {
5496 opaque = PyTuple_GetItem(result, 1);
5497 ff = PyTuple_GetItem(result, 2);
5498 cff = PyvirFreeCallback_Get(ff);
5499 if (cff)
5500 (*cff)(PyvirVoidPtr_Get(opaque));
5501 retval = 0;
5504 cleanup:
5505 Py_XDECREF(result);
5506 Py_XDECREF(pyobj_args);
5508 LIBVIRT_RELEASE_THREAD_STATE;
5510 return retval;
5513 static PyObject *
5514 libvirt_virEventRegisterImpl(PyObject *self ATTRIBUTE_UNUSED,
5515 PyObject *args)
5517 /* Unref the previously-registered impl (if any) */
5518 Py_XDECREF(addHandleObj);
5519 Py_XDECREF(updateHandleObj);
5520 Py_XDECREF(removeHandleObj);
5521 Py_XDECREF(addTimeoutObj);
5522 Py_XDECREF(updateTimeoutObj);
5523 Py_XDECREF(removeTimeoutObj);
5524 VIR_FREE(addHandleName);
5525 VIR_FREE(updateHandleName);
5526 VIR_FREE(removeHandleName);
5527 VIR_FREE(addTimeoutName);
5528 VIR_FREE(updateTimeoutName);
5529 VIR_FREE(removeTimeoutName);
5531 /* Parse and check arguments */
5532 if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
5533 &addHandleObj, &updateHandleObj,
5534 &removeHandleObj, &addTimeoutObj,
5535 &updateTimeoutObj, &removeTimeoutObj) ||
5536 !PyCallable_Check(addHandleObj) ||
5537 !PyCallable_Check(updateHandleObj) ||
5538 !PyCallable_Check(removeHandleObj) ||
5539 !PyCallable_Check(addTimeoutObj) ||
5540 !PyCallable_Check(updateTimeoutObj) ||
5541 !PyCallable_Check(removeTimeoutObj))
5542 return NULL;
5544 /* Get argument string representations (for error reporting) */
5545 addHandleName = py_str(addHandleObj);
5546 updateHandleName = py_str(updateHandleObj);
5547 removeHandleName = py_str(removeHandleObj);
5548 addTimeoutName = py_str(addTimeoutObj);
5549 updateTimeoutName = py_str(updateTimeoutObj);
5550 removeTimeoutName = py_str(removeTimeoutObj);
5552 /* Inc refs since we're holding on to these objects until
5553 * the next call (if any) to this function.
5555 Py_INCREF(addHandleObj);
5556 Py_INCREF(updateHandleObj);
5557 Py_INCREF(removeHandleObj);
5558 Py_INCREF(addTimeoutObj);
5559 Py_INCREF(updateTimeoutObj);
5560 Py_INCREF(removeTimeoutObj);
5562 LIBVIRT_BEGIN_ALLOW_THREADS;
5564 /* Now register our C EventImpl, which will dispatch
5565 * to the Python callbacks passed in as args.
5567 virEventRegisterImpl(libvirt_virEventAddHandleFunc,
5568 libvirt_virEventUpdateHandleFunc,
5569 libvirt_virEventRemoveHandleFunc,
5570 libvirt_virEventAddTimeoutFunc,
5571 libvirt_virEventUpdateTimeoutFunc,
5572 libvirt_virEventRemoveTimeoutFunc);
5574 LIBVIRT_END_ALLOW_THREADS;
5576 return VIR_PY_INT_SUCCESS;
5579 static PyObject *
5580 libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
5581 PyObject *args)
5583 int watch, fd, event;
5584 PyObject *py_f;
5585 PyObject *py_opaque;
5586 virEventHandleCallback cb;
5587 void *opaque;
5589 if (!PyArg_ParseTuple(args, (char *) "iiiOO:virEventInvokeHandleCallback",
5590 &watch, &fd, &event, &py_f, &py_opaque))
5591 return NULL;
5593 cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
5594 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5596 if (cb) {
5597 LIBVIRT_BEGIN_ALLOW_THREADS;
5598 cb(watch, fd, event, opaque);
5599 LIBVIRT_END_ALLOW_THREADS;
5602 return VIR_PY_INT_SUCCESS;
5605 static PyObject *
5606 libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
5607 PyObject *args)
5609 int timer;
5610 PyObject *py_f;
5611 PyObject *py_opaque;
5612 virEventTimeoutCallback cb;
5613 void *opaque;
5615 if (!PyArg_ParseTuple(args, (char *) "iOO:virEventInvokeTimeoutCallback",
5616 &timer, &py_f, &py_opaque))
5617 return NULL;
5619 cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
5620 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5621 if (cb) {
5622 LIBVIRT_BEGIN_ALLOW_THREADS;
5623 cb(timer, opaque);
5624 LIBVIRT_END_ALLOW_THREADS;
5627 return VIR_PY_INT_SUCCESS;
5630 static void
5631 libvirt_virEventHandleCallback(int watch,
5632 int fd,
5633 int events,
5634 void *opaque)
5636 PyObject *pyobj_cbData = (PyObject *)opaque;
5637 PyObject *pyobj_ret;
5638 PyObject *python_cb;
5640 LIBVIRT_ENSURE_THREAD_STATE;
5642 /* Lookup the python callback */
5643 python_cb = libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
5644 if (!python_cb) {
5645 goto cleanup;
5648 Py_INCREF(pyobj_cbData);
5650 /* Call the pure python dispatcher */
5651 pyobj_ret = PyObject_CallFunction(python_cb,
5652 (char *)"iiiO",
5653 watch, fd, events, pyobj_cbData);
5655 Py_DECREF(pyobj_cbData);
5657 if (!pyobj_ret) {
5658 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5659 PyErr_Print();
5660 } else {
5661 Py_DECREF(pyobj_ret);
5664 cleanup:
5665 LIBVIRT_RELEASE_THREAD_STATE;
5668 static PyObject *
5669 libvirt_virEventAddHandle(PyObject *self ATTRIBUTE_UNUSED,
5670 PyObject *args)
5672 PyObject *pyobj_cbData;
5673 virEventHandleCallback cb = libvirt_virEventHandleCallback;
5674 int events;
5675 int fd;
5676 int ret;
5678 if (!PyArg_ParseTuple(args, (char *) "iiO:virEventAddHandle",
5679 &fd, &events, &pyobj_cbData))
5680 return NULL;
5682 Py_INCREF(pyobj_cbData);
5684 LIBVIRT_BEGIN_ALLOW_THREADS;
5685 ret = virEventAddHandle(fd, events, cb, pyobj_cbData, NULL);
5686 LIBVIRT_END_ALLOW_THREADS;
5688 if (ret < 0) {
5689 Py_DECREF(pyobj_cbData);
5692 return libvirt_intWrap(ret);
5695 static void
5696 libvirt_virEventTimeoutCallback(int timer,
5697 void *opaque)
5699 PyObject *pyobj_cbData = (PyObject *)opaque;
5700 PyObject *pyobj_ret;
5701 PyObject *python_cb;
5703 LIBVIRT_ENSURE_THREAD_STATE;
5705 /* Lookup the python callback */
5706 python_cb = libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
5707 if (!python_cb) {
5708 goto cleanup;
5711 Py_INCREF(pyobj_cbData);
5713 /* Call the pure python dispatcher */
5714 pyobj_ret = PyObject_CallFunction(python_cb,
5715 (char *)"iO",
5716 timer, pyobj_cbData);
5718 Py_DECREF(pyobj_cbData);
5720 if (!pyobj_ret) {
5721 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5722 PyErr_Print();
5723 } else {
5724 Py_DECREF(pyobj_ret);
5727 cleanup:
5728 LIBVIRT_RELEASE_THREAD_STATE;
5731 static PyObject *
5732 libvirt_virEventAddTimeout(PyObject *self ATTRIBUTE_UNUSED,
5733 PyObject *args)
5735 PyObject *pyobj_cbData;
5736 virEventTimeoutCallback cb = libvirt_virEventTimeoutCallback;
5737 int timeout;
5738 int ret;
5740 if (!PyArg_ParseTuple(args, (char *) "iO:virEventAddTimeout",
5741 &timeout, &pyobj_cbData))
5742 return NULL;
5744 Py_INCREF(pyobj_cbData);
5746 LIBVIRT_BEGIN_ALLOW_THREADS;
5747 ret = virEventAddTimeout(timeout, cb, pyobj_cbData, NULL);
5748 LIBVIRT_END_ALLOW_THREADS;
5750 if (ret < 0) {
5751 Py_DECREF(pyobj_cbData);
5754 return libvirt_intWrap(ret);
5757 static void
5758 libvirt_virConnectDomainEventFreeFunc(void *opaque)
5760 PyObject *pyobj_conn = (PyObject*)opaque;
5761 LIBVIRT_ENSURE_THREAD_STATE;
5762 Py_DECREF(pyobj_conn);
5763 LIBVIRT_RELEASE_THREAD_STATE;
5766 static int
5767 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5768 virDomainPtr dom,
5769 int event,
5770 int detail,
5771 void *opaque)
5773 PyObject *pyobj_cbData = (PyObject*)opaque;
5774 PyObject *pyobj_dom;
5775 PyObject *pyobj_ret = NULL;
5776 PyObject *pyobj_conn;
5777 PyObject *dictKey;
5778 int ret = -1;
5780 LIBVIRT_ENSURE_THREAD_STATE;
5782 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5783 goto cleanup;
5784 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5785 Py_DECREF(dictKey);
5787 /* Create a python instance of this virDomainPtr */
5788 virDomainRef(dom);
5789 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5790 virDomainFree(dom);
5791 goto cleanup;
5793 Py_INCREF(pyobj_cbData);
5795 /* Call the Callback Dispatcher */
5796 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5797 (char*)"_dispatchDomainEventLifecycleCallback",
5798 (char*)"OiiO",
5799 pyobj_dom,
5800 event, detail,
5801 pyobj_cbData);
5803 Py_DECREF(pyobj_cbData);
5804 Py_DECREF(pyobj_dom);
5806 cleanup:
5807 if (!pyobj_ret) {
5808 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5809 PyErr_Print();
5810 } else {
5811 Py_DECREF(pyobj_ret);
5812 ret = 0;
5815 LIBVIRT_RELEASE_THREAD_STATE;
5816 return ret;
5819 static int
5820 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5821 virDomainPtr dom,
5822 void *opaque)
5824 PyObject *pyobj_cbData = (PyObject*)opaque;
5825 PyObject *pyobj_dom;
5826 PyObject *pyobj_ret = NULL;
5827 PyObject *pyobj_conn;
5828 PyObject *dictKey;
5829 int ret = -1;
5831 LIBVIRT_ENSURE_THREAD_STATE;
5833 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5834 goto cleanup;
5835 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5836 Py_DECREF(dictKey);
5838 /* Create a python instance of this virDomainPtr */
5839 virDomainRef(dom);
5840 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5841 virDomainFree(dom);
5842 goto cleanup;
5844 Py_INCREF(pyobj_cbData);
5846 /* Call the Callback Dispatcher */
5847 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5848 (char*)"_dispatchDomainEventGenericCallback",
5849 (char*)"OO",
5850 pyobj_dom, pyobj_cbData);
5852 Py_DECREF(pyobj_cbData);
5853 Py_DECREF(pyobj_dom);
5855 cleanup:
5856 if (!pyobj_ret) {
5857 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5858 PyErr_Print();
5859 } else {
5860 Py_DECREF(pyobj_ret);
5861 ret = 0;
5864 LIBVIRT_RELEASE_THREAD_STATE;
5865 return ret;
5868 static int
5869 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5870 virDomainPtr dom,
5871 long long utcoffset,
5872 void *opaque)
5874 PyObject *pyobj_cbData = (PyObject*)opaque;
5875 PyObject *pyobj_dom;
5876 PyObject *pyobj_ret = NULL;
5877 PyObject *pyobj_conn;
5878 PyObject *dictKey;
5879 int ret = -1;
5881 LIBVIRT_ENSURE_THREAD_STATE;
5883 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5884 goto cleanup;
5885 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5886 Py_DECREF(dictKey);
5888 /* Create a python instance of this virDomainPtr */
5889 virDomainRef(dom);
5890 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5891 virDomainFree(dom);
5892 goto cleanup;
5894 Py_INCREF(pyobj_cbData);
5896 /* Call the Callback Dispatcher */
5897 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5898 (char*)"_dispatchDomainEventRTCChangeCallback",
5899 (char*)"OLO",
5900 pyobj_dom,
5901 (PY_LONG_LONG)utcoffset,
5902 pyobj_cbData);
5904 Py_DECREF(pyobj_cbData);
5905 Py_DECREF(pyobj_dom);
5907 cleanup:
5908 if (!pyobj_ret) {
5909 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5910 PyErr_Print();
5911 } else {
5912 Py_DECREF(pyobj_ret);
5913 ret = 0;
5916 LIBVIRT_RELEASE_THREAD_STATE;
5917 return ret;
5920 static int
5921 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5922 virDomainPtr dom,
5923 int action,
5924 void *opaque)
5926 PyObject *pyobj_cbData = (PyObject*)opaque;
5927 PyObject *pyobj_dom;
5928 PyObject *pyobj_ret = NULL;
5929 PyObject *pyobj_conn;
5930 PyObject *dictKey;
5931 int ret = -1;
5933 LIBVIRT_ENSURE_THREAD_STATE;
5935 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5936 goto cleanup;
5937 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5938 Py_DECREF(dictKey);
5940 /* Create a python instance of this virDomainPtr */
5941 virDomainRef(dom);
5942 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5943 virDomainFree(dom);
5944 goto cleanup;
5946 Py_INCREF(pyobj_cbData);
5948 /* Call the Callback Dispatcher */
5949 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5950 (char*)"_dispatchDomainEventWatchdogCallback",
5951 (char*)"OiO",
5952 pyobj_dom,
5953 action,
5954 pyobj_cbData);
5956 Py_DECREF(pyobj_cbData);
5957 Py_DECREF(pyobj_dom);
5959 cleanup:
5960 if (!pyobj_ret) {
5961 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5962 PyErr_Print();
5963 } else {
5964 Py_DECREF(pyobj_ret);
5965 ret = 0;
5968 LIBVIRT_RELEASE_THREAD_STATE;
5969 return ret;
5972 static int
5973 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5974 virDomainPtr dom,
5975 const char *srcPath,
5976 const char *devAlias,
5977 int action,
5978 void *opaque)
5980 PyObject *pyobj_cbData = (PyObject*)opaque;
5981 PyObject *pyobj_dom;
5982 PyObject *pyobj_ret = NULL;
5983 PyObject *pyobj_conn;
5984 PyObject *dictKey;
5985 int ret = -1;
5987 LIBVIRT_ENSURE_THREAD_STATE;
5989 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5990 goto cleanup;
5991 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5992 Py_DECREF(dictKey);
5994 /* Create a python instance of this virDomainPtr */
5995 virDomainRef(dom);
5996 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5997 virDomainFree(dom);
5998 goto cleanup;
6000 Py_INCREF(pyobj_cbData);
6002 /* Call the Callback Dispatcher */
6003 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6004 (char*)"_dispatchDomainEventIOErrorCallback",
6005 (char*)"OssiO",
6006 pyobj_dom,
6007 srcPath, devAlias, action,
6008 pyobj_cbData);
6010 Py_DECREF(pyobj_cbData);
6011 Py_DECREF(pyobj_dom);
6013 cleanup:
6014 if (!pyobj_ret) {
6015 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6016 PyErr_Print();
6017 } else {
6018 Py_DECREF(pyobj_ret);
6019 ret = 0;
6022 LIBVIRT_RELEASE_THREAD_STATE;
6023 return ret;
6026 static int
6027 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6028 virDomainPtr dom,
6029 const char *srcPath,
6030 const char *devAlias,
6031 int action,
6032 const char *reason,
6033 void *opaque)
6035 PyObject *pyobj_cbData = (PyObject*)opaque;
6036 PyObject *pyobj_dom;
6037 PyObject *pyobj_ret = NULL;
6038 PyObject *pyobj_conn;
6039 PyObject *dictKey;
6040 int ret = -1;
6042 LIBVIRT_ENSURE_THREAD_STATE;
6044 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6045 goto cleanup;
6046 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6047 Py_DECREF(dictKey);
6049 /* Create a python instance of this virDomainPtr */
6050 virDomainRef(dom);
6051 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6052 virDomainFree(dom);
6053 goto cleanup;
6055 Py_INCREF(pyobj_cbData);
6057 /* Call the Callback Dispatcher */
6058 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6059 (char*)"_dispatchDomainEventIOErrorReasonCallback",
6060 (char*)"OssisO",
6061 pyobj_dom,
6062 srcPath, devAlias, action, reason,
6063 pyobj_cbData);
6065 Py_DECREF(pyobj_cbData);
6066 Py_DECREF(pyobj_dom);
6068 cleanup:
6069 if (!pyobj_ret) {
6070 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6071 PyErr_Print();
6072 } else {
6073 Py_DECREF(pyobj_ret);
6074 ret = 0;
6077 LIBVIRT_RELEASE_THREAD_STATE;
6078 return ret;
6081 static int
6082 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6083 virDomainPtr dom,
6084 int phase,
6085 virDomainEventGraphicsAddressPtr local,
6086 virDomainEventGraphicsAddressPtr remote,
6087 const char *authScheme,
6088 virDomainEventGraphicsSubjectPtr subject,
6089 void *opaque)
6091 PyObject *pyobj_cbData = (PyObject*)opaque;
6092 PyObject *pyobj_dom = NULL;
6093 PyObject *pyobj_ret = NULL;
6094 PyObject *pyobj_conn;
6095 PyObject *dictKey;
6096 PyObject *pyobj_local = NULL;
6097 PyObject *pyobj_remote = NULL;
6098 PyObject *pyobj_subject = NULL;
6099 int ret = -1;
6100 size_t i;
6102 LIBVIRT_ENSURE_THREAD_STATE;
6104 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6105 goto cleanup;
6106 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6107 Py_DECREF(dictKey);
6109 /* Create a python instance of this virDomainPtr */
6110 virDomainRef(dom);
6111 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6112 virDomainFree(dom);
6113 goto cleanup;
6115 Py_INCREF(pyobj_cbData);
6117 if ((pyobj_local = PyDict_New()) == NULL)
6118 goto cleanup;
6120 VIR_PY_DICT_SET_GOTO(pyobj_local,
6121 libvirt_constcharPtrWrap("family"),
6122 libvirt_intWrap(local->family),
6123 cleanup);
6124 VIR_PY_DICT_SET_GOTO(pyobj_local,
6125 libvirt_constcharPtrWrap("node"),
6126 libvirt_constcharPtrWrap(local->node),
6127 cleanup);
6128 VIR_PY_DICT_SET_GOTO(pyobj_local,
6129 libvirt_constcharPtrWrap("service"),
6130 libvirt_constcharPtrWrap(local->service),
6131 cleanup);
6133 if ((pyobj_remote = PyDict_New()) == NULL)
6134 goto cleanup;
6136 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6137 libvirt_constcharPtrWrap("family"),
6138 libvirt_intWrap(remote->family),
6139 cleanup);
6140 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6141 libvirt_constcharPtrWrap("node"),
6142 libvirt_constcharPtrWrap(remote->node),
6143 cleanup);
6144 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6145 libvirt_constcharPtrWrap("service"),
6146 libvirt_constcharPtrWrap(remote->service),
6147 cleanup);
6149 if ((pyobj_subject = PyList_New(subject->nidentity)) == NULL)
6150 goto cleanup;
6152 for (i = 0; i < subject->nidentity; i++) {
6153 PyObject *pair = PyTuple_New(2);
6154 if (pair == NULL)
6155 goto cleanup;
6157 VIR_PY_LIST_SET_GOTO(pyobj_subject, i, pair, cleanup);
6159 VIR_PY_TUPLE_SET_GOTO(pair, 0,
6160 libvirt_constcharPtrWrap(subject->identities[i].type),
6161 cleanup);
6162 VIR_PY_TUPLE_SET_GOTO(pair, 1,
6163 libvirt_constcharPtrWrap(subject->identities[i].name),
6164 cleanup);
6167 /* Call the Callback Dispatcher */
6168 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6169 (char*)"_dispatchDomainEventGraphicsCallback",
6170 (char*)"OiOOsOO",
6171 pyobj_dom,
6172 phase, pyobj_local, pyobj_remote,
6173 authScheme, pyobj_subject,
6174 pyobj_cbData);
6176 cleanup:
6177 Py_DECREF(pyobj_cbData);
6178 Py_XDECREF(pyobj_dom);
6180 if (!pyobj_ret) {
6181 Py_XDECREF(pyobj_local);
6182 Py_XDECREF(pyobj_remote);
6183 Py_XDECREF(pyobj_subject);
6184 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6185 PyErr_Print();
6186 } else {
6187 Py_DECREF(pyobj_ret);
6188 ret = 0;
6191 LIBVIRT_RELEASE_THREAD_STATE;
6192 return ret;
6195 static int
6196 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6197 virDomainPtr dom,
6198 const char *disk,
6199 int type,
6200 int status,
6201 void *opaque)
6203 PyObject *pyobj_cbData = (PyObject*)opaque;
6204 PyObject *pyobj_dom;
6205 PyObject *pyobj_ret = NULL;
6206 PyObject *pyobj_conn;
6207 PyObject *dictKey;
6208 int ret = -1;
6210 LIBVIRT_ENSURE_THREAD_STATE;
6212 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6213 goto cleanup;
6214 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6215 Py_DECREF(dictKey);
6217 /* Create a python instance of this virDomainPtr */
6218 virDomainRef(dom);
6219 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6220 virDomainFree(dom);
6221 goto cleanup;
6223 Py_INCREF(pyobj_cbData);
6225 /* Call the Callback Dispatcher */
6226 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6227 (char*)"_dispatchDomainEventBlockJobCallback",
6228 (char*)"OsiiO",
6229 pyobj_dom, disk, type, status, pyobj_cbData);
6231 Py_DECREF(pyobj_cbData);
6232 Py_DECREF(pyobj_dom);
6234 cleanup:
6235 if (!pyobj_ret) {
6236 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6237 PyErr_Print();
6238 } else {
6239 Py_DECREF(pyobj_ret);
6240 ret = 0;
6243 LIBVIRT_RELEASE_THREAD_STATE;
6244 return ret;
6247 static int
6248 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6249 virDomainPtr dom,
6250 const char *oldSrcPath,
6251 const char *newSrcPath,
6252 const char *devAlias,
6253 int reason,
6254 void *opaque)
6256 PyObject *pyobj_cbData = (PyObject*)opaque;
6257 PyObject *pyobj_dom;
6258 PyObject *pyobj_ret = NULL;
6259 PyObject *pyobj_conn;
6260 PyObject *dictKey;
6261 int ret = -1;
6263 LIBVIRT_ENSURE_THREAD_STATE;
6265 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6266 goto cleanup;
6267 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6268 Py_DECREF(dictKey);
6270 /* Create a python instance of this virDomainPtr */
6271 virDomainRef(dom);
6272 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6273 virDomainFree(dom);
6274 goto cleanup;
6276 Py_INCREF(pyobj_cbData);
6278 /* Call the Callback Dispatcher */
6279 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6280 (char*)"_dispatchDomainEventDiskChangeCallback",
6281 (char*)"OsssiO",
6282 pyobj_dom,
6283 oldSrcPath, newSrcPath,
6284 devAlias, reason, pyobj_cbData);
6286 Py_DECREF(pyobj_cbData);
6287 Py_DECREF(pyobj_dom);
6289 cleanup:
6290 if (!pyobj_ret) {
6291 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6292 PyErr_Print();
6293 } else {
6294 Py_DECREF(pyobj_ret);
6295 ret = 0;
6298 LIBVIRT_RELEASE_THREAD_STATE;
6299 return ret;
6302 static int
6303 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6304 virDomainPtr dom,
6305 const char *devAlias,
6306 int reason,
6307 void *opaque)
6309 PyObject *pyobj_cbData = (PyObject*)opaque;
6310 PyObject *pyobj_dom;
6311 PyObject *pyobj_ret = NULL;
6312 PyObject *pyobj_conn;
6313 PyObject *dictKey;
6314 int ret = -1;
6316 LIBVIRT_ENSURE_THREAD_STATE;
6318 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6319 goto cleanup;
6320 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6321 Py_DECREF(dictKey);
6323 /* Create a python instance of this virDomainPtr */
6324 virDomainRef(dom);
6325 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6326 virDomainFree(dom);
6327 goto cleanup;
6329 Py_INCREF(pyobj_cbData);
6331 /* Call the Callback Dispatcher */
6332 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6333 (char*)"_dispatchDomainEventTrayChangeCallback",
6334 (char*)"OsiO",
6335 pyobj_dom,
6336 devAlias, reason, pyobj_cbData);
6338 Py_DECREF(pyobj_cbData);
6339 Py_DECREF(pyobj_dom);
6341 cleanup:
6342 if (!pyobj_ret) {
6343 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6344 PyErr_Print();
6345 } else {
6346 Py_DECREF(pyobj_ret);
6347 ret = 0;
6350 LIBVIRT_RELEASE_THREAD_STATE;
6351 return ret;
6354 static int
6355 libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6356 virDomainPtr dom,
6357 int reason,
6358 void *opaque)
6360 PyObject *pyobj_cbData = (PyObject*)opaque;
6361 PyObject *pyobj_dom;
6362 PyObject *pyobj_ret = NULL;
6363 PyObject *pyobj_conn;
6364 PyObject *dictKey;
6365 int ret = -1;
6367 LIBVIRT_ENSURE_THREAD_STATE;
6369 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6370 goto cleanup;
6371 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6372 Py_DECREF(dictKey);
6374 /* Create a python instance of this virDomainPtr */
6375 virDomainRef(dom);
6376 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6377 virDomainFree(dom);
6378 goto cleanup;
6380 Py_INCREF(pyobj_cbData);
6382 /* Call the Callback Dispatcher */
6383 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6384 (char*)"_dispatchDomainEventPMWakeupCallback",
6385 (char*)"OiO",
6386 pyobj_dom,
6387 reason,
6388 pyobj_cbData);
6390 Py_DECREF(pyobj_cbData);
6391 Py_DECREF(pyobj_dom);
6393 cleanup:
6394 if (!pyobj_ret) {
6395 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6396 PyErr_Print();
6397 } else {
6398 Py_DECREF(pyobj_ret);
6399 ret = 0;
6402 LIBVIRT_RELEASE_THREAD_STATE;
6403 return ret;
6406 static int
6407 libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6408 virDomainPtr dom,
6409 int reason,
6410 void *opaque)
6412 PyObject *pyobj_cbData = (PyObject*)opaque;
6413 PyObject *pyobj_dom;
6414 PyObject *pyobj_ret = NULL;
6415 PyObject *pyobj_conn;
6416 PyObject *dictKey;
6417 int ret = -1;
6419 LIBVIRT_ENSURE_THREAD_STATE;
6421 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6422 goto cleanup;
6423 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6424 Py_DECREF(dictKey);
6426 /* Create a python instance of this virDomainPtr */
6427 virDomainRef(dom);
6428 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6429 virDomainFree(dom);
6430 goto cleanup;
6432 Py_INCREF(pyobj_cbData);
6434 /* Call the Callback Dispatcher */
6435 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6436 (char*)"_dispatchDomainEventPMSuspendCallback",
6437 (char*)"OiO",
6438 pyobj_dom,
6439 reason,
6440 pyobj_cbData);
6442 Py_DECREF(pyobj_cbData);
6443 Py_DECREF(pyobj_dom);
6445 cleanup:
6446 if (!pyobj_ret) {
6447 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6448 PyErr_Print();
6449 } else {
6450 Py_DECREF(pyobj_ret);
6451 ret = 0;
6454 LIBVIRT_RELEASE_THREAD_STATE;
6455 return ret;
6459 #ifdef VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
6460 static int
6461 libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6462 virDomainPtr dom,
6463 unsigned long long actual,
6464 void *opaque)
6466 PyObject *pyobj_cbData = (PyObject*)opaque;
6467 PyObject *pyobj_dom;
6468 PyObject *pyobj_ret = NULL;
6469 PyObject *pyobj_conn;
6470 PyObject *dictKey;
6471 int ret = -1;
6473 LIBVIRT_ENSURE_THREAD_STATE;
6475 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6476 goto cleanup;
6477 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6478 Py_DECREF(dictKey);
6480 /* Create a python instance of this virDomainPtr */
6481 virDomainRef(dom);
6482 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6483 virDomainFree(dom);
6484 goto cleanup;
6486 Py_INCREF(pyobj_cbData);
6488 /* Call the Callback Dispatcher */
6489 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6490 (char*)"_dispatchDomainEventBalloonChangeCallback",
6491 (char*)"OLO",
6492 pyobj_dom,
6493 (PY_LONG_LONG)actual,
6494 pyobj_cbData);
6496 Py_DECREF(pyobj_cbData);
6497 Py_DECREF(pyobj_dom);
6499 cleanup:
6500 if (!pyobj_ret) {
6501 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6502 PyErr_Print();
6503 } else {
6504 Py_DECREF(pyobj_ret);
6505 ret = 0;
6508 LIBVIRT_RELEASE_THREAD_STATE;
6509 return ret;
6511 #endif /* VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE */
6513 #ifdef VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
6514 static int
6515 libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6516 virDomainPtr dom,
6517 int reason,
6518 void *opaque)
6520 PyObject *pyobj_cbData = (PyObject*)opaque;
6521 PyObject *pyobj_dom;
6522 PyObject *pyobj_ret = NULL;
6523 PyObject *pyobj_conn;
6524 PyObject *dictKey;
6525 int ret = -1;
6527 LIBVIRT_ENSURE_THREAD_STATE;
6529 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6530 goto cleanup;
6531 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6532 Py_DECREF(dictKey);
6534 /* Create a python instance of this virDomainPtr */
6535 virDomainRef(dom);
6536 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6537 virDomainFree(dom);
6538 goto cleanup;
6540 Py_INCREF(pyobj_cbData);
6542 /* Call the Callback Dispatcher */
6543 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6544 (char*)"_dispatchDomainEventPMSuspendDiskCallback",
6545 (char*)"OiO",
6546 pyobj_dom,
6547 reason,
6548 pyobj_cbData);
6550 Py_DECREF(pyobj_cbData);
6551 Py_DECREF(pyobj_dom);
6553 cleanup:
6554 if (!pyobj_ret) {
6555 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6556 PyErr_Print();
6557 } else {
6558 Py_DECREF(pyobj_ret);
6559 ret = 0;
6562 LIBVIRT_RELEASE_THREAD_STATE;
6563 return ret;
6565 #endif /* VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK */
6567 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
6568 static int
6569 libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6570 virDomainPtr dom,
6571 const char *devAlias,
6572 void *opaque)
6574 PyObject *pyobj_cbData = (PyObject*)opaque;
6575 PyObject *pyobj_dom;
6576 PyObject *pyobj_ret = NULL;
6577 PyObject *pyobj_conn;
6578 PyObject *dictKey;
6579 int ret = -1;
6581 LIBVIRT_ENSURE_THREAD_STATE;
6583 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6584 goto cleanup;
6585 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6586 Py_DECREF(dictKey);
6588 /* Create a python instance of this virDomainPtr */
6589 virDomainRef(dom);
6590 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6591 virDomainFree(dom);
6592 goto cleanup;
6594 Py_INCREF(pyobj_cbData);
6596 /* Call the Callback Dispatcher */
6597 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6598 (char*)"_dispatchDomainEventDeviceRemovedCallback",
6599 (char*)"OsO",
6600 pyobj_dom, devAlias, pyobj_cbData);
6602 Py_DECREF(pyobj_cbData);
6603 Py_DECREF(pyobj_dom);
6605 cleanup:
6606 if (!pyobj_ret) {
6607 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6608 PyErr_Print();
6609 } else {
6610 Py_DECREF(pyobj_ret);
6611 ret = 0;
6614 LIBVIRT_RELEASE_THREAD_STATE;
6615 return ret;
6617 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED */
6619 #ifdef VIR_DOMAIN_EVENT_ID_TUNABLE
6620 static int
6621 libvirt_virConnectDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6622 virDomainPtr dom,
6623 virTypedParameterPtr params,
6624 int nparams,
6625 void *opaque)
6627 PyObject *pyobj_cbData = (PyObject*)opaque;
6628 PyObject *pyobj_dom;
6629 PyObject *pyobj_ret = NULL;
6630 PyObject *pyobj_conn;
6631 PyObject *dictKey;
6632 PyObject *pyobj_dict = NULL;
6633 int ret = -1;
6635 LIBVIRT_ENSURE_THREAD_STATE;
6637 pyobj_dict = getPyVirTypedParameter(params, nparams);
6638 if (!pyobj_dict)
6639 goto cleanup;
6641 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6642 goto cleanup;
6643 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6644 Py_DECREF(dictKey);
6646 /* Create a python instance of this virDomainPtr */
6647 virDomainRef(dom);
6648 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6649 virDomainFree(dom);
6650 goto cleanup;
6652 Py_INCREF(pyobj_cbData);
6654 /* Call the Callback Dispatcher */
6655 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6656 (char*)"_dispatchDomainEventTunableCallback",
6657 (char*)"OOO",
6658 pyobj_dom, pyobj_dict, pyobj_cbData);
6660 Py_DECREF(pyobj_cbData);
6661 Py_DECREF(pyobj_dom);
6663 cleanup:
6664 if (!pyobj_ret) {
6665 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6666 PyErr_Print();
6667 Py_XDECREF(pyobj_dict);
6668 } else {
6669 Py_DECREF(pyobj_ret);
6670 ret = 0;
6673 LIBVIRT_RELEASE_THREAD_STATE;
6674 return ret;
6677 #endif /* VIR_DOMAIN_EVENT_ID_TUNABLE */
6679 #ifdef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
6680 static int
6681 libvirt_virConnectDomainEventAgentLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6682 virDomainPtr dom,
6683 int state,
6684 int reason,
6685 void *opaque)
6687 PyObject *pyobj_cbData = (PyObject*)opaque;
6688 PyObject *pyobj_dom;
6689 PyObject *pyobj_ret = NULL;
6690 PyObject *pyobj_conn;
6691 PyObject *dictKey;
6692 int ret = -1;
6694 LIBVIRT_ENSURE_THREAD_STATE;
6696 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6697 goto cleanup;
6698 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6699 Py_DECREF(dictKey);
6701 /* Create a python instance of this virDomainPtr */
6702 virDomainRef(dom);
6703 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6704 virDomainFree(dom);
6705 goto cleanup;
6707 Py_INCREF(pyobj_cbData);
6709 /* Call the Callback Dispatcher */
6710 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6711 (char*)"_dispatchDomainEventAgentLifecycleCallback",
6712 (char*)"OiiO",
6713 pyobj_dom, state, reason, pyobj_cbData);
6715 Py_DECREF(pyobj_cbData);
6716 Py_DECREF(pyobj_dom);
6718 cleanup:
6719 if (!pyobj_ret) {
6720 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6721 PyErr_Print();
6722 } else {
6723 Py_DECREF(pyobj_ret);
6724 ret = 0;
6727 LIBVIRT_RELEASE_THREAD_STATE;
6728 return ret;
6731 #endif /* VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE */
6733 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
6734 static int
6735 libvirt_virConnectDomainEventDeviceAddedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6736 virDomainPtr dom,
6737 const char *devAlias,
6738 void *opaque)
6740 PyObject *pyobj_cbData = (PyObject*)opaque;
6741 PyObject *pyobj_dom;
6742 PyObject *pyobj_ret = NULL;
6743 PyObject *pyobj_conn;
6744 PyObject *dictKey;
6745 int ret = -1;
6747 LIBVIRT_ENSURE_THREAD_STATE;
6749 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6750 goto cleanup;
6751 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6752 Py_DECREF(dictKey);
6754 /* Create a python instance of this virDomainPtr */
6755 virDomainRef(dom);
6756 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6757 virDomainFree(dom);
6758 goto cleanup;
6760 Py_INCREF(pyobj_cbData);
6762 /* Call the Callback Dispatcher */
6763 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6764 (char*)"_dispatchDomainEventDeviceAddedCallback",
6765 (char*)"OsO",
6766 pyobj_dom, devAlias, pyobj_cbData);
6768 Py_DECREF(pyobj_cbData);
6769 Py_DECREF(pyobj_dom);
6771 cleanup:
6772 if (!pyobj_ret) {
6773 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6774 PyErr_Print();
6775 } else {
6776 Py_DECREF(pyobj_ret);
6777 ret = 0;
6780 LIBVIRT_RELEASE_THREAD_STATE;
6781 return ret;
6784 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_ADDED */
6786 #ifdef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
6787 static int
6788 libvirt_virConnectDomainEventMigrationIterationCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6789 virDomainPtr dom,
6790 int iteration,
6791 void *opaque)
6793 PyObject *pyobj_cbData = (PyObject*)opaque;
6794 PyObject *pyobj_dom;
6795 PyObject *pyobj_ret = NULL;
6796 PyObject *pyobj_conn;
6797 PyObject *dictKey;
6798 int ret = -1;
6800 LIBVIRT_ENSURE_THREAD_STATE;
6802 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6803 goto cleanup;
6804 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6805 Py_DECREF(dictKey);
6807 /* Create a python instance of this virDomainPtr */
6808 virDomainRef(dom);
6809 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6810 virDomainFree(dom);
6811 goto cleanup;
6813 Py_INCREF(pyobj_cbData);
6815 /* Call the Callback Dispatcher */
6816 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6817 (char*)"_dispatchDomainEventMigrationIterationCallback",
6818 (char*)"OiO",
6819 pyobj_dom, iteration, pyobj_cbData);
6821 Py_DECREF(pyobj_cbData);
6822 Py_DECREF(pyobj_dom);
6824 cleanup:
6825 if (!pyobj_ret) {
6826 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6827 PyErr_Print();
6828 } else {
6829 Py_DECREF(pyobj_ret);
6830 ret = 0;
6833 LIBVIRT_RELEASE_THREAD_STATE;
6834 return ret;
6836 #endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
6838 #ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
6839 static int
6840 libvirt_virConnectDomainEventJobCompletedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6841 virDomainPtr dom,
6842 virTypedParameterPtr params,
6843 int nparams,
6844 void *opaque)
6846 PyObject *pyobj_cbData = (PyObject*)opaque;
6847 PyObject *pyobj_dom;
6848 PyObject *pyobj_ret = NULL;
6849 PyObject *pyobj_conn;
6850 PyObject *dictKey;
6851 PyObject *pyobj_dict = NULL;
6852 int ret = -1;
6854 LIBVIRT_ENSURE_THREAD_STATE;
6856 pyobj_dict = getPyVirTypedParameter(params, nparams);
6857 if (!pyobj_dict)
6858 goto cleanup;
6860 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6861 goto cleanup;
6862 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6863 Py_DECREF(dictKey);
6865 /* Create a python instance of this virDomainPtr */
6866 virDomainRef(dom);
6867 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6868 virDomainFree(dom);
6869 goto cleanup;
6871 Py_INCREF(pyobj_cbData);
6873 /* Call the Callback Dispatcher */
6874 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6875 (char*)"_dispatchDomainEventJobCompletedCallback",
6876 (char*)"OOO",
6877 pyobj_dom, pyobj_dict, pyobj_cbData);
6879 Py_DECREF(pyobj_cbData);
6880 Py_DECREF(pyobj_dom);
6882 cleanup:
6883 if (!pyobj_ret) {
6884 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6885 PyErr_Print();
6886 Py_XDECREF(pyobj_dict);
6887 } else {
6888 Py_DECREF(pyobj_ret);
6889 ret = 0;
6892 LIBVIRT_RELEASE_THREAD_STATE;
6893 return ret;
6895 #endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
6898 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
6899 static int
6900 libvirt_virConnectDomainEventDeviceRemovalFailedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6901 virDomainPtr dom,
6902 const char *devAlias,
6903 void *opaque)
6905 PyObject *pyobj_cbData = (PyObject*)opaque;
6906 PyObject *pyobj_dom;
6907 PyObject *pyobj_ret = NULL;
6908 PyObject *pyobj_conn;
6909 PyObject *dictKey;
6910 int ret = -1;
6912 LIBVIRT_ENSURE_THREAD_STATE;
6914 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6915 goto cleanup;
6916 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6917 Py_DECREF(dictKey);
6919 /* Create a python instance of this virDomainPtr */
6920 virDomainRef(dom);
6921 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6922 virDomainFree(dom);
6923 goto cleanup;
6925 Py_INCREF(pyobj_cbData);
6927 /* Call the Callback Dispatcher */
6928 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6929 (char*)"_dispatchDomainEventDeviceRemovalFailedCallback",
6930 (char*)"OsO",
6931 pyobj_dom, devAlias, pyobj_cbData);
6933 Py_DECREF(pyobj_cbData);
6934 Py_DECREF(pyobj_dom);
6936 cleanup:
6937 if (!pyobj_ret) {
6938 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6939 PyErr_Print();
6940 } else {
6941 Py_DECREF(pyobj_ret);
6942 ret = 0;
6945 LIBVIRT_RELEASE_THREAD_STATE;
6946 return ret;
6949 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED */
6952 static PyObject *
6953 libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
6954 PyObject *args)
6956 PyObject *py_retval; /* return value */
6957 PyObject *pyobj_conn; /* virConnectPtr */
6958 PyObject *pyobj_dom;
6959 PyObject *pyobj_cbData; /* hash of callback data */
6960 int eventID;
6961 virConnectPtr conn;
6962 int ret = 0;
6963 virConnectDomainEventGenericCallback cb = NULL;
6964 virDomainPtr dom;
6966 if (!PyArg_ParseTuple(args,
6967 (char *) "OOiO:virConnectDomainEventRegisterAny",
6968 &pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData))
6969 return NULL;
6971 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
6972 pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
6973 conn = PyvirConnect_Get(pyobj_conn);
6974 if (pyobj_dom == Py_None)
6975 dom = NULL;
6976 else
6977 dom = PyvirDomain_Get(pyobj_dom);
6979 switch ((virDomainEventID) eventID) {
6980 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
6981 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback);
6982 break;
6983 case VIR_DOMAIN_EVENT_ID_REBOOT:
6984 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
6985 break;
6986 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
6987 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback);
6988 break;
6989 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
6990 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback);
6991 break;
6992 case VIR_DOMAIN_EVENT_ID_IO_ERROR:
6993 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback);
6994 break;
6995 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
6996 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback);
6997 break;
6998 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
6999 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback);
7000 break;
7001 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
7002 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
7003 break;
7004 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
7005 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
7006 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2:
7007 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 */
7008 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback);
7009 break;
7010 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
7011 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
7012 break;
7013 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
7014 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
7015 break;
7016 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
7017 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
7018 break;
7019 case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
7020 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
7021 break;
7022 #ifdef VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
7023 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
7024 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback);
7025 break;
7026 #endif /* VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE */
7027 #ifdef VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
7028 case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
7029 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback);
7030 break;
7031 #endif /* VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK */
7032 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
7033 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
7034 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback);
7035 break;
7036 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED */
7037 #ifdef VIR_DOMAIN_EVENT_ID_TUNABLE
7038 case VIR_DOMAIN_EVENT_ID_TUNABLE:
7039 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTunableCallback);
7040 break;
7041 #endif /* VIR_DOMAIN_EVENT_ID_TUNABLE */
7042 #ifdef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
7043 case VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE:
7044 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventAgentLifecycleCallback);
7045 break;
7046 #endif /* VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE */
7047 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
7048 case VIR_DOMAIN_EVENT_ID_DEVICE_ADDED:
7049 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceAddedCallback);
7050 break;
7051 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_ADDED */
7052 #ifdef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
7053 case VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION:
7054 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMigrationIterationCallback);
7055 break;
7056 #endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
7057 #ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
7058 case VIR_DOMAIN_EVENT_ID_JOB_COMPLETED:
7059 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventJobCompletedCallback);
7060 break;
7061 #endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
7062 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
7063 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED:
7064 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovalFailedCallback);
7065 break;
7066 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED */
7067 case VIR_DOMAIN_EVENT_ID_LAST:
7068 break;
7071 if (!cb) {
7072 return VIR_PY_INT_FAIL;
7075 Py_INCREF(pyobj_cbData);
7077 LIBVIRT_BEGIN_ALLOW_THREADS;
7078 ret = virConnectDomainEventRegisterAny(conn, dom, eventID,
7079 cb, pyobj_cbData,
7080 libvirt_virConnectDomainEventFreeFunc);
7081 LIBVIRT_END_ALLOW_THREADS;
7083 if (ret < 0) {
7084 Py_DECREF(pyobj_cbData);
7087 py_retval = libvirt_intWrap(ret);
7088 return py_retval;
7091 static PyObject *
7092 libvirt_virConnectDomainEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
7093 PyObject *args)
7095 PyObject *pyobj_conn;
7096 int callbackID;
7097 virConnectPtr conn;
7098 int ret = 0;
7100 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectDomainEventDeregister",
7101 &pyobj_conn, &callbackID))
7102 return NULL;
7104 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
7106 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7108 LIBVIRT_BEGIN_ALLOW_THREADS;
7110 ret = virConnectDomainEventDeregisterAny(conn, callbackID);
7112 LIBVIRT_END_ALLOW_THREADS;
7114 return libvirt_intWrap(ret);
7117 #if LIBVIR_CHECK_VERSION(1, 2, 1)
7118 static void
7119 libvirt_virConnectNetworkEventFreeFunc(void *opaque)
7121 PyObject *pyobj_conn = (PyObject*)opaque;
7122 LIBVIRT_ENSURE_THREAD_STATE;
7123 Py_DECREF(pyobj_conn);
7124 LIBVIRT_RELEASE_THREAD_STATE;
7127 static int
7128 libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7129 virNetworkPtr net,
7130 int event,
7131 int detail,
7132 void *opaque)
7134 PyObject *pyobj_cbData = (PyObject*)opaque;
7135 PyObject *pyobj_net;
7136 PyObject *pyobj_ret = NULL;
7137 PyObject *pyobj_conn;
7138 PyObject *dictKey;
7139 int ret = -1;
7141 LIBVIRT_ENSURE_THREAD_STATE;
7143 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7144 goto cleanup;
7145 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7146 Py_DECREF(dictKey);
7148 /* Create a python instance of this virNetworkPtr */
7149 virNetworkRef(net);
7150 if (!(pyobj_net = libvirt_virNetworkPtrWrap(net))) {
7151 virNetworkFree(net);
7152 goto cleanup;
7154 Py_INCREF(pyobj_cbData);
7156 /* Call the Callback Dispatcher */
7157 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7158 (char*)"_dispatchNetworkEventLifecycleCallback",
7159 (char*)"OiiO",
7160 pyobj_net,
7161 event,
7162 detail,
7163 pyobj_cbData);
7165 Py_DECREF(pyobj_cbData);
7166 Py_DECREF(pyobj_net);
7168 cleanup:
7169 if (!pyobj_ret) {
7170 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7171 PyErr_Print();
7172 } else {
7173 Py_DECREF(pyobj_ret);
7174 ret = 0;
7177 LIBVIRT_RELEASE_THREAD_STATE;
7178 return ret;
7181 static PyObject *
7182 libvirt_virConnectNetworkEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
7183 PyObject *args)
7185 PyObject *pyobj_conn; /* virConnectPtr */
7186 PyObject *pyobj_net;
7187 PyObject *pyobj_cbData; /* hash of callback data */
7188 int eventID;
7189 virConnectPtr conn;
7190 int ret = 0;
7191 virConnectNetworkEventGenericCallback cb = NULL;
7192 virNetworkPtr net;
7194 if (!PyArg_ParseTuple(args,
7195 (char *) "OOiO:virConnectNetworkEventRegisterAny",
7196 &pyobj_conn, &pyobj_net, &eventID, &pyobj_cbData))
7197 return NULL;
7199 DEBUG("libvirt_virConnectNetworkEventRegister(%p %p %d %p) called\n",
7200 pyobj_conn, pyobj_net, eventID, pyobj_cbData);
7201 conn = PyvirConnect_Get(pyobj_conn);
7202 if (pyobj_net == Py_None)
7203 net = NULL;
7204 else
7205 net = PyvirNetwork_Get(pyobj_net);
7207 switch ((virNetworkEventID) eventID) {
7208 case VIR_NETWORK_EVENT_ID_LIFECYCLE:
7209 cb = VIR_NETWORK_EVENT_CALLBACK(libvirt_virConnectNetworkEventLifecycleCallback);
7210 break;
7212 case VIR_NETWORK_EVENT_ID_LAST:
7213 break;
7216 if (!cb) {
7217 return VIR_PY_INT_FAIL;
7220 Py_INCREF(pyobj_cbData);
7222 LIBVIRT_BEGIN_ALLOW_THREADS;
7223 ret = virConnectNetworkEventRegisterAny(conn, net, eventID,
7224 cb, pyobj_cbData,
7225 libvirt_virConnectNetworkEventFreeFunc);
7226 LIBVIRT_END_ALLOW_THREADS;
7228 if (ret < 0) {
7229 Py_DECREF(pyobj_cbData);
7232 return libvirt_intWrap(ret);
7235 static PyObject *
7236 libvirt_virConnectNetworkEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
7237 PyObject *args)
7239 PyObject *pyobj_conn;
7240 int callbackID;
7241 virConnectPtr conn;
7242 int ret = 0;
7244 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectNetworkEventDeregister",
7245 &pyobj_conn, &callbackID))
7246 return NULL;
7248 DEBUG("libvirt_virConnectNetworkEventDeregister(%p) called\n", pyobj_conn);
7250 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7252 LIBVIRT_BEGIN_ALLOW_THREADS;
7254 ret = virConnectNetworkEventDeregisterAny(conn, callbackID);
7256 LIBVIRT_END_ALLOW_THREADS;
7258 return libvirt_intWrap(ret);
7260 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1)*/
7262 #if LIBVIR_CHECK_VERSION(0, 10, 0)
7263 static void
7264 libvirt_virConnectCloseCallbackDispatch(virConnectPtr conn ATTRIBUTE_UNUSED,
7265 int reason,
7266 void *opaque)
7268 PyObject *pyobj_cbData = (PyObject*)opaque;
7269 PyObject *pyobj_ret;
7270 PyObject *pyobj_conn;
7271 PyObject *dictKey;
7273 LIBVIRT_ENSURE_THREAD_STATE;
7275 Py_INCREF(pyobj_cbData);
7277 dictKey = libvirt_constcharPtrWrap("conn");
7278 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7279 Py_DECREF(dictKey);
7281 /* Call the Callback Dispatcher */
7282 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7283 (char*)"_dispatchCloseCallback",
7284 (char*)"iO",
7285 reason,
7286 pyobj_cbData);
7288 Py_DECREF(pyobj_cbData);
7290 if (!pyobj_ret) {
7291 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7292 PyErr_Print();
7293 } else {
7294 Py_DECREF(pyobj_ret);
7297 LIBVIRT_RELEASE_THREAD_STATE;
7300 static PyObject *
7301 libvirt_virConnectRegisterCloseCallback(PyObject *self ATTRIBUTE_UNUSED,
7302 PyObject *args)
7304 PyObject *pyobj_conn; /* virConnectPtr */
7305 PyObject *pyobj_cbData; /* hash of callback data */
7306 virConnectPtr conn;
7307 int ret = 0;
7309 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectRegisterCloseCallback",
7310 &pyobj_conn, &pyobj_cbData))
7311 return NULL;
7313 DEBUG("libvirt_virConnectRegisterCloseCallback(%p %p) called\n",
7314 pyobj_conn, pyobj_cbData);
7315 conn = PyvirConnect_Get(pyobj_conn);
7317 Py_INCREF(pyobj_cbData);
7319 LIBVIRT_BEGIN_ALLOW_THREADS;
7320 ret = virConnectRegisterCloseCallback(conn,
7321 libvirt_virConnectCloseCallbackDispatch,
7322 pyobj_cbData,
7323 libvirt_virConnectDomainEventFreeFunc);
7324 LIBVIRT_END_ALLOW_THREADS;
7326 if (ret < 0) {
7327 Py_DECREF(pyobj_cbData);
7330 return libvirt_intWrap(ret);
7333 static PyObject *
7334 libvirt_virConnectUnregisterCloseCallback(PyObject * self ATTRIBUTE_UNUSED,
7335 PyObject * args)
7337 PyObject *pyobj_conn;
7338 virConnectPtr conn;
7339 int ret = 0;
7341 if (!PyArg_ParseTuple(args, (char *) "O:virConnectUnregisterCloseCallback",
7342 &pyobj_conn))
7343 return NULL;
7345 DEBUG("libvirt_virConnectDomainEventUnregister(%p) called\n",
7346 pyobj_conn);
7348 conn = PyvirConnect_Get(pyobj_conn);
7350 LIBVIRT_BEGIN_ALLOW_THREADS;
7352 ret = virConnectUnregisterCloseCallback(conn,
7353 libvirt_virConnectCloseCallbackDispatch);
7355 LIBVIRT_END_ALLOW_THREADS;
7357 return libvirt_intWrap(ret);
7359 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
7361 static void
7362 libvirt_virStreamEventFreeFunc(void *opaque)
7364 PyObject *pyobj_stream = (PyObject*)opaque;
7365 LIBVIRT_ENSURE_THREAD_STATE;
7366 Py_DECREF(pyobj_stream);
7367 LIBVIRT_RELEASE_THREAD_STATE;
7370 static void
7371 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED,
7372 int events,
7373 void *opaque)
7375 PyObject *pyobj_cbData = (PyObject *)opaque;
7376 PyObject *pyobj_stream;
7377 PyObject *pyobj_ret;
7378 PyObject *dictKey;
7380 LIBVIRT_ENSURE_THREAD_STATE;
7382 Py_INCREF(pyobj_cbData);
7383 dictKey = libvirt_constcharPtrWrap("stream");
7384 pyobj_stream = PyDict_GetItem(pyobj_cbData, dictKey);
7385 Py_DECREF(dictKey);
7387 /* Call the pure python dispatcher */
7388 pyobj_ret = PyObject_CallMethod(pyobj_stream,
7389 (char *)"_dispatchStreamEventCallback",
7390 (char *)"iO",
7391 events, pyobj_cbData);
7393 Py_DECREF(pyobj_cbData);
7395 if (!pyobj_ret) {
7396 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7397 PyErr_Print();
7398 } else {
7399 Py_DECREF(pyobj_ret);
7402 LIBVIRT_RELEASE_THREAD_STATE;
7405 static PyObject *
7406 libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
7407 PyObject *args)
7409 PyObject *pyobj_stream;
7410 PyObject *pyobj_cbData;
7411 virStreamPtr stream;
7412 virStreamEventCallback cb = libvirt_virStreamEventCallback;
7413 int ret;
7414 int events;
7416 if (!PyArg_ParseTuple(args, (char *) "OiO:virStreamEventAddCallback",
7417 &pyobj_stream, &events, &pyobj_cbData))
7418 return NULL;
7420 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
7421 pyobj_stream, events, pyobj_cbData);
7422 stream = PyvirStream_Get(pyobj_stream);
7424 Py_INCREF(pyobj_cbData);
7426 LIBVIRT_BEGIN_ALLOW_THREADS;
7427 ret = virStreamEventAddCallback(stream, events, cb, pyobj_cbData,
7428 libvirt_virStreamEventFreeFunc);
7429 LIBVIRT_END_ALLOW_THREADS;
7431 if (ret < 0) {
7432 Py_DECREF(pyobj_cbData);
7435 return libvirt_intWrap(ret);
7438 static PyObject *
7439 libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
7440 PyObject *args)
7442 PyObject *pyobj_stream;
7443 PyObject *rv;
7444 virStreamPtr stream;
7445 char *buf = NULL;
7446 int ret;
7447 int nbytes;
7449 if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
7450 &pyobj_stream, &nbytes)) {
7451 return NULL;
7453 stream = PyvirStream_Get(pyobj_stream);
7455 if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0)
7456 return PyErr_NoMemory();
7458 LIBVIRT_BEGIN_ALLOW_THREADS;
7459 ret = virStreamRecv(stream, buf, nbytes);
7460 LIBVIRT_END_ALLOW_THREADS;
7462 buf[ret > -1 ? ret : 0] = '\0';
7463 DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
7465 if (ret == -2)
7466 return libvirt_intWrap(ret);
7467 if (ret < 0)
7468 return VIR_PY_NONE;
7469 rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
7470 VIR_FREE(buf);
7471 return rv;
7474 static PyObject *
7475 libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
7476 PyObject *args)
7478 PyObject *pyobj_stream;
7479 PyObject *pyobj_data;
7480 virStreamPtr stream;
7481 char *data;
7482 Py_ssize_t datalen;
7483 int ret;
7485 if (!PyArg_ParseTuple(args, (char *) "OO:virStreamSend",
7486 &pyobj_stream, &pyobj_data))
7487 return NULL;
7489 stream = PyvirStream_Get(pyobj_stream);
7490 libvirt_charPtrSizeUnwrap(pyobj_data, &data, &datalen);
7492 LIBVIRT_BEGIN_ALLOW_THREADS;
7493 ret = virStreamSend(stream, data, datalen);
7494 LIBVIRT_END_ALLOW_THREADS;
7496 DEBUG("StreamSend ret=%d\n", ret);
7498 return libvirt_intWrap(ret);
7501 static PyObject *
7502 libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
7503 PyObject *args)
7505 virDomainPtr domain;
7506 PyObject *pyobj_domain;
7507 PyObject *pyobj_list;
7508 int codeset;
7509 int holdtime;
7510 unsigned int flags;
7511 int ret;
7512 size_t i;
7513 unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
7514 unsigned int nkeycodes;
7516 if (!PyArg_ParseTuple(args, (char *)"OiiOII:virDomainSendKey",
7517 &pyobj_domain, &codeset, &holdtime, &pyobj_list,
7518 &nkeycodes, &flags))
7519 return NULL;
7521 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7523 if (!PyList_Check(pyobj_list)) {
7524 return VIR_PY_INT_FAIL;
7527 if (nkeycodes != PyList_Size(pyobj_list) ||
7528 nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
7529 return VIR_PY_INT_FAIL;
7532 for (i = 0; i < nkeycodes; i++) {
7533 if (libvirt_uintUnwrap(PyList_GetItem(pyobj_list, i), &keycodes[i]) < 0)
7534 return NULL;
7537 LIBVIRT_BEGIN_ALLOW_THREADS;
7538 ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
7539 LIBVIRT_END_ALLOW_THREADS;
7541 DEBUG("virDomainSendKey ret=%d\n", ret);
7543 return libvirt_intWrap(ret);
7546 #if LIBVIR_CHECK_VERSION(1, 0, 3)
7547 static PyObject *
7548 libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED,
7549 PyObject *args)
7551 PyObject *pyobj_domain;
7552 virDomainPtr domain;
7553 unsigned int flags;
7554 unsigned long long cacheSize;
7555 int rc;
7557 if (!PyArg_ParseTuple(args,
7558 (char *) "OI:virDomainMigrateGetCompressionCache",
7559 &pyobj_domain, &flags))
7560 return NULL;
7562 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7564 LIBVIRT_BEGIN_ALLOW_THREADS;
7565 rc = virDomainMigrateGetCompressionCache(domain, &cacheSize, flags);
7566 LIBVIRT_END_ALLOW_THREADS;
7568 if (rc < 0)
7569 return VIR_PY_NONE;
7571 return libvirt_ulonglongWrap(cacheSize);
7573 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
7575 static PyObject *
7576 libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED,
7577 PyObject *args)
7579 int c_retval;
7580 unsigned long bandwidth;
7581 virDomainPtr domain;
7582 PyObject *pyobj_domain;
7583 unsigned int flags = 0;
7585 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainMigrateGetMaxSpeed",
7586 &pyobj_domain, &flags))
7587 return NULL;
7589 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7591 LIBVIRT_BEGIN_ALLOW_THREADS;
7592 c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, flags);
7593 LIBVIRT_END_ALLOW_THREADS;
7595 if (c_retval < 0)
7596 return VIR_PY_INT_FAIL;
7598 return libvirt_ulongWrap(bandwidth);
7601 #if LIBVIR_CHECK_VERSION(1, 1, 0)
7602 static PyObject *
7603 libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
7604 PyObject *args)
7606 PyObject *pyobj_domain;
7607 virDomainPtr domain;
7608 PyObject *pyobj_dconn;
7609 virConnectPtr dconn;
7610 PyObject *dict;
7611 unsigned int flags;
7612 virTypedParameterPtr params;
7613 int nparams;
7614 virDomainPtr ddom = NULL;
7616 if (!PyArg_ParseTuple(args, (char *) "OOOI:virDomainMigrate3",
7617 &pyobj_domain, &pyobj_dconn, &dict, &flags))
7618 return NULL;
7620 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7621 dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);
7623 if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
7624 return NULL;
7626 LIBVIRT_BEGIN_ALLOW_THREADS;
7627 ddom = virDomainMigrate3(domain, dconn, params, nparams, flags);
7628 LIBVIRT_END_ALLOW_THREADS;
7630 virTypedParamsFree(params, nparams);
7631 return libvirt_virDomainPtrWrap(ddom);
7634 static PyObject *
7635 libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,
7636 PyObject *args)
7638 PyObject *pyobj_domain;
7639 virDomainPtr domain;
7640 char *dconnuri;
7641 PyObject *dict;
7642 unsigned int flags;
7643 virTypedParameterPtr params;
7644 int nparams;
7645 int ret = -1;
7647 if (!PyArg_ParseTuple(args, (char *) "OzOI:virDomainMigrate3",
7648 &pyobj_domain, &dconnuri, &dict, &flags))
7649 return NULL;
7651 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7653 if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
7654 return NULL;
7656 LIBVIRT_BEGIN_ALLOW_THREADS;
7657 ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
7658 LIBVIRT_END_ALLOW_THREADS;
7660 virTypedParamsFree(params, nparams);
7661 return libvirt_intWrap(ret);
7663 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
7665 static PyObject *
7666 libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED,
7667 PyObject *args)
7669 PyObject *py_retval = NULL;
7670 int c_retval;
7671 virDomainPtr domain;
7672 PyObject *pyobj_domain;
7673 const char *disk;
7674 unsigned long long offset;
7675 size_t size;
7676 char *buf;
7677 unsigned int flags;
7679 if (!PyArg_ParseTuple(args, (char *)"OzKkI:virDomainBlockPeek",
7680 &pyobj_domain, &disk, &offset, &size, &flags))
7681 return NULL;
7683 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7685 if (VIR_ALLOC_N(buf, size) < 0)
7686 return PyErr_NoMemory();
7688 LIBVIRT_BEGIN_ALLOW_THREADS;
7689 c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags);
7690 LIBVIRT_END_ALLOW_THREADS;
7692 if (c_retval < 0) {
7693 py_retval = VIR_PY_NONE;
7694 goto cleanup;
7697 py_retval = libvirt_charPtrSizeWrap(buf, size);
7699 cleanup:
7700 VIR_FREE(buf);
7701 return py_retval;
7704 static PyObject *
7705 libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED,
7706 PyObject *args)
7708 PyObject *py_retval = NULL;
7709 int c_retval;
7710 virDomainPtr domain;
7711 PyObject *pyobj_domain;
7712 unsigned long long start;
7713 size_t size;
7714 char *buf;
7715 unsigned int flags;
7717 if (!PyArg_ParseTuple(args, (char *)"OKkI:virDomainMemoryPeek",
7718 &pyobj_domain, &start, &size, &flags))
7719 return NULL;
7721 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7723 if (VIR_ALLOC_N(buf, size) < 0)
7724 return PyErr_NoMemory();
7726 LIBVIRT_BEGIN_ALLOW_THREADS;
7727 c_retval = virDomainMemoryPeek(domain, start, size, buf, flags);
7728 LIBVIRT_END_ALLOW_THREADS;
7730 if (c_retval < 0) {
7731 py_retval = VIR_PY_NONE;
7732 goto cleanup;
7735 py_retval = libvirt_charPtrSizeWrap(buf, size);
7737 cleanup:
7738 VIR_FREE(buf);
7739 return py_retval;
7742 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7743 static PyObject *
7744 libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
7745 PyObject *args)
7747 virConnectPtr conn;
7748 PyObject *pyobj_conn, *info;
7749 PyObject *ret = NULL;
7750 int i_retval;
7751 int nparams = 0;
7752 Py_ssize_t size = 0;
7753 unsigned int flags;
7754 virTypedParameterPtr params, new_params = NULL;
7756 if (!PyArg_ParseTuple(args,
7757 (char *)"OOI:virNodeSetMemoryParameters",
7758 &pyobj_conn, &info, &flags))
7759 return NULL;
7760 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7762 if ((size = PyDict_Size(info)) < 0)
7763 return NULL;
7765 if (size == 0) {
7766 PyErr_Format(PyExc_LookupError,
7767 "Need non-empty dictionary to set attributes");
7768 return NULL;
7771 LIBVIRT_BEGIN_ALLOW_THREADS;
7772 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
7773 LIBVIRT_END_ALLOW_THREADS;
7775 if (i_retval < 0)
7776 return VIR_PY_INT_FAIL;
7778 if (nparams == 0) {
7779 PyErr_Format(PyExc_LookupError,
7780 "no settable attributes");
7781 return NULL;
7784 if (VIR_ALLOC_N(params, nparams) < 0)
7785 return PyErr_NoMemory();
7787 LIBVIRT_BEGIN_ALLOW_THREADS;
7788 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
7789 LIBVIRT_END_ALLOW_THREADS;
7791 if (i_retval < 0) {
7792 ret = VIR_PY_INT_FAIL;
7793 goto cleanup;
7796 new_params = setPyVirTypedParameter(info, params, nparams);
7797 if (!new_params)
7798 goto cleanup;
7800 LIBVIRT_BEGIN_ALLOW_THREADS;
7801 i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
7802 LIBVIRT_END_ALLOW_THREADS;
7804 if (i_retval < 0) {
7805 ret = VIR_PY_INT_FAIL;
7806 goto cleanup;
7809 ret = VIR_PY_INT_SUCCESS;
7811 cleanup:
7812 virTypedParamsFree(params, nparams);
7813 virTypedParamsFree(new_params, nparams);
7814 return ret;
7817 static PyObject *
7818 libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
7819 PyObject *args)
7821 virConnectPtr conn;
7822 PyObject *pyobj_conn;
7823 PyObject *ret = NULL;
7824 int i_retval;
7825 int nparams = 0;
7826 unsigned int flags;
7827 virTypedParameterPtr params;
7829 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetMemoryParameters",
7830 &pyobj_conn, &flags))
7831 return NULL;
7832 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7834 LIBVIRT_BEGIN_ALLOW_THREADS;
7835 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
7836 LIBVIRT_END_ALLOW_THREADS;
7838 if (i_retval < 0)
7839 return VIR_PY_NONE;
7841 if (!nparams)
7842 return PyDict_New();
7844 if (VIR_ALLOC_N(params, nparams) < 0)
7845 return PyErr_NoMemory();
7847 LIBVIRT_BEGIN_ALLOW_THREADS;
7848 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
7849 LIBVIRT_END_ALLOW_THREADS;
7851 if (i_retval < 0) {
7852 ret = VIR_PY_NONE;
7853 goto cleanup;
7856 ret = getPyVirTypedParameter(params, nparams);
7858 cleanup:
7859 virTypedParamsFree(params, nparams);
7860 return ret;
7862 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7864 #if LIBVIR_CHECK_VERSION(1, 0, 0)
7865 static PyObject *
7866 libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
7867 PyObject *args)
7869 virConnectPtr conn;
7870 PyObject *pyobj_conn;
7871 PyObject *ret = NULL;
7872 PyObject *pycpumap = NULL;
7873 int i_retval;
7874 unsigned char *cpumap = NULL;
7875 unsigned int online = 0;
7876 unsigned int flags;
7877 size_t i;
7879 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetCPUMap",
7880 &pyobj_conn, &flags))
7881 return NULL;
7882 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7884 LIBVIRT_BEGIN_ALLOW_THREADS;
7885 i_retval = virNodeGetCPUMap(conn, &cpumap, &online, flags);
7886 LIBVIRT_END_ALLOW_THREADS;
7888 if (i_retval < 0)
7889 return VIR_PY_NONE;
7891 if ((ret = PyTuple_New(3)) == NULL)
7892 goto error;
7894 /* 0: number of CPUs */
7895 VIR_PY_TUPLE_SET_GOTO(ret, 0, libvirt_intWrap(i_retval), error);
7897 /* 1: CPU map */
7898 if ((pycpumap = PyList_New(i_retval)) == NULL)
7899 goto error;
7901 VIR_PY_TUPLE_SET_GOTO(ret, 1, pycpumap, error);
7903 for (i = 0; i < i_retval; i++)
7904 VIR_PY_LIST_SET_GOTO(pycpumap, i,
7905 PyBool_FromLong(VIR_CPU_USED(cpumap, i)), error);
7907 /* 2: number of online CPUs */
7908 VIR_PY_TUPLE_SET_GOTO(ret, 2, libvirt_uintWrap(online), error);
7910 cleanup:
7911 VIR_FREE(cpumap);
7912 return ret;
7914 error:
7915 Py_CLEAR(ret);
7916 goto cleanup;
7918 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
7921 #if LIBVIR_CHECK_VERSION(1, 1, 1)
7922 static PyObject *
7923 libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED,
7924 PyObject *args)
7926 PyObject *py_retval = NULL;
7927 int c_retval;
7928 virDomainPtr domain;
7929 PyObject *pyobj_domain;
7930 PyObject *pyobj_files;
7931 unsigned int flags;
7932 unsigned int nfiles;
7933 int *files = NULL;
7934 size_t i;
7936 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainCreateWithFiles",
7937 &pyobj_domain, &pyobj_files, &flags))
7938 return NULL;
7939 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7941 nfiles = PyList_Size(pyobj_files);
7943 if (VIR_ALLOC_N(files, nfiles) < 0)
7944 return PyErr_NoMemory();
7946 for (i = 0; i < nfiles; i++) {
7947 PyObject *pyfd;
7948 int fd;
7950 pyfd = PyList_GetItem(pyobj_files, i);
7952 if (libvirt_intUnwrap(pyfd, &fd) < 0)
7953 goto cleanup;
7955 files[i] = fd;
7958 LIBVIRT_BEGIN_ALLOW_THREADS;
7959 c_retval = virDomainCreateWithFiles(domain, nfiles, files, flags);
7960 LIBVIRT_END_ALLOW_THREADS;
7961 py_retval = libvirt_intWrap((int) c_retval);
7963 cleanup:
7964 VIR_FREE(files);
7965 return py_retval;
7969 static PyObject *
7970 libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED,
7971 PyObject *args)
7973 PyObject *py_retval = NULL;
7974 virDomainPtr c_retval;
7975 virConnectPtr conn;
7976 PyObject *pyobj_conn;
7977 char * xmlDesc;
7978 PyObject *pyobj_files;
7979 unsigned int flags;
7980 unsigned int nfiles;
7981 int *files = NULL;
7982 size_t i;
7984 if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainCreateXMLWithFiles",
7985 &pyobj_conn, &xmlDesc, &pyobj_files, &flags))
7986 return NULL;
7987 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7989 nfiles = PyList_Size(pyobj_files);
7991 if (VIR_ALLOC_N(files, nfiles) < 0)
7992 return PyErr_NoMemory();
7994 for (i = 0; i < nfiles; i++) {
7995 PyObject *pyfd;
7996 int fd;
7998 pyfd = PyList_GetItem(pyobj_files, i);
8000 if (libvirt_intUnwrap(pyfd, &fd) < 0)
8001 goto cleanup;
8003 files[i] = fd;
8006 LIBVIRT_BEGIN_ALLOW_THREADS;
8007 c_retval = virDomainCreateXMLWithFiles(conn, xmlDesc, nfiles, files, flags);
8008 LIBVIRT_END_ALLOW_THREADS;
8009 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
8011 cleanup:
8012 VIR_FREE(files);
8013 return py_retval;
8015 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
8018 #if LIBVIR_CHECK_VERSION(1, 2, 5)
8019 static PyObject *
8020 libvirt_virDomainFSFreeze(PyObject *self ATTRIBUTE_UNUSED,
8021 PyObject *args)
8023 PyObject *py_retval = NULL;
8024 int c_retval;
8025 virDomainPtr domain;
8026 PyObject *pyobj_domain;
8027 PyObject *pyobj_list;
8028 unsigned int flags;
8029 unsigned int nmountpoints = 0;
8030 char **mountpoints = NULL;
8031 size_t i = 0, j;
8033 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSFreeze",
8034 &pyobj_domain, &pyobj_list, &flags))
8035 return NULL;
8036 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8038 if (PyList_Check(pyobj_list)) {
8039 nmountpoints = PyList_Size(pyobj_list);
8041 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
8042 return PyErr_NoMemory();
8044 for (i = 0; i < nmountpoints; i++) {
8045 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
8046 mountpoints+i) < 0 ||
8047 mountpoints[i] == NULL)
8048 goto cleanup;
8052 LIBVIRT_BEGIN_ALLOW_THREADS;
8053 c_retval = virDomainFSFreeze(domain, (const char **) mountpoints,
8054 nmountpoints, flags);
8055 LIBVIRT_END_ALLOW_THREADS;
8057 py_retval = libvirt_intWrap(c_retval);
8059 cleanup:
8060 for (j = 0 ; j < i ; j++)
8061 VIR_FREE(mountpoints[j]);
8062 VIR_FREE(mountpoints);
8063 return py_retval;
8067 static PyObject *
8068 libvirt_virDomainFSThaw(PyObject *self ATTRIBUTE_UNUSED,
8069 PyObject *args)
8071 PyObject *py_retval = NULL;
8072 int c_retval;
8073 virDomainPtr domain;
8074 PyObject *pyobj_domain;
8075 PyObject *pyobj_list;
8076 unsigned int flags;
8077 unsigned int nmountpoints = 0;
8078 char **mountpoints = NULL;
8079 size_t i = 0, j;
8081 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSThaw",
8082 &pyobj_domain, &pyobj_list, &flags))
8083 return NULL;
8084 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8086 if (PyList_Check(pyobj_list)) {
8087 nmountpoints = PyList_Size(pyobj_list);
8089 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
8090 return PyErr_NoMemory();
8092 for (i = 0; i < nmountpoints; i++) {
8093 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
8094 mountpoints+i) < 0 ||
8095 mountpoints[i] == NULL)
8096 goto cleanup;
8100 LIBVIRT_BEGIN_ALLOW_THREADS;
8101 c_retval = virDomainFSThaw(domain, (const char **) mountpoints,
8102 nmountpoints, flags);
8103 LIBVIRT_END_ALLOW_THREADS;
8105 py_retval = libvirt_intWrap(c_retval);
8107 cleanup:
8108 for (j = 0 ; j < i ; j++)
8109 VIR_FREE(mountpoints[j]);
8110 VIR_FREE(mountpoints);
8111 return py_retval;
8114 static PyObject *
8115 libvirt_virDomainGetTime(PyObject *self ATTRIBUTE_UNUSED,
8116 PyObject *args)
8118 PyObject *py_retval = NULL;
8119 PyObject *dict = NULL;
8120 PyObject *pyobj_domain;
8121 virDomainPtr domain;
8122 long long seconds;
8123 unsigned int nseconds;
8124 unsigned int flags;
8125 int c_retval;
8127 if (!PyArg_ParseTuple(args, (char*)"OI:virDomainGetTime",
8128 &pyobj_domain, &flags))
8129 return NULL;
8130 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8132 if (!(dict = PyDict_New()))
8133 goto cleanup;
8135 LIBVIRT_BEGIN_ALLOW_THREADS;
8136 c_retval = virDomainGetTime(domain, &seconds, &nseconds, flags);
8137 LIBVIRT_END_ALLOW_THREADS;
8139 if (c_retval < 0) {
8140 py_retval = VIR_PY_NONE;
8141 goto cleanup;
8144 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("seconds"),
8145 libvirt_longlongWrap(seconds), cleanup);
8146 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("nseconds"),
8147 libvirt_longlongWrap(nseconds), cleanup);
8149 py_retval = dict;
8150 dict = NULL;
8151 cleanup:
8152 Py_XDECREF(dict);
8153 return py_retval;
8157 static PyObject *
8158 libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED,
8159 PyObject *args)
8161 PyObject *pyobj_domain;
8162 PyObject *pyobj_seconds;
8163 PyObject *pyobj_nseconds;
8164 PyObject *py_dict;
8165 virDomainPtr domain;
8166 long long seconds = 0;
8167 unsigned int nseconds = 0;
8168 unsigned int flags;
8169 ssize_t py_dict_size = 0;
8170 int c_retval;
8172 if (!PyArg_ParseTuple(args, (char*)"OOI:virDomainSetTime",
8173 &pyobj_domain, &py_dict, &flags))
8174 return NULL;
8175 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8177 if (PyDict_Check(py_dict)) {
8178 py_dict_size = PyDict_Size(py_dict);
8179 if ((pyobj_seconds = PyDict_GetItemString(py_dict, "seconds"))) {
8180 if (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)
8181 return NULL;
8182 } else {
8183 PyErr_Format(PyExc_LookupError, "Dictionary must contains 'seconds'");
8184 return NULL;
8187 if ((pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds"))) {
8188 if (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)
8189 return NULL;
8190 } else if (py_dict_size > 1) {
8191 PyErr_Format(PyExc_LookupError, "Dictionary contains unknown key");
8192 return NULL;
8194 } else if (py_dict != Py_None || !flags) {
8195 PyErr_Format(PyExc_TypeError, "time must be a dictionary "
8196 "or None with flags set");
8197 return NULL;
8200 LIBVIRT_BEGIN_ALLOW_THREADS;
8201 c_retval = virDomainSetTime(domain, seconds, nseconds, flags);
8202 LIBVIRT_END_ALLOW_THREADS;
8204 return libvirt_intWrap(c_retval);
8206 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
8209 #if LIBVIR_CHECK_VERSION(1, 2, 6)
8210 static PyObject *
8211 libvirt_virNodeGetFreePages(PyObject *self ATTRIBUTE_UNUSED,
8212 PyObject *args)
8214 PyObject *py_retval = NULL;
8215 PyObject *pyobj_conn;
8216 PyObject *pyobj_pagesize;
8217 PyObject *pyobj_counts = NULL;
8218 virConnectPtr conn;
8219 unsigned int *pages = NULL;
8220 int startCell;
8221 unsigned int cellCount;
8222 unsigned int flags;
8223 unsigned long long *counts = NULL;
8224 int c_retval;
8225 ssize_t pyobj_pagesize_size, i, j;
8227 if (!PyArg_ParseTuple(args, (char *)"OOiII:virNodeGetFreePages",
8228 &pyobj_conn, &pyobj_pagesize, &startCell,
8229 &cellCount, &flags))
8230 return NULL;
8232 if (!PyList_Check(pyobj_pagesize)) {
8233 PyErr_Format(PyExc_TypeError, "pagesize must be list");
8234 return NULL;
8237 if (cellCount == 0) {
8238 PyErr_Format(PyExc_LookupError, "cellCount must not be zero");
8239 return NULL;
8242 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8244 pyobj_pagesize_size = PyList_Size(pyobj_pagesize);
8245 if (VIR_ALLOC_N(pages, pyobj_pagesize_size) < 0 ||
8246 VIR_ALLOC_N(counts, pyobj_pagesize_size * cellCount) < 0) {
8247 PyErr_NoMemory();
8248 goto cleanup;
8251 if (!(pyobj_counts = PyDict_New()))
8252 goto cleanup;
8254 for (i = 0; i < pyobj_pagesize_size; i++) {
8255 PyObject *tmp = PyList_GetItem(pyobj_pagesize, i);
8257 if (libvirt_uintUnwrap(tmp, &pages[i]) < 0)
8258 goto cleanup;
8261 LIBVIRT_BEGIN_ALLOW_THREADS;
8262 c_retval = virNodeGetFreePages(conn,
8263 pyobj_pagesize_size, pages,
8264 startCell, cellCount,
8265 counts, flags);
8266 LIBVIRT_END_ALLOW_THREADS;
8268 if (c_retval < 0) {
8269 py_retval = VIR_PY_NONE;
8270 goto cleanup;
8273 for (i = 0; i < c_retval;) {
8274 PyObject *per_node = NULL;
8276 if (!(per_node = PyDict_New()))
8277 goto cleanup;
8279 VIR_PY_DICT_SET_GOTO(pyobj_counts,
8280 libvirt_intWrap(startCell + i/pyobj_pagesize_size),
8281 per_node, cleanup);
8283 for (j = 0; j < pyobj_pagesize_size; j ++)
8284 VIR_PY_DICT_SET_GOTO(per_node, libvirt_intWrap(pages[j]),
8285 libvirt_intWrap(counts[i + j]), cleanup);
8287 i += pyobj_pagesize_size;
8290 py_retval = pyobj_counts;
8291 pyobj_counts = NULL;
8292 cleanup:
8293 Py_XDECREF(pyobj_counts);
8294 VIR_FREE(pages);
8295 VIR_FREE(counts);
8296 return py_retval;
8300 static PyObject *
8301 libvirt_virNetworkGetDHCPLeases(PyObject *self ATTRIBUTE_UNUSED,
8302 PyObject *args)
8304 PyObject *py_retval = NULL;
8305 PyObject *py_lease = NULL;
8306 virNetworkPtr network;
8307 PyObject *pyobj_network;
8308 unsigned int flags;
8309 virNetworkDHCPLeasePtr *leases = NULL;
8310 int leases_count;
8311 char *mac = NULL;
8312 size_t i;
8314 if (!PyArg_ParseTuple(args, (char *) "OzI:virNetworkGetDHCPLeases",
8315 &pyobj_network, &mac, &flags))
8316 return NULL;
8318 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
8320 LIBVIRT_BEGIN_ALLOW_THREADS;
8321 leases_count = virNetworkGetDHCPLeases(network, mac, &leases, flags);
8322 LIBVIRT_END_ALLOW_THREADS;
8324 if (leases_count < 0) {
8325 py_retval = VIR_PY_NONE;
8326 goto cleanup;
8329 if (!(py_retval = PyList_New(leases_count)))
8330 goto error;
8332 for (i = 0; i < leases_count; i++) {
8333 virNetworkDHCPLeasePtr lease = leases[i];
8335 if ((py_lease = PyDict_New()) == NULL)
8336 goto error;
8338 VIR_PY_LIST_SET_GOTO(py_retval, i, py_lease, error);
8340 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("iface"),
8341 libvirt_charPtrWrap(lease->iface), error);
8342 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("expirytime"),
8343 libvirt_longlongWrap(lease->expirytime), error);
8344 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("type"),
8345 libvirt_intWrap(lease->type), error);
8346 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("mac"),
8347 libvirt_charPtrWrap(lease->mac), error);
8348 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("ipaddr"),
8349 libvirt_charPtrWrap(lease->ipaddr), error);
8350 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("prefix"),
8351 libvirt_uintWrap(lease->prefix), error);
8352 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("hostname"),
8353 libvirt_charPtrWrap(lease->hostname), error);
8354 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("clientid"),
8355 libvirt_charPtrWrap(lease->clientid), error);
8356 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("iaid"),
8357 libvirt_charPtrWrap(lease->iaid), error);
8360 cleanup:
8361 if (leases_count > 0)
8362 for (i = 0; i < leases_count; i++)
8363 virNetworkDHCPLeaseFree(leases[i]);
8364 VIR_FREE(leases);
8366 return py_retval;
8368 error:
8369 Py_CLEAR(py_retval);
8370 goto cleanup;
8373 #endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
8375 #if LIBVIR_CHECK_VERSION(1, 2, 8)
8377 static PyObject *
8378 convertDomainStatsRecord(virDomainStatsRecordPtr *records,
8379 int nrecords)
8381 PyObject *py_retval;
8382 PyObject *py_record;
8383 PyObject *py_record_stats = NULL;
8384 virDomainPtr dom = NULL;
8385 size_t i;
8387 if (!(py_retval = PyList_New(nrecords)))
8388 return NULL;
8390 for (i = 0; i < nrecords; i++) {
8391 if (!(py_record = PyTuple_New(2)))
8392 goto error;
8394 VIR_PY_LIST_SET_GOTO(py_retval, i, py_record, error);
8396 dom = records[i]->dom;
8397 virDomainRef(dom);
8398 VIR_PY_TUPLE_SET_GOTO(py_record, 0,
8399 libvirt_virDomainPtrWrap(dom),
8400 error);
8401 dom = NULL;
8403 if (!(py_record_stats = getPyVirTypedParameter(records[i]->params,
8404 records[i]->nparams)))
8405 goto error;
8406 VIR_PY_TUPLE_SET_GOTO(py_record, 1, py_record_stats, error);
8410 return py_retval;
8412 error:
8413 if (dom)
8414 virDomainFree(dom);
8415 Py_XDECREF(py_retval);
8416 return NULL;
8420 static PyObject *
8421 libvirt_virConnectGetAllDomainStats(PyObject *self ATTRIBUTE_UNUSED,
8422 PyObject *args)
8424 PyObject *pyobj_conn;
8425 PyObject *py_retval;
8426 virConnectPtr conn;
8427 virDomainStatsRecordPtr *records;
8428 int nrecords;
8429 unsigned int flags;
8430 unsigned int stats;
8432 if (!PyArg_ParseTuple(args, (char *)"OII:virConnectGetAllDomainStats",
8433 &pyobj_conn, &stats, &flags))
8434 return NULL;
8435 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8437 LIBVIRT_BEGIN_ALLOW_THREADS;
8438 nrecords = virConnectGetAllDomainStats(conn, stats, &records, flags);
8439 LIBVIRT_END_ALLOW_THREADS;
8441 if (nrecords < 0)
8442 return VIR_PY_NONE;
8444 py_retval = convertDomainStatsRecord(records, nrecords);
8446 virDomainStatsRecordListFree(records);
8448 return py_retval;
8452 static PyObject *
8453 libvirt_virDomainListGetStats(PyObject *self ATTRIBUTE_UNUSED,
8454 PyObject *args)
8456 PyObject *pyobj_conn;
8457 PyObject *py_retval;
8458 PyObject *py_domlist;
8459 virDomainStatsRecordPtr *records = NULL;
8460 virDomainPtr *doms = NULL;
8461 int nrecords;
8462 int ndoms;
8463 size_t i;
8464 unsigned int flags;
8465 unsigned int stats;
8467 if (!PyArg_ParseTuple(args, (char *)"OOII:virDomainListGetStats",
8468 &pyobj_conn, &py_domlist, &stats, &flags))
8469 return NULL;
8471 if (PyList_Check(py_domlist)) {
8472 ndoms = PyList_Size(py_domlist);
8474 if (VIR_ALLOC_N(doms, ndoms + 1) < 0)
8475 return PyErr_NoMemory();
8477 for (i = 0; i < ndoms; i++)
8478 doms[i] = PyvirDomain_Get(PyList_GetItem(py_domlist, i));
8481 LIBVIRT_BEGIN_ALLOW_THREADS;
8482 nrecords = virDomainListGetStats(doms, stats, &records, flags);
8483 LIBVIRT_END_ALLOW_THREADS;
8485 if (nrecords < 0) {
8486 py_retval = VIR_PY_NONE;
8487 goto cleanup;
8490 py_retval = convertDomainStatsRecord(records, nrecords);
8492 cleanup:
8493 virDomainStatsRecordListFree(records);
8494 VIR_FREE(doms);
8496 return py_retval;
8500 static PyObject *
8501 libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED,
8502 PyObject *args)
8504 PyObject *pyobj_dom = NULL;
8505 PyObject *pyobj_dict = NULL;
8507 virDomainPtr dom;
8508 char *disk = NULL;
8509 char *destxml = NULL;
8510 virTypedParameterPtr params = NULL;
8511 int nparams = 0;
8512 unsigned int flags = 0;
8513 int c_retval;
8515 if (!PyArg_ParseTuple(args, (char *) "Ozz|OI:virDomainBlockCopy",
8516 &pyobj_dom, &disk, &destxml, &pyobj_dict, &flags))
8517 return NULL;
8519 if (PyDict_Check(pyobj_dict)) {
8520 if (virPyDictToTypedParams(pyobj_dict, &params, &nparams, NULL, 0) < 0)
8521 return NULL;
8524 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
8526 LIBVIRT_BEGIN_ALLOW_THREADS;
8527 c_retval = virDomainBlockCopy(dom, disk, destxml, params, nparams, flags);
8528 LIBVIRT_END_ALLOW_THREADS;
8530 return libvirt_intWrap(c_retval);
8533 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
8535 #if LIBVIR_CHECK_VERSION(1, 2, 9)
8536 static PyObject *
8537 libvirt_virNodeAllocPages(PyObject *self ATTRIBUTE_UNUSED,
8538 PyObject *args)
8540 PyObject *pyobj_conn;
8541 PyObject *pyobj_pages;
8542 Py_ssize_t size = 0;
8543 Py_ssize_t pos = 0;
8544 PyObject *key, *value;
8545 virConnectPtr conn;
8546 unsigned int npages = 0;
8547 unsigned int *pageSizes = NULL;
8548 unsigned long long *pageCounts = NULL;
8549 int startCell = -1;
8550 unsigned int cellCount = 1;
8551 unsigned int flags = VIR_NODE_ALLOC_PAGES_ADD;
8552 int c_retval;
8554 if (!PyArg_ParseTuple(args, (char *)"OOiII:virNodeAllocPages",
8555 &pyobj_conn, &pyobj_pages,
8556 &startCell, &cellCount, &flags))
8557 return NULL;
8558 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8560 if ((size = PyDict_Size(pyobj_pages)) < 0)
8561 return NULL;
8563 if (size == 0) {
8564 PyErr_Format(PyExc_LookupError,
8565 "Need non-empty dictionary to pages attribute");
8566 return NULL;
8569 if (VIR_ALLOC_N(pageSizes, size) < 0 ||
8570 VIR_ALLOC_N(pageCounts, size) < 0) {
8571 PyErr_NoMemory();
8572 goto error;
8575 while (PyDict_Next(pyobj_pages, &pos, &key, &value)) {
8576 if (libvirt_uintUnwrap(key, &pageSizes[npages]) < 0 ||
8577 libvirt_ulonglongUnwrap(value, &pageCounts[npages]) < 0)
8578 goto error;
8579 npages++;
8582 LIBVIRT_BEGIN_ALLOW_THREADS;
8583 c_retval = virNodeAllocPages(conn, npages, pageSizes,
8584 pageCounts, startCell, cellCount, flags);
8585 LIBVIRT_END_ALLOW_THREADS;
8587 VIR_FREE(pageSizes);
8588 VIR_FREE(pageCounts);
8590 return libvirt_intWrap(c_retval);
8592 error:
8593 VIR_FREE(pageSizes);
8594 VIR_FREE(pageCounts);
8595 return NULL;
8597 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
8599 #if LIBVIR_CHECK_VERSION(1, 2, 11)
8601 static PyObject *
8602 libvirt_virDomainGetFSInfo(PyObject *self ATTRIBUTE_UNUSED,
8603 PyObject *args)
8605 virDomainPtr domain;
8606 PyObject *pyobj_domain;
8607 unsigned int flags;
8608 virDomainFSInfoPtr *fsinfo = NULL;
8609 int c_retval, i;
8610 size_t j;
8611 PyObject *py_retval = NULL;
8613 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetFSInfo",
8614 &pyobj_domain, &flags))
8615 return NULL;
8616 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8618 LIBVIRT_BEGIN_ALLOW_THREADS;
8619 c_retval = virDomainGetFSInfo(domain, &fsinfo, flags);
8620 LIBVIRT_END_ALLOW_THREADS;
8622 if (c_retval < 0) {
8623 py_retval = VIR_PY_NONE;
8624 goto cleanup;
8627 /* convert to a Python list */
8628 if ((py_retval = PyList_New(c_retval)) == NULL)
8629 goto error;
8631 for (i = 0; i < c_retval; i++) {
8632 virDomainFSInfoPtr fs = fsinfo[i];
8633 PyObject *info, *alias;
8635 if (fs == NULL)
8636 goto error;
8638 info = PyTuple_New(4);
8639 if (info == NULL)
8640 goto error;
8642 VIR_PY_LIST_SET_GOTO(py_retval, i, info, error);
8644 VIR_PY_TUPLE_SET_GOTO(info, 0,
8645 libvirt_constcharPtrWrap(fs->mountpoint), error);
8646 VIR_PY_TUPLE_SET_GOTO(info, 1,
8647 libvirt_constcharPtrWrap(fs->name), error);
8648 VIR_PY_TUPLE_SET_GOTO(info, 2,
8649 libvirt_constcharPtrWrap(fs->fstype), error);
8651 alias = PyList_New(0);
8652 if (alias == NULL)
8653 goto error;
8654 VIR_PY_TUPLE_SET_GOTO(info, 3, alias, error);
8656 for (j = 0; j < fs->ndevAlias; j++)
8657 VIR_PY_LIST_APPEND_GOTO(alias,
8658 libvirt_constcharPtrWrap(fs->devAlias[j]),
8659 error);
8662 cleanup:
8663 if (c_retval > 0)
8664 for (i = 0; i < c_retval; i++)
8665 virDomainFSInfoFree(fsinfo[i]);
8666 VIR_FREE(fsinfo);
8667 return py_retval;
8669 error:
8670 Py_CLEAR(py_retval);
8671 goto cleanup;
8674 #endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
8676 #if LIBVIR_CHECK_VERSION(1, 3, 3)
8677 static PyObject *
8678 libvirt_virDomainGetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
8679 PyObject *args)
8681 PyObject *pyobj_domain;
8682 virDomainPtr domain;
8683 virTypedParameterPtr params = NULL;
8684 int nparams = 0;
8685 PyObject *dict = NULL;
8686 unsigned int flags;
8687 int rc;
8689 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetPerfEvents",
8690 &pyobj_domain, &flags))
8691 return NULL;
8692 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8694 LIBVIRT_BEGIN_ALLOW_THREADS;
8695 rc = virDomainGetPerfEvents(domain, &params, &nparams, flags);
8696 LIBVIRT_END_ALLOW_THREADS;
8697 if (rc < 0)
8698 return VIR_PY_NONE;
8700 if (!(dict = getPyVirTypedParameter(params, nparams)))
8701 goto cleanup;
8703 cleanup:
8704 virTypedParamsFree(params, nparams);
8705 return dict;
8708 static PyObject *
8709 libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
8710 PyObject *args)
8712 virDomainPtr domain;
8713 PyObject *pyobj_domain, *info;
8714 PyObject *ret = NULL;
8715 int i_retval;
8716 int nparams = 0;
8717 Py_ssize_t size = 0;
8718 unsigned int flags;
8719 virTypedParameterPtr params = NULL, new_params = NULL;
8721 if (!PyArg_ParseTuple(args,
8722 (char *)"OOI:virDomainSetPerfEvents",
8723 &pyobj_domain, &info, &flags))
8724 return NULL;
8725 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8727 if ((size = PyDict_Size(info)) < 0)
8728 return NULL;
8730 if (size == 0) {
8731 PyErr_Format(PyExc_LookupError,
8732 "Need non-empty dictionary to set attributes");
8733 return NULL;
8736 LIBVIRT_BEGIN_ALLOW_THREADS;
8737 i_retval = virDomainGetPerfEvents(domain, &params, &nparams, flags);
8738 LIBVIRT_END_ALLOW_THREADS;
8740 if (i_retval < 0)
8741 return VIR_PY_INT_FAIL;
8743 if (nparams == 0) {
8744 PyErr_Format(PyExc_LookupError,
8745 "Domain has no settable attributes");
8746 return NULL;
8749 new_params = setPyVirTypedParameter(info, params, nparams);
8750 if (!new_params)
8751 goto cleanup;
8753 LIBVIRT_BEGIN_ALLOW_THREADS;
8754 i_retval = virDomainSetPerfEvents(domain, new_params, size, flags);
8755 LIBVIRT_END_ALLOW_THREADS;
8757 if (i_retval < 0) {
8758 ret = VIR_PY_INT_FAIL;
8759 goto cleanup;
8762 ret = VIR_PY_INT_SUCCESS;
8764 cleanup:
8765 virTypedParamsFree(params, nparams);
8766 virTypedParamsFree(new_params, size);
8767 return ret;
8769 #endif /* LIBVIR_CHECK_VERSION(1, 3, 3) */
8771 #if LIBVIR_CHECK_VERSION(2, 0, 0)
8772 static void
8773 libvirt_virConnectStoragePoolEventFreeFunc(void *opaque)
8775 PyObject *pyobj_conn = (PyObject*)opaque;
8776 LIBVIRT_ENSURE_THREAD_STATE;
8777 Py_DECREF(pyobj_conn);
8778 LIBVIRT_RELEASE_THREAD_STATE;
8781 static int
8782 libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
8783 virStoragePoolPtr pool,
8784 int event,
8785 int detail,
8786 void *opaque)
8788 PyObject *pyobj_cbData = (PyObject*)opaque;
8789 PyObject *pyobj_pool;
8790 PyObject *pyobj_ret = NULL;
8791 PyObject *pyobj_conn;
8792 PyObject *dictKey;
8793 int ret = -1;
8795 LIBVIRT_ENSURE_THREAD_STATE;
8797 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
8798 goto cleanup;
8799 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
8800 Py_DECREF(dictKey);
8802 /* Create a python instance of this virStoragePoolPtr */
8803 virStoragePoolRef(pool);
8804 if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
8805 virStoragePoolFree(pool);
8806 goto cleanup;
8808 Py_INCREF(pyobj_cbData);
8810 /* Call the Callback Dispatcher */
8811 pyobj_ret = PyObject_CallMethod(pyobj_conn,
8812 (char*)"_dispatchStoragePoolEventLifecycleCallback",
8813 (char*)"OiiO",
8814 pyobj_pool,
8815 event,
8816 detail,
8817 pyobj_cbData);
8819 Py_DECREF(pyobj_cbData);
8820 Py_DECREF(pyobj_pool);
8822 cleanup:
8823 if (!pyobj_ret) {
8824 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
8825 PyErr_Print();
8826 } else {
8827 Py_DECREF(pyobj_ret);
8828 ret = 0;
8831 LIBVIRT_RELEASE_THREAD_STATE;
8832 return ret;
8835 static int
8836 libvirt_virConnectStoragePoolEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
8837 virStoragePoolPtr pool,
8838 void *opaque)
8840 PyObject *pyobj_cbData = (PyObject*)opaque;
8841 PyObject *pyobj_pool;
8842 PyObject *pyobj_ret = NULL;
8843 PyObject *pyobj_conn;
8844 PyObject *dictKey;
8845 int ret = -1;
8847 LIBVIRT_ENSURE_THREAD_STATE;
8849 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
8850 goto cleanup;
8851 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
8852 Py_DECREF(dictKey);
8854 /* Create a python instance of this virStoragePoolPtr */
8855 virStoragePoolRef(pool);
8856 if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
8857 virStoragePoolFree(pool);
8858 goto cleanup;
8860 Py_INCREF(pyobj_cbData);
8862 /* Call the Callback Dispatcher */
8863 pyobj_ret = PyObject_CallMethod(pyobj_conn,
8864 (char*)"_dispatchStoragePoolEventGenericCallback",
8865 (char*)"OO",
8866 pyobj_pool,
8867 pyobj_cbData);
8869 Py_DECREF(pyobj_cbData);
8870 Py_DECREF(pyobj_pool);
8872 cleanup:
8873 if (!pyobj_ret) {
8874 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
8875 PyErr_Print();
8876 } else {
8877 Py_DECREF(pyobj_ret);
8878 ret = 0;
8881 LIBVIRT_RELEASE_THREAD_STATE;
8882 return ret;
8885 static PyObject *
8886 libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
8887 PyObject *args)
8889 PyObject *pyobj_conn; /* virConnectPtr */
8890 PyObject *pyobj_pool;
8891 PyObject *pyobj_cbData; /* hash of callback data */
8892 int eventID;
8893 virConnectPtr conn;
8894 int ret = 0;
8895 virConnectStoragePoolEventGenericCallback cb = NULL;
8896 virStoragePoolPtr pool;
8898 if (!PyArg_ParseTuple(args,
8899 (char *) "OOiO:virConnectStoragePoolEventRegisterAny",
8900 &pyobj_conn, &pyobj_pool, &eventID, &pyobj_cbData))
8901 return NULL;
8903 DEBUG("libvirt_virConnectStoragePoolEventRegister(%p %p %d %p) called\n",
8904 pyobj_conn, pyobj_pool, eventID, pyobj_cbData);
8905 conn = PyvirConnect_Get(pyobj_conn);
8906 if (pyobj_pool == Py_None)
8907 pool = NULL;
8908 else
8909 pool = PyvirStoragePool_Get(pyobj_pool);
8911 switch ((virStoragePoolEventID) eventID) {
8912 case VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE:
8913 cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventLifecycleCallback);
8914 break;
8916 case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
8917 cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventGenericCallback);
8918 break;
8920 case VIR_STORAGE_POOL_EVENT_ID_LAST:
8921 break;
8924 if (!cb) {
8925 return VIR_PY_INT_FAIL;
8928 Py_INCREF(pyobj_cbData);
8930 LIBVIRT_BEGIN_ALLOW_THREADS;
8931 ret = virConnectStoragePoolEventRegisterAny(conn,
8932 pool,
8933 eventID,
8935 pyobj_cbData,
8936 libvirt_virConnectStoragePoolEventFreeFunc);
8937 LIBVIRT_END_ALLOW_THREADS;
8939 if (ret < 0) {
8940 Py_DECREF(pyobj_cbData);
8943 return libvirt_intWrap(ret);
8946 static PyObject *
8947 libvirt_virConnectStoragePoolEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
8948 PyObject *args)
8950 PyObject *pyobj_conn;
8951 int callbackID;
8952 virConnectPtr conn;
8953 int ret = 0;
8955 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectStoragePoolEventDeregisterAny",
8956 &pyobj_conn, &callbackID))
8957 return NULL;
8959 DEBUG("libvirt_virConnectStoragePoolEventDeregister(%p) called\n",
8960 pyobj_conn);
8962 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8964 LIBVIRT_BEGIN_ALLOW_THREADS;
8966 ret = virConnectStoragePoolEventDeregisterAny(conn, callbackID);
8968 LIBVIRT_END_ALLOW_THREADS;
8970 return libvirt_intWrap(ret);
8973 static PyObject *
8974 libvirt_virDomainGetGuestVcpus(PyObject *self ATTRIBUTE_UNUSED,
8975 PyObject *args)
8977 PyObject *pyobj_domain;
8978 virDomainPtr domain;
8979 virTypedParameterPtr params = NULL;
8980 unsigned int nparams = 0;
8981 unsigned int flags;
8982 int i_retval;
8983 PyObject *ret = NULL;
8985 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetGuestVcpus",
8986 &pyobj_domain, &flags))
8987 return NULL;
8988 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8990 LIBVIRT_BEGIN_ALLOW_THREADS;
8991 i_retval = virDomainGetGuestVcpus(domain, &params, &nparams, flags);
8992 LIBVIRT_END_ALLOW_THREADS;
8994 if (i_retval < 0) {
8995 ret = VIR_PY_NONE;
8996 goto cleanup;
8999 ret = getPyVirTypedParameter(params, nparams);
9000 cleanup:
9001 virTypedParamsFree(params, nparams);
9002 return ret;
9004 #endif /* LIBVIR_CHECK_VERSION(2, 0, 0)*/
9006 #if LIBVIR_CHECK_VERSION(2, 2, 0)
9007 static void
9008 libvirt_virConnectNodeDeviceEventFreeFunc(void *opaque)
9010 PyObject *pyobj_conn = (PyObject*)opaque;
9011 LIBVIRT_ENSURE_THREAD_STATE;
9012 Py_DECREF(pyobj_conn);
9013 LIBVIRT_RELEASE_THREAD_STATE;
9016 static int
9017 libvirt_virConnectNodeDeviceEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9018 virNodeDevicePtr dev,
9019 int event,
9020 int detail,
9021 void *opaque)
9023 PyObject *pyobj_cbData = (PyObject*)opaque;
9024 PyObject *pyobj_dev;
9025 PyObject *pyobj_ret = NULL;
9026 PyObject *pyobj_conn;
9027 PyObject *dictKey;
9028 int ret = -1;
9030 LIBVIRT_ENSURE_THREAD_STATE;
9032 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9033 goto cleanup;
9034 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9035 Py_DECREF(dictKey);
9037 /* Create a python instance of this virNodeDevicePtr */
9038 virNodeDeviceRef(dev);
9039 if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) {
9040 virNodeDeviceFree(dev);
9041 goto cleanup;
9043 Py_INCREF(pyobj_cbData);
9045 /* Call the Callback Dispatcher */
9046 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9047 (char*)"_dispatchNodeDeviceEventLifecycleCallback",
9048 (char*)"OiiO",
9049 pyobj_dev,
9050 event,
9051 detail,
9052 pyobj_cbData);
9054 Py_DECREF(pyobj_cbData);
9055 Py_DECREF(pyobj_dev);
9057 cleanup:
9058 if (!pyobj_ret) {
9059 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9060 PyErr_Print();
9061 } else {
9062 Py_DECREF(pyobj_ret);
9063 ret = 0;
9066 LIBVIRT_RELEASE_THREAD_STATE;
9067 return ret;
9070 static int
9071 libvirt_virConnectNodeDeviceEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9072 virNodeDevicePtr dev,
9073 void *opaque)
9075 PyObject *pyobj_cbData = (PyObject*)opaque;
9076 PyObject *pyobj_dev;
9077 PyObject *pyobj_ret = NULL;
9078 PyObject *pyobj_conn;
9079 PyObject *dictKey;
9080 int ret = -1;
9082 LIBVIRT_ENSURE_THREAD_STATE;
9084 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9085 goto cleanup;
9086 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9087 Py_DECREF(dictKey);
9089 /* Create a python instance of this virNodeDevicePtr */
9090 virNodeDeviceRef(dev);
9091 if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) {
9092 virNodeDeviceFree(dev);
9093 goto cleanup;
9095 Py_INCREF(pyobj_cbData);
9097 /* Call the Callback Dispatcher */
9098 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9099 (char*)"_dispatchNodeDeviceEventGenericCallback",
9100 (char*)"OO",
9101 pyobj_dev,
9102 pyobj_cbData);
9104 Py_DECREF(pyobj_cbData);
9105 Py_DECREF(pyobj_dev);
9107 cleanup:
9108 if (!pyobj_ret) {
9109 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9110 PyErr_Print();
9111 } else {
9112 Py_DECREF(pyobj_ret);
9113 ret = 0;
9116 LIBVIRT_RELEASE_THREAD_STATE;
9117 return ret;
9120 static PyObject *
9121 libvirt_virConnectNodeDeviceEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9122 PyObject *args)
9124 PyObject *pyobj_conn; /* virConnectPtr */
9125 PyObject *pyobj_dev;
9126 PyObject *pyobj_cbData; /* hash of callback data */
9127 int eventID;
9128 virConnectPtr conn;
9129 int ret = 0;
9130 virConnectNodeDeviceEventGenericCallback cb = NULL;
9131 virNodeDevicePtr dev;
9133 if (!PyArg_ParseTuple(args,
9134 (char *) "OOiO:virConnectNodeDeviceEventRegisterAny",
9135 &pyobj_conn, &pyobj_dev, &eventID, &pyobj_cbData))
9136 return NULL;
9138 DEBUG("libvirt_virConnectNodeDeviceEventRegister(%p %p %d %p) called\n",
9139 pyobj_conn, pyobj_dev, eventID, pyobj_cbData);
9140 conn = PyvirConnect_Get(pyobj_conn);
9141 if (pyobj_dev == Py_None)
9142 dev = NULL;
9143 else
9144 dev = PyvirNodeDevice_Get(pyobj_dev);
9146 switch ((virNodeDeviceEventID) eventID) {
9147 case VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE:
9148 cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventLifecycleCallback);
9149 break;
9151 case VIR_NODE_DEVICE_EVENT_ID_UPDATE:
9152 cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventGenericCallback);
9153 break;
9155 case VIR_NODE_DEVICE_EVENT_ID_LAST:
9156 break;
9159 if (!cb) {
9160 return VIR_PY_INT_FAIL;
9163 Py_INCREF(pyobj_cbData);
9165 LIBVIRT_BEGIN_ALLOW_THREADS;
9166 ret = virConnectNodeDeviceEventRegisterAny(conn,
9167 dev,
9168 eventID,
9170 pyobj_cbData,
9171 libvirt_virConnectNodeDeviceEventFreeFunc);
9172 LIBVIRT_END_ALLOW_THREADS;
9174 if (ret < 0) {
9175 Py_DECREF(pyobj_cbData);
9178 return libvirt_intWrap(ret);
9181 static PyObject *
9182 libvirt_virConnectNodeDeviceEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9183 PyObject *args)
9185 PyObject *pyobj_conn;
9186 int callbackID;
9187 virConnectPtr conn;
9188 int ret = 0;
9190 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectNodeDeviceEventDeregister",
9191 &pyobj_conn, &callbackID))
9192 return NULL;
9194 DEBUG("libvirt_virConnectNodeDeviceEventDeregister(%p) called\n",
9195 pyobj_conn);
9197 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9199 LIBVIRT_BEGIN_ALLOW_THREADS;
9201 ret = virConnectNodeDeviceEventDeregisterAny(conn, callbackID);
9203 LIBVIRT_END_ALLOW_THREADS;
9205 return libvirt_intWrap(ret);
9208 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0)*/
9210 /************************************************************************
9212 * The registration stuff *
9214 ************************************************************************/
9215 static PyMethodDef libvirtMethods[] = {
9216 #include "build/libvirt-export.c"
9217 {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
9218 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL},
9219 #if LIBVIR_CHECK_VERSION(1, 1, 3)
9220 {(char *) "virConnectGetCPUModelNames", libvirt_virConnectGetCPUModelNames, METH_VARARGS, NULL},
9221 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
9222 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
9223 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
9224 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
9225 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
9226 #if LIBVIR_CHECK_VERSION(0, 9, 13)
9227 {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
9228 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
9229 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
9230 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
9231 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
9232 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
9233 #if LIBVIR_CHECK_VERSION(1, 2, 1)
9234 {(char *) "virConnectNetworkEventRegisterAny", libvirt_virConnectNetworkEventRegisterAny, METH_VARARGS, NULL},
9235 {(char *) "virConnectNetworkEventDeregisterAny", libvirt_virConnectNetworkEventDeregisterAny, METH_VARARGS, NULL},
9236 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1) */
9237 #if LIBVIR_CHECK_VERSION(0, 10, 0)
9238 {(char *) "virConnectRegisterCloseCallback", libvirt_virConnectRegisterCloseCallback, METH_VARARGS, NULL},
9239 {(char *) "virConnectUnregisterCloseCallback", libvirt_virConnectUnregisterCloseCallback, METH_VARARGS, NULL},
9240 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
9241 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
9242 {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
9243 {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
9244 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
9245 {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
9246 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
9247 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
9248 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
9249 {(char *) "virNodeGetSecurityModel", libvirt_virNodeGetSecurityModel, METH_VARARGS, NULL},
9250 {(char *) "virDomainGetSecurityLabel", libvirt_virDomainGetSecurityLabel, METH_VARARGS, NULL},
9251 #if LIBVIR_CHECK_VERSION(0, 10, 0)
9252 {(char *) "virDomainGetSecurityLabelList", libvirt_virDomainGetSecurityLabelList, METH_VARARGS, NULL},
9253 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
9254 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
9255 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
9256 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
9257 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
9258 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
9259 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
9260 {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
9261 {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
9262 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
9263 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
9264 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9265 {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
9266 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9267 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
9268 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
9269 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},
9270 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL},
9271 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
9272 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
9273 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL},
9274 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats, METH_VARARGS, NULL},
9275 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
9276 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
9277 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
9278 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
9279 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
9280 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags, METH_VARARGS, NULL},
9281 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
9282 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags, METH_VARARGS, NULL},
9283 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters, METH_VARARGS, NULL},
9284 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters, METH_VARARGS, NULL},
9285 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters, METH_VARARGS, NULL},
9286 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
9287 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
9288 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
9289 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
9290 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
9291 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
9292 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
9293 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
9294 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
9295 #if LIBVIR_CHECK_VERSION(0, 10, 0)
9296 {(char *) "virDomainGetEmulatorPinInfo", libvirt_virDomainGetEmulatorPinInfo, METH_VARARGS, NULL},
9297 {(char *) "virDomainPinEmulator", libvirt_virDomainPinEmulator, METH_VARARGS, NULL},
9298 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
9299 #if LIBVIR_CHECK_VERSION(1, 2, 14)
9300 {(char *) "virDomainGetIOThreadInfo", libvirt_virDomainGetIOThreadInfo, METH_VARARGS, NULL},
9301 {(char *) "virDomainPinIOThread", libvirt_virDomainPinIOThread, METH_VARARGS, NULL},
9302 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
9303 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
9304 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
9305 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9306 {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
9307 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9308 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
9309 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
9310 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9311 {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
9312 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9313 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL},
9314 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL},
9315 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL},
9316 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL},
9317 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL},
9318 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
9319 {(char *) "virEventAddHandle", libvirt_virEventAddHandle, METH_VARARGS, NULL},
9320 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout, METH_VARARGS, NULL},
9321 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
9322 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
9323 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
9324 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9325 {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
9326 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9327 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
9328 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
9329 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},
9330 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL},
9331 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
9332 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9333 {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL},
9334 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9335 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
9336 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
9337 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL},
9338 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
9339 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
9340 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
9341 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9342 {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
9343 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9344 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
9345 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
9346 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9347 {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
9348 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9349 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
9350 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
9351 #if LIBVIR_CHECK_VERSION(1, 0, 3)
9352 {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL},
9353 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
9354 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
9355 #if LIBVIR_CHECK_VERSION(0, 9, 13)
9356 {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
9357 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
9358 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
9359 #if LIBVIR_CHECK_VERSION(0, 9, 13)
9360 {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
9361 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
9362 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
9363 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
9364 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
9365 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL},
9366 {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
9367 #if LIBVIR_CHECK_VERSION(1, 0, 3)
9368 {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL},
9369 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
9370 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
9371 #if LIBVIR_CHECK_VERSION(1, 1, 0)
9372 {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL},
9373 {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL},
9374 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
9375 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
9376 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
9377 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
9378 #if LIBVIR_CHECK_VERSION(0, 10, 2)
9379 {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
9380 {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
9381 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
9382 #if LIBVIR_CHECK_VERSION(1, 0, 0)
9383 {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
9384 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
9385 #if LIBVIR_CHECK_VERSION(1, 1, 1)
9386 {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL},
9387 {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL},
9388 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
9389 #if LIBVIR_CHECK_VERSION(1, 2, 5)
9390 {(char *) "virDomainFSFreeze", libvirt_virDomainFSFreeze, METH_VARARGS, NULL},
9391 {(char *) "virDomainFSThaw", libvirt_virDomainFSThaw, METH_VARARGS, NULL},
9392 {(char *) "virDomainGetTime", libvirt_virDomainGetTime, METH_VARARGS, NULL},
9393 {(char *) "virDomainSetTime", libvirt_virDomainSetTime, METH_VARARGS, NULL},
9394 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
9395 #if LIBVIR_CHECK_VERSION(1, 2, 6)
9396 {(char *) "virNodeGetFreePages", libvirt_virNodeGetFreePages, METH_VARARGS, NULL},
9397 {(char *) "virNetworkGetDHCPLeases", libvirt_virNetworkGetDHCPLeases, METH_VARARGS, NULL},
9398 #endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
9399 #if LIBVIR_CHECK_VERSION(1, 2, 8)
9400 {(char *) "virConnectGetAllDomainStats", libvirt_virConnectGetAllDomainStats, METH_VARARGS, NULL},
9401 {(char *) "virDomainListGetStats", libvirt_virDomainListGetStats, METH_VARARGS, NULL},
9402 {(char *) "virDomainBlockCopy", libvirt_virDomainBlockCopy, METH_VARARGS, NULL},
9403 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
9404 #if LIBVIR_CHECK_VERSION(1, 2, 9)
9405 {(char *) "virNodeAllocPages", libvirt_virNodeAllocPages, METH_VARARGS, NULL},
9406 #endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
9407 #if LIBVIR_CHECK_VERSION(1, 2, 11)
9408 {(char *) "virDomainGetFSInfo", libvirt_virDomainGetFSInfo, METH_VARARGS, NULL},
9409 #endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
9410 #if LIBVIR_CHECK_VERSION(1, 2, 14)
9411 {(char *) "virDomainInterfaceAddresses", libvirt_virDomainInterfaceAddresses, METH_VARARGS, NULL},
9412 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
9413 #if LIBVIR_CHECK_VERSION(1, 3, 3)
9414 {(char *) "virDomainGetPerfEvents", libvirt_virDomainGetPerfEvents, METH_VARARGS, NULL},
9415 {(char *) "virDomainSetPerfEvents", libvirt_virDomainSetPerfEvents, METH_VARARGS, NULL},
9416 #endif /* LIBVIR_CHECK_VERSION(1, 3, 3) */
9417 #if LIBVIR_CHECK_VERSION(2, 0, 0)
9418 {(char *) "virConnectStoragePoolEventRegisterAny", libvirt_virConnectStoragePoolEventRegisterAny, METH_VARARGS, NULL},
9419 {(char *) "virConnectStoragePoolEventDeregisterAny", libvirt_virConnectStoragePoolEventDeregisterAny, METH_VARARGS, NULL},
9420 {(char *) "virDomainGetGuestVcpus", libvirt_virDomainGetGuestVcpus, METH_VARARGS, NULL},
9421 #endif /* LIBVIR_CHECK_VERSION(2, 0, 0) */
9422 #if LIBVIR_CHECK_VERSION(2, 2, 0)
9423 {(char *) "virConnectNodeDeviceEventRegisterAny", libvirt_virConnectNodeDeviceEventRegisterAny, METH_VARARGS, NULL},
9424 {(char *) "virConnectNodeDeviceEventDeregisterAny", libvirt_virConnectNodeDeviceEventDeregisterAny, METH_VARARGS, NULL},
9425 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0) */
9426 {NULL, NULL, 0, NULL}
9429 #if PY_MAJOR_VERSION > 2
9430 static struct PyModuleDef moduledef = {
9431 PyModuleDef_HEAD_INIT,
9432 # ifndef __CYGWIN__
9433 "libvirtmod",
9434 # else
9435 "cygvirtmod",
9436 # endif
9437 NULL,
9439 libvirtMethods,
9440 NULL,
9441 NULL,
9442 NULL,
9443 NULL
9446 PyObject *
9447 # ifndef __CYGWIN__
9448 PyInit_libvirtmod
9449 # else
9450 PyInit_cygvirtmod
9451 # endif
9452 (void)
9454 PyObject *module;
9456 if (virInitialize() < 0)
9457 return NULL;
9459 module = PyModule_Create(&moduledef);
9461 return module;
9463 #else /* ! PY_MAJOR_VERSION > 2 */
9464 void
9465 # ifndef __CYGWIN__
9466 initlibvirtmod
9467 # else
9468 initcygvirtmod
9469 # endif
9470 (void)
9472 if (virInitialize() < 0)
9473 return;
9475 /* initialize the python extension module */
9476 Py_InitModule((char *)
9477 # ifndef __CYGWIN__
9478 "libvirtmod",
9479 # else
9480 "cygvirtmod",
9481 # endif
9482 libvirtMethods);
9484 #endif /* ! PY_MAJOR_VERSION > 2 */