Define virNetworkPortPtr typedef on old libvirt
[libvirt-python/ericb.git] / libvirt-override.c
blobc73305b00a4375640489578040d1f536107069c7
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 ssize_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 ssize_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 LIBVIRT_BEGIN_ALLOW_THREADS;
367 nr_stats = virDomainMemoryStats(domain, stats,
368 VIR_DOMAIN_MEMORY_STAT_NR, 0);
369 LIBVIRT_END_ALLOW_THREADS;
371 if (nr_stats == (unsigned int)-1)
372 return VIR_PY_NONE;
374 /* convert to a Python dictionary */
375 if ((info = PyDict_New()) == NULL)
376 return NULL;
378 for (i = 0; i < nr_stats; i++) {
379 switch (stats[i].tag) {
380 case VIR_DOMAIN_MEMORY_STAT_SWAP_IN:
381 key = libvirt_constcharPtrWrap("swap_in");
382 break;
383 case VIR_DOMAIN_MEMORY_STAT_SWAP_OUT:
384 key = libvirt_constcharPtrWrap("swap_out");
385 break;
386 case VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT:
387 key = libvirt_constcharPtrWrap("major_fault");
388 break;
389 case VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT:
390 key = libvirt_constcharPtrWrap("minor_fault");
391 break;
392 case VIR_DOMAIN_MEMORY_STAT_UNUSED:
393 key = libvirt_constcharPtrWrap("unused");
394 break;
395 case VIR_DOMAIN_MEMORY_STAT_AVAILABLE:
396 key = libvirt_constcharPtrWrap("available");
397 break;
398 case VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON:
399 key = libvirt_constcharPtrWrap("actual");
400 break;
401 case VIR_DOMAIN_MEMORY_STAT_RSS:
402 key = libvirt_constcharPtrWrap("rss");
403 break;
404 #if LIBVIR_CHECK_VERSION(2, 1, 0)
405 case VIR_DOMAIN_MEMORY_STAT_USABLE:
406 key = libvirt_constcharPtrWrap("usable");
407 break;
408 case VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE:
409 key = libvirt_constcharPtrWrap("last_update");
410 break;
411 #endif /* LIBVIR_CHECK_VERSION(2, 1, 0) */
412 default:
413 continue;
415 val = libvirt_ulonglongWrap(stats[i].val);
417 VIR_PY_DICT_SET_GOTO(info, key, val, error);
420 return info;
422 error:
423 Py_DECREF(info);
424 return NULL;
427 static PyObject *
428 libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
429 PyObject *args)
431 virDomainPtr domain;
432 PyObject *pyobj_domain, *info;
433 char *c_retval;
434 int nparams;
436 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerType",
437 &pyobj_domain))
438 return NULL;
439 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
441 LIBVIRT_BEGIN_ALLOW_THREADS;
442 c_retval = virDomainGetSchedulerType(domain, &nparams);
443 LIBVIRT_END_ALLOW_THREADS;
445 if (c_retval == NULL)
446 return VIR_PY_NONE;
448 /* convert to a Python tuple of long objects */
449 if ((info = PyTuple_New(2)) == NULL)
450 goto cleanup;
452 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_constcharPtrWrap(c_retval), error);
453 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)nparams), error);
455 cleanup:
456 VIR_FREE(c_retval);
457 return info;
459 error:
460 Py_CLEAR(info);
461 goto cleanup;
465 static PyObject *
466 libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
467 PyObject *args)
469 virDomainPtr domain;
470 PyObject *pyobj_domain;
471 PyObject *ret = NULL;
472 char *c_retval;
473 int i_retval;
474 int nparams = 0;
475 virTypedParameterPtr params;
477 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerParameters",
478 &pyobj_domain))
479 return NULL;
480 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
482 LIBVIRT_BEGIN_ALLOW_THREADS;
483 c_retval = virDomainGetSchedulerType(domain, &nparams);
484 LIBVIRT_END_ALLOW_THREADS;
486 if (c_retval == NULL)
487 return VIR_PY_NONE;
488 VIR_FREE(c_retval);
490 if (!nparams)
491 return PyDict_New();
493 if (VIR_ALLOC_N(params, nparams) < 0)
494 return PyErr_NoMemory();
496 LIBVIRT_BEGIN_ALLOW_THREADS;
497 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
498 LIBVIRT_END_ALLOW_THREADS;
500 if (i_retval < 0) {
501 ret = VIR_PY_NONE;
502 goto cleanup;
505 ret = getPyVirTypedParameter(params, nparams);
507 cleanup:
508 virTypedParamsFree(params, nparams);
509 return ret;
512 static PyObject *
513 libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
514 PyObject *args)
516 virDomainPtr domain;
517 PyObject *pyobj_domain;
518 PyObject *ret = NULL;
519 char *c_retval;
520 int i_retval;
521 int nparams = 0;
522 unsigned int flags;
523 virTypedParameterPtr params;
525 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetScedulerParametersFlags",
526 &pyobj_domain, &flags))
527 return NULL;
528 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
530 LIBVIRT_BEGIN_ALLOW_THREADS;
531 c_retval = virDomainGetSchedulerType(domain, &nparams);
532 LIBVIRT_END_ALLOW_THREADS;
534 if (c_retval == NULL)
535 return VIR_PY_NONE;
536 VIR_FREE(c_retval);
538 if (!nparams)
539 return PyDict_New();
541 if (VIR_ALLOC_N(params, nparams) < 0)
542 return PyErr_NoMemory();
544 LIBVIRT_BEGIN_ALLOW_THREADS;
545 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams,
546 flags);
547 LIBVIRT_END_ALLOW_THREADS;
549 if (i_retval < 0) {
550 ret = VIR_PY_NONE;
551 goto cleanup;
554 ret = getPyVirTypedParameter(params, nparams);
556 cleanup:
557 virTypedParamsFree(params, nparams);
558 return ret;
561 static PyObject *
562 libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
563 PyObject *args)
565 virDomainPtr domain;
566 PyObject *pyobj_domain, *info;
567 PyObject *ret = NULL;
568 char *c_retval;
569 int i_retval;
570 int nparams = 0;
571 Py_ssize_t size = 0;
572 virTypedParameterPtr params = NULL, new_params = NULL;
574 if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetSchedulerParameters",
575 &pyobj_domain, &info))
576 return NULL;
577 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
579 if ((size = PyDict_Size(info)) < 0)
580 return NULL;
582 if (size == 0) {
583 PyErr_Format(PyExc_LookupError,
584 "Need non-empty dictionary to set attributes");
585 return NULL;
588 LIBVIRT_BEGIN_ALLOW_THREADS;
589 c_retval = virDomainGetSchedulerType(domain, &nparams);
590 LIBVIRT_END_ALLOW_THREADS;
592 if (c_retval == NULL)
593 return VIR_PY_INT_FAIL;
594 VIR_FREE(c_retval);
596 if (nparams == 0) {
597 PyErr_Format(PyExc_LookupError,
598 "Domain has no settable attributes");
599 return NULL;
602 if (VIR_ALLOC_N(params, nparams) < 0)
603 return PyErr_NoMemory();
605 LIBVIRT_BEGIN_ALLOW_THREADS;
606 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
607 LIBVIRT_END_ALLOW_THREADS;
609 if (i_retval < 0) {
610 ret = VIR_PY_INT_FAIL;
611 goto cleanup;
614 new_params = setPyVirTypedParameter(info, params, nparams);
615 if (!new_params)
616 goto cleanup;
618 LIBVIRT_BEGIN_ALLOW_THREADS;
619 i_retval = virDomainSetSchedulerParameters(domain, new_params, size);
620 LIBVIRT_END_ALLOW_THREADS;
622 if (i_retval < 0) {
623 ret = VIR_PY_INT_FAIL;
624 goto cleanup;
627 ret = VIR_PY_INT_SUCCESS;
629 cleanup:
630 virTypedParamsFree(params, nparams);
631 virTypedParamsFree(new_params, size);
632 return ret;
635 static PyObject *
636 libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
637 PyObject *args)
639 virDomainPtr domain;
640 PyObject *pyobj_domain, *info;
641 PyObject *ret = NULL;
642 char *c_retval;
643 int i_retval;
644 int nparams = 0;
645 Py_ssize_t size = 0;
646 unsigned int flags;
647 virTypedParameterPtr params = NULL, new_params = NULL;
649 if (!PyArg_ParseTuple(args,
650 (char *)"OOI:virDomainSetSchedulerParametersFlags",
651 &pyobj_domain, &info, &flags))
652 return NULL;
653 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
655 if ((size = PyDict_Size(info)) < 0)
656 return NULL;
658 if (size == 0) {
659 PyErr_Format(PyExc_LookupError,
660 "Need non-empty dictionary to set attributes");
661 return NULL;
664 LIBVIRT_BEGIN_ALLOW_THREADS;
665 c_retval = virDomainGetSchedulerType(domain, &nparams);
666 LIBVIRT_END_ALLOW_THREADS;
668 if (c_retval == NULL)
669 return VIR_PY_INT_FAIL;
670 VIR_FREE(c_retval);
672 if (nparams == 0) {
673 PyErr_Format(PyExc_LookupError,
674 "Domain has no settable attributes");
675 return NULL;
678 if (VIR_ALLOC_N(params, nparams) < 0)
679 return PyErr_NoMemory();
681 LIBVIRT_BEGIN_ALLOW_THREADS;
682 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams,
683 flags);
684 LIBVIRT_END_ALLOW_THREADS;
686 if (i_retval < 0) {
687 ret = VIR_PY_INT_FAIL;
688 goto cleanup;
691 new_params = setPyVirTypedParameter(info, params, nparams);
692 if (!new_params)
693 goto cleanup;
695 LIBVIRT_BEGIN_ALLOW_THREADS;
696 i_retval = virDomainSetSchedulerParametersFlags(domain, new_params, size,
697 flags);
698 LIBVIRT_END_ALLOW_THREADS;
700 if (i_retval < 0) {
701 ret = VIR_PY_INT_FAIL;
702 goto cleanup;
705 ret = VIR_PY_INT_SUCCESS;
707 cleanup:
708 virTypedParamsFree(params, nparams);
709 virTypedParamsFree(new_params, size);
710 return ret;
713 static PyObject *
714 libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
715 PyObject *args)
717 virDomainPtr domain;
718 PyObject *pyobj_domain, *info;
719 PyObject *ret = NULL;
720 int i_retval;
721 int nparams = 0;
722 Py_ssize_t size = 0;
723 unsigned int flags;
724 virTypedParameterPtr params = NULL, new_params = NULL;
726 if (!PyArg_ParseTuple(args,
727 (char *)"OOI:virDomainSetBlkioParameters",
728 &pyobj_domain, &info, &flags))
729 return NULL;
730 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
732 if ((size = PyDict_Size(info)) < 0)
733 return NULL;
735 if (size == 0) {
736 PyErr_Format(PyExc_LookupError,
737 "Need non-empty dictionary to set attributes");
738 return NULL;
741 LIBVIRT_BEGIN_ALLOW_THREADS;
742 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
743 LIBVIRT_END_ALLOW_THREADS;
745 if (i_retval < 0)
746 return VIR_PY_INT_FAIL;
748 if (nparams == 0) {
749 PyErr_Format(PyExc_LookupError,
750 "Domain has no settable attributes");
751 return NULL;
754 if (VIR_ALLOC_N(params, nparams) < 0)
755 return PyErr_NoMemory();
757 LIBVIRT_BEGIN_ALLOW_THREADS;
758 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
759 LIBVIRT_END_ALLOW_THREADS;
761 if (i_retval < 0) {
762 ret = VIR_PY_INT_FAIL;
763 goto cleanup;
766 new_params = setPyVirTypedParameter(info, params, nparams);
767 if (!new_params)
768 goto cleanup;
770 LIBVIRT_BEGIN_ALLOW_THREADS;
771 i_retval = virDomainSetBlkioParameters(domain, new_params, size, flags);
772 LIBVIRT_END_ALLOW_THREADS;
774 if (i_retval < 0) {
775 ret = VIR_PY_INT_FAIL;
776 goto cleanup;
779 ret = VIR_PY_INT_SUCCESS;
781 cleanup:
782 virTypedParamsFree(params, nparams);
783 virTypedParamsFree(new_params, size);
784 return ret;
787 static PyObject *
788 libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
789 PyObject *args)
791 virDomainPtr domain;
792 PyObject *pyobj_domain;
793 PyObject *ret = NULL;
794 int i_retval;
795 int nparams = 0;
796 unsigned int flags;
797 virTypedParameterPtr params;
799 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetBlkioParameters",
800 &pyobj_domain, &flags))
801 return NULL;
802 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
804 LIBVIRT_BEGIN_ALLOW_THREADS;
805 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
806 LIBVIRT_END_ALLOW_THREADS;
808 if (i_retval < 0)
809 return VIR_PY_NONE;
811 if (!nparams)
812 return PyDict_New();
814 if (VIR_ALLOC_N(params, nparams) < 0)
815 return PyErr_NoMemory();
817 LIBVIRT_BEGIN_ALLOW_THREADS;
818 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
819 LIBVIRT_END_ALLOW_THREADS;
821 if (i_retval < 0) {
822 ret = VIR_PY_NONE;
823 goto cleanup;
826 ret = getPyVirTypedParameter(params, nparams);
828 cleanup:
829 virTypedParamsFree(params, nparams);
830 return ret;
833 static PyObject *
834 libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
835 PyObject *args)
837 virDomainPtr domain;
838 PyObject *pyobj_domain, *info;
839 PyObject *ret = NULL;
840 int i_retval;
841 int nparams = 0;
842 Py_ssize_t size = 0;
843 unsigned int flags;
844 virTypedParameterPtr params = NULL, new_params = NULL;
846 if (!PyArg_ParseTuple(args,
847 (char *)"OOI:virDomainSetMemoryParameters",
848 &pyobj_domain, &info, &flags))
849 return NULL;
850 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
852 if ((size = PyDict_Size(info)) < 0)
853 return NULL;
855 if (size == 0) {
856 PyErr_Format(PyExc_LookupError,
857 "Need non-empty dictionary to set attributes");
858 return NULL;
861 LIBVIRT_BEGIN_ALLOW_THREADS;
862 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
863 LIBVIRT_END_ALLOW_THREADS;
865 if (i_retval < 0)
866 return VIR_PY_INT_FAIL;
868 if (nparams == 0) {
869 PyErr_Format(PyExc_LookupError,
870 "Domain has no settable attributes");
871 return NULL;
874 if (VIR_ALLOC_N(params, nparams) < 0)
875 return PyErr_NoMemory();
877 LIBVIRT_BEGIN_ALLOW_THREADS;
878 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
879 LIBVIRT_END_ALLOW_THREADS;
881 if (i_retval < 0) {
882 ret = VIR_PY_INT_FAIL;
883 goto cleanup;
886 new_params = setPyVirTypedParameter(info, params, nparams);
887 if (!new_params)
888 goto cleanup;
890 LIBVIRT_BEGIN_ALLOW_THREADS;
891 i_retval = virDomainSetMemoryParameters(domain, new_params, size, flags);
892 LIBVIRT_END_ALLOW_THREADS;
894 if (i_retval < 0) {
895 ret = VIR_PY_INT_FAIL;
896 goto cleanup;
899 ret = VIR_PY_INT_SUCCESS;
901 cleanup:
902 virTypedParamsFree(params, nparams);
903 virTypedParamsFree(new_params, size);
904 return ret;
907 static PyObject *
908 libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
909 PyObject *args)
911 virDomainPtr domain;
912 PyObject *pyobj_domain;
913 PyObject *ret = NULL;
914 int i_retval;
915 int nparams = 0;
916 unsigned int flags;
917 virTypedParameterPtr params;
919 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetMemoryParameters",
920 &pyobj_domain, &flags))
921 return NULL;
922 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
924 LIBVIRT_BEGIN_ALLOW_THREADS;
925 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
926 LIBVIRT_END_ALLOW_THREADS;
928 if (i_retval < 0)
929 return VIR_PY_NONE;
931 if (!nparams)
932 return PyDict_New();
934 if (VIR_ALLOC_N(params, nparams) < 0)
935 return PyErr_NoMemory();
937 LIBVIRT_BEGIN_ALLOW_THREADS;
938 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
939 LIBVIRT_END_ALLOW_THREADS;
941 if (i_retval < 0) {
942 ret = VIR_PY_NONE;
943 goto cleanup;
946 ret = getPyVirTypedParameter(params, nparams);
948 cleanup:
949 virTypedParamsFree(params, nparams);
950 return ret;
953 static PyObject *
954 libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
955 PyObject *args)
957 virDomainPtr domain;
958 PyObject *pyobj_domain, *info;
959 PyObject *ret = NULL;
960 int i_retval;
961 int nparams = 0;
962 Py_ssize_t size = 0;
963 unsigned int flags;
964 virTypedParameterPtr params = NULL, new_params = NULL;
966 if (!PyArg_ParseTuple(args,
967 (char *)"OOI:virDomainSetNumaParameters",
968 &pyobj_domain, &info, &flags))
969 return NULL;
970 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
972 if ((size = PyDict_Size(info)) < 0)
973 return NULL;
975 if (size == 0) {
976 PyErr_Format(PyExc_LookupError,
977 "Need non-empty dictionary to set attributes");
978 return NULL;
981 LIBVIRT_BEGIN_ALLOW_THREADS;
982 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
983 LIBVIRT_END_ALLOW_THREADS;
985 if (i_retval < 0)
986 return VIR_PY_INT_FAIL;
988 if (nparams == 0) {
989 PyErr_Format(PyExc_LookupError,
990 "Domain has no settable attributes");
991 return NULL;
994 if (VIR_ALLOC_N(params, nparams) < 0)
995 return PyErr_NoMemory();
997 LIBVIRT_BEGIN_ALLOW_THREADS;
998 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
999 LIBVIRT_END_ALLOW_THREADS;
1001 if (i_retval < 0) {
1002 ret = VIR_PY_INT_FAIL;
1003 goto cleanup;
1006 new_params = setPyVirTypedParameter(info, params, nparams);
1007 if (!new_params)
1008 goto cleanup;
1010 LIBVIRT_BEGIN_ALLOW_THREADS;
1011 i_retval = virDomainSetNumaParameters(domain, new_params, size, flags);
1012 LIBVIRT_END_ALLOW_THREADS;
1014 if (i_retval < 0) {
1015 ret = VIR_PY_INT_FAIL;
1016 goto cleanup;
1019 ret = VIR_PY_INT_SUCCESS;
1021 cleanup:
1022 virTypedParamsFree(params, nparams);
1023 virTypedParamsFree(new_params, size);
1024 return ret;
1027 static PyObject *
1028 libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1029 PyObject *args)
1031 virDomainPtr domain;
1032 PyObject *pyobj_domain;
1033 PyObject *ret = NULL;
1034 int i_retval;
1035 int nparams = 0;
1036 unsigned int flags;
1037 virTypedParameterPtr params;
1039 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetNumaParameters",
1040 &pyobj_domain, &flags))
1041 return NULL;
1042 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1044 LIBVIRT_BEGIN_ALLOW_THREADS;
1045 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1046 LIBVIRT_END_ALLOW_THREADS;
1048 if (i_retval < 0)
1049 return VIR_PY_NONE;
1051 if (!nparams)
1052 return PyDict_New();
1054 if (VIR_ALLOC_N(params, nparams) < 0)
1055 return PyErr_NoMemory();
1057 LIBVIRT_BEGIN_ALLOW_THREADS;
1058 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1059 LIBVIRT_END_ALLOW_THREADS;
1061 if (i_retval < 0) {
1062 ret = VIR_PY_NONE;
1063 goto cleanup;
1066 ret = getPyVirTypedParameter(params, nparams);
1068 cleanup:
1069 virTypedParamsFree(params, nparams);
1070 return ret;
1073 static PyObject *
1074 libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1075 PyObject *args)
1077 virDomainPtr domain;
1078 PyObject *pyobj_domain, *info;
1079 PyObject *ret = NULL;
1080 int i_retval;
1081 int nparams = 0;
1082 Py_ssize_t size = 0;
1083 unsigned int flags;
1084 const char *device = NULL;
1085 virTypedParameterPtr params = NULL, new_params = NULL;
1087 if (!PyArg_ParseTuple(args,
1088 (char *)"OzOI:virDomainSetInterfaceParameters",
1089 &pyobj_domain, &device, &info, &flags))
1090 return NULL;
1091 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1093 if ((size = PyDict_Size(info)) < 0)
1094 return NULL;
1096 if (size == 0) {
1097 PyErr_Format(PyExc_LookupError,
1098 "Need non-empty dictionary to set attributes");
1099 return NULL;
1102 LIBVIRT_BEGIN_ALLOW_THREADS;
1103 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams,
1104 flags);
1105 LIBVIRT_END_ALLOW_THREADS;
1107 if (i_retval < 0)
1108 return VIR_PY_INT_FAIL;
1110 if (nparams == 0) {
1111 PyErr_Format(PyExc_LookupError,
1112 "Domain has no settable attributes");
1113 return NULL;
1116 if (VIR_ALLOC_N(params, nparams) < 0)
1117 return PyErr_NoMemory();
1119 LIBVIRT_BEGIN_ALLOW_THREADS;
1120 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams,
1121 flags);
1122 LIBVIRT_END_ALLOW_THREADS;
1124 if (i_retval < 0) {
1125 ret = VIR_PY_INT_FAIL;
1126 goto cleanup;
1129 new_params = setPyVirTypedParameter(info, params, nparams);
1130 if (!new_params)
1131 goto cleanup;
1133 LIBVIRT_BEGIN_ALLOW_THREADS;
1134 i_retval = virDomainSetInterfaceParameters(domain, device, new_params, size,
1135 flags);
1136 LIBVIRT_END_ALLOW_THREADS;
1138 if (i_retval < 0) {
1139 ret = VIR_PY_INT_FAIL;
1140 goto cleanup;
1143 ret = VIR_PY_INT_SUCCESS;
1145 cleanup:
1146 virTypedParamsFree(params, nparams);
1147 virTypedParamsFree(new_params, size);
1148 return ret;
1151 static PyObject *
1152 libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1153 PyObject *args)
1155 virDomainPtr domain;
1156 PyObject *pyobj_domain;
1157 PyObject *ret = NULL;
1158 int i_retval;
1159 int nparams = 0;
1160 unsigned int flags;
1161 const char *device = NULL;
1162 virTypedParameterPtr params;
1164 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetInterfaceParameters",
1165 &pyobj_domain, &device, &flags))
1166 return NULL;
1167 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1169 LIBVIRT_BEGIN_ALLOW_THREADS;
1170 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams,
1171 flags);
1172 LIBVIRT_END_ALLOW_THREADS;
1174 if (i_retval < 0)
1175 return VIR_PY_NONE;
1177 if (!nparams)
1178 return PyDict_New();
1180 if (VIR_ALLOC_N(params, nparams) < 0)
1181 return PyErr_NoMemory();
1183 LIBVIRT_BEGIN_ALLOW_THREADS;
1184 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams,
1185 flags);
1186 LIBVIRT_END_ALLOW_THREADS;
1188 if (i_retval < 0) {
1189 ret = VIR_PY_NONE;
1190 goto cleanup;
1193 ret = getPyVirTypedParameter(params, nparams);
1195 cleanup:
1196 virTypedParamsFree(params, nparams);
1197 return ret;
1200 static PyObject *
1201 libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
1202 PyObject *args)
1204 virDomainPtr domain;
1205 PyObject *pyobj_domain, *pyretval = NULL;
1206 PyObject *pycpuinfo = NULL, *pycpumap = NULL;
1207 PyObject *error = NULL;
1208 virDomainInfo dominfo;
1209 virVcpuInfoPtr cpuinfo = NULL;
1210 unsigned char *cpumap = NULL;
1211 ssize_t cpumaplen, i;
1212 int i_retval, cpunum;
1214 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
1215 &pyobj_domain))
1216 return NULL;
1217 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1219 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1220 return VIR_PY_NONE;
1222 LIBVIRT_BEGIN_ALLOW_THREADS;
1223 i_retval = virDomainGetInfo(domain, &dominfo);
1224 LIBVIRT_END_ALLOW_THREADS;
1226 if (i_retval < 0)
1227 return VIR_PY_NONE;
1229 if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0)
1230 return PyErr_NoMemory();
1232 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1233 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1234 VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) {
1235 error = PyErr_NoMemory();
1236 goto cleanup;
1239 LIBVIRT_BEGIN_ALLOW_THREADS;
1240 i_retval = virDomainGetVcpus(domain,
1241 cpuinfo, dominfo.nrVirtCpu,
1242 cpumap, cpumaplen);
1243 LIBVIRT_END_ALLOW_THREADS;
1245 if (i_retval < 0) {
1246 error = VIR_PY_NONE;
1247 goto cleanup;
1250 /* convert to a Python tuple of long objects */
1251 if ((pyretval = PyTuple_New(2)) == NULL)
1252 goto cleanup;
1253 if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
1254 goto cleanup;
1256 VIR_PY_TUPLE_SET_GOTO(pyretval, 0, pycpuinfo, cleanup);
1258 if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
1259 goto cleanup;
1261 VIR_PY_TUPLE_SET_GOTO(pyretval, 1, pycpumap, cleanup);
1263 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1264 PyObject *info = PyTuple_New(4);
1266 if (info == NULL)
1267 goto cleanup;
1269 VIR_PY_LIST_SET_GOTO(pycpuinfo, i, info, cleanup);
1271 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)cpuinfo[i].number),
1272 cleanup);
1273 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)cpuinfo[i].state),
1274 cleanup);
1275 VIR_PY_TUPLE_SET_GOTO(info, 2,
1276 libvirt_ulonglongWrap((long)cpuinfo[i].cpuTime),
1277 cleanup);
1278 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)cpuinfo[i].cpu),
1279 cleanup);
1281 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1282 PyObject *info = PyTuple_New(cpunum);
1283 ssize_t j;
1284 if (info == NULL)
1285 goto cleanup;
1287 VIR_PY_LIST_SET_GOTO(pycpumap, i, info, cleanup);
1289 for (j = 0; j < cpunum; j++) {
1290 VIR_PY_TUPLE_SET_GOTO(info, j,
1291 PyBool_FromLong(VIR_CPU_USABLE(cpumap,
1292 cpumaplen,
1293 i, j)),
1294 cleanup);
1298 VIR_FREE(cpuinfo);
1299 VIR_FREE(cpumap);
1301 return pyretval;
1303 cleanup:
1304 VIR_FREE(cpuinfo);
1305 VIR_FREE(cpumap);
1306 Py_XDECREF(pyretval);
1307 return error;
1311 static PyObject *
1312 libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
1313 PyObject *args)
1315 virDomainPtr domain;
1316 PyObject *pyobj_domain, *pycpumap;
1317 PyObject *ret = NULL;
1318 unsigned char *cpumap;
1319 int cpumaplen, vcpu, cpunum;
1320 int i_retval;
1322 if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu",
1323 &pyobj_domain, &vcpu, &pycpumap))
1324 return NULL;
1325 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1327 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1328 return VIR_PY_INT_FAIL;
1330 if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0)
1331 return NULL;
1333 LIBVIRT_BEGIN_ALLOW_THREADS;
1334 i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen);
1335 LIBVIRT_END_ALLOW_THREADS;
1337 if (i_retval < 0) {
1338 ret = VIR_PY_INT_FAIL;
1339 goto cleanup;
1341 ret = VIR_PY_INT_SUCCESS;
1343 cleanup:
1344 VIR_FREE(cpumap);
1345 return ret;
1348 static PyObject *
1349 libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED,
1350 PyObject *args)
1352 virDomainPtr domain;
1353 PyObject *pyobj_domain, *pycpumap;
1354 PyObject *ret = NULL;
1355 unsigned char *cpumap;
1356 int cpumaplen, vcpu, cpunum;
1357 unsigned int flags;
1358 int i_retval;
1360 if (!PyArg_ParseTuple(args, (char *)"OiOI:virDomainPinVcpuFlags",
1361 &pyobj_domain, &vcpu, &pycpumap, &flags))
1362 return NULL;
1363 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1365 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1366 return VIR_PY_INT_FAIL;
1368 if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0)
1369 return NULL;
1371 LIBVIRT_BEGIN_ALLOW_THREADS;
1372 i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags);
1373 LIBVIRT_END_ALLOW_THREADS;
1374 if (i_retval < 0) {
1375 ret = VIR_PY_INT_FAIL;
1376 goto cleanup;
1378 ret = VIR_PY_INT_SUCCESS;
1380 cleanup:
1381 VIR_FREE(cpumap);
1382 return ret;
1385 static PyObject *
1386 libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1387 PyObject *args)
1389 virDomainPtr domain;
1390 PyObject *pyobj_domain, *pycpumaps = NULL, *error = NULL;
1391 virDomainInfo dominfo;
1392 unsigned char *cpumaps = NULL;
1393 ssize_t cpumaplen, vcpu, pcpu;
1394 unsigned int flags;
1395 int i_retval, cpunum;
1397 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetVcpuPinInfo",
1398 &pyobj_domain, &flags))
1399 return NULL;
1400 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1402 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1403 return VIR_PY_NONE;
1405 LIBVIRT_BEGIN_ALLOW_THREADS;
1406 i_retval = virDomainGetInfo(domain, &dominfo);
1407 LIBVIRT_END_ALLOW_THREADS;
1409 if (i_retval < 0)
1410 return VIR_PY_NONE;
1412 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1413 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1414 VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0)
1415 goto cleanup;
1417 LIBVIRT_BEGIN_ALLOW_THREADS;
1418 i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu,
1419 cpumaps, cpumaplen, flags);
1420 LIBVIRT_END_ALLOW_THREADS;
1422 if (i_retval < 0) {
1423 error = VIR_PY_NONE;
1424 goto cleanup;
1427 if ((pycpumaps = PyList_New(dominfo.nrVirtCpu)) == NULL)
1428 goto cleanup;
1430 for (vcpu = 0; vcpu < dominfo.nrVirtCpu; vcpu++) {
1431 PyObject *mapinfo = PyTuple_New(cpunum);
1432 if (mapinfo == NULL)
1433 goto cleanup;
1435 VIR_PY_LIST_SET_GOTO(pycpumaps, vcpu, mapinfo, cleanup);
1437 for (pcpu = 0; pcpu < cpunum; pcpu++) {
1438 VIR_PY_TUPLE_SET_GOTO(mapinfo,
1439 pcpu,
1440 PyBool_FromLong(VIR_CPU_USABLE(cpumaps,
1441 cpumaplen,
1442 vcpu,
1443 pcpu)),
1444 cleanup);
1448 VIR_FREE(cpumaps);
1450 return pycpumaps;
1452 cleanup:
1453 VIR_FREE(cpumaps);
1455 Py_XDECREF(pycpumaps);
1457 return error;
1461 #if LIBVIR_CHECK_VERSION(0, 10, 0)
1462 static PyObject *
1463 libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED,
1464 PyObject *args)
1466 virDomainPtr domain;
1467 PyObject *pyobj_domain, *pycpumap;
1468 unsigned char *cpumap = NULL;
1469 int cpumaplen, cpunum;
1470 int i_retval;
1471 unsigned int flags;
1473 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainPinEmulator",
1474 &pyobj_domain, &pycpumap, &flags))
1475 return NULL;
1477 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1479 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1480 return VIR_PY_INT_FAIL;
1482 if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0)
1483 return NULL;
1485 LIBVIRT_BEGIN_ALLOW_THREADS;
1486 i_retval = virDomainPinEmulator(domain, cpumap, cpumaplen, flags);
1487 LIBVIRT_END_ALLOW_THREADS;
1489 VIR_FREE(cpumap);
1491 if (i_retval < 0)
1492 return VIR_PY_INT_FAIL;
1494 return VIR_PY_INT_SUCCESS;
1498 static PyObject *
1499 libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1500 PyObject *args)
1502 virDomainPtr domain;
1503 PyObject *pyobj_domain;
1504 PyObject *pycpumap;
1505 unsigned char *cpumap;
1506 ssize_t cpumaplen;
1507 ssize_t pcpu;
1508 unsigned int flags;
1509 int ret;
1510 int cpunum;
1512 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetEmulatorPinInfo",
1513 &pyobj_domain, &flags))
1514 return NULL;
1516 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1518 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1519 return VIR_PY_NONE;
1521 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1523 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1524 return PyErr_NoMemory();
1526 LIBVIRT_BEGIN_ALLOW_THREADS;
1527 ret = virDomainGetEmulatorPinInfo(domain, cpumap, cpumaplen, flags);
1528 LIBVIRT_END_ALLOW_THREADS;
1530 if (ret < 0) {
1531 VIR_FREE(cpumap);
1532 return VIR_PY_NONE;
1535 if (!(pycpumap = PyTuple_New(cpunum))) {
1536 VIR_FREE(cpumap);
1537 return NULL;
1540 for (pcpu = 0; pcpu < cpunum; pcpu++) {
1541 VIR_PY_TUPLE_SET_GOTO(pycpumap,
1542 pcpu,
1543 PyBool_FromLong(VIR_CPU_USABLE(cpumap,
1544 cpumaplen,
1546 pcpu)),
1547 error);
1550 cleanup:
1551 VIR_FREE(cpumap);
1552 return pycpumap;
1554 error:
1555 Py_CLEAR(pycpumap);
1556 goto cleanup;
1558 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
1560 #if LIBVIR_CHECK_VERSION(1, 2, 14)
1561 static PyObject *
1562 libvirt_virDomainGetIOThreadInfo(PyObject *self ATTRIBUTE_UNUSED,
1563 PyObject *args)
1565 virDomainPtr domain;
1566 PyObject *pyobj_domain;
1567 PyObject *py_retval = NULL;
1568 PyObject *py_iothrinfo = NULL;
1569 virDomainIOThreadInfoPtr *iothrinfo = NULL;
1570 unsigned int flags;
1571 ssize_t pcpu, i;
1572 int niothreads, cpunum;
1574 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetIOThreadInfo",
1575 &pyobj_domain, &flags))
1576 return NULL;
1577 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1579 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1580 return VIR_PY_NONE;
1582 LIBVIRT_BEGIN_ALLOW_THREADS;
1583 niothreads = virDomainGetIOThreadInfo(domain, &iothrinfo, flags);
1584 LIBVIRT_END_ALLOW_THREADS;
1586 if (niothreads < 0) {
1587 py_retval = VIR_PY_NONE;
1588 goto cleanup;
1591 /* convert to a Python list */
1592 if ((py_iothrinfo = PyList_New(niothreads)) == NULL)
1593 goto cleanup;
1595 /* NOTE: If there are zero IOThreads we will return an empty list */
1596 for (i = 0; i < niothreads; i++) {
1597 PyObject *iothrtpl = NULL;
1598 PyObject *iothrmap = NULL;
1599 virDomainIOThreadInfoPtr iothr = iothrinfo[i];
1601 if (iothr == NULL) {
1602 py_retval = VIR_PY_NONE;
1603 goto cleanup;
1606 if ((iothrtpl = PyTuple_New(2)) == NULL)
1607 goto cleanup;
1609 VIR_PY_LIST_SET_GOTO(py_iothrinfo, i, iothrtpl, cleanup);
1611 /* 0: IOThread ID */
1612 VIR_PY_TUPLE_SET_GOTO(iothrtpl, 0, libvirt_uintWrap(iothr->iothread_id),
1613 cleanup);
1615 /* 1: CPU map */
1616 if ((iothrmap = PyList_New(cpunum)) == NULL)
1617 goto cleanup;
1619 VIR_PY_TUPLE_SET_GOTO(iothrtpl, 1, iothrmap, cleanup);
1621 for (pcpu = 0; pcpu < cpunum; pcpu++)
1622 VIR_PY_LIST_SET_GOTO(iothrmap, pcpu,
1623 PyBool_FromLong(VIR_CPU_USED(iothr->cpumap,
1624 pcpu)),
1625 cleanup);
1628 py_retval = py_iothrinfo;
1629 py_iothrinfo = NULL;
1631 cleanup:
1632 if (niothreads > 0) {
1633 for (i = 0; i < niothreads; i++)
1634 virDomainIOThreadInfoFree(iothrinfo[i]);
1636 VIR_FREE(iothrinfo);
1637 Py_XDECREF(py_iothrinfo);
1638 return py_retval;
1641 static PyObject *
1642 libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED,
1643 PyObject *args)
1645 virDomainPtr domain;
1646 PyObject *pyobj_domain, *pycpumap;
1647 PyObject *ret = NULL;
1648 unsigned char *cpumap;
1649 int cpumaplen, iothread_val, cpunum;
1650 unsigned int flags;
1651 int i_retval;
1653 if (!PyArg_ParseTuple(args, (char *)"OiOI:virDomainPinIOThread",
1654 &pyobj_domain, &iothread_val, &pycpumap, &flags))
1655 return NULL;
1656 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1658 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1659 return VIR_PY_INT_FAIL;
1661 if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0)
1662 return NULL;
1664 LIBVIRT_BEGIN_ALLOW_THREADS;
1665 i_retval = virDomainPinIOThread(domain, iothread_val,
1666 cpumap, cpumaplen, flags);
1667 LIBVIRT_END_ALLOW_THREADS;
1669 if (i_retval < 0) {
1670 ret = VIR_PY_INT_FAIL;
1671 goto cleanup;
1673 ret = VIR_PY_INT_SUCCESS;
1675 cleanup:
1676 VIR_FREE(cpumap);
1677 return ret;
1680 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
1682 #if LIBVIR_CHECK_VERSION(4, 10, 0)
1684 static virPyTypedParamsHint virPyDomainSetIOThreadParams[] = {
1685 { VIR_DOMAIN_IOTHREAD_POLL_MAX_NS, VIR_TYPED_PARAM_ULLONG },
1686 { VIR_DOMAIN_IOTHREAD_POLL_GROW, VIR_TYPED_PARAM_UINT },
1687 { VIR_DOMAIN_IOTHREAD_POLL_SHRINK, VIR_TYPED_PARAM_UINT },
1690 static PyObject *
1691 libvirt_virDomainSetIOThreadParams(PyObject *self ATTRIBUTE_UNUSED,
1692 PyObject *args)
1694 PyObject *pyobj_dom = NULL;
1695 PyObject *pyobj_dict = NULL;
1697 virDomainPtr dom;
1698 int iothread_val;
1699 virTypedParameterPtr params = NULL;
1700 int nparams = 0;
1701 unsigned int flags;
1702 int c_retval;
1704 if (!PyArg_ParseTuple(args, (char *)"OiOI:virDomainSetIOThreadParams",
1705 &pyobj_dom, &iothread_val, &pyobj_dict, &flags))
1706 return NULL;
1708 if (PyDict_Check(pyobj_dict)) {
1709 if (virPyDictToTypedParams(pyobj_dict, &params, &nparams,
1710 virPyDomainSetIOThreadParams,
1711 VIR_N_ELEMENTS(virPyDomainSetIOThreadParams)) < 0) {
1712 return NULL;
1714 } else {
1715 PyErr_Format(PyExc_TypeError, "IOThread polling params must be "
1716 "a dictionary");
1717 return NULL;
1720 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
1722 LIBVIRT_BEGIN_ALLOW_THREADS;
1723 c_retval = virDomainSetIOThreadParams(dom, iothread_val,
1724 params, nparams, flags);
1725 LIBVIRT_END_ALLOW_THREADS;
1727 virTypedParamsFree(params, nparams);
1729 return libvirt_intWrap(c_retval);
1731 #endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */
1733 /************************************************************************
1735 * Global error handler at the Python level *
1737 ************************************************************************/
1739 static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
1740 static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
1742 static PyObject *
1743 libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED,
1744 PyObject *args ATTRIBUTE_UNUSED)
1746 virError *err;
1747 PyObject *info;
1749 if ((err = virGetLastError()) == NULL)
1750 return VIR_PY_NONE;
1752 if ((info = PyTuple_New(9)) == NULL)
1753 return NULL;
1755 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), error);
1756 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), error);
1757 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), error);
1758 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), error);
1759 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), error);
1760 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), error);
1761 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), error);
1762 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), error);
1763 VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), error);
1765 return info;
1767 error:
1768 Py_XDECREF(info);
1769 return NULL;
1772 static PyObject *
1773 libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED,
1774 PyObject *args)
1776 virError *err;
1777 PyObject *info;
1778 virConnectPtr conn;
1779 PyObject *pyobj_conn;
1781 if (!PyArg_ParseTuple(args, (char *)"O:virConGetLastError", &pyobj_conn))
1782 return NULL;
1783 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1785 LIBVIRT_BEGIN_ALLOW_THREADS;
1786 err = virConnGetLastError(conn);
1787 LIBVIRT_END_ALLOW_THREADS;
1789 if (err == NULL)
1790 return VIR_PY_NONE;
1792 if ((info = PyTuple_New(9)) == NULL)
1793 return NULL;
1795 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), error);
1796 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), error);
1797 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), error);
1798 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), error);
1799 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), error);
1800 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), error);
1801 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), error);
1802 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), error);
1803 VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), error);
1805 return info;
1807 error:
1808 Py_XDECREF(info);
1809 return NULL;
1812 static void
1813 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx,
1814 virErrorPtr err)
1816 PyObject *list = NULL, *info = NULL;
1817 PyObject *result;
1819 DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
1820 err->message);
1822 if ((err == NULL) || (err->code == VIR_ERR_OK))
1823 return;
1825 LIBVIRT_ENSURE_THREAD_STATE;
1827 if ((libvirt_virPythonErrorFuncHandler == NULL) ||
1828 (libvirt_virPythonErrorFuncHandler == Py_None)) {
1829 virDefaultErrorFunc(err);
1830 } else {
1831 if ((list = PyTuple_New(2)) == NULL)
1832 goto cleanup;
1834 Py_XINCREF(libvirt_virPythonErrorFuncCtxt);
1835 VIR_PY_TUPLE_SET_GOTO(list, 0, libvirt_virPythonErrorFuncCtxt, cleanup);
1837 if ((info = PyTuple_New(9)) == NULL)
1838 goto cleanup;
1840 VIR_PY_TUPLE_SET_GOTO(list, 1, info, cleanup);
1842 VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), cleanup);
1843 VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), cleanup);
1844 VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), cleanup);
1845 VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), cleanup);
1846 VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), cleanup);
1847 VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), cleanup);
1848 VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), cleanup);
1849 VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), cleanup);
1850 VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), cleanup);
1852 /* TODO pass conn and dom if available */
1853 result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
1854 Py_XDECREF(result);
1857 cleanup:
1858 Py_XDECREF(list);
1859 LIBVIRT_RELEASE_THREAD_STATE;
1862 static PyObject *
1863 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject *self,
1864 PyObject *args)
1866 PyObject *py_retval;
1867 PyObject *pyobj_f;
1868 PyObject *pyobj_ctx;
1870 if (!PyArg_ParseTuple(args, (char *) "OO:virRegisterErrorHandler",
1871 &pyobj_f, &pyobj_ctx))
1872 return NULL;
1874 DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
1875 pyobj_f);
1877 virSetErrorFunc(NULL, libvirt_virErrorFuncHandler);
1879 Py_XDECREF(libvirt_virPythonErrorFuncHandler);
1880 Py_XDECREF(libvirt_virPythonErrorFuncCtxt);
1882 if ((pyobj_f == Py_None) && (pyobj_ctx == Py_None)) {
1883 libvirt_virPythonErrorFuncHandler = NULL;
1884 libvirt_virPythonErrorFuncCtxt = NULL;
1885 } else {
1886 Py_XINCREF(pyobj_ctx);
1887 Py_XINCREF(pyobj_f);
1889 /* TODO: check f is a function ! */
1890 libvirt_virPythonErrorFuncHandler = pyobj_f;
1891 libvirt_virPythonErrorFuncCtxt = pyobj_ctx;
1894 py_retval = libvirt_intWrap(1);
1895 return py_retval;
1898 static int
1899 virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
1900 unsigned int ncred,
1901 void *cbdata)
1903 PyObject *list = NULL;
1904 PyObject *pycred;
1905 PyObject *pyauth = (PyObject *)cbdata;
1906 PyObject *pycbdata;
1907 PyObject *pycb;
1908 PyObject *pyret = NULL;
1909 int ret = -1;
1910 ssize_t i;
1912 LIBVIRT_ENSURE_THREAD_STATE;
1914 pycb = PyList_GetItem(pyauth, 1);
1915 pycbdata = PyList_GetItem(pyauth, 2);
1917 if ((list = PyTuple_New(2)) == NULL)
1918 goto cleanup;
1920 if ((pycred = PyTuple_New(ncred)) == NULL)
1921 goto cleanup;
1923 VIR_PY_TUPLE_SET_GOTO(list, 0, pycred, cleanup);
1925 for (i = 0; i < ncred; i++) {
1926 PyObject *pycreditem;
1927 if ((pycreditem = PyList_New(5)) == NULL)
1928 goto cleanup;
1930 VIR_PY_TUPLE_SET_GOTO(pycred, i, pycreditem, cleanup);
1932 VIR_PY_LIST_SET_GOTO(pycreditem, 0,
1933 libvirt_intWrap((long)cred[i].type), cleanup);
1934 VIR_PY_LIST_SET_GOTO(pycreditem, 1,
1935 libvirt_constcharPtrWrap(cred[i].prompt), cleanup);
1937 if (cred[i].challenge) {
1938 VIR_PY_LIST_SET_GOTO(pycreditem, 2,
1939 libvirt_constcharPtrWrap(cred[i].challenge),
1940 cleanup);
1941 } else {
1942 VIR_PY_LIST_SET_GOTO(pycreditem, 2, VIR_PY_NONE, cleanup);
1944 if (cred[i].defresult) {
1945 VIR_PY_LIST_SET_GOTO(pycreditem, 3,
1946 libvirt_constcharPtrWrap(cred[i].defresult),
1947 cleanup);
1948 } else {
1949 VIR_PY_LIST_SET_GOTO(pycreditem, 3, VIR_PY_NONE, cleanup);
1951 VIR_PY_LIST_SET_GOTO(pycreditem, 4, VIR_PY_NONE, cleanup);
1954 Py_XINCREF(pycbdata);
1955 VIR_PY_TUPLE_SET_GOTO(list, 1, pycbdata, cleanup);
1957 PyErr_Clear();
1958 pyret = PyEval_CallObject(pycb, list);
1959 if (PyErr_Occurred()) {
1960 PyErr_Print();
1961 goto cleanup;
1964 ret = PyLong_AsLong(pyret);
1965 if (ret == 0) {
1966 for (i = 0; i < ncred; i++) {
1967 PyObject *pycreditem;
1968 PyObject *pyresult;
1969 char *result = NULL;
1970 pycreditem = PyTuple_GetItem(pycred, i);
1971 pyresult = PyList_GetItem(pycreditem, 4);
1972 if (pyresult != Py_None) {
1973 libvirt_charPtrUnwrap(pyresult, &result);
1974 PyErr_Clear();
1976 if (result != NULL) {
1977 cred[i].result = result;
1978 cred[i].resultlen = strlen(result);
1979 } else {
1980 cred[i].result = NULL;
1981 cred[i].resultlen = 0;
1986 cleanup:
1987 Py_XDECREF(list);
1988 Py_XDECREF(pyret);
1990 LIBVIRT_RELEASE_THREAD_STATE;
1992 return ret;
1996 static PyObject *
1997 libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED,
1998 PyObject *args)
2000 PyObject *py_retval;
2001 virConnectPtr c_retval;
2002 char * name;
2003 unsigned int flags;
2004 PyObject *pyauth;
2005 PyObject *pycredcb;
2006 PyObject *pycredtype;
2007 virConnectAuth auth;
2009 memset(&auth, 0, sizeof(auth));
2010 if (!PyArg_ParseTuple(args, (char *)"zOI:virConnectOpenAuth",
2011 &name, &pyauth, &flags))
2012 return NULL;
2014 pycredtype = PyList_GetItem(pyauth, 0);
2015 pycredcb = PyList_GetItem(pyauth, 1);
2017 auth.ncredtype = PyList_Size(pycredtype);
2018 if (auth.ncredtype) {
2019 ssize_t i;
2020 if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0)
2021 return PyErr_NoMemory();
2022 for (i = 0; i < auth.ncredtype; i++) {
2023 PyObject *val;
2024 val = PyList_GetItem(pycredtype, i);
2025 auth.credtype[i] = (int)PyLong_AsLong(val);
2028 if (pycredcb && pycredcb != Py_None)
2029 auth.cb = virConnectCredCallbackWrapper;
2030 auth.cbdata = pyauth;
2032 LIBVIRT_BEGIN_ALLOW_THREADS;
2033 c_retval = virConnectOpenAuth(name, &auth, flags);
2034 LIBVIRT_END_ALLOW_THREADS;
2036 VIR_FREE(auth.credtype);
2037 py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval);
2038 return py_retval;
2042 /************************************************************************
2044 * Wrappers for functions where generator fails *
2046 ************************************************************************/
2048 static PyObject *
2049 libvirt_virGetVersion(PyObject *self ATTRIBUTE_UNUSED,
2050 PyObject *args)
2052 char *type = NULL;
2053 unsigned long libVer, typeVer = 0;
2054 int c_retval;
2056 if (!PyArg_ParseTuple(args, (char *) "|s:virGetVersion", &type))
2057 return NULL;
2059 LIBVIRT_BEGIN_ALLOW_THREADS;
2060 if (type == NULL)
2061 c_retval = virGetVersion(&libVer, NULL, NULL);
2062 else
2063 c_retval = virGetVersion(&libVer, type, &typeVer);
2064 LIBVIRT_END_ALLOW_THREADS;
2066 if (c_retval == -1)
2067 return VIR_PY_NONE;
2069 if (type == NULL)
2070 return libvirt_intWrap(libVer);
2071 else
2072 return Py_BuildValue((char *) "kk", libVer, typeVer);
2075 static PyObject *
2076 libvirt_virConnectGetVersion(PyObject *self ATTRIBUTE_UNUSED,
2077 PyObject *args)
2079 unsigned long hvVersion;
2080 int c_retval;
2081 virConnectPtr conn;
2082 PyObject *pyobj_conn;
2084 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetVersion",
2085 &pyobj_conn))
2086 return NULL;
2087 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2089 LIBVIRT_BEGIN_ALLOW_THREADS;
2090 c_retval = virConnectGetVersion(conn, &hvVersion);
2091 LIBVIRT_END_ALLOW_THREADS;
2093 if (c_retval == -1)
2094 return VIR_PY_INT_FAIL;
2096 return libvirt_intWrap(hvVersion);
2099 #if LIBVIR_CHECK_VERSION(1, 1, 3)
2100 static PyObject *
2101 libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED,
2102 PyObject *args)
2104 int c_retval;
2105 virConnectPtr conn;
2106 PyObject *rv = NULL, *pyobj_conn;
2107 char **models = NULL;
2108 ssize_t i;
2109 unsigned int flags = 0;
2110 const char *arch = NULL;
2112 if (!PyArg_ParseTuple(args, (char *)"OsI:virConnectGetCPUModelNames",
2113 &pyobj_conn, &arch, &flags))
2114 return NULL;
2115 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2117 LIBVIRT_BEGIN_ALLOW_THREADS;
2118 c_retval = virConnectGetCPUModelNames(conn, arch, &models, flags);
2119 LIBVIRT_END_ALLOW_THREADS;
2121 if (c_retval == -1)
2122 return VIR_PY_NONE;
2124 if ((rv = PyList_New(c_retval)) == NULL)
2125 goto error;
2127 for (i = 0; i < c_retval; i++)
2128 VIR_PY_LIST_SET_GOTO(rv, i, libvirt_constcharPtrWrap(models[i]), error);
2130 done:
2131 if (models) {
2132 for (i = 0; i < c_retval; i++)
2133 VIR_FREE(models[i]);
2134 VIR_FREE(models);
2137 return rv;
2139 error:
2140 Py_CLEAR(rv);
2141 goto done;
2143 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
2145 static PyObject *
2146 libvirt_virConnectGetLibVersion(PyObject *self ATTRIBUTE_UNUSED,
2147 PyObject *args)
2149 unsigned long libVer;
2150 int c_retval;
2151 virConnectPtr conn;
2152 PyObject *pyobj_conn;
2154 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetLibVersion",
2155 &pyobj_conn))
2156 return NULL;
2157 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2159 LIBVIRT_BEGIN_ALLOW_THREADS;
2160 c_retval = virConnectGetLibVersion(conn, &libVer);
2161 LIBVIRT_END_ALLOW_THREADS;
2163 if (c_retval == -1)
2164 return VIR_PY_INT_FAIL;
2166 return libvirt_intWrap(libVer);
2169 static PyObject *
2170 libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
2171 PyObject *args)
2173 PyObject *py_retval;
2174 int *ids = NULL, c_retval;
2175 ssize_t i;
2176 virConnectPtr conn;
2177 PyObject *pyobj_conn;
2180 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDomains", &pyobj_conn))
2181 return NULL;
2182 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2184 LIBVIRT_BEGIN_ALLOW_THREADS;
2185 c_retval = virConnectNumOfDomains(conn);
2186 LIBVIRT_END_ALLOW_THREADS;
2188 if (c_retval < 0)
2189 return VIR_PY_NONE;
2191 if (c_retval) {
2192 if (VIR_ALLOC_N(ids, c_retval) < 0)
2193 return PyErr_NoMemory();
2195 LIBVIRT_BEGIN_ALLOW_THREADS;
2196 c_retval = virConnectListDomains(conn, ids, c_retval);
2197 LIBVIRT_END_ALLOW_THREADS;
2199 if (c_retval < 0) {
2200 py_retval = VIR_PY_NONE;
2201 goto cleanup;
2205 if ((py_retval = PyList_New(c_retval)) == NULL)
2206 goto cleanup;
2208 if (ids)
2209 for (i = 0; i < c_retval; i++)
2210 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_intWrap(ids[i]), error);
2212 cleanup:
2213 VIR_FREE(ids);
2214 return py_retval;
2216 error:
2217 VIR_FREE(ids);
2218 Py_XDECREF(py_retval);
2219 return NULL;
2222 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2223 static PyObject *
2224 libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
2225 PyObject *args)
2227 PyObject *pyobj_conn;
2228 PyObject *py_retval = NULL;
2229 virConnectPtr conn;
2230 virDomainPtr *doms = NULL;
2231 int c_retval = 0;
2232 ssize_t i;
2233 unsigned int flags;
2235 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllDomains",
2236 &pyobj_conn, &flags))
2237 return NULL;
2238 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2240 LIBVIRT_BEGIN_ALLOW_THREADS;
2241 c_retval = virConnectListAllDomains(conn, &doms, flags);
2242 LIBVIRT_END_ALLOW_THREADS;
2244 if (c_retval < 0)
2245 return VIR_PY_NONE;
2247 if (!(py_retval = PyList_New(c_retval)))
2248 goto cleanup;
2250 for (i = 0; i < c_retval; i++) {
2251 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_virDomainPtrWrap(doms[i]), error);
2252 /* python steals the pointer */
2253 doms[i] = NULL;
2256 cleanup:
2257 for (i = 0; i < c_retval; i++)
2258 if (doms[i])
2259 virDomainFree(doms[i]);
2260 VIR_FREE(doms);
2261 return py_retval;
2263 error:
2264 Py_CLEAR(py_retval);
2265 goto cleanup;
2267 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2269 static PyObject *
2270 libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
2271 PyObject *args)
2273 PyObject *py_retval;
2274 char **names = NULL;
2275 int c_retval;
2276 ssize_t i;
2277 virConnectPtr conn;
2278 PyObject *pyobj_conn;
2281 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedDomains",
2282 &pyobj_conn))
2283 return NULL;
2284 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2286 LIBVIRT_BEGIN_ALLOW_THREADS;
2287 c_retval = virConnectNumOfDefinedDomains(conn);
2288 LIBVIRT_END_ALLOW_THREADS;
2290 if (c_retval < 0)
2291 return VIR_PY_NONE;
2293 if (c_retval) {
2294 if (VIR_ALLOC_N(names, c_retval) < 0)
2295 return PyErr_NoMemory();
2297 LIBVIRT_BEGIN_ALLOW_THREADS;
2298 c_retval = virConnectListDefinedDomains(conn, names, c_retval);
2299 LIBVIRT_END_ALLOW_THREADS;
2301 if (c_retval < 0) {
2302 py_retval = VIR_PY_NONE;
2303 goto cleanup;
2307 if ((py_retval = PyList_New(c_retval)) == NULL)
2308 goto cleanup;
2310 if (names) {
2311 for (i = 0; i < c_retval; i++)
2312 VIR_PY_LIST_SET_GOTO(py_retval, i,
2313 libvirt_constcharPtrWrap(names[i]), error);
2316 cleanup:
2317 if (c_retval > 0)
2318 for (i = 0; i < c_retval; i++)
2319 VIR_FREE(names[i]);
2320 VIR_FREE(names);
2321 return py_retval;
2323 error:
2324 Py_CLEAR(py_retval);
2325 goto cleanup;
2328 static PyObject *
2329 libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
2330 PyObject *args)
2332 PyObject *py_retval;
2333 char **names = NULL;
2334 int c_retval;
2335 ssize_t i;
2336 virDomainPtr dom;
2337 PyObject *pyobj_dom;
2338 unsigned int flags;
2340 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListNames",
2341 &pyobj_dom, &flags))
2342 return NULL;
2343 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2345 LIBVIRT_BEGIN_ALLOW_THREADS;
2346 c_retval = virDomainSnapshotNum(dom, flags);
2347 LIBVIRT_END_ALLOW_THREADS;
2349 if (c_retval < 0)
2350 return VIR_PY_NONE;
2352 if (c_retval) {
2353 if (VIR_ALLOC_N(names, c_retval) < 0)
2354 return PyErr_NoMemory();
2356 LIBVIRT_BEGIN_ALLOW_THREADS;
2357 c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
2358 LIBVIRT_END_ALLOW_THREADS;
2360 if (c_retval < 0) {
2361 py_retval = VIR_PY_NONE;
2362 goto cleanup;
2365 py_retval = PyList_New(c_retval);
2366 if (!py_retval)
2367 goto cleanup;
2369 for (i = 0; i < c_retval; i++)
2370 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_constcharPtrWrap(names[i]), error);
2372 cleanup:
2373 if (c_retval > 0)
2374 for (i = 0; i < c_retval; i++)
2375 VIR_FREE(names[i]);
2376 VIR_FREE(names);
2377 return py_retval;
2379 error:
2380 Py_CLEAR(py_retval);
2381 goto cleanup;
2384 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2385 static PyObject *
2386 libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
2387 PyObject *args)
2389 PyObject *py_retval = NULL;
2390 virDomainSnapshotPtr *snaps = NULL;
2391 int c_retval;
2392 ssize_t i;
2393 virDomainPtr dom;
2394 PyObject *pyobj_dom;
2395 unsigned int flags;
2397 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainListAllSnapshots",
2398 &pyobj_dom, &flags))
2399 return NULL;
2400 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2402 LIBVIRT_BEGIN_ALLOW_THREADS;
2403 c_retval = virDomainListAllSnapshots(dom, &snaps, flags);
2404 LIBVIRT_END_ALLOW_THREADS;
2406 if (c_retval < 0)
2407 return VIR_PY_NONE;
2409 if (!(py_retval = PyList_New(c_retval)))
2410 goto cleanup;
2412 for (i = 0; i < c_retval; i++) {
2413 VIR_PY_LIST_SET_GOTO(py_retval, i,
2414 libvirt_virDomainSnapshotPtrWrap(snaps[i]), error);
2415 snaps[i] = NULL;
2418 cleanup:
2419 for (i = 0; i < c_retval; i++)
2420 if (snaps[i])
2421 virDomainSnapshotFree(snaps[i]);
2422 VIR_FREE(snaps);
2423 return py_retval;
2425 error:
2426 Py_CLEAR(py_retval);
2427 goto cleanup;
2429 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2431 static PyObject *
2432 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
2433 PyObject *args)
2435 PyObject *py_retval;
2436 char **names = NULL;
2437 int c_retval;
2438 ssize_t i;
2439 virDomainSnapshotPtr snap;
2440 PyObject *pyobj_snap;
2441 unsigned int flags;
2443 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListChildrenNames",
2444 &pyobj_snap, &flags))
2445 return NULL;
2446 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2448 LIBVIRT_BEGIN_ALLOW_THREADS;
2449 c_retval = virDomainSnapshotNumChildren(snap, flags);
2450 LIBVIRT_END_ALLOW_THREADS;
2452 if (c_retval < 0)
2453 return VIR_PY_NONE;
2455 if (c_retval) {
2456 if (VIR_ALLOC_N(names, c_retval) < 0)
2457 return PyErr_NoMemory();
2459 LIBVIRT_BEGIN_ALLOW_THREADS;
2460 c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
2461 flags);
2462 LIBVIRT_END_ALLOW_THREADS;
2464 if (c_retval < 0) {
2465 py_retval = VIR_PY_NONE;
2466 goto cleanup;
2470 if ((py_retval = PyList_New(c_retval)) == NULL)
2471 goto cleanup;
2473 for (i = 0; i < c_retval; i++)
2474 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_constcharPtrWrap(names[i]), error);
2476 cleanup:
2477 if (c_retval > 0)
2478 for (i = 0; i < c_retval; i++)
2479 VIR_FREE(names[i]);
2480 VIR_FREE(names);
2481 return py_retval;
2483 error:
2484 Py_CLEAR(py_retval);
2485 goto cleanup;
2488 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2489 static PyObject *
2490 libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2491 PyObject *args)
2493 PyObject *py_retval = NULL;
2494 virDomainSnapshotPtr *snaps = NULL;
2495 int c_retval;
2496 ssize_t i;
2497 virDomainSnapshotPtr parent;
2498 PyObject *pyobj_parent;
2499 unsigned int flags;
2501 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListAllChildren",
2502 &pyobj_parent, &flags))
2503 return NULL;
2504 parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
2506 LIBVIRT_BEGIN_ALLOW_THREADS;
2507 c_retval = virDomainSnapshotListAllChildren(parent, &snaps, flags);
2508 LIBVIRT_END_ALLOW_THREADS;
2510 if (c_retval < 0)
2511 return VIR_PY_NONE;
2513 if (!(py_retval = PyList_New(c_retval)))
2514 goto cleanup;
2516 for (i = 0; i < c_retval; i++) {
2517 VIR_PY_LIST_SET_GOTO(py_retval, i,
2518 libvirt_virDomainSnapshotPtrWrap(snaps[i]), error);
2519 snaps[i] = NULL;
2522 cleanup:
2523 for (i = 0; i < c_retval; i++)
2524 if (snaps[i])
2525 virDomainSnapshotFree(snaps[i]);
2526 VIR_FREE(snaps);
2527 return py_retval;
2529 error:
2530 Py_CLEAR(py_retval);
2531 goto cleanup;
2533 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2535 static PyObject *
2536 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
2537 PyObject *args)
2539 int c_retval;
2540 virDomainSnapshotPtr snap;
2541 PyObject *pyobj_snap;
2542 PyObject *pyobj_dom;
2543 unsigned int flags;
2545 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainRevertToSnapshot",
2546 &pyobj_dom, &pyobj_snap, &flags))
2547 return NULL;
2548 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2550 LIBVIRT_BEGIN_ALLOW_THREADS;
2551 c_retval = virDomainRevertToSnapshot(snap, flags);
2552 LIBVIRT_END_ALLOW_THREADS;
2554 if (c_retval < 0)
2555 return VIR_PY_INT_FAIL;
2557 return libvirt_intWrap(c_retval);
2560 static PyObject *
2561 libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED,
2562 PyObject *args)
2564 PyObject *py_retval;
2565 int c_retval;
2566 virDomainPtr domain;
2567 PyObject *pyobj_domain;
2568 virDomainInfo info;
2570 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_domain))
2571 return NULL;
2572 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2574 LIBVIRT_BEGIN_ALLOW_THREADS;
2575 c_retval = virDomainGetInfo(domain, &info);
2576 LIBVIRT_END_ALLOW_THREADS;
2578 if (c_retval < 0)
2579 return VIR_PY_NONE;
2581 if ((py_retval = PyList_New(5)) == NULL)
2582 return NULL;
2584 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap((int) info.state), error);
2585 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_ulongWrap(info.maxMem), error);
2586 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_ulongWrap(info.memory), error);
2587 VIR_PY_LIST_SET_GOTO(py_retval, 3,
2588 libvirt_intWrap((int) info.nrVirtCpu), error);
2589 VIR_PY_LIST_SET_GOTO(py_retval, 4,
2590 libvirt_ulonglongWrap(info.cpuTime), error);
2592 return py_retval;
2594 error:
2595 Py_XDECREF(py_retval);
2596 return NULL;
2599 static PyObject *
2600 libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED,
2601 PyObject *args)
2603 PyObject *py_retval;
2604 int c_retval;
2605 virDomainPtr domain;
2606 PyObject *pyobj_domain;
2607 int state;
2608 int reason;
2609 unsigned int flags;
2611 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetState",
2612 &pyobj_domain, &flags))
2613 return NULL;
2615 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2617 LIBVIRT_BEGIN_ALLOW_THREADS;
2618 c_retval = virDomainGetState(domain, &state, &reason, flags);
2619 LIBVIRT_END_ALLOW_THREADS;
2621 if (c_retval < 0)
2622 return VIR_PY_NONE;
2624 if ((py_retval = PyList_New(2)) == NULL)
2625 return NULL;
2627 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap(state), error);
2628 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_intWrap(reason), error);
2630 return py_retval;
2632 error:
2633 Py_XDECREF(py_retval);
2634 return NULL;
2637 static PyObject *
2638 libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED,
2639 PyObject *args)
2641 PyObject *py_retval;
2642 int c_retval;
2643 virDomainPtr domain;
2644 PyObject *pyobj_domain;
2645 virDomainControlInfo info;
2646 unsigned int flags;
2648 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetControlInfo",
2649 &pyobj_domain, &flags))
2650 return NULL;
2651 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2653 LIBVIRT_BEGIN_ALLOW_THREADS;
2654 c_retval = virDomainGetControlInfo(domain, &info, flags);
2655 LIBVIRT_END_ALLOW_THREADS;
2657 if (c_retval < 0)
2658 return VIR_PY_NONE;
2660 if ((py_retval = PyList_New(3)) == NULL)
2661 return NULL;
2663 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap(info.state), error);
2664 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_intWrap(info.details), error);
2665 VIR_PY_LIST_SET_GOTO(py_retval, 2,
2666 libvirt_ulonglongWrap(info.stateTime), error);
2668 return py_retval;
2670 error:
2671 Py_XDECREF(py_retval);
2672 return NULL;
2675 static PyObject *
2676 libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED,
2677 PyObject *args)
2679 PyObject *py_retval;
2680 int c_retval;
2681 virDomainPtr domain;
2682 PyObject *pyobj_domain;
2683 virDomainBlockInfo info;
2684 const char *path;
2685 unsigned int flags;
2687 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockInfo",
2688 &pyobj_domain, &path, &flags))
2689 return NULL;
2690 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2692 LIBVIRT_BEGIN_ALLOW_THREADS;
2693 c_retval = virDomainGetBlockInfo(domain, path, &info, flags);
2694 LIBVIRT_END_ALLOW_THREADS;
2696 if (c_retval < 0)
2697 return VIR_PY_NONE;
2699 if ((py_retval = PyList_New(3)) == NULL)
2700 return NULL;
2702 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2703 libvirt_ulonglongWrap(info.capacity), error);
2704 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2705 libvirt_ulonglongWrap(info.allocation), error);
2706 VIR_PY_LIST_SET_GOTO(py_retval, 2,
2707 libvirt_ulonglongWrap(info.physical), error);
2709 return py_retval;
2711 error:
2712 Py_XDECREF(py_retval);
2713 return NULL;
2716 static PyObject *
2717 libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED,
2718 PyObject *args)
2720 PyObject *py_retval;
2721 int c_retval;
2722 virConnectPtr conn;
2723 PyObject *pyobj_conn;
2724 virNodeInfo info;
2726 if (!PyArg_ParseTuple(args, (char *)"O:virNodeGetInfo", &pyobj_conn))
2727 return NULL;
2728 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2730 LIBVIRT_BEGIN_ALLOW_THREADS;
2731 c_retval = virNodeGetInfo(conn, &info);
2732 LIBVIRT_END_ALLOW_THREADS;
2734 if (c_retval < 0)
2735 return VIR_PY_NONE;
2737 if ((py_retval = PyList_New(8)) == NULL)
2738 return NULL;
2740 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2741 libvirt_constcharPtrWrap(&info.model[0]), error);
2742 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2743 libvirt_longWrap((long) info.memory >> 10), error);
2744 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_intWrap((int) info.cpus), error);
2745 VIR_PY_LIST_SET_GOTO(py_retval, 3, libvirt_intWrap((int) info.mhz), error);
2746 VIR_PY_LIST_SET_GOTO(py_retval, 4, libvirt_intWrap((int) info.nodes), error);
2747 VIR_PY_LIST_SET_GOTO(py_retval, 5, libvirt_intWrap((int) info.sockets), error);
2748 VIR_PY_LIST_SET_GOTO(py_retval, 6, libvirt_intWrap((int) info.cores), error);
2749 VIR_PY_LIST_SET_GOTO(py_retval, 7, libvirt_intWrap((int) info.threads), error);
2751 return py_retval;
2753 error:
2754 Py_XDECREF(py_retval);
2755 return NULL;
2758 static PyObject *
2759 libvirt_virNodeGetSecurityModel(PyObject *self ATTRIBUTE_UNUSED,
2760 PyObject *args)
2762 PyObject *py_retval;
2763 int c_retval;
2764 virConnectPtr conn;
2765 PyObject *pyobj_conn;
2766 virSecurityModel model;
2768 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityModel",
2769 &pyobj_conn))
2770 return NULL;
2771 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2773 LIBVIRT_BEGIN_ALLOW_THREADS;
2774 c_retval = virNodeGetSecurityModel(conn, &model);
2775 LIBVIRT_END_ALLOW_THREADS;
2777 if (c_retval < 0)
2778 return VIR_PY_NONE;
2780 if ((py_retval = PyList_New(2)) == NULL)
2781 return NULL;
2783 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2784 libvirt_constcharPtrWrap(&model.model[0]), error);
2785 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2786 libvirt_constcharPtrWrap(&model.doi[0]), error);
2788 return py_retval;
2790 error:
2791 Py_XDECREF(py_retval);
2792 return NULL;
2795 static PyObject *
2796 libvirt_virDomainGetSecurityLabel(PyObject *self ATTRIBUTE_UNUSED,
2797 PyObject *args)
2799 PyObject *py_retval;
2800 int c_retval;
2801 virDomainPtr dom;
2802 PyObject *pyobj_dom;
2803 virSecurityLabel label;
2805 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabel",
2806 &pyobj_dom))
2807 return NULL;
2808 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2810 LIBVIRT_BEGIN_ALLOW_THREADS;
2811 c_retval = virDomainGetSecurityLabel(dom, &label);
2812 LIBVIRT_END_ALLOW_THREADS;
2814 if (c_retval < 0)
2815 return VIR_PY_NONE;
2817 if ((py_retval = PyList_New(2)) == NULL)
2818 return NULL;
2820 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2821 libvirt_constcharPtrWrap(&label.label[0]), error);
2822 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2823 libvirt_boolWrap(label.enforcing), error);
2825 return py_retval;
2827 error:
2828 Py_XDECREF(py_retval);
2829 return NULL;
2832 #if LIBVIR_CHECK_VERSION(0, 10, 0)
2833 static PyObject *
2834 libvirt_virDomainGetSecurityLabelList(PyObject *self ATTRIBUTE_UNUSED,
2835 PyObject *args)
2837 PyObject *py_retval;
2838 int c_retval;
2839 virDomainPtr dom;
2840 PyObject *pyobj_dom;
2841 virSecurityLabel *labels = NULL;
2842 ssize_t i;
2844 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabelList",
2845 &pyobj_dom))
2846 return NULL;
2848 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2850 LIBVIRT_BEGIN_ALLOW_THREADS;
2851 c_retval = virDomainGetSecurityLabelList(dom, &labels);
2852 LIBVIRT_END_ALLOW_THREADS;
2854 if (c_retval < 0)
2855 return VIR_PY_NONE;
2857 if (!(py_retval = PyList_New(0)))
2858 goto error;
2860 for (i = 0 ; i < c_retval ; i++) {
2861 PyObject *entry;
2863 if (!(entry = PyList_New(2)))
2864 goto error;
2866 VIR_PY_LIST_APPEND_GOTO(py_retval, entry, error);
2868 VIR_PY_LIST_SET_GOTO(entry, 0,
2869 libvirt_constcharPtrWrap(&labels[i].label[0]),
2870 error);
2871 VIR_PY_LIST_SET_GOTO(entry, 1,
2872 libvirt_boolWrap(labels[i].enforcing), error);
2875 cleanup:
2876 VIR_FREE(labels);
2877 return py_retval;
2879 error:
2880 Py_CLEAR(py_retval);
2881 goto cleanup;
2883 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
2885 static PyObject *
2886 libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED,
2887 PyObject *args)
2889 unsigned char uuid[VIR_UUID_BUFLEN];
2890 virDomainPtr domain;
2891 PyObject *pyobj_domain;
2892 int c_retval;
2894 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
2895 return NULL;
2896 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2898 if (domain == NULL)
2899 return VIR_PY_NONE;
2901 LIBVIRT_BEGIN_ALLOW_THREADS;
2902 c_retval = virDomainGetUUID(domain, &uuid[0]);
2903 LIBVIRT_END_ALLOW_THREADS;
2905 if (c_retval < 0)
2906 return VIR_PY_NONE;
2908 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
2911 static PyObject *
2912 libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
2913 PyObject *args)
2915 char uuidstr[VIR_UUID_STRING_BUFLEN];
2916 virDomainPtr dom;
2917 PyObject *pyobj_dom;
2918 int c_retval;
2920 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString",
2921 &pyobj_dom))
2922 return NULL;
2923 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2925 if (dom == NULL)
2926 return VIR_PY_NONE;
2928 LIBVIRT_BEGIN_ALLOW_THREADS;
2929 c_retval = virDomainGetUUIDString(dom, &uuidstr[0]);
2930 LIBVIRT_END_ALLOW_THREADS;
2932 if (c_retval < 0)
2933 return VIR_PY_NONE;
2935 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
2938 static PyObject *
2939 libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
2940 PyObject *args)
2942 virDomainPtr c_retval;
2943 virConnectPtr conn;
2944 PyObject *pyobj_conn;
2945 unsigned char * uuid;
2946 int len;
2948 if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID",
2949 &pyobj_conn, &uuid, &len))
2950 return NULL;
2951 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2953 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
2954 return VIR_PY_NONE;
2956 LIBVIRT_BEGIN_ALLOW_THREADS;
2957 c_retval = virDomainLookupByUUID(conn, uuid);
2958 LIBVIRT_END_ALLOW_THREADS;
2960 return libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
2964 static PyObject *
2965 libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
2966 PyObject *args)
2968 PyObject *py_retval;
2969 char **names = NULL;
2970 int c_retval;
2971 ssize_t i;
2972 virConnectPtr conn;
2973 PyObject *pyobj_conn;
2976 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks",
2977 &pyobj_conn))
2978 return NULL;
2979 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2981 LIBVIRT_BEGIN_ALLOW_THREADS;
2982 c_retval = virConnectNumOfNetworks(conn);
2983 LIBVIRT_END_ALLOW_THREADS;
2985 if (c_retval < 0)
2986 return VIR_PY_NONE;
2988 if (c_retval) {
2989 if (VIR_ALLOC_N(names, c_retval) < 0)
2990 return PyErr_NoMemory();
2992 LIBVIRT_BEGIN_ALLOW_THREADS;
2993 c_retval = virConnectListNetworks(conn, names, c_retval);
2994 LIBVIRT_END_ALLOW_THREADS;
2996 if (c_retval < 0) {
2997 py_retval = VIR_PY_NONE;
2998 goto cleanup;
3002 if ((py_retval = PyList_New(c_retval)) == NULL)
3003 goto cleanup;
3005 if (names)
3006 for (i = 0; i < c_retval; i++)
3007 VIR_PY_LIST_SET_GOTO(py_retval, i,
3008 libvirt_constcharPtrWrap(names[i]), error);
3010 cleanup:
3011 if (c_retval > 0)
3012 for (i = 0; i < c_retval; i++)
3013 VIR_FREE(names[i]);
3014 VIR_FREE(names);
3015 return py_retval;
3017 error:
3018 Py_CLEAR(py_retval);
3019 goto cleanup;
3023 static PyObject *
3024 libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
3025 PyObject *args)
3027 PyObject *py_retval;
3028 char **names = NULL;
3029 int c_retval;
3030 ssize_t i;
3031 virConnectPtr conn;
3032 PyObject *pyobj_conn;
3035 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks",
3036 &pyobj_conn))
3037 return NULL;
3038 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3040 LIBVIRT_BEGIN_ALLOW_THREADS;
3041 c_retval = virConnectNumOfDefinedNetworks(conn);
3042 LIBVIRT_END_ALLOW_THREADS;
3044 if (c_retval < 0)
3045 return VIR_PY_NONE;
3047 if (c_retval) {
3048 if (VIR_ALLOC_N(names, c_retval) < 0)
3049 return PyErr_NoMemory();
3051 LIBVIRT_BEGIN_ALLOW_THREADS;
3052 c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
3053 LIBVIRT_END_ALLOW_THREADS;
3055 if (c_retval < 0) {
3056 py_retval = VIR_PY_NONE;
3057 goto cleanup;
3061 if ((py_retval = PyList_New(c_retval)) == NULL)
3062 goto cleanup;
3064 for (i = 0; i < c_retval; i++)
3065 VIR_PY_LIST_SET_GOTO(py_retval, i,
3066 libvirt_constcharPtrWrap(names[i]), error);
3068 cleanup:
3069 if (c_retval > 0)
3070 for (i = 0; i < c_retval; i++)
3071 VIR_FREE(names[i]);
3072 VIR_FREE(names);
3073 return py_retval;
3075 error:
3076 Py_CLEAR(py_retval);
3077 goto cleanup;
3080 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3081 static PyObject *
3082 libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
3083 PyObject *args)
3085 PyObject *pyobj_conn;
3086 PyObject *py_retval = NULL;
3087 virConnectPtr conn;
3088 virNetworkPtr *nets = NULL;
3089 int c_retval = 0;
3090 ssize_t i;
3091 unsigned int flags;
3093 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNetworks",
3094 &pyobj_conn, &flags))
3095 return NULL;
3096 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3098 LIBVIRT_BEGIN_ALLOW_THREADS;
3099 c_retval = virConnectListAllNetworks(conn, &nets, flags);
3100 LIBVIRT_END_ALLOW_THREADS;
3102 if (c_retval < 0)
3103 return VIR_PY_NONE;
3105 if (!(py_retval = PyList_New(c_retval)))
3106 goto cleanup;
3108 for (i = 0; i < c_retval; i++) {
3109 VIR_PY_LIST_SET_GOTO(py_retval, i,
3110 libvirt_virNetworkPtrWrap(nets[i]), error);
3111 nets[i] = NULL;
3114 cleanup:
3115 for (i = 0; i < c_retval; i++)
3116 if (nets[i])
3117 virNetworkFree(nets[i]);
3118 VIR_FREE(nets);
3119 return py_retval;
3121 error:
3122 Py_CLEAR(py_retval);
3123 goto cleanup;
3125 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3128 static PyObject *
3129 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED,
3130 PyObject *args)
3132 unsigned char uuid[VIR_UUID_BUFLEN];
3133 virNetworkPtr domain;
3134 PyObject *pyobj_domain;
3135 int c_retval;
3137 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain))
3138 return NULL;
3139 domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
3141 if (domain == NULL)
3142 return VIR_PY_NONE;
3144 LIBVIRT_BEGIN_ALLOW_THREADS;
3145 c_retval = virNetworkGetUUID(domain, &uuid[0]);
3146 LIBVIRT_END_ALLOW_THREADS;
3148 if (c_retval < 0)
3149 return VIR_PY_NONE;
3151 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3154 static PyObject *
3155 libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3156 PyObject *args)
3158 char uuidstr[VIR_UUID_STRING_BUFLEN];
3159 virNetworkPtr net;
3160 PyObject *pyobj_net;
3161 int c_retval;
3163 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString",
3164 &pyobj_net))
3165 return NULL;
3166 net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net);
3168 if (net == NULL)
3169 return VIR_PY_NONE;
3171 LIBVIRT_BEGIN_ALLOW_THREADS;
3172 c_retval = virNetworkGetUUIDString(net, &uuidstr[0]);
3173 LIBVIRT_END_ALLOW_THREADS;
3175 if (c_retval < 0)
3176 return VIR_PY_NONE;
3178 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3181 static PyObject *
3182 libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3183 PyObject *args)
3185 virNetworkPtr c_retval;
3186 virConnectPtr conn;
3187 PyObject *pyobj_conn;
3188 unsigned char * uuid;
3189 int len;
3191 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID",
3192 &pyobj_conn, &uuid, &len))
3193 return NULL;
3194 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3196 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3197 return VIR_PY_NONE;
3199 LIBVIRT_BEGIN_ALLOW_THREADS;
3200 c_retval = virNetworkLookupByUUID(conn, uuid);
3201 LIBVIRT_END_ALLOW_THREADS;
3203 return libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval);
3207 static PyObject *
3208 libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3209 PyObject *args)
3211 int c_retval, autostart;
3212 virDomainPtr domain;
3213 PyObject *pyobj_domain;
3215 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetAutostart",
3216 &pyobj_domain))
3217 return NULL;
3219 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
3221 LIBVIRT_BEGIN_ALLOW_THREADS;
3222 c_retval = virDomainGetAutostart(domain, &autostart);
3223 LIBVIRT_END_ALLOW_THREADS;
3225 if (c_retval < 0)
3226 return VIR_PY_INT_FAIL;
3228 return libvirt_intWrap(autostart);
3232 static PyObject *
3233 libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3234 PyObject *args)
3236 int c_retval, autostart;
3237 virNetworkPtr network;
3238 PyObject *pyobj_network;
3240 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetAutostart",
3241 &pyobj_network))
3242 return NULL;
3244 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
3246 LIBVIRT_BEGIN_ALLOW_THREADS;
3247 c_retval = virNetworkGetAutostart(network, &autostart);
3248 LIBVIRT_END_ALLOW_THREADS;
3250 if (c_retval < 0)
3251 return VIR_PY_INT_FAIL;
3253 return libvirt_intWrap(autostart);
3256 static PyObject *
3257 libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
3258 PyObject *args)
3260 PyObject *py_retval;
3261 PyObject *pyobj_conn;
3262 int startCell, maxCells, c_retval;
3263 ssize_t i;
3264 virConnectPtr conn;
3265 unsigned long long *freeMems;
3267 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory",
3268 &pyobj_conn, &startCell, &maxCells))
3269 return NULL;
3271 if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
3272 return VIR_PY_NONE;
3274 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3275 if (VIR_ALLOC_N(freeMems, maxCells) < 0)
3276 return PyErr_NoMemory();
3278 LIBVIRT_BEGIN_ALLOW_THREADS;
3279 c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
3280 LIBVIRT_END_ALLOW_THREADS;
3282 if (c_retval < 0) {
3283 py_retval = VIR_PY_NONE;
3284 goto cleanup;
3287 if ((py_retval = PyList_New(c_retval)) == NULL)
3288 goto cleanup;
3290 for (i = 0; i < c_retval; i++)
3291 VIR_PY_LIST_SET_GOTO(py_retval, i,
3292 libvirt_ulonglongWrap(freeMems[i]), error);
3294 cleanup:
3295 VIR_FREE(freeMems);
3296 return py_retval;
3298 error:
3299 Py_CLEAR(py_retval);
3300 goto cleanup;
3303 static PyObject *
3304 libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED,
3305 PyObject *args)
3307 PyObject *ret = NULL;
3308 PyObject *key = NULL;
3309 PyObject *val = NULL;
3310 PyObject *pyobj_conn;
3311 virConnectPtr conn;
3312 unsigned int flags;
3313 int cpuNum, c_retval;
3314 ssize_t i;
3315 int nparams = 0;
3316 virNodeCPUStatsPtr stats = NULL;
3318 if (!PyArg_ParseTuple(args, (char *)"OiI:virNodeGetCPUStats",
3319 &pyobj_conn, &cpuNum, &flags))
3320 return ret;
3321 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3323 LIBVIRT_BEGIN_ALLOW_THREADS;
3324 c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
3325 LIBVIRT_END_ALLOW_THREADS;
3327 if (c_retval < 0)
3328 return VIR_PY_NONE;
3330 if (nparams) {
3331 if (VIR_ALLOC_N(stats, nparams) < 0)
3332 return PyErr_NoMemory();
3334 LIBVIRT_BEGIN_ALLOW_THREADS;
3335 c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
3336 LIBVIRT_END_ALLOW_THREADS;
3338 if (c_retval < 0) {
3339 VIR_FREE(stats);
3340 return VIR_PY_NONE;
3344 if (!(ret = PyDict_New()))
3345 goto error;
3347 for (i = 0; i < nparams; i++) {
3348 key = libvirt_constcharPtrWrap(stats[i].field);
3349 val = libvirt_ulonglongWrap(stats[i].value);
3351 VIR_PY_DICT_SET_GOTO(ret, key, val, error);
3354 cleanup:
3355 VIR_FREE(stats);
3356 return ret;
3358 error:
3359 Py_CLEAR(ret);
3360 goto cleanup;
3363 static PyObject *
3364 libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED,
3365 PyObject *args)
3367 PyObject *ret = NULL;
3368 PyObject *key = NULL;
3369 PyObject *val = NULL;
3370 PyObject *pyobj_conn;
3371 virConnectPtr conn;
3372 unsigned int flags;
3373 int cellNum, c_retval;
3374 ssize_t i;
3375 int nparams = 0;
3376 virNodeMemoryStatsPtr stats = NULL;
3378 if (!PyArg_ParseTuple(args, (char *)"OiI:virNodeGetMemoryStats",
3379 &pyobj_conn, &cellNum, &flags))
3380 return NULL;
3381 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3383 LIBVIRT_BEGIN_ALLOW_THREADS;
3384 c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
3385 LIBVIRT_END_ALLOW_THREADS;
3387 if (c_retval < 0)
3388 return VIR_PY_NONE;
3390 if (nparams) {
3391 if (VIR_ALLOC_N(stats, nparams) < 0)
3392 return PyErr_NoMemory();
3394 LIBVIRT_BEGIN_ALLOW_THREADS;
3395 c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
3396 LIBVIRT_END_ALLOW_THREADS;
3398 if (c_retval < 0) {
3399 VIR_FREE(stats);
3400 return VIR_PY_NONE;
3404 if (!(ret = PyDict_New()))
3405 goto error;
3407 for (i = 0; i < nparams; i++) {
3408 key = libvirt_constcharPtrWrap(stats[i].field);
3409 val = libvirt_ulonglongWrap(stats[i].value);
3411 VIR_PY_DICT_SET_GOTO(ret, key, val, error);
3414 cleanup:
3415 VIR_FREE(stats);
3416 return ret;
3418 error:
3419 Py_CLEAR(ret);
3420 goto cleanup;
3423 static PyObject *
3424 libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3425 PyObject *args)
3427 PyObject *py_retval;
3428 char **names = NULL;
3429 int c_retval;
3430 ssize_t i;
3431 virConnectPtr conn;
3432 PyObject *pyobj_conn;
3434 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListStoragePools",
3435 &pyobj_conn))
3436 return NULL;
3437 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3439 LIBVIRT_BEGIN_ALLOW_THREADS;
3440 c_retval = virConnectNumOfStoragePools(conn);
3441 LIBVIRT_END_ALLOW_THREADS;
3443 if (c_retval < 0)
3444 return VIR_PY_NONE;
3446 if (c_retval) {
3447 if (VIR_ALLOC_N(names, c_retval) < 0)
3448 return PyErr_NoMemory();
3450 LIBVIRT_BEGIN_ALLOW_THREADS;
3451 c_retval = virConnectListStoragePools(conn, names, c_retval);
3452 LIBVIRT_END_ALLOW_THREADS;
3454 if (c_retval < 0) {
3455 py_retval = VIR_PY_NONE;
3456 goto cleanup;
3460 if ((py_retval = PyList_New(c_retval)) == NULL)
3461 goto cleanup;
3463 for (i = 0; i < c_retval; i++)
3464 VIR_PY_LIST_SET_GOTO(py_retval, i,
3465 libvirt_constcharPtrWrap(names[i]), error);
3467 cleanup:
3468 if (c_retval > 0)
3469 for (i = 0; i < c_retval; i++)
3470 VIR_FREE(names[i]);
3471 VIR_FREE(names);
3472 return py_retval;
3474 error:
3475 Py_CLEAR(py_retval);
3476 goto cleanup;
3480 static PyObject *
3481 libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3482 PyObject *args)
3484 PyObject *py_retval;
3485 char **names = NULL;
3486 int c_retval;
3487 ssize_t i;
3488 virConnectPtr conn;
3489 PyObject *pyobj_conn;
3491 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedStoragePools",
3492 &pyobj_conn))
3493 return NULL;
3494 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3496 LIBVIRT_BEGIN_ALLOW_THREADS;
3497 c_retval = virConnectNumOfDefinedStoragePools(conn);
3498 LIBVIRT_END_ALLOW_THREADS;
3500 if (c_retval < 0)
3501 return VIR_PY_NONE;
3503 if (c_retval) {
3504 if (VIR_ALLOC_N(names, c_retval) < 0)
3505 return PyErr_NoMemory();
3507 LIBVIRT_BEGIN_ALLOW_THREADS;
3508 c_retval = virConnectListDefinedStoragePools(conn, names, c_retval);
3509 LIBVIRT_END_ALLOW_THREADS;
3511 if (c_retval < 0) {
3512 py_retval = VIR_PY_NONE;
3513 goto cleanup;
3517 if ((py_retval = PyList_New(c_retval)) == NULL)
3518 goto cleanup;
3520 if (names) {
3521 for (i = 0; i < c_retval; i++)
3522 VIR_PY_LIST_SET_GOTO(py_retval, i,
3523 libvirt_constcharPtrWrap(names[i]), error);
3526 cleanup:
3527 if (c_retval > 0)
3528 for (i = 0; i < c_retval; i++)
3529 VIR_FREE(names[i]);
3530 VIR_FREE(names);
3531 return py_retval;
3533 error:
3534 Py_CLEAR(py_retval);
3535 goto cleanup;
3538 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3539 static PyObject *
3540 libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3541 PyObject *args)
3543 PyObject *pyobj_conn;
3544 PyObject *py_retval = NULL;
3545 virConnectPtr conn;
3546 virStoragePoolPtr *pools = NULL;
3547 int c_retval = 0;
3548 ssize_t i;
3549 unsigned int flags;
3551 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllStoragePools",
3552 &pyobj_conn, &flags))
3553 return NULL;
3554 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3556 LIBVIRT_BEGIN_ALLOW_THREADS;
3557 c_retval = virConnectListAllStoragePools(conn, &pools, flags);
3558 LIBVIRT_END_ALLOW_THREADS;
3560 if (c_retval < 0)
3561 return VIR_PY_NONE;
3563 if (!(py_retval = PyList_New(c_retval)))
3564 goto cleanup;
3566 for (i = 0; i < c_retval; i++) {
3567 VIR_PY_LIST_SET_GOTO(py_retval, i,
3568 libvirt_virStoragePoolPtrWrap(pools[i]), error);
3569 /* python steals the pointer */
3570 pools[i] = NULL;
3573 cleanup:
3574 for (i = 0; i < c_retval; i++)
3575 if (pools[i])
3576 virStoragePoolFree(pools[i]);
3577 VIR_FREE(pools);
3578 return py_retval;
3580 error:
3581 Py_CLEAR(py_retval);
3582 goto cleanup;
3584 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3586 static PyObject *
3587 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
3588 PyObject *args)
3590 PyObject *py_retval;
3591 char **names = NULL;
3592 int c_retval;
3593 ssize_t i;
3594 virStoragePoolPtr pool;
3595 PyObject *pyobj_pool;
3597 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolListVolumes",
3598 &pyobj_pool))
3599 return NULL;
3600 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3602 LIBVIRT_BEGIN_ALLOW_THREADS;
3603 c_retval = virStoragePoolNumOfVolumes(pool);
3604 LIBVIRT_END_ALLOW_THREADS;
3606 if (c_retval < 0)
3607 return VIR_PY_NONE;
3609 if (c_retval) {
3610 if (VIR_ALLOC_N(names, c_retval) < 0)
3611 return PyErr_NoMemory();
3613 LIBVIRT_BEGIN_ALLOW_THREADS;
3614 c_retval = virStoragePoolListVolumes(pool, names, c_retval);
3615 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 ssize_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;
3666 if (c_retval < 0)
3667 return VIR_PY_NONE;
3669 if (!(py_retval = PyList_New(c_retval)))
3670 goto cleanup;
3672 for (i = 0; i < c_retval; i++) {
3673 VIR_PY_LIST_SET_GOTO(py_retval, i,
3674 libvirt_virStorageVolPtrWrap(vols[i]), error);
3675 /* python steals the pointer */
3676 vols[i] = NULL;
3679 cleanup:
3680 for (i = 0; i < c_retval; i++)
3681 if (vols[i])
3682 virStorageVolFree(vols[i]);
3683 VIR_FREE(vols);
3684 return py_retval;
3686 error:
3687 Py_CLEAR(py_retval);
3688 goto cleanup;
3690 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3693 static PyObject *
3694 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3695 PyObject *args)
3697 int c_retval, autostart;
3698 virStoragePoolPtr pool;
3699 PyObject *pyobj_pool;
3701 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetAutostart",
3702 &pyobj_pool))
3703 return NULL;
3705 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3707 LIBVIRT_BEGIN_ALLOW_THREADS;
3708 c_retval = virStoragePoolGetAutostart(pool, &autostart);
3709 LIBVIRT_END_ALLOW_THREADS;
3711 if (c_retval < 0)
3712 return VIR_PY_INT_FAIL;
3714 return libvirt_intWrap(autostart);
3717 static PyObject *
3718 libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED,
3719 PyObject *args)
3721 PyObject *py_retval;
3722 int c_retval;
3723 virStoragePoolPtr pool;
3724 PyObject *pyobj_pool;
3725 virStoragePoolInfo info;
3727 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetInfo", &pyobj_pool))
3728 return NULL;
3729 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3731 LIBVIRT_BEGIN_ALLOW_THREADS;
3732 c_retval = virStoragePoolGetInfo(pool, &info);
3733 LIBVIRT_END_ALLOW_THREADS;
3735 if (c_retval < 0)
3736 return VIR_PY_NONE;
3738 if ((py_retval = PyList_New(4)) == NULL)
3739 return NULL;
3741 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3742 libvirt_intWrap((int) info.state), error);
3743 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3744 libvirt_ulonglongWrap(info.capacity), error);
3745 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3746 libvirt_ulonglongWrap(info.allocation), error);
3747 VIR_PY_LIST_SET_GOTO(py_retval, 3,
3748 libvirt_ulonglongWrap(info.available), error);
3750 return py_retval;
3752 error:
3753 Py_XDECREF(py_retval);
3754 return NULL;
3758 static PyObject *
3759 libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED,
3760 PyObject *args)
3762 PyObject *py_retval;
3763 int c_retval;
3764 virStorageVolPtr pool;
3765 PyObject *pyobj_pool;
3766 virStorageVolInfo info;
3768 if (!PyArg_ParseTuple(args, (char *)"O:virStorageVolGetInfo", &pyobj_pool))
3769 return NULL;
3770 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3772 LIBVIRT_BEGIN_ALLOW_THREADS;
3773 c_retval = virStorageVolGetInfo(pool, &info);
3774 LIBVIRT_END_ALLOW_THREADS;
3776 if (c_retval < 0)
3777 return VIR_PY_NONE;
3779 if ((py_retval = PyList_New(3)) == NULL)
3780 return NULL;
3782 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3783 libvirt_intWrap((int) info.type), error);
3784 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3785 libvirt_ulonglongWrap(info.capacity), error);
3786 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3787 libvirt_ulonglongWrap(info.allocation), error);
3789 return py_retval;
3791 error:
3792 Py_DECREF(py_retval);
3793 return NULL;
3796 #if LIBVIR_CHECK_VERSION(3, 0, 0)
3797 static PyObject *
3798 libvirt_virStorageVolGetInfoFlags(PyObject *self ATTRIBUTE_UNUSED,
3799 PyObject *args)
3801 PyObject *py_retval;
3802 int c_retval;
3803 virStorageVolPtr pool;
3804 PyObject *pyobj_pool;
3805 virStorageVolInfo info;
3806 unsigned int flags;
3808 if (!PyArg_ParseTuple(args, (char *)"OI:virStorageVolGetInfoFlags", &pyobj_pool, &flags))
3809 return NULL;
3810 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3812 LIBVIRT_BEGIN_ALLOW_THREADS;
3813 c_retval = virStorageVolGetInfoFlags(pool, &info, flags);
3814 LIBVIRT_END_ALLOW_THREADS;
3816 if (c_retval < 0)
3817 return VIR_PY_NONE;
3819 if ((py_retval = PyList_New(3)) == NULL)
3820 return NULL;
3822 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3823 libvirt_intWrap((int) info.type), error);
3824 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3825 libvirt_ulonglongWrap(info.capacity), error);
3826 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3827 libvirt_ulonglongWrap(info.allocation), error);
3829 return py_retval;
3831 error:
3832 Py_DECREF(py_retval);
3833 return NULL;
3835 #endif
3837 static PyObject *
3838 libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED,
3839 PyObject *args)
3841 unsigned char uuid[VIR_UUID_BUFLEN];
3842 virStoragePoolPtr pool;
3843 PyObject *pyobj_pool;
3844 int c_retval;
3846 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUID", &pyobj_pool))
3847 return NULL;
3848 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3850 if (pool == NULL)
3851 return VIR_PY_NONE;
3853 LIBVIRT_BEGIN_ALLOW_THREADS;
3854 c_retval = virStoragePoolGetUUID(pool, &uuid[0]);
3855 LIBVIRT_END_ALLOW_THREADS;
3857 if (c_retval < 0)
3858 return VIR_PY_NONE;
3860 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3863 static PyObject *
3864 libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3865 PyObject *args)
3867 char uuidstr[VIR_UUID_STRING_BUFLEN];
3868 virStoragePoolPtr pool;
3869 PyObject *pyobj_pool;
3870 int c_retval;
3872 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString",
3873 &pyobj_pool))
3874 return NULL;
3875 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3877 if (pool == NULL)
3878 return VIR_PY_NONE;
3880 LIBVIRT_BEGIN_ALLOW_THREADS;
3881 c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]);
3882 LIBVIRT_END_ALLOW_THREADS;
3884 if (c_retval < 0)
3885 return VIR_PY_NONE;
3887 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3890 static PyObject *
3891 libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3892 PyObject *args)
3894 virStoragePoolPtr c_retval;
3895 virConnectPtr conn;
3896 PyObject *pyobj_conn;
3897 unsigned char * uuid;
3898 int len;
3900 if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID",
3901 &pyobj_conn, &uuid, &len))
3902 return NULL;
3903 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3905 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3906 return VIR_PY_NONE;
3908 LIBVIRT_BEGIN_ALLOW_THREADS;
3909 c_retval = virStoragePoolLookupByUUID(conn, uuid);
3910 LIBVIRT_END_ALLOW_THREADS;
3912 return libvirt_virStoragePoolPtrWrap((virStoragePoolPtr) c_retval);
3915 static PyObject *
3916 libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
3917 PyObject *args)
3919 PyObject *py_retval;
3920 char **names = NULL;
3921 int c_retval;
3922 ssize_t i;
3923 virConnectPtr conn;
3924 PyObject *pyobj_conn;
3925 char *cap;
3926 unsigned int flags;
3928 if (!PyArg_ParseTuple(args, (char *)"OzI:virNodeListDevices",
3929 &pyobj_conn, &cap, &flags))
3930 return NULL;
3931 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3933 LIBVIRT_BEGIN_ALLOW_THREADS;
3934 c_retval = virNodeNumOfDevices(conn, cap, flags);
3935 LIBVIRT_END_ALLOW_THREADS;
3937 if (c_retval < 0)
3938 return VIR_PY_NONE;
3940 if (c_retval) {
3941 if (VIR_ALLOC_N(names, c_retval) < 0)
3942 return PyErr_NoMemory();
3944 LIBVIRT_BEGIN_ALLOW_THREADS;
3945 c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
3946 LIBVIRT_END_ALLOW_THREADS;
3948 if (c_retval < 0) {
3949 py_retval = VIR_PY_NONE;
3950 goto cleanup;
3954 if ((py_retval = PyList_New(c_retval)) == NULL)
3955 goto cleanup;
3957 if (names)
3958 for (i = 0; i < c_retval; i++)
3959 VIR_PY_LIST_SET_GOTO(py_retval, i,
3960 libvirt_constcharPtrWrap(names[i]), error);
3962 cleanup:
3963 if (c_retval > 0)
3964 for (i = 0; i < c_retval; i++)
3965 VIR_FREE(names[i]);
3966 VIR_FREE(names);
3967 return py_retval;
3969 error:
3970 Py_CLEAR(py_retval);
3971 goto cleanup;
3974 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3975 static PyObject *
3976 libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
3977 PyObject *args)
3979 PyObject *pyobj_conn;
3980 PyObject *py_retval = NULL;
3981 virConnectPtr conn;
3982 virNodeDevicePtr *devices = NULL;
3983 int c_retval = 0;
3984 ssize_t i;
3985 unsigned int flags;
3987 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNodeDevices",
3988 &pyobj_conn, &flags))
3989 return NULL;
3990 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3992 LIBVIRT_BEGIN_ALLOW_THREADS;
3993 c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
3994 LIBVIRT_END_ALLOW_THREADS;
3996 if (c_retval < 0)
3997 return VIR_PY_NONE;
3999 if (!(py_retval = PyList_New(c_retval)))
4000 goto cleanup;
4002 for (i = 0; i < c_retval; i++) {
4003 VIR_PY_LIST_SET_GOTO(py_retval, i,
4004 libvirt_virNodeDevicePtrWrap(devices[i]), error);
4005 /* python steals the pointer */
4006 devices[i] = NULL;
4009 cleanup:
4010 for (i = 0; i < c_retval; i++)
4011 if (devices[i])
4012 virNodeDeviceFree(devices[i]);
4013 VIR_FREE(devices);
4014 return py_retval;
4016 error:
4017 Py_CLEAR(py_retval);
4018 goto cleanup;
4020 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4022 static PyObject *
4023 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
4024 PyObject *args)
4026 PyObject *py_retval;
4027 char **names = NULL;
4028 int c_retval;
4029 ssize_t i;
4030 virNodeDevicePtr dev;
4031 PyObject *pyobj_dev;
4033 if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
4034 return NULL;
4035 dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
4037 LIBVIRT_BEGIN_ALLOW_THREADS;
4038 c_retval = virNodeDeviceNumOfCaps(dev);
4039 LIBVIRT_END_ALLOW_THREADS;
4041 if (c_retval < 0)
4042 return VIR_PY_NONE;
4044 if (c_retval) {
4045 if (VIR_ALLOC_N(names, c_retval) < 0)
4046 return PyErr_NoMemory();
4048 LIBVIRT_BEGIN_ALLOW_THREADS;
4049 c_retval = virNodeDeviceListCaps(dev, names, c_retval);
4050 LIBVIRT_END_ALLOW_THREADS;
4052 if (c_retval < 0) {
4053 py_retval = VIR_PY_NONE;
4054 goto cleanup;
4058 if ((py_retval = PyList_New(c_retval)) == NULL)
4059 goto cleanup;
4061 if (names)
4062 for (i = 0; i < c_retval; i++)
4063 VIR_PY_LIST_SET_GOTO(py_retval, i,
4064 libvirt_constcharPtrWrap(names[i]), error);
4066 cleanup:
4067 if (c_retval > 0)
4068 for (i = 0; i < c_retval; i++)
4069 VIR_FREE(names[i]);
4070 VIR_FREE(names);
4071 return py_retval;
4073 error:
4074 Py_CLEAR(py_retval);
4075 goto cleanup;
4078 static PyObject *
4079 libvirt_virSecretGetUUID(PyObject *self ATTRIBUTE_UNUSED,
4080 PyObject *args)
4082 unsigned char uuid[VIR_UUID_BUFLEN];
4083 virSecretPtr secret;
4084 PyObject *pyobj_secret;
4085 int c_retval;
4087 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUID", &pyobj_secret))
4088 return NULL;
4089 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4091 if (secret == NULL)
4092 return VIR_PY_NONE;
4094 LIBVIRT_BEGIN_ALLOW_THREADS;
4095 c_retval = virSecretGetUUID(secret, &uuid[0]);
4096 LIBVIRT_END_ALLOW_THREADS;
4098 if (c_retval < 0)
4099 return VIR_PY_NONE;
4101 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4104 static PyObject *
4105 libvirt_virSecretGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4106 PyObject *args)
4108 char uuidstr[VIR_UUID_STRING_BUFLEN];
4109 virSecretPtr dom;
4110 PyObject *pyobj_dom;
4111 int c_retval;
4113 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUIDString",
4114 &pyobj_dom))
4115 return NULL;
4116 dom = (virSecretPtr) PyvirSecret_Get(pyobj_dom);
4118 if (dom == NULL)
4119 return VIR_PY_NONE;
4121 LIBVIRT_BEGIN_ALLOW_THREADS;
4122 c_retval = virSecretGetUUIDString(dom, &uuidstr[0]);
4123 LIBVIRT_END_ALLOW_THREADS;
4125 if (c_retval < 0)
4126 return VIR_PY_NONE;
4128 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4131 static PyObject *
4132 libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
4133 PyObject *args)
4135 virSecretPtr c_retval;
4136 virConnectPtr conn;
4137 PyObject *pyobj_conn;
4138 unsigned char * uuid;
4139 int len;
4141 if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID",
4142 &pyobj_conn, &uuid, &len))
4143 return NULL;
4144 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4146 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4147 return VIR_PY_NONE;
4149 LIBVIRT_BEGIN_ALLOW_THREADS;
4150 c_retval = virSecretLookupByUUID(conn, uuid);
4151 LIBVIRT_END_ALLOW_THREADS;
4153 return libvirt_virSecretPtrWrap((virSecretPtr) c_retval);
4157 static PyObject *
4158 libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
4159 PyObject *args)
4161 PyObject *py_retval;
4162 char **uuids = NULL;
4163 virConnectPtr conn;
4164 int c_retval;
4165 ssize_t i;
4166 PyObject *pyobj_conn;
4168 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
4169 return NULL;
4170 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4172 LIBVIRT_BEGIN_ALLOW_THREADS;
4173 c_retval = virConnectNumOfSecrets(conn);
4174 LIBVIRT_END_ALLOW_THREADS;
4176 if (c_retval < 0)
4177 return VIR_PY_NONE;
4179 if (c_retval) {
4180 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4181 return PyErr_NoMemory();
4183 LIBVIRT_BEGIN_ALLOW_THREADS;
4184 c_retval = virConnectListSecrets(conn, uuids, c_retval);
4185 LIBVIRT_END_ALLOW_THREADS;
4187 if (c_retval < 0) {
4188 py_retval = VIR_PY_NONE;
4189 goto cleanup;
4193 if ((py_retval = PyList_New(c_retval)) == NULL)
4194 goto cleanup;
4196 if (uuids) {
4197 for (i = 0; i < c_retval; i++)
4198 VIR_PY_LIST_SET_GOTO(py_retval, i,
4199 libvirt_constcharPtrWrap(uuids[i]), error);
4202 cleanup:
4203 if (c_retval > 0)
4204 for (i = 0; i < c_retval; i++)
4205 VIR_FREE(uuids[i]);
4206 VIR_FREE(uuids);
4207 return py_retval;
4209 error:
4210 Py_CLEAR(py_retval);
4211 goto cleanup;
4214 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4215 static PyObject *
4216 libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
4217 PyObject *args)
4219 PyObject *pyobj_conn;
4220 PyObject *py_retval = NULL;
4221 virConnectPtr conn;
4222 virSecretPtr *secrets = NULL;
4223 int c_retval = 0;
4224 ssize_t i;
4225 unsigned int flags;
4227 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllSecrets",
4228 &pyobj_conn, &flags))
4229 return NULL;
4230 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4232 LIBVIRT_BEGIN_ALLOW_THREADS;
4233 c_retval = virConnectListAllSecrets(conn, &secrets, flags);
4234 LIBVIRT_END_ALLOW_THREADS;
4236 if (c_retval < 0)
4237 return VIR_PY_NONE;
4239 if (!(py_retval = PyList_New(c_retval)))
4240 goto cleanup;
4242 for (i = 0; i < c_retval; i++) {
4243 VIR_PY_LIST_SET_GOTO(py_retval, i,
4244 libvirt_virSecretPtrWrap(secrets[i]), error);
4245 /* python steals the pointer */
4246 secrets[i] = NULL;
4249 cleanup:
4250 for (i = 0; i < c_retval; i++)
4251 if (secrets[i])
4252 virSecretFree(secrets[i]);
4253 VIR_FREE(secrets);
4254 return py_retval;
4256 error:
4257 Py_CLEAR(py_retval);
4258 goto cleanup;
4260 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4262 static PyObject *
4263 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
4264 PyObject *args)
4266 PyObject *py_retval;
4267 unsigned char *c_retval;
4268 size_t size;
4269 virSecretPtr secret;
4270 PyObject *pyobj_secret;
4271 unsigned int flags;
4273 if (!PyArg_ParseTuple(args, (char *)"OI:virSecretGetValue", &pyobj_secret,
4274 &flags))
4275 return NULL;
4276 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4278 LIBVIRT_BEGIN_ALLOW_THREADS;
4279 c_retval = virSecretGetValue(secret, &size, flags);
4280 LIBVIRT_END_ALLOW_THREADS;
4282 if (c_retval == NULL)
4283 return VIR_PY_NONE;
4285 py_retval = libvirt_charPtrSizeWrap((char*)c_retval, size);
4286 VIR_FREE(c_retval);
4288 return py_retval;
4291 static PyObject *
4292 libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
4293 PyObject *args)
4295 int c_retval;
4296 virSecretPtr secret;
4297 PyObject *pyobj_secret;
4298 const char *value;
4299 int size;
4300 unsigned int flags;
4302 if (!PyArg_ParseTuple(args, (char *)"Oz#I:virSecretSetValue", &pyobj_secret,
4303 &value, &size, &flags))
4304 return NULL;
4305 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4307 LIBVIRT_BEGIN_ALLOW_THREADS;
4308 c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
4309 flags);
4310 LIBVIRT_END_ALLOW_THREADS;
4312 return libvirt_intWrap(c_retval);
4315 static PyObject *
4316 libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED,
4317 PyObject *args)
4319 unsigned char uuid[VIR_UUID_BUFLEN];
4320 virNWFilterPtr nwfilter;
4321 PyObject *pyobj_nwfilter;
4322 int c_retval;
4324 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID",
4325 &pyobj_nwfilter))
4326 return NULL;
4327 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4329 if (nwfilter == NULL)
4330 return VIR_PY_NONE;
4332 LIBVIRT_BEGIN_ALLOW_THREADS;
4333 c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
4334 LIBVIRT_END_ALLOW_THREADS;
4336 if (c_retval < 0)
4337 return VIR_PY_NONE;
4339 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4342 static PyObject *
4343 libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4344 PyObject *args)
4346 char uuidstr[VIR_UUID_STRING_BUFLEN];
4347 virNWFilterPtr nwfilter;
4348 PyObject *pyobj_nwfilter;
4349 int c_retval;
4351 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
4352 &pyobj_nwfilter))
4353 return NULL;
4354 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4356 if (nwfilter == NULL)
4357 return VIR_PY_NONE;
4359 LIBVIRT_BEGIN_ALLOW_THREADS;
4360 c_retval = virNWFilterGetUUIDString(nwfilter, &uuidstr[0]);
4361 LIBVIRT_END_ALLOW_THREADS;
4363 if (c_retval < 0)
4364 return VIR_PY_NONE;
4366 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4369 static PyObject *
4370 libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
4371 PyObject *args)
4373 virNWFilterPtr c_retval;
4374 virConnectPtr conn;
4375 PyObject *pyobj_conn;
4376 unsigned char * uuid;
4377 int len;
4379 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID",
4380 &pyobj_conn, &uuid, &len))
4381 return NULL;
4382 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4384 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4385 return VIR_PY_NONE;
4387 LIBVIRT_BEGIN_ALLOW_THREADS;
4388 c_retval = virNWFilterLookupByUUID(conn, uuid);
4389 LIBVIRT_END_ALLOW_THREADS;
4391 return libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
4395 static PyObject *
4396 libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4397 PyObject *args)
4399 PyObject *py_retval;
4400 char **uuids = NULL;
4401 virConnectPtr conn;
4402 int c_retval;
4403 ssize_t i;
4404 PyObject *pyobj_conn;
4406 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters",
4407 &pyobj_conn))
4408 return NULL;
4409 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4411 LIBVIRT_BEGIN_ALLOW_THREADS;
4412 c_retval = virConnectNumOfNWFilters(conn);
4413 LIBVIRT_END_ALLOW_THREADS;
4415 if (c_retval < 0)
4416 return VIR_PY_NONE;
4418 if (c_retval) {
4419 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4420 return PyErr_NoMemory();
4422 LIBVIRT_BEGIN_ALLOW_THREADS;
4423 c_retval = virConnectListNWFilters(conn, uuids, c_retval);
4424 LIBVIRT_END_ALLOW_THREADS;
4426 if (c_retval < 0) {
4427 py_retval = VIR_PY_NONE;
4428 goto cleanup;
4432 if ((py_retval = PyList_New(c_retval)) == NULL)
4433 goto cleanup;
4435 if (uuids)
4436 for (i = 0; i < c_retval; i++)
4437 VIR_PY_LIST_SET_GOTO(py_retval, i,
4438 libvirt_constcharPtrWrap(uuids[i]), error);
4440 cleanup:
4441 if (c_retval > 0)
4442 for (i = 0; i < c_retval; i++)
4443 VIR_FREE(uuids[i]);
4444 VIR_FREE(uuids);
4445 return py_retval;
4447 error:
4448 Py_CLEAR(py_retval);
4449 goto cleanup;
4452 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4453 static PyObject *
4454 libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4455 PyObject *args)
4457 PyObject *pyobj_conn;
4458 PyObject *py_retval = NULL;
4459 virConnectPtr conn;
4460 virNWFilterPtr *filters = NULL;
4461 int c_retval = 0;
4462 ssize_t i;
4463 unsigned int flags;
4465 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNWFilters",
4466 &pyobj_conn, &flags))
4467 return NULL;
4468 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4470 LIBVIRT_BEGIN_ALLOW_THREADS;
4471 c_retval = virConnectListAllNWFilters(conn, &filters, flags);
4472 LIBVIRT_END_ALLOW_THREADS;
4474 if (c_retval < 0)
4475 return VIR_PY_NONE;
4477 if (!(py_retval = PyList_New(c_retval)))
4478 goto cleanup;
4480 for (i = 0; i < c_retval; i++) {
4481 VIR_PY_LIST_SET_GOTO(py_retval, i,
4482 libvirt_virNWFilterPtrWrap(filters[i]), error);
4483 /* python steals the pointer */
4484 filters[i] = NULL;
4487 cleanup:
4488 for (i = 0; i < c_retval; i++)
4489 if (filters[i])
4490 virNWFilterFree(filters[i]);
4491 VIR_FREE(filters);
4492 return py_retval;
4494 error:
4495 Py_CLEAR(py_retval);
4496 goto cleanup;
4498 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4500 #if LIBVIR_CHECK_VERSION(4, 5, 0)
4501 static PyObject *
4502 libvirt_virConnectListAllNWFilterBindings(PyObject *self ATTRIBUTE_UNUSED,
4503 PyObject *args)
4505 PyObject *pyobj_conn;
4506 PyObject *py_retval = NULL;
4507 virConnectPtr conn;
4508 virNWFilterBindingPtr *bindings = NULL;
4509 int c_retval = 0;
4510 ssize_t i;
4511 unsigned int flags;
4513 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNWFilterBindings",
4514 &pyobj_conn, &flags))
4515 return NULL;
4516 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4518 LIBVIRT_BEGIN_ALLOW_THREADS;
4519 c_retval = virConnectListAllNWFilterBindings(conn, &bindings, flags);
4520 LIBVIRT_END_ALLOW_THREADS;
4522 if (c_retval < 0)
4523 return VIR_PY_NONE;
4525 if (!(py_retval = PyList_New(c_retval)))
4526 goto cleanup;
4528 for (i = 0; i < c_retval; i++) {
4529 VIR_PY_LIST_SET_GOTO(py_retval, i,
4530 libvirt_virNWFilterBindingPtrWrap(bindings[i]), error);
4531 /* python steals the pointer */
4532 bindings[i] = NULL;
4535 cleanup:
4536 for (i = 0; i < c_retval; i++)
4537 if (bindings[i])
4538 virNWFilterBindingFree(bindings[i]);
4539 VIR_FREE(bindings);
4540 return py_retval;
4542 error:
4543 Py_CLEAR(py_retval);
4544 goto cleanup;
4546 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
4548 static PyObject *
4549 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4550 PyObject *args)
4552 PyObject *py_retval;
4553 char **names = NULL;
4554 int c_retval;
4555 ssize_t i;
4556 virConnectPtr conn;
4557 PyObject *pyobj_conn;
4560 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListInterfaces",
4561 &pyobj_conn))
4562 return NULL;
4563 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4565 LIBVIRT_BEGIN_ALLOW_THREADS;
4566 c_retval = virConnectNumOfInterfaces(conn);
4567 LIBVIRT_END_ALLOW_THREADS;
4569 if (c_retval < 0)
4570 return VIR_PY_NONE;
4572 if (c_retval) {
4573 if (VIR_ALLOC_N(names, c_retval) < 0)
4574 return PyErr_NoMemory();
4576 LIBVIRT_BEGIN_ALLOW_THREADS;
4577 c_retval = virConnectListInterfaces(conn, names, c_retval);
4578 LIBVIRT_END_ALLOW_THREADS;
4580 if (c_retval < 0) {
4581 py_retval = VIR_PY_NONE;
4582 goto cleanup;
4586 if ((py_retval = PyList_New(c_retval)) == NULL)
4587 goto cleanup;
4589 if (names)
4590 for (i = 0; i < c_retval; i++)
4591 VIR_PY_LIST_SET_GOTO(py_retval, i,
4592 libvirt_constcharPtrWrap(names[i]), error);
4594 cleanup:
4595 if (c_retval > 0)
4596 for (i = 0; i < c_retval; i++)
4597 VIR_FREE(names[i]);
4598 VIR_FREE(names);
4599 return py_retval;
4601 error:
4602 Py_CLEAR(py_retval);
4603 goto cleanup;
4607 static PyObject *
4608 libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4609 PyObject *args)
4611 PyObject *py_retval;
4612 char **names = NULL;
4613 int c_retval;
4614 ssize_t i;
4615 virConnectPtr conn;
4616 PyObject *pyobj_conn;
4619 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedInterfaces",
4620 &pyobj_conn))
4621 return NULL;
4622 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4624 LIBVIRT_BEGIN_ALLOW_THREADS;
4625 c_retval = virConnectNumOfDefinedInterfaces(conn);
4626 LIBVIRT_END_ALLOW_THREADS;
4628 if (c_retval < 0)
4629 return VIR_PY_NONE;
4631 if (c_retval) {
4632 if (VIR_ALLOC_N(names, c_retval) < 0)
4633 return PyErr_NoMemory();
4635 LIBVIRT_BEGIN_ALLOW_THREADS;
4636 c_retval = virConnectListDefinedInterfaces(conn, names, c_retval);
4637 LIBVIRT_END_ALLOW_THREADS;
4639 if (c_retval < 0) {
4640 py_retval = VIR_PY_NONE;
4641 goto cleanup;
4645 if ((py_retval = PyList_New(c_retval)) == NULL)
4646 goto cleanup;
4648 if (names) {
4649 for (i = 0; i < c_retval; i++)
4650 VIR_PY_LIST_SET_GOTO(py_retval, i,
4651 libvirt_constcharPtrWrap(names[i]), error);
4654 cleanup:
4655 if (c_retval > 0)
4656 for (i = 0; i < c_retval; i++)
4657 VIR_FREE(names[i]);
4658 VIR_FREE(names);
4659 return py_retval;
4661 error:
4662 Py_CLEAR(py_retval);
4663 goto cleanup;
4667 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4668 static PyObject *
4669 libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4670 PyObject *args)
4672 PyObject *pyobj_conn;
4673 PyObject *py_retval = NULL;
4674 virConnectPtr conn;
4675 virInterfacePtr *ifaces = NULL;
4676 int c_retval = 0;
4677 ssize_t i;
4678 unsigned int flags;
4680 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllInterfaces",
4681 &pyobj_conn, &flags))
4682 return NULL;
4683 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4685 LIBVIRT_BEGIN_ALLOW_THREADS;
4686 c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
4687 LIBVIRT_END_ALLOW_THREADS;
4689 if (c_retval < 0)
4690 return VIR_PY_NONE;
4692 if (!(py_retval = PyList_New(c_retval)))
4693 goto cleanup;
4695 for (i = 0; i < c_retval; i++) {
4696 VIR_PY_LIST_SET_GOTO(py_retval, i,
4697 libvirt_virInterfacePtrWrap(ifaces[i]), error);
4698 /* python steals the pointer */
4699 ifaces[i] = NULL;
4702 cleanup:
4703 for (i = 0; i < c_retval; i++)
4704 if (ifaces[i])
4705 virInterfaceFree(ifaces[i]);
4706 VIR_FREE(ifaces);
4707 return py_retval;
4709 error:
4710 Py_CLEAR(py_retval);
4711 goto cleanup;
4713 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4715 static PyObject *
4716 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
4717 PyObject *args)
4719 PyObject *pyobj_conn;
4720 PyObject *list;
4721 virConnectPtr conn;
4722 unsigned int flags;
4723 char **xmlcpus = NULL;
4724 int ncpus = 0;
4725 char *base_cpu;
4726 PyObject *pybase_cpu;
4727 ssize_t i, j;
4729 if (!PyArg_ParseTuple(args, (char *)"OOI:virConnectBaselineCPU",
4730 &pyobj_conn, &list, &flags))
4731 return NULL;
4732 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4734 if (PyList_Check(list)) {
4735 ncpus = PyList_Size(list);
4736 if (VIR_ALLOC_N(xmlcpus, ncpus) < 0)
4737 return PyErr_NoMemory();
4739 for (i = 0; i < ncpus; i++) {
4740 if (libvirt_charPtrUnwrap(PyList_GetItem(list, i),
4741 &(xmlcpus[i])) < 0) {
4742 for (j = 0 ; j < i ; j++)
4743 VIR_FREE(xmlcpus[j]);
4744 VIR_FREE(xmlcpus);
4745 return NULL;
4750 LIBVIRT_BEGIN_ALLOW_THREADS;
4751 base_cpu = virConnectBaselineCPU(conn, (const char **)xmlcpus, ncpus, flags);
4752 LIBVIRT_END_ALLOW_THREADS;
4754 for (i = 0 ; i < ncpus ; i++)
4755 VIR_FREE(xmlcpus[i]);
4756 VIR_FREE(xmlcpus);
4758 if (base_cpu == NULL)
4759 return VIR_PY_NONE;
4761 pybase_cpu = libvirt_constcharPtrWrap(base_cpu);
4762 VIR_FREE(base_cpu);
4764 return pybase_cpu;
4768 static PyObject *
4769 libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4770 PyObject *args)
4772 PyObject *py_retval;
4773 int c_retval;
4774 virDomainPtr domain;
4775 PyObject *pyobj_domain;
4776 virDomainJobInfo info;
4778 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetJobInfo", &pyobj_domain))
4779 return NULL;
4780 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4782 LIBVIRT_BEGIN_ALLOW_THREADS;
4783 c_retval = virDomainGetJobInfo(domain, &info);
4784 LIBVIRT_END_ALLOW_THREADS;
4786 if (c_retval < 0)
4787 return VIR_PY_NONE;
4789 if ((py_retval = PyList_New(12)) == NULL)
4790 return NULL;
4792 VIR_PY_LIST_SET_GOTO(py_retval, 0,
4793 libvirt_intWrap((int) info.type), error);
4794 VIR_PY_LIST_SET_GOTO(py_retval, 1,
4795 libvirt_ulonglongWrap(info.timeElapsed), error);
4796 VIR_PY_LIST_SET_GOTO(py_retval, 2,
4797 libvirt_ulonglongWrap(info.timeRemaining), error);
4798 VIR_PY_LIST_SET_GOTO(py_retval, 3,
4799 libvirt_ulonglongWrap(info.dataTotal), error);
4800 VIR_PY_LIST_SET_GOTO(py_retval, 4,
4801 libvirt_ulonglongWrap(info.dataProcessed), error);
4802 VIR_PY_LIST_SET_GOTO(py_retval, 5,
4803 libvirt_ulonglongWrap(info.dataRemaining), error);
4804 VIR_PY_LIST_SET_GOTO(py_retval, 6,
4805 libvirt_ulonglongWrap(info.memTotal), error);
4806 VIR_PY_LIST_SET_GOTO(py_retval, 7,
4807 libvirt_ulonglongWrap(info.memProcessed), error);
4808 VIR_PY_LIST_SET_GOTO(py_retval, 8,
4809 libvirt_ulonglongWrap(info.memRemaining), error);
4810 VIR_PY_LIST_SET_GOTO(py_retval, 9,
4811 libvirt_ulonglongWrap(info.fileTotal), error);
4812 VIR_PY_LIST_SET_GOTO(py_retval, 10,
4813 libvirt_ulonglongWrap(info.fileProcessed), error);
4814 VIR_PY_LIST_SET_GOTO(py_retval, 11,
4815 libvirt_ulonglongWrap(info.fileRemaining), error);
4817 return py_retval;
4819 error:
4820 Py_DECREF(py_retval);
4821 return NULL;
4824 #if LIBVIR_CHECK_VERSION(1, 0, 3)
4825 static PyObject *
4826 libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED,
4827 PyObject *args)
4829 PyObject *pyobj_domain;
4830 virDomainPtr domain;
4831 unsigned int flags;
4832 virTypedParameterPtr params = NULL;
4833 int nparams = 0;
4834 int type;
4835 PyObject *dict = NULL;
4836 int rc;
4838 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetJobStats",
4839 &pyobj_domain, &flags))
4840 return NULL;
4841 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4843 LIBVIRT_BEGIN_ALLOW_THREADS;
4844 rc = virDomainGetJobStats(domain, &type, &params, &nparams, flags);
4845 LIBVIRT_END_ALLOW_THREADS;
4847 if (rc < 0)
4848 return VIR_PY_NONE;
4850 if (!(dict = getPyVirTypedParameter(params, nparams)))
4851 goto cleanup;
4853 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("type"),
4854 libvirt_intWrap(type), error);
4856 cleanup:
4857 virTypedParamsFree(params, nparams);
4858 return dict;
4860 error:
4861 Py_CLEAR(dict);
4862 goto cleanup;
4864 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
4866 static PyObject *
4867 libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4868 PyObject *args)
4870 virDomainPtr domain;
4871 PyObject *pyobj_domain;
4872 const char *path;
4873 unsigned int flags;
4874 virDomainBlockJobInfo info;
4875 int c_ret;
4876 PyObject *dict;
4878 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockJobInfo",
4879 &pyobj_domain, &path, &flags))
4880 return NULL;
4881 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4883 LIBVIRT_BEGIN_ALLOW_THREADS;
4884 c_ret = virDomainGetBlockJobInfo(domain, path, &info, flags);
4885 LIBVIRT_END_ALLOW_THREADS;
4887 if (c_ret < 0)
4888 return VIR_PY_NONE;
4890 if ((dict = PyDict_New()) == NULL)
4891 return NULL;
4893 if (c_ret == 0)
4894 return dict;
4896 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("type"),
4897 libvirt_intWrap(info.type), error);
4898 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("bandwidth"),
4899 libvirt_ulongWrap(info.bandwidth), error);
4900 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("cur"),
4901 libvirt_ulonglongWrap(info.cur), error);
4902 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("end"),
4903 libvirt_ulonglongWrap(info.end), error);
4905 return dict;
4907 error:
4908 Py_DECREF(dict);
4909 return NULL;
4912 static PyObject *
4913 libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4914 PyObject *args)
4916 virDomainPtr domain;
4917 PyObject *pyobj_domain, *info;
4918 PyObject *ret = NULL;
4919 int i_retval;
4920 int nparams = 0;
4921 Py_ssize_t size = 0;
4922 const char *disk;
4923 unsigned int flags;
4924 virTypedParameterPtr params = NULL, new_params = NULL;
4926 if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainSetBlockIoTune",
4927 &pyobj_domain, &disk, &info, &flags))
4928 return NULL;
4929 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4931 if ((size = PyDict_Size(info)) < 0)
4932 return NULL;
4934 if (size == 0) {
4935 PyErr_Format(PyExc_LookupError,
4936 "Need non-empty dictionary to set attributes");
4937 return NULL;
4940 LIBVIRT_BEGIN_ALLOW_THREADS;
4941 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4942 LIBVIRT_END_ALLOW_THREADS;
4944 if (i_retval < 0)
4945 return VIR_PY_INT_FAIL;
4947 if (nparams == 0) {
4948 PyErr_Format(PyExc_LookupError,
4949 "Domain has no settable attributes");
4950 return NULL;
4953 if (VIR_ALLOC_N(params, nparams) < 0)
4954 return PyErr_NoMemory();
4956 LIBVIRT_BEGIN_ALLOW_THREADS;
4957 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4958 LIBVIRT_END_ALLOW_THREADS;
4960 if (i_retval < 0) {
4961 ret = VIR_PY_INT_FAIL;
4962 goto cleanup;
4965 new_params = setPyVirTypedParameter(info, params, nparams);
4966 if (!new_params)
4967 goto cleanup;
4969 LIBVIRT_BEGIN_ALLOW_THREADS;
4970 i_retval = virDomainSetBlockIoTune(domain, disk, new_params, size, flags);
4971 LIBVIRT_END_ALLOW_THREADS;
4973 if (i_retval < 0) {
4974 ret = VIR_PY_INT_FAIL;
4975 goto cleanup;
4978 ret = VIR_PY_INT_SUCCESS;
4980 cleanup:
4981 virTypedParamsFree(params, nparams);
4982 virTypedParamsFree(new_params, size);
4983 return ret;
4986 static PyObject *
4987 libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4988 PyObject *args)
4990 virDomainPtr domain;
4991 PyObject *pyobj_domain;
4992 PyObject *ret = NULL;
4993 int i_retval;
4994 int nparams = 0;
4995 const char *disk;
4996 unsigned int flags;
4997 virTypedParameterPtr params;
4999 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockIoTune",
5000 &pyobj_domain, &disk, &flags))
5001 return NULL;
5002 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5004 LIBVIRT_BEGIN_ALLOW_THREADS;
5005 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
5006 LIBVIRT_END_ALLOW_THREADS;
5008 if (i_retval < 0)
5009 return VIR_PY_NONE;
5011 if (!nparams)
5012 return PyDict_New();
5014 if (VIR_ALLOC_N(params, nparams) < 0)
5015 return PyErr_NoMemory();
5017 LIBVIRT_BEGIN_ALLOW_THREADS;
5018 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
5019 LIBVIRT_END_ALLOW_THREADS;
5021 if (i_retval < 0) {
5022 ret = VIR_PY_NONE;
5023 goto cleanup;
5026 ret = getPyVirTypedParameter(params, nparams);
5028 cleanup:
5029 virTypedParamsFree(params, nparams);
5030 return ret;
5033 static PyObject *
5034 libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED,
5035 PyObject *args)
5037 PyObject *py_retval = VIR_PY_NONE;
5038 virDomainPtr domain;
5039 PyObject *pyobj_domain;
5040 unsigned int flags;
5041 virDomainDiskErrorPtr disks = NULL;
5042 unsigned int ndisks;
5043 int count;
5044 ssize_t i;
5046 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetDiskErrors",
5047 &pyobj_domain, &flags))
5048 return NULL;
5050 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5052 LIBVIRT_BEGIN_ALLOW_THREADS;
5053 count = virDomainGetDiskErrors(domain, NULL, 0, 0);
5054 LIBVIRT_END_ALLOW_THREADS;
5056 if (count < 0)
5057 return VIR_PY_NONE;
5058 ndisks = count;
5060 if (ndisks) {
5061 if (VIR_ALLOC_N(disks, ndisks) < 0)
5062 return PyErr_NoMemory();
5064 LIBVIRT_BEGIN_ALLOW_THREADS;
5065 count = virDomainGetDiskErrors(domain, disks, ndisks, 0);
5066 LIBVIRT_END_ALLOW_THREADS;
5068 if (count < 0) {
5069 py_retval = VIR_PY_NONE;
5070 goto cleanup;
5074 if (!(py_retval = PyDict_New()))
5075 goto cleanup;
5077 for (i = 0; i < count; i++) {
5078 VIR_PY_DICT_SET_GOTO(py_retval,
5079 libvirt_constcharPtrWrap(disks[i].disk),
5080 libvirt_intWrap(disks[i].error),
5081 error);
5084 cleanup:
5085 if (count > 0)
5086 for (i = 0; i < count; i++)
5087 VIR_FREE(disks[i].disk);
5088 VIR_FREE(disks);
5089 return py_retval;
5091 error:
5092 Py_CLEAR(py_retval);
5093 goto cleanup;
5097 #if LIBVIR_CHECK_VERSION(1, 2, 14)
5098 static PyObject *
5099 libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED,
5100 PyObject *args)
5102 PyObject *py_retval = VIR_PY_NONE;
5103 PyObject *pyobj_domain;
5104 virDomainPtr domain;
5105 virDomainInterfacePtr *ifaces = NULL;
5106 unsigned int source;
5107 unsigned int flags;
5108 int ifaces_count = 0;
5109 ssize_t i, j;
5111 if (!PyArg_ParseTuple(args, (char *) "OII:virDomainInterfaceAddresses",
5112 &pyobj_domain, &source, &flags))
5113 return NULL;
5115 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5117 LIBVIRT_BEGIN_ALLOW_THREADS;
5118 ifaces_count = virDomainInterfaceAddresses(domain, &ifaces, source, flags);
5119 LIBVIRT_END_ALLOW_THREADS;
5121 if (ifaces_count < 0)
5122 goto cleanup;
5124 if (!(py_retval = PyDict_New()))
5125 goto error;
5127 for (i = 0; i < ifaces_count; i++) {
5128 virDomainInterfacePtr iface = ifaces[i];
5129 PyObject *py_addrs = NULL;
5130 PyObject *py_iface = NULL;
5132 if (!(py_iface = PyDict_New()))
5133 goto error;
5135 VIR_PY_DICT_SET_GOTO(py_retval, libvirt_charPtrWrap(iface->name),
5136 py_iface, error);
5138 if (iface->naddrs) {
5139 if (!(py_addrs = PyList_New(iface->naddrs))) {
5140 goto error;
5142 } else {
5143 py_addrs = VIR_PY_NONE;
5146 VIR_PY_DICT_SET_GOTO(py_iface, libvirt_constcharPtrWrap("addrs"),
5147 py_addrs, error);
5149 VIR_PY_DICT_SET_GOTO(py_iface, libvirt_constcharPtrWrap("hwaddr"),
5150 libvirt_constcharPtrWrap(iface->hwaddr), error);
5152 for (j = 0; j < iface->naddrs; j++) {
5153 virDomainIPAddressPtr addr = &(iface->addrs[j]);
5154 PyObject *py_addr = PyDict_New();
5156 if (!py_addr)
5157 goto error;
5159 VIR_PY_LIST_SET_GOTO(py_addrs, j, py_addr, error);
5161 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("addr"),
5162 libvirt_constcharPtrWrap(addr->addr), error);
5163 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("prefix"),
5164 libvirt_uintWrap(addr->prefix), error);
5165 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("type"),
5166 libvirt_intWrap(addr->type), error);
5170 cleanup:
5171 if (ifaces && ifaces_count > 0) {
5172 for (i = 0; i < ifaces_count; i++) {
5173 virDomainInterfaceFree(ifaces[i]);
5176 VIR_FREE(ifaces);
5178 return py_retval;
5180 error:
5181 Py_CLEAR(py_retval);
5182 goto cleanup;
5184 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
5187 /*******************************************
5188 * Helper functions to avoid importing modules
5189 * for every callback
5190 *******************************************/
5191 static PyObject *libvirt_module = NULL;
5192 static PyObject *libvirt_dict = NULL;
5194 static PyObject *
5195 getLibvirtModuleObject(void)
5197 if (libvirt_module)
5198 return libvirt_module;
5200 // PyImport_ImportModule returns a new reference
5201 /* Bogus (char *) cast for RHEL-5 python API brokenness */
5202 libvirt_module = PyImport_ImportModule((char *)"libvirt");
5203 if (!libvirt_module) {
5204 DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
5205 PyErr_Print();
5206 return NULL;
5209 return libvirt_module;
5212 static PyObject *
5213 getLibvirtDictObject(void)
5215 if (libvirt_dict)
5216 return libvirt_dict;
5218 // PyModule_GetDict returns a borrowed reference
5219 libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
5220 if (!libvirt_dict) {
5221 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
5222 PyErr_Print();
5223 return NULL;
5226 Py_INCREF(libvirt_dict);
5227 return libvirt_dict;
5231 static PyObject *
5232 libvirt_lookupPythonFunc(const char *funcname)
5234 PyObject *python_cb;
5236 /* Lookup the python callback */
5237 python_cb = PyDict_GetItemString(getLibvirtDictObject(), funcname);
5239 if (!python_cb) {
5240 DEBUG("%s: Error finding %s\n", __FUNCTION__, funcname);
5241 PyErr_Print();
5242 PyErr_Clear();
5243 return NULL;
5246 if (!PyCallable_Check(python_cb)) {
5247 DEBUG("%s: %s is not callable\n", __FUNCTION__, funcname);
5248 return NULL;
5251 return python_cb;
5254 /*******************************************
5255 * Domain Events
5256 *******************************************/
5258 static int
5259 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5260 virDomainPtr dom,
5261 int event,
5262 int detail,
5263 void *opaque)
5265 PyObject *pyobj_ret = NULL;
5267 PyObject *pyobj_conn = (PyObject*)opaque;
5268 PyObject *pyobj_dom;
5270 int ret = -1;
5272 LIBVIRT_ENSURE_THREAD_STATE;
5274 /* Create a python instance of this virDomainPtr */
5275 virDomainRef(dom);
5276 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5277 virDomainFree(dom);
5278 goto cleanup;
5281 /* Call the Callback Dispatcher */
5282 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5283 (char*)"_dispatchDomainEventCallbacks",
5284 (char*)"Oii",
5285 pyobj_dom,
5286 event, detail);
5288 Py_DECREF(pyobj_dom);
5290 cleanup:
5291 if (!pyobj_ret) {
5292 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5293 PyErr_Print();
5294 } else {
5295 Py_DECREF(pyobj_ret);
5296 ret = 0;
5299 LIBVIRT_RELEASE_THREAD_STATE;
5300 return ret;
5303 static PyObject *
5304 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject *self,
5305 PyObject *args)
5307 PyObject *pyobj_conn; /* virConnectPtr */
5308 PyObject *pyobj_conn_inst; /* virConnect Python object */
5310 virConnectPtr conn;
5311 int ret = 0;
5313 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectDomainEventRegister",
5314 &pyobj_conn, &pyobj_conn_inst))
5315 return NULL;
5317 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
5318 pyobj_conn, pyobj_conn_inst);
5319 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5321 Py_INCREF(pyobj_conn_inst);
5323 LIBVIRT_BEGIN_ALLOW_THREADS;
5324 ret = virConnectDomainEventRegister(conn,
5325 libvirt_virConnectDomainEventCallback,
5326 pyobj_conn_inst, NULL);
5327 LIBVIRT_END_ALLOW_THREADS;
5329 return libvirt_intWrap(ret);
5332 static PyObject *
5333 libvirt_virConnectDomainEventDeregister(PyObject *self ATTRIBUTE_UNUSED,
5334 PyObject *args)
5336 PyObject *pyobj_conn;
5337 PyObject *pyobj_conn_inst;
5339 virConnectPtr conn;
5340 int ret = 0;
5342 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectDomainEventDeregister",
5343 &pyobj_conn, &pyobj_conn_inst))
5344 return NULL;
5346 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
5348 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5350 LIBVIRT_BEGIN_ALLOW_THREADS;
5351 ret = virConnectDomainEventDeregister(conn, libvirt_virConnectDomainEventCallback);
5352 LIBVIRT_END_ALLOW_THREADS;
5354 Py_DECREF(pyobj_conn_inst);
5355 return libvirt_intWrap(ret);
5358 /*******************************************
5359 * Event Impl
5360 *******************************************/
5361 static PyObject *addHandleObj;
5362 static PyObject *updateHandleObj;
5363 static PyObject *removeHandleObj;
5364 static PyObject *addTimeoutObj;
5365 static PyObject *updateTimeoutObj;
5366 static PyObject *removeTimeoutObj;
5368 static int
5369 libvirt_virEventAddHandleFunc(int fd,
5370 int event,
5371 virEventHandleCallback cb,
5372 void *opaque,
5373 virFreeCallback ff)
5375 PyObject *result;
5376 PyObject *python_cb = NULL;
5377 PyObject *cb_args = NULL;
5378 PyObject *pyobj_args = NULL;
5379 int retval = -1;
5381 LIBVIRT_ENSURE_THREAD_STATE;
5383 if ((pyobj_args = PyTuple_New(4)) == NULL)
5384 goto cleanup;
5386 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(fd), cleanup);
5387 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
5389 /* Lookup the python callback */
5390 python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
5391 if (!python_cb) {
5392 goto cleanup;
5394 Py_INCREF(python_cb);
5396 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, python_cb, cleanup);
5398 if ((cb_args = PyTuple_New(3)) == NULL)
5399 goto cleanup;
5401 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 3, cb_args, cleanup);
5403 /* If changing contents of the opaque object, please also change
5404 * virEventInvokeFreeCallback() in libvirt-override.py
5406 VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventHandleCallbackWrap(cb), cleanup);
5407 VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
5408 VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
5410 result = PyEval_CallObject(addHandleObj, pyobj_args);
5411 if (!result) {
5412 PyErr_Print();
5413 PyErr_Clear();
5414 } else {
5415 libvirt_intUnwrap(result, &retval);
5418 Py_XDECREF(result);
5420 cleanup:
5421 Py_XDECREF(pyobj_args);
5423 LIBVIRT_RELEASE_THREAD_STATE;
5425 return retval;
5428 static void
5429 libvirt_virEventUpdateHandleFunc(int watch,
5430 int event)
5432 PyObject *result = NULL;
5433 PyObject *pyobj_args;
5435 LIBVIRT_ENSURE_THREAD_STATE;
5437 if ((pyobj_args = PyTuple_New(2)) == NULL)
5438 goto cleanup;
5440 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
5441 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
5443 result = PyEval_CallObject(updateHandleObj, pyobj_args);
5444 if (!result) {
5445 PyErr_Print();
5446 PyErr_Clear();
5449 cleanup:
5450 Py_XDECREF(result);
5451 Py_XDECREF(pyobj_args);
5453 LIBVIRT_RELEASE_THREAD_STATE;
5457 static int
5458 libvirt_virEventRemoveHandleFunc(int watch)
5460 PyObject *result = NULL;
5461 PyObject *pyobj_args;
5462 int retval = -1;
5464 LIBVIRT_ENSURE_THREAD_STATE;
5466 if ((pyobj_args = PyTuple_New(1)) == NULL)
5467 goto cleanup;
5469 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
5471 result = PyEval_CallObject(removeHandleObj, pyobj_args);
5472 if (result) {
5473 retval = 0;
5474 } else {
5475 PyErr_Print();
5476 PyErr_Clear();
5479 cleanup:
5480 Py_XDECREF(result);
5481 Py_XDECREF(pyobj_args);
5483 LIBVIRT_RELEASE_THREAD_STATE;
5485 return retval;
5489 static int
5490 libvirt_virEventAddTimeoutFunc(int timeout,
5491 virEventTimeoutCallback cb,
5492 void *opaque,
5493 virFreeCallback ff)
5495 PyObject *result = NULL;
5496 PyObject *python_cb = NULL;
5497 PyObject *cb_args = NULL;
5498 PyObject *pyobj_args = NULL;
5499 int retval = -1;
5501 LIBVIRT_ENSURE_THREAD_STATE;
5503 if ((pyobj_args = PyTuple_New(3)) == NULL)
5504 goto cleanup;
5506 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timeout), cleanup);
5508 /* Lookup the python callback */
5509 python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
5510 if (!python_cb) {
5511 goto cleanup;
5513 Py_INCREF(python_cb);
5514 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, python_cb, cleanup);
5516 if ((cb_args = PyTuple_New(3)) == NULL)
5517 goto cleanup;
5519 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, cb_args, cleanup);
5521 /* If changing contents of the opaque object, please also change
5522 * virEventInvokeFreeCallback() in libvirt-override.py
5524 VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventTimeoutCallbackWrap(cb), cleanup);
5525 VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
5526 VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
5528 result = PyEval_CallObject(addTimeoutObj, pyobj_args);
5529 if (!result) {
5530 PyErr_Print();
5531 PyErr_Clear();
5532 } else {
5533 libvirt_intUnwrap(result, &retval);
5536 cleanup:
5537 Py_XDECREF(result);
5538 Py_XDECREF(pyobj_args);
5540 LIBVIRT_RELEASE_THREAD_STATE;
5541 return retval;
5544 static void
5545 libvirt_virEventUpdateTimeoutFunc(int timer,
5546 int timeout)
5548 PyObject *result = NULL;
5549 PyObject *pyobj_args;
5551 LIBVIRT_ENSURE_THREAD_STATE;
5553 if ((pyobj_args = PyTuple_New(2)) == NULL)
5554 goto cleanup;
5556 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
5557 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(timeout), cleanup);
5559 result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
5560 if (!result) {
5561 PyErr_Print();
5562 PyErr_Clear();
5565 cleanup:
5566 Py_XDECREF(result);
5567 Py_XDECREF(pyobj_args);
5569 LIBVIRT_RELEASE_THREAD_STATE;
5572 static int
5573 libvirt_virEventRemoveTimeoutFunc(int timer)
5575 PyObject *result = NULL;
5576 PyObject *pyobj_args;
5577 int retval = -1;
5579 LIBVIRT_ENSURE_THREAD_STATE;
5581 if ((pyobj_args = PyTuple_New(1)) == NULL)
5582 goto cleanup;
5584 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
5586 result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
5587 if (result) {
5588 retval = 0;
5589 } else {
5590 PyErr_Print();
5591 PyErr_Clear();
5594 cleanup:
5595 Py_XDECREF(result);
5596 Py_XDECREF(pyobj_args);
5598 LIBVIRT_RELEASE_THREAD_STATE;
5600 return retval;
5603 static PyObject *
5604 libvirt_virEventRegisterImpl(PyObject *self ATTRIBUTE_UNUSED,
5605 PyObject *args)
5607 if (addHandleObj || updateHandleObj || removeHandleObj ||
5608 addTimeoutObj || updateTimeoutObj || removeTimeoutObj) {
5609 PyErr_SetString(PyExc_RuntimeError,
5610 "Event loop is already registered");
5611 return NULL;
5614 /* Parse and check arguments */
5615 if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
5616 &addHandleObj, &updateHandleObj,
5617 &removeHandleObj, &addTimeoutObj,
5618 &updateTimeoutObj, &removeTimeoutObj) ||
5619 !PyCallable_Check(addHandleObj) ||
5620 !PyCallable_Check(updateHandleObj) ||
5621 !PyCallable_Check(removeHandleObj) ||
5622 !PyCallable_Check(addTimeoutObj) ||
5623 !PyCallable_Check(updateTimeoutObj) ||
5624 !PyCallable_Check(removeTimeoutObj))
5625 return NULL;
5627 /* Inc refs since we're holding on to these objects until
5628 * the next call (if any) to this function.
5630 Py_INCREF(addHandleObj);
5631 Py_INCREF(updateHandleObj);
5632 Py_INCREF(removeHandleObj);
5633 Py_INCREF(addTimeoutObj);
5634 Py_INCREF(updateTimeoutObj);
5635 Py_INCREF(removeTimeoutObj);
5637 /* Now register our C EventImpl, which will dispatch
5638 * to the Python callbacks passed in as args.
5640 LIBVIRT_BEGIN_ALLOW_THREADS;
5641 virEventRegisterImpl(libvirt_virEventAddHandleFunc,
5642 libvirt_virEventUpdateHandleFunc,
5643 libvirt_virEventRemoveHandleFunc,
5644 libvirt_virEventAddTimeoutFunc,
5645 libvirt_virEventUpdateTimeoutFunc,
5646 libvirt_virEventRemoveTimeoutFunc);
5647 LIBVIRT_END_ALLOW_THREADS;
5649 return VIR_PY_INT_SUCCESS;
5652 static PyObject *
5653 libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
5654 PyObject *args)
5656 int watch, fd, event;
5657 PyObject *py_f;
5658 PyObject *py_opaque;
5659 virEventHandleCallback cb;
5660 void *opaque;
5662 if (!PyArg_ParseTuple(args, (char *) "iiiOO:virEventInvokeHandleCallback",
5663 &watch, &fd, &event, &py_f, &py_opaque))
5664 return NULL;
5666 cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
5667 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5669 if (cb) {
5670 LIBVIRT_BEGIN_ALLOW_THREADS;
5671 cb(watch, fd, event, opaque);
5672 LIBVIRT_END_ALLOW_THREADS;
5675 return VIR_PY_INT_SUCCESS;
5678 static PyObject *
5679 libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
5680 PyObject *args)
5682 int timer;
5683 PyObject *py_f;
5684 PyObject *py_opaque;
5685 virEventTimeoutCallback cb;
5686 void *opaque;
5688 if (!PyArg_ParseTuple(args, (char *) "iOO:virEventInvokeTimeoutCallback",
5689 &timer, &py_f, &py_opaque))
5690 return NULL;
5692 cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
5693 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5694 if (cb) {
5695 LIBVIRT_BEGIN_ALLOW_THREADS;
5696 cb(timer, opaque);
5697 LIBVIRT_END_ALLOW_THREADS;
5700 return VIR_PY_INT_SUCCESS;
5703 static PyObject *
5704 libvirt_virEventInvokeFreeCallback(PyObject *self ATTRIBUTE_UNUSED,
5705 PyObject *args)
5707 PyObject *py_f;
5708 PyObject *py_opaque;
5709 virFreeCallback cb;
5710 void *opaque;
5712 if (!PyArg_ParseTuple(args, (char *) "OO:virEventInvokeFreeCallback",
5713 &py_f, &py_opaque))
5714 return NULL;
5716 cb = (virFreeCallback) PyvirEventHandleCallback_Get(py_f);
5717 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5719 if (cb) {
5720 LIBVIRT_BEGIN_ALLOW_THREADS;
5721 cb(opaque);
5722 LIBVIRT_END_ALLOW_THREADS;
5725 return VIR_PY_INT_SUCCESS;
5728 static void
5729 libvirt_virEventHandleCallback(int watch,
5730 int fd,
5731 int events,
5732 void *opaque)
5734 PyObject *pyobj_cbData = (PyObject *)opaque;
5735 PyObject *pyobj_ret;
5736 PyObject *python_cb;
5738 LIBVIRT_ENSURE_THREAD_STATE;
5740 /* Lookup the python callback */
5741 python_cb = libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
5742 if (!python_cb) {
5743 goto cleanup;
5746 Py_INCREF(pyobj_cbData);
5748 /* Call the pure python dispatcher */
5749 pyobj_ret = PyObject_CallFunction(python_cb,
5750 (char *)"iiiO",
5751 watch, fd, events, pyobj_cbData);
5753 Py_DECREF(pyobj_cbData);
5755 if (!pyobj_ret) {
5756 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5757 PyErr_Print();
5758 } else {
5759 Py_DECREF(pyobj_ret);
5762 cleanup:
5763 LIBVIRT_RELEASE_THREAD_STATE;
5766 static PyObject *
5767 libvirt_virEventAddHandle(PyObject *self ATTRIBUTE_UNUSED,
5768 PyObject *args)
5770 PyObject *pyobj_cbData;
5771 virEventHandleCallback cb = libvirt_virEventHandleCallback;
5772 int events;
5773 int fd;
5774 int ret;
5776 if (!PyArg_ParseTuple(args, (char *) "iiO:virEventAddHandle",
5777 &fd, &events, &pyobj_cbData))
5778 return NULL;
5780 Py_INCREF(pyobj_cbData);
5782 LIBVIRT_BEGIN_ALLOW_THREADS;
5783 ret = virEventAddHandle(fd, events, cb, pyobj_cbData, NULL);
5784 LIBVIRT_END_ALLOW_THREADS;
5786 if (ret < 0) {
5787 Py_DECREF(pyobj_cbData);
5790 return libvirt_intWrap(ret);
5793 static void
5794 libvirt_virEventTimeoutCallback(int timer,
5795 void *opaque)
5797 PyObject *pyobj_cbData = (PyObject *)opaque;
5798 PyObject *pyobj_ret;
5799 PyObject *python_cb;
5801 LIBVIRT_ENSURE_THREAD_STATE;
5803 /* Lookup the python callback */
5804 python_cb = libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
5805 if (!python_cb) {
5806 goto cleanup;
5809 Py_INCREF(pyobj_cbData);
5811 /* Call the pure python dispatcher */
5812 pyobj_ret = PyObject_CallFunction(python_cb,
5813 (char *)"iO",
5814 timer, pyobj_cbData);
5816 Py_DECREF(pyobj_cbData);
5818 if (!pyobj_ret) {
5819 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5820 PyErr_Print();
5821 } else {
5822 Py_DECREF(pyobj_ret);
5825 cleanup:
5826 LIBVIRT_RELEASE_THREAD_STATE;
5829 static PyObject *
5830 libvirt_virEventAddTimeout(PyObject *self ATTRIBUTE_UNUSED,
5831 PyObject *args)
5833 PyObject *pyobj_cbData;
5834 virEventTimeoutCallback cb = libvirt_virEventTimeoutCallback;
5835 int timeout;
5836 int ret;
5838 if (!PyArg_ParseTuple(args, (char *) "iO:virEventAddTimeout",
5839 &timeout, &pyobj_cbData))
5840 return NULL;
5842 Py_INCREF(pyobj_cbData);
5844 LIBVIRT_BEGIN_ALLOW_THREADS;
5845 ret = virEventAddTimeout(timeout, cb, pyobj_cbData, NULL);
5846 LIBVIRT_END_ALLOW_THREADS;
5848 if (ret < 0) {
5849 Py_DECREF(pyobj_cbData);
5852 return libvirt_intWrap(ret);
5855 static void
5856 libvirt_virConnectDomainEventFreeFunc(void *opaque)
5858 PyObject *pyobj_conn = (PyObject*)opaque;
5859 LIBVIRT_ENSURE_THREAD_STATE;
5860 Py_DECREF(pyobj_conn);
5861 LIBVIRT_RELEASE_THREAD_STATE;
5864 static int
5865 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5866 virDomainPtr dom,
5867 int event,
5868 int detail,
5869 void *opaque)
5871 PyObject *pyobj_cbData = (PyObject*)opaque;
5872 PyObject *pyobj_dom;
5873 PyObject *pyobj_ret = NULL;
5874 PyObject *pyobj_conn;
5875 PyObject *dictKey;
5876 int ret = -1;
5878 LIBVIRT_ENSURE_THREAD_STATE;
5880 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5881 goto cleanup;
5882 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5883 Py_DECREF(dictKey);
5885 /* Create a python instance of this virDomainPtr */
5886 virDomainRef(dom);
5887 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5888 virDomainFree(dom);
5889 goto cleanup;
5891 Py_INCREF(pyobj_cbData);
5893 /* Call the Callback Dispatcher */
5894 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5895 (char*)"_dispatchDomainEventLifecycleCallback",
5896 (char*)"OiiO",
5897 pyobj_dom,
5898 event, detail,
5899 pyobj_cbData);
5901 Py_DECREF(pyobj_cbData);
5902 Py_DECREF(pyobj_dom);
5904 cleanup:
5905 if (!pyobj_ret) {
5906 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5907 PyErr_Print();
5908 } else {
5909 Py_DECREF(pyobj_ret);
5910 ret = 0;
5913 LIBVIRT_RELEASE_THREAD_STATE;
5914 return ret;
5917 static int
5918 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5919 virDomainPtr dom,
5920 void *opaque)
5922 PyObject *pyobj_cbData = (PyObject*)opaque;
5923 PyObject *pyobj_dom;
5924 PyObject *pyobj_ret = NULL;
5925 PyObject *pyobj_conn;
5926 PyObject *dictKey;
5927 int ret = -1;
5929 LIBVIRT_ENSURE_THREAD_STATE;
5931 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5932 goto cleanup;
5933 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5934 Py_DECREF(dictKey);
5936 /* Create a python instance of this virDomainPtr */
5937 virDomainRef(dom);
5938 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5939 virDomainFree(dom);
5940 goto cleanup;
5942 Py_INCREF(pyobj_cbData);
5944 /* Call the Callback Dispatcher */
5945 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5946 (char*)"_dispatchDomainEventGenericCallback",
5947 (char*)"OO",
5948 pyobj_dom, pyobj_cbData);
5950 Py_DECREF(pyobj_cbData);
5951 Py_DECREF(pyobj_dom);
5953 cleanup:
5954 if (!pyobj_ret) {
5955 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5956 PyErr_Print();
5957 } else {
5958 Py_DECREF(pyobj_ret);
5959 ret = 0;
5962 LIBVIRT_RELEASE_THREAD_STATE;
5963 return ret;
5966 static int
5967 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5968 virDomainPtr dom,
5969 long long utcoffset,
5970 void *opaque)
5972 PyObject *pyobj_cbData = (PyObject*)opaque;
5973 PyObject *pyobj_dom;
5974 PyObject *pyobj_ret = NULL;
5975 PyObject *pyobj_conn;
5976 PyObject *dictKey;
5977 int ret = -1;
5979 LIBVIRT_ENSURE_THREAD_STATE;
5981 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5982 goto cleanup;
5983 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5984 Py_DECREF(dictKey);
5986 /* Create a python instance of this virDomainPtr */
5987 virDomainRef(dom);
5988 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5989 virDomainFree(dom);
5990 goto cleanup;
5992 Py_INCREF(pyobj_cbData);
5994 /* Call the Callback Dispatcher */
5995 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5996 (char*)"_dispatchDomainEventRTCChangeCallback",
5997 (char*)"OLO",
5998 pyobj_dom,
5999 (PY_LONG_LONG)utcoffset,
6000 pyobj_cbData);
6002 Py_DECREF(pyobj_cbData);
6003 Py_DECREF(pyobj_dom);
6005 cleanup:
6006 if (!pyobj_ret) {
6007 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6008 PyErr_Print();
6009 } else {
6010 Py_DECREF(pyobj_ret);
6011 ret = 0;
6014 LIBVIRT_RELEASE_THREAD_STATE;
6015 return ret;
6018 static int
6019 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6020 virDomainPtr dom,
6021 int action,
6022 void *opaque)
6024 PyObject *pyobj_cbData = (PyObject*)opaque;
6025 PyObject *pyobj_dom;
6026 PyObject *pyobj_ret = NULL;
6027 PyObject *pyobj_conn;
6028 PyObject *dictKey;
6029 int ret = -1;
6031 LIBVIRT_ENSURE_THREAD_STATE;
6033 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6034 goto cleanup;
6035 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6036 Py_DECREF(dictKey);
6038 /* Create a python instance of this virDomainPtr */
6039 virDomainRef(dom);
6040 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6041 virDomainFree(dom);
6042 goto cleanup;
6044 Py_INCREF(pyobj_cbData);
6046 /* Call the Callback Dispatcher */
6047 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6048 (char*)"_dispatchDomainEventWatchdogCallback",
6049 (char*)"OiO",
6050 pyobj_dom,
6051 action,
6052 pyobj_cbData);
6054 Py_DECREF(pyobj_cbData);
6055 Py_DECREF(pyobj_dom);
6057 cleanup:
6058 if (!pyobj_ret) {
6059 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6060 PyErr_Print();
6061 } else {
6062 Py_DECREF(pyobj_ret);
6063 ret = 0;
6066 LIBVIRT_RELEASE_THREAD_STATE;
6067 return ret;
6070 static int
6071 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6072 virDomainPtr dom,
6073 const char *srcPath,
6074 const char *devAlias,
6075 int action,
6076 void *opaque)
6078 PyObject *pyobj_cbData = (PyObject*)opaque;
6079 PyObject *pyobj_dom;
6080 PyObject *pyobj_ret = NULL;
6081 PyObject *pyobj_conn;
6082 PyObject *dictKey;
6083 int ret = -1;
6085 LIBVIRT_ENSURE_THREAD_STATE;
6087 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6088 goto cleanup;
6089 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6090 Py_DECREF(dictKey);
6092 /* Create a python instance of this virDomainPtr */
6093 virDomainRef(dom);
6094 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6095 virDomainFree(dom);
6096 goto cleanup;
6098 Py_INCREF(pyobj_cbData);
6100 /* Call the Callback Dispatcher */
6101 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6102 (char*)"_dispatchDomainEventIOErrorCallback",
6103 (char*)"OssiO",
6104 pyobj_dom,
6105 srcPath, devAlias, action,
6106 pyobj_cbData);
6108 Py_DECREF(pyobj_cbData);
6109 Py_DECREF(pyobj_dom);
6111 cleanup:
6112 if (!pyobj_ret) {
6113 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6114 PyErr_Print();
6115 } else {
6116 Py_DECREF(pyobj_ret);
6117 ret = 0;
6120 LIBVIRT_RELEASE_THREAD_STATE;
6121 return ret;
6124 static int
6125 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6126 virDomainPtr dom,
6127 const char *srcPath,
6128 const char *devAlias,
6129 int action,
6130 const char *reason,
6131 void *opaque)
6133 PyObject *pyobj_cbData = (PyObject*)opaque;
6134 PyObject *pyobj_dom;
6135 PyObject *pyobj_ret = NULL;
6136 PyObject *pyobj_conn;
6137 PyObject *dictKey;
6138 int ret = -1;
6140 LIBVIRT_ENSURE_THREAD_STATE;
6142 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6143 goto cleanup;
6144 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6145 Py_DECREF(dictKey);
6147 /* Create a python instance of this virDomainPtr */
6148 virDomainRef(dom);
6149 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6150 virDomainFree(dom);
6151 goto cleanup;
6153 Py_INCREF(pyobj_cbData);
6155 /* Call the Callback Dispatcher */
6156 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6157 (char*)"_dispatchDomainEventIOErrorReasonCallback",
6158 (char*)"OssisO",
6159 pyobj_dom,
6160 srcPath, devAlias, action, reason,
6161 pyobj_cbData);
6163 Py_DECREF(pyobj_cbData);
6164 Py_DECREF(pyobj_dom);
6166 cleanup:
6167 if (!pyobj_ret) {
6168 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6169 PyErr_Print();
6170 } else {
6171 Py_DECREF(pyobj_ret);
6172 ret = 0;
6175 LIBVIRT_RELEASE_THREAD_STATE;
6176 return ret;
6179 static int
6180 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6181 virDomainPtr dom,
6182 int phase,
6183 virDomainEventGraphicsAddressPtr local,
6184 virDomainEventGraphicsAddressPtr remote,
6185 const char *authScheme,
6186 virDomainEventGraphicsSubjectPtr subject,
6187 void *opaque)
6189 PyObject *pyobj_cbData = (PyObject*)opaque;
6190 PyObject *pyobj_dom = NULL;
6191 PyObject *pyobj_ret = NULL;
6192 PyObject *pyobj_conn;
6193 PyObject *dictKey;
6194 PyObject *pyobj_local = NULL;
6195 PyObject *pyobj_remote = NULL;
6196 PyObject *pyobj_subject = NULL;
6197 int ret = -1;
6198 ssize_t i;
6200 LIBVIRT_ENSURE_THREAD_STATE;
6202 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6203 goto cleanup;
6204 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6205 Py_DECREF(dictKey);
6207 /* Create a python instance of this virDomainPtr */
6208 virDomainRef(dom);
6209 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6210 virDomainFree(dom);
6211 goto cleanup;
6213 Py_INCREF(pyobj_cbData);
6215 if ((pyobj_local = PyDict_New()) == NULL)
6216 goto cleanup;
6218 VIR_PY_DICT_SET_GOTO(pyobj_local,
6219 libvirt_constcharPtrWrap("family"),
6220 libvirt_intWrap(local->family),
6221 cleanup);
6222 VIR_PY_DICT_SET_GOTO(pyobj_local,
6223 libvirt_constcharPtrWrap("node"),
6224 libvirt_constcharPtrWrap(local->node),
6225 cleanup);
6226 VIR_PY_DICT_SET_GOTO(pyobj_local,
6227 libvirt_constcharPtrWrap("service"),
6228 libvirt_constcharPtrWrap(local->service),
6229 cleanup);
6231 if ((pyobj_remote = PyDict_New()) == NULL)
6232 goto cleanup;
6234 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6235 libvirt_constcharPtrWrap("family"),
6236 libvirt_intWrap(remote->family),
6237 cleanup);
6238 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6239 libvirt_constcharPtrWrap("node"),
6240 libvirt_constcharPtrWrap(remote->node),
6241 cleanup);
6242 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6243 libvirt_constcharPtrWrap("service"),
6244 libvirt_constcharPtrWrap(remote->service),
6245 cleanup);
6247 if ((pyobj_subject = PyList_New(subject->nidentity)) == NULL)
6248 goto cleanup;
6250 for (i = 0; i < subject->nidentity; i++) {
6251 PyObject *pair = PyTuple_New(2);
6252 if (pair == NULL)
6253 goto cleanup;
6255 VIR_PY_LIST_SET_GOTO(pyobj_subject, i, pair, cleanup);
6257 VIR_PY_TUPLE_SET_GOTO(pair, 0,
6258 libvirt_constcharPtrWrap(subject->identities[i].type),
6259 cleanup);
6260 VIR_PY_TUPLE_SET_GOTO(pair, 1,
6261 libvirt_constcharPtrWrap(subject->identities[i].name),
6262 cleanup);
6265 /* Call the Callback Dispatcher */
6266 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6267 (char*)"_dispatchDomainEventGraphicsCallback",
6268 (char*)"OiOOsOO",
6269 pyobj_dom,
6270 phase, pyobj_local, pyobj_remote,
6271 authScheme, pyobj_subject,
6272 pyobj_cbData);
6274 cleanup:
6275 Py_DECREF(pyobj_cbData);
6276 Py_XDECREF(pyobj_dom);
6278 if (!pyobj_ret) {
6279 Py_XDECREF(pyobj_local);
6280 Py_XDECREF(pyobj_remote);
6281 Py_XDECREF(pyobj_subject);
6282 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6283 PyErr_Print();
6284 } else {
6285 Py_DECREF(pyobj_ret);
6286 ret = 0;
6289 LIBVIRT_RELEASE_THREAD_STATE;
6290 return ret;
6293 static int
6294 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6295 virDomainPtr dom,
6296 const char *disk,
6297 int type,
6298 int status,
6299 void *opaque)
6301 PyObject *pyobj_cbData = (PyObject*)opaque;
6302 PyObject *pyobj_dom;
6303 PyObject *pyobj_ret = NULL;
6304 PyObject *pyobj_conn;
6305 PyObject *dictKey;
6306 int ret = -1;
6308 LIBVIRT_ENSURE_THREAD_STATE;
6310 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6311 goto cleanup;
6312 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6313 Py_DECREF(dictKey);
6315 /* Create a python instance of this virDomainPtr */
6316 virDomainRef(dom);
6317 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6318 virDomainFree(dom);
6319 goto cleanup;
6321 Py_INCREF(pyobj_cbData);
6323 /* Call the Callback Dispatcher */
6324 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6325 (char*)"_dispatchDomainEventBlockJobCallback",
6326 (char*)"OsiiO",
6327 pyobj_dom, disk, type, status, pyobj_cbData);
6329 Py_DECREF(pyobj_cbData);
6330 Py_DECREF(pyobj_dom);
6332 cleanup:
6333 if (!pyobj_ret) {
6334 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6335 PyErr_Print();
6336 } else {
6337 Py_DECREF(pyobj_ret);
6338 ret = 0;
6341 LIBVIRT_RELEASE_THREAD_STATE;
6342 return ret;
6345 static int
6346 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6347 virDomainPtr dom,
6348 const char *oldSrcPath,
6349 const char *newSrcPath,
6350 const char *devAlias,
6351 int reason,
6352 void *opaque)
6354 PyObject *pyobj_cbData = (PyObject*)opaque;
6355 PyObject *pyobj_dom;
6356 PyObject *pyobj_ret = NULL;
6357 PyObject *pyobj_conn;
6358 PyObject *dictKey;
6359 int ret = -1;
6361 LIBVIRT_ENSURE_THREAD_STATE;
6363 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6364 goto cleanup;
6365 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6366 Py_DECREF(dictKey);
6368 /* Create a python instance of this virDomainPtr */
6369 virDomainRef(dom);
6370 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6371 virDomainFree(dom);
6372 goto cleanup;
6374 Py_INCREF(pyobj_cbData);
6376 /* Call the Callback Dispatcher */
6377 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6378 (char*)"_dispatchDomainEventDiskChangeCallback",
6379 (char*)"OsssiO",
6380 pyobj_dom,
6381 oldSrcPath, newSrcPath,
6382 devAlias, reason, pyobj_cbData);
6384 Py_DECREF(pyobj_cbData);
6385 Py_DECREF(pyobj_dom);
6387 cleanup:
6388 if (!pyobj_ret) {
6389 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6390 PyErr_Print();
6391 } else {
6392 Py_DECREF(pyobj_ret);
6393 ret = 0;
6396 LIBVIRT_RELEASE_THREAD_STATE;
6397 return ret;
6400 static int
6401 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6402 virDomainPtr dom,
6403 const char *devAlias,
6404 int reason,
6405 void *opaque)
6407 PyObject *pyobj_cbData = (PyObject*)opaque;
6408 PyObject *pyobj_dom;
6409 PyObject *pyobj_ret = NULL;
6410 PyObject *pyobj_conn;
6411 PyObject *dictKey;
6412 int ret = -1;
6414 LIBVIRT_ENSURE_THREAD_STATE;
6416 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6417 goto cleanup;
6418 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6419 Py_DECREF(dictKey);
6421 /* Create a python instance of this virDomainPtr */
6422 virDomainRef(dom);
6423 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6424 virDomainFree(dom);
6425 goto cleanup;
6427 Py_INCREF(pyobj_cbData);
6429 /* Call the Callback Dispatcher */
6430 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6431 (char*)"_dispatchDomainEventTrayChangeCallback",
6432 (char*)"OsiO",
6433 pyobj_dom,
6434 devAlias, reason, pyobj_cbData);
6436 Py_DECREF(pyobj_cbData);
6437 Py_DECREF(pyobj_dom);
6439 cleanup:
6440 if (!pyobj_ret) {
6441 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6442 PyErr_Print();
6443 } else {
6444 Py_DECREF(pyobj_ret);
6445 ret = 0;
6448 LIBVIRT_RELEASE_THREAD_STATE;
6449 return ret;
6452 static int
6453 libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6454 virDomainPtr dom,
6455 int reason,
6456 void *opaque)
6458 PyObject *pyobj_cbData = (PyObject*)opaque;
6459 PyObject *pyobj_dom;
6460 PyObject *pyobj_ret = NULL;
6461 PyObject *pyobj_conn;
6462 PyObject *dictKey;
6463 int ret = -1;
6465 LIBVIRT_ENSURE_THREAD_STATE;
6467 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6468 goto cleanup;
6469 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6470 Py_DECREF(dictKey);
6472 /* Create a python instance of this virDomainPtr */
6473 virDomainRef(dom);
6474 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6475 virDomainFree(dom);
6476 goto cleanup;
6478 Py_INCREF(pyobj_cbData);
6480 /* Call the Callback Dispatcher */
6481 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6482 (char*)"_dispatchDomainEventPMWakeupCallback",
6483 (char*)"OiO",
6484 pyobj_dom,
6485 reason,
6486 pyobj_cbData);
6488 Py_DECREF(pyobj_cbData);
6489 Py_DECREF(pyobj_dom);
6491 cleanup:
6492 if (!pyobj_ret) {
6493 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6494 PyErr_Print();
6495 } else {
6496 Py_DECREF(pyobj_ret);
6497 ret = 0;
6500 LIBVIRT_RELEASE_THREAD_STATE;
6501 return ret;
6504 static int
6505 libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6506 virDomainPtr dom,
6507 int reason,
6508 void *opaque)
6510 PyObject *pyobj_cbData = (PyObject*)opaque;
6511 PyObject *pyobj_dom;
6512 PyObject *pyobj_ret = NULL;
6513 PyObject *pyobj_conn;
6514 PyObject *dictKey;
6515 int ret = -1;
6517 LIBVIRT_ENSURE_THREAD_STATE;
6519 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6520 goto cleanup;
6521 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6522 Py_DECREF(dictKey);
6524 /* Create a python instance of this virDomainPtr */
6525 virDomainRef(dom);
6526 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6527 virDomainFree(dom);
6528 goto cleanup;
6530 Py_INCREF(pyobj_cbData);
6532 /* Call the Callback Dispatcher */
6533 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6534 (char*)"_dispatchDomainEventPMSuspendCallback",
6535 (char*)"OiO",
6536 pyobj_dom,
6537 reason,
6538 pyobj_cbData);
6540 Py_DECREF(pyobj_cbData);
6541 Py_DECREF(pyobj_dom);
6543 cleanup:
6544 if (!pyobj_ret) {
6545 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6546 PyErr_Print();
6547 } else {
6548 Py_DECREF(pyobj_ret);
6549 ret = 0;
6552 LIBVIRT_RELEASE_THREAD_STATE;
6553 return ret;
6557 #ifdef VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
6558 static int
6559 libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6560 virDomainPtr dom,
6561 unsigned long long actual,
6562 void *opaque)
6564 PyObject *pyobj_cbData = (PyObject*)opaque;
6565 PyObject *pyobj_dom;
6566 PyObject *pyobj_ret = NULL;
6567 PyObject *pyobj_conn;
6568 PyObject *dictKey;
6569 int ret = -1;
6571 LIBVIRT_ENSURE_THREAD_STATE;
6573 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6574 goto cleanup;
6575 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6576 Py_DECREF(dictKey);
6578 /* Create a python instance of this virDomainPtr */
6579 virDomainRef(dom);
6580 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6581 virDomainFree(dom);
6582 goto cleanup;
6584 Py_INCREF(pyobj_cbData);
6586 /* Call the Callback Dispatcher */
6587 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6588 (char*)"_dispatchDomainEventBalloonChangeCallback",
6589 (char*)"OLO",
6590 pyobj_dom,
6591 (PY_LONG_LONG)actual,
6592 pyobj_cbData);
6594 Py_DECREF(pyobj_cbData);
6595 Py_DECREF(pyobj_dom);
6597 cleanup:
6598 if (!pyobj_ret) {
6599 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6600 PyErr_Print();
6601 } else {
6602 Py_DECREF(pyobj_ret);
6603 ret = 0;
6606 LIBVIRT_RELEASE_THREAD_STATE;
6607 return ret;
6609 #endif /* VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE */
6611 #ifdef VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
6612 static int
6613 libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6614 virDomainPtr dom,
6615 int reason,
6616 void *opaque)
6618 PyObject *pyobj_cbData = (PyObject*)opaque;
6619 PyObject *pyobj_dom;
6620 PyObject *pyobj_ret = NULL;
6621 PyObject *pyobj_conn;
6622 PyObject *dictKey;
6623 int ret = -1;
6625 LIBVIRT_ENSURE_THREAD_STATE;
6627 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6628 goto cleanup;
6629 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6630 Py_DECREF(dictKey);
6632 /* Create a python instance of this virDomainPtr */
6633 virDomainRef(dom);
6634 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6635 virDomainFree(dom);
6636 goto cleanup;
6638 Py_INCREF(pyobj_cbData);
6640 /* Call the Callback Dispatcher */
6641 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6642 (char*)"_dispatchDomainEventPMSuspendDiskCallback",
6643 (char*)"OiO",
6644 pyobj_dom,
6645 reason,
6646 pyobj_cbData);
6648 Py_DECREF(pyobj_cbData);
6649 Py_DECREF(pyobj_dom);
6651 cleanup:
6652 if (!pyobj_ret) {
6653 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6654 PyErr_Print();
6655 } else {
6656 Py_DECREF(pyobj_ret);
6657 ret = 0;
6660 LIBVIRT_RELEASE_THREAD_STATE;
6661 return ret;
6663 #endif /* VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK */
6665 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
6666 static int
6667 libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6668 virDomainPtr dom,
6669 const char *devAlias,
6670 void *opaque)
6672 PyObject *pyobj_cbData = (PyObject*)opaque;
6673 PyObject *pyobj_dom;
6674 PyObject *pyobj_ret = NULL;
6675 PyObject *pyobj_conn;
6676 PyObject *dictKey;
6677 int ret = -1;
6679 LIBVIRT_ENSURE_THREAD_STATE;
6681 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6682 goto cleanup;
6683 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6684 Py_DECREF(dictKey);
6686 /* Create a python instance of this virDomainPtr */
6687 virDomainRef(dom);
6688 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6689 virDomainFree(dom);
6690 goto cleanup;
6692 Py_INCREF(pyobj_cbData);
6694 /* Call the Callback Dispatcher */
6695 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6696 (char*)"_dispatchDomainEventDeviceRemovedCallback",
6697 (char*)"OsO",
6698 pyobj_dom, devAlias, pyobj_cbData);
6700 Py_DECREF(pyobj_cbData);
6701 Py_DECREF(pyobj_dom);
6703 cleanup:
6704 if (!pyobj_ret) {
6705 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6706 PyErr_Print();
6707 } else {
6708 Py_DECREF(pyobj_ret);
6709 ret = 0;
6712 LIBVIRT_RELEASE_THREAD_STATE;
6713 return ret;
6715 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED */
6717 #ifdef VIR_DOMAIN_EVENT_ID_TUNABLE
6718 static int
6719 libvirt_virConnectDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6720 virDomainPtr dom,
6721 virTypedParameterPtr params,
6722 int nparams,
6723 void *opaque)
6725 PyObject *pyobj_cbData = (PyObject*)opaque;
6726 PyObject *pyobj_dom;
6727 PyObject *pyobj_ret = NULL;
6728 PyObject *pyobj_conn;
6729 PyObject *dictKey;
6730 PyObject *pyobj_dict = NULL;
6731 int ret = -1;
6733 LIBVIRT_ENSURE_THREAD_STATE;
6735 pyobj_dict = getPyVirTypedParameter(params, nparams);
6736 if (!pyobj_dict)
6737 goto cleanup;
6739 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6740 goto cleanup;
6741 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6742 Py_DECREF(dictKey);
6744 /* Create a python instance of this virDomainPtr */
6745 virDomainRef(dom);
6746 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6747 virDomainFree(dom);
6748 goto cleanup;
6750 Py_INCREF(pyobj_cbData);
6752 /* Call the Callback Dispatcher */
6753 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6754 (char*)"_dispatchDomainEventTunableCallback",
6755 (char*)"OOO",
6756 pyobj_dom, pyobj_dict, pyobj_cbData);
6758 Py_DECREF(pyobj_cbData);
6759 Py_DECREF(pyobj_dom);
6761 cleanup:
6762 if (!pyobj_ret) {
6763 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6764 PyErr_Print();
6765 } else {
6766 Py_DECREF(pyobj_ret);
6767 ret = 0;
6769 Py_XDECREF(pyobj_dict);
6771 LIBVIRT_RELEASE_THREAD_STATE;
6772 return ret;
6775 #endif /* VIR_DOMAIN_EVENT_ID_TUNABLE */
6777 #ifdef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
6778 static int
6779 libvirt_virConnectDomainEventAgentLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6780 virDomainPtr dom,
6781 int state,
6782 int reason,
6783 void *opaque)
6785 PyObject *pyobj_cbData = (PyObject*)opaque;
6786 PyObject *pyobj_dom;
6787 PyObject *pyobj_ret = NULL;
6788 PyObject *pyobj_conn;
6789 PyObject *dictKey;
6790 int ret = -1;
6792 LIBVIRT_ENSURE_THREAD_STATE;
6794 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6795 goto cleanup;
6796 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6797 Py_DECREF(dictKey);
6799 /* Create a python instance of this virDomainPtr */
6800 virDomainRef(dom);
6801 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6802 virDomainFree(dom);
6803 goto cleanup;
6805 Py_INCREF(pyobj_cbData);
6807 /* Call the Callback Dispatcher */
6808 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6809 (char*)"_dispatchDomainEventAgentLifecycleCallback",
6810 (char*)"OiiO",
6811 pyobj_dom, state, reason, pyobj_cbData);
6813 Py_DECREF(pyobj_cbData);
6814 Py_DECREF(pyobj_dom);
6816 cleanup:
6817 if (!pyobj_ret) {
6818 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6819 PyErr_Print();
6820 } else {
6821 Py_DECREF(pyobj_ret);
6822 ret = 0;
6825 LIBVIRT_RELEASE_THREAD_STATE;
6826 return ret;
6829 #endif /* VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE */
6831 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
6832 static int
6833 libvirt_virConnectDomainEventDeviceAddedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6834 virDomainPtr dom,
6835 const char *devAlias,
6836 void *opaque)
6838 PyObject *pyobj_cbData = (PyObject*)opaque;
6839 PyObject *pyobj_dom;
6840 PyObject *pyobj_ret = NULL;
6841 PyObject *pyobj_conn;
6842 PyObject *dictKey;
6843 int ret = -1;
6845 LIBVIRT_ENSURE_THREAD_STATE;
6847 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6848 goto cleanup;
6849 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6850 Py_DECREF(dictKey);
6852 /* Create a python instance of this virDomainPtr */
6853 virDomainRef(dom);
6854 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6855 virDomainFree(dom);
6856 goto cleanup;
6858 Py_INCREF(pyobj_cbData);
6860 /* Call the Callback Dispatcher */
6861 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6862 (char*)"_dispatchDomainEventDeviceAddedCallback",
6863 (char*)"OsO",
6864 pyobj_dom, devAlias, pyobj_cbData);
6866 Py_DECREF(pyobj_cbData);
6867 Py_DECREF(pyobj_dom);
6869 cleanup:
6870 if (!pyobj_ret) {
6871 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6872 PyErr_Print();
6873 } else {
6874 Py_DECREF(pyobj_ret);
6875 ret = 0;
6878 LIBVIRT_RELEASE_THREAD_STATE;
6879 return ret;
6882 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_ADDED */
6884 #ifdef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
6885 static int
6886 libvirt_virConnectDomainEventMigrationIterationCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6887 virDomainPtr dom,
6888 int iteration,
6889 void *opaque)
6891 PyObject *pyobj_cbData = (PyObject*)opaque;
6892 PyObject *pyobj_dom;
6893 PyObject *pyobj_ret = NULL;
6894 PyObject *pyobj_conn;
6895 PyObject *dictKey;
6896 int ret = -1;
6898 LIBVIRT_ENSURE_THREAD_STATE;
6900 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6901 goto cleanup;
6902 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6903 Py_DECREF(dictKey);
6905 /* Create a python instance of this virDomainPtr */
6906 virDomainRef(dom);
6907 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6908 virDomainFree(dom);
6909 goto cleanup;
6911 Py_INCREF(pyobj_cbData);
6913 /* Call the Callback Dispatcher */
6914 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6915 (char*)"_dispatchDomainEventMigrationIterationCallback",
6916 (char*)"OiO",
6917 pyobj_dom, iteration, pyobj_cbData);
6919 Py_DECREF(pyobj_cbData);
6920 Py_DECREF(pyobj_dom);
6922 cleanup:
6923 if (!pyobj_ret) {
6924 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6925 PyErr_Print();
6926 } else {
6927 Py_DECREF(pyobj_ret);
6928 ret = 0;
6931 LIBVIRT_RELEASE_THREAD_STATE;
6932 return ret;
6934 #endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
6936 #ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
6937 static int
6938 libvirt_virConnectDomainEventJobCompletedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6939 virDomainPtr dom,
6940 virTypedParameterPtr params,
6941 int nparams,
6942 void *opaque)
6944 PyObject *pyobj_cbData = (PyObject*)opaque;
6945 PyObject *pyobj_dom;
6946 PyObject *pyobj_ret = NULL;
6947 PyObject *pyobj_conn;
6948 PyObject *dictKey;
6949 PyObject *pyobj_dict = NULL;
6950 int ret = -1;
6952 LIBVIRT_ENSURE_THREAD_STATE;
6954 pyobj_dict = getPyVirTypedParameter(params, nparams);
6955 if (!pyobj_dict)
6956 goto cleanup;
6958 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6959 goto cleanup;
6960 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6961 Py_DECREF(dictKey);
6963 /* Create a python instance of this virDomainPtr */
6964 virDomainRef(dom);
6965 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6966 virDomainFree(dom);
6967 goto cleanup;
6969 Py_INCREF(pyobj_cbData);
6971 /* Call the Callback Dispatcher */
6972 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6973 (char*)"_dispatchDomainEventJobCompletedCallback",
6974 (char*)"OOO",
6975 pyobj_dom, pyobj_dict, pyobj_cbData);
6977 Py_DECREF(pyobj_cbData);
6978 Py_DECREF(pyobj_dom);
6980 cleanup:
6981 if (!pyobj_ret) {
6982 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6983 PyErr_Print();
6984 Py_XDECREF(pyobj_dict);
6985 } else {
6986 Py_DECREF(pyobj_ret);
6987 ret = 0;
6990 LIBVIRT_RELEASE_THREAD_STATE;
6991 return ret;
6993 #endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
6996 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
6997 static int
6998 libvirt_virConnectDomainEventDeviceRemovalFailedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6999 virDomainPtr dom,
7000 const char *devAlias,
7001 void *opaque)
7003 PyObject *pyobj_cbData = (PyObject*)opaque;
7004 PyObject *pyobj_dom;
7005 PyObject *pyobj_ret = NULL;
7006 PyObject *pyobj_conn;
7007 PyObject *dictKey;
7008 int ret = -1;
7010 LIBVIRT_ENSURE_THREAD_STATE;
7012 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7013 goto cleanup;
7014 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7015 Py_DECREF(dictKey);
7017 /* Create a python instance of this virDomainPtr */
7018 virDomainRef(dom);
7019 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7020 virDomainFree(dom);
7021 goto cleanup;
7023 Py_INCREF(pyobj_cbData);
7025 /* Call the Callback Dispatcher */
7026 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7027 (char*)"_dispatchDomainEventDeviceRemovalFailedCallback",
7028 (char*)"OsO",
7029 pyobj_dom, devAlias, pyobj_cbData);
7031 Py_DECREF(pyobj_cbData);
7032 Py_DECREF(pyobj_dom);
7034 cleanup:
7035 if (!pyobj_ret) {
7036 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7037 PyErr_Print();
7038 } else {
7039 Py_DECREF(pyobj_ret);
7040 ret = 0;
7043 LIBVIRT_RELEASE_THREAD_STATE;
7044 return ret;
7047 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED */
7049 #ifdef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
7050 static int
7051 libvirt_virConnectDomainEventMetadataChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7052 virDomainPtr dom,
7053 int type,
7054 const char *nsuri,
7055 void *opaque)
7057 PyObject *pyobj_cbData = (PyObject*)opaque;
7058 PyObject *pyobj_dom;
7059 PyObject *pyobj_ret = NULL;
7060 PyObject *pyobj_conn;
7061 PyObject *dictKey;
7062 int ret = -1;
7064 LIBVIRT_ENSURE_THREAD_STATE;
7066 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7067 goto cleanup;
7068 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7069 Py_DECREF(dictKey);
7071 /* Create a python instance of this virDomainPtr */
7072 virDomainRef(dom);
7073 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7074 virDomainFree(dom);
7075 goto cleanup;
7077 Py_INCREF(pyobj_cbData);
7079 /* Call the Callback Dispatcher */
7080 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7081 (char*)"_dispatchDomainEventMetadataChangeCallback",
7082 (char*)"OisO",
7083 pyobj_dom, type, nsuri, pyobj_cbData);
7085 Py_DECREF(pyobj_cbData);
7086 Py_DECREF(pyobj_dom);
7088 cleanup:
7089 if (!pyobj_ret) {
7090 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7091 PyErr_Print();
7092 } else {
7093 Py_DECREF(pyobj_ret);
7094 ret = 0;
7097 LIBVIRT_RELEASE_THREAD_STATE;
7098 return ret;
7100 #endif /* VIR_DOMAIN_EVENT_ID_METADATA_CHANGE */
7102 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
7103 static int
7104 libvirt_virConnectDomainEventBlockThresholdCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7105 virDomainPtr dom,
7106 const char *dev,
7107 const char *path,
7108 unsigned long long threshold,
7109 unsigned long long excess,
7110 void *opaque)
7112 PyObject *pyobj_cbData = (PyObject*)opaque;
7113 PyObject *pyobj_dom;
7114 PyObject *pyobj_ret = NULL;
7115 PyObject *pyobj_conn;
7116 PyObject *dictKey;
7117 int ret = -1;
7119 LIBVIRT_ENSURE_THREAD_STATE;
7121 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7122 goto cleanup;
7123 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7124 Py_DECREF(dictKey);
7126 /* Create a python instance of this virDomainPtr */
7127 virDomainRef(dom);
7128 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7129 virDomainFree(dom);
7130 goto cleanup;
7132 Py_INCREF(pyobj_cbData);
7134 /* Call the Callback Dispatcher */
7135 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7136 (char*)"_dispatchDomainEventBlockThresholdCallback",
7137 (char*)"OssiiO",
7138 pyobj_dom, dev, path, threshold, excess,
7139 pyobj_cbData);
7141 Py_DECREF(pyobj_cbData);
7142 Py_DECREF(pyobj_dom);
7144 cleanup:
7145 if (!pyobj_ret) {
7146 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7147 PyErr_Print();
7148 } else {
7149 Py_DECREF(pyobj_ret);
7150 ret = 0;
7153 LIBVIRT_RELEASE_THREAD_STATE;
7154 return ret;
7156 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
7159 static PyObject *
7160 libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
7161 PyObject *args)
7163 PyObject *py_retval; /* return value */
7164 PyObject *pyobj_conn; /* virConnectPtr */
7165 PyObject *pyobj_dom;
7166 PyObject *pyobj_cbData; /* hash of callback data */
7167 int eventID;
7168 virConnectPtr conn;
7169 int ret = 0;
7170 virConnectDomainEventGenericCallback cb = NULL;
7171 virDomainPtr dom;
7173 if (!PyArg_ParseTuple(args,
7174 (char *) "OOiO:virConnectDomainEventRegisterAny",
7175 &pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData))
7176 return NULL;
7178 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
7179 pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
7180 conn = PyvirConnect_Get(pyobj_conn);
7181 if (pyobj_dom == Py_None)
7182 dom = NULL;
7183 else
7184 dom = PyvirDomain_Get(pyobj_dom);
7186 switch ((virDomainEventID) eventID) {
7187 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
7188 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback);
7189 break;
7190 case VIR_DOMAIN_EVENT_ID_REBOOT:
7191 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
7192 break;
7193 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
7194 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback);
7195 break;
7196 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
7197 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback);
7198 break;
7199 case VIR_DOMAIN_EVENT_ID_IO_ERROR:
7200 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback);
7201 break;
7202 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
7203 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback);
7204 break;
7205 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
7206 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback);
7207 break;
7208 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
7209 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
7210 break;
7211 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
7212 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
7213 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2:
7214 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 */
7215 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback);
7216 break;
7217 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
7218 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
7219 break;
7220 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
7221 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
7222 break;
7223 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
7224 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
7225 break;
7226 case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
7227 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
7228 break;
7229 #ifdef VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
7230 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
7231 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback);
7232 break;
7233 #endif /* VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE */
7234 #ifdef VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
7235 case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
7236 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback);
7237 break;
7238 #endif /* VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK */
7239 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
7240 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
7241 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback);
7242 break;
7243 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED */
7244 #ifdef VIR_DOMAIN_EVENT_ID_TUNABLE
7245 case VIR_DOMAIN_EVENT_ID_TUNABLE:
7246 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTunableCallback);
7247 break;
7248 #endif /* VIR_DOMAIN_EVENT_ID_TUNABLE */
7249 #ifdef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
7250 case VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE:
7251 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventAgentLifecycleCallback);
7252 break;
7253 #endif /* VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE */
7254 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
7255 case VIR_DOMAIN_EVENT_ID_DEVICE_ADDED:
7256 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceAddedCallback);
7257 break;
7258 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_ADDED */
7259 #ifdef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
7260 case VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION:
7261 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMigrationIterationCallback);
7262 break;
7263 #endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
7264 #ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
7265 case VIR_DOMAIN_EVENT_ID_JOB_COMPLETED:
7266 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventJobCompletedCallback);
7267 break;
7268 #endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
7269 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
7270 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED:
7271 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovalFailedCallback);
7272 break;
7273 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED */
7274 #ifdef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
7275 case VIR_DOMAIN_EVENT_ID_METADATA_CHANGE:
7276 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMetadataChangeCallback);
7277 break;
7278 #endif /* VIR_DOMAIN_EVENT_ID_METADATA_CHANGE */
7279 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
7280 case VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD:
7281 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockThresholdCallback);
7282 break;
7283 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
7284 case VIR_DOMAIN_EVENT_ID_LAST:
7285 break;
7288 if (!cb) {
7289 return VIR_PY_INT_FAIL;
7292 Py_INCREF(pyobj_cbData);
7294 LIBVIRT_BEGIN_ALLOW_THREADS;
7295 ret = virConnectDomainEventRegisterAny(conn, dom, eventID,
7296 cb, pyobj_cbData,
7297 libvirt_virConnectDomainEventFreeFunc);
7298 LIBVIRT_END_ALLOW_THREADS;
7300 if (ret < 0) {
7301 Py_DECREF(pyobj_cbData);
7304 py_retval = libvirt_intWrap(ret);
7305 return py_retval;
7308 static PyObject *
7309 libvirt_virConnectDomainEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
7310 PyObject *args)
7312 PyObject *pyobj_conn;
7313 int callbackID;
7314 virConnectPtr conn;
7315 int ret = 0;
7317 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectDomainEventDeregister",
7318 &pyobj_conn, &callbackID))
7319 return NULL;
7321 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
7323 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7325 LIBVIRT_BEGIN_ALLOW_THREADS;
7326 ret = virConnectDomainEventDeregisterAny(conn, callbackID);
7327 LIBVIRT_END_ALLOW_THREADS;
7329 return libvirt_intWrap(ret);
7332 #if LIBVIR_CHECK_VERSION(1, 2, 1)
7333 static void
7334 libvirt_virConnectNetworkEventFreeFunc(void *opaque)
7336 PyObject *pyobj_conn = (PyObject*)opaque;
7337 LIBVIRT_ENSURE_THREAD_STATE;
7338 Py_DECREF(pyobj_conn);
7339 LIBVIRT_RELEASE_THREAD_STATE;
7342 static int
7343 libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7344 virNetworkPtr net,
7345 int event,
7346 int detail,
7347 void *opaque)
7349 PyObject *pyobj_cbData = (PyObject*)opaque;
7350 PyObject *pyobj_net;
7351 PyObject *pyobj_ret = NULL;
7352 PyObject *pyobj_conn;
7353 PyObject *dictKey;
7354 int ret = -1;
7356 LIBVIRT_ENSURE_THREAD_STATE;
7358 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7359 goto cleanup;
7360 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7361 Py_DECREF(dictKey);
7363 /* Create a python instance of this virNetworkPtr */
7364 virNetworkRef(net);
7365 if (!(pyobj_net = libvirt_virNetworkPtrWrap(net))) {
7366 virNetworkFree(net);
7367 goto cleanup;
7369 Py_INCREF(pyobj_cbData);
7371 /* Call the Callback Dispatcher */
7372 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7373 (char*)"_dispatchNetworkEventLifecycleCallback",
7374 (char*)"OiiO",
7375 pyobj_net,
7376 event,
7377 detail,
7378 pyobj_cbData);
7380 Py_DECREF(pyobj_cbData);
7381 Py_DECREF(pyobj_net);
7383 cleanup:
7384 if (!pyobj_ret) {
7385 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7386 PyErr_Print();
7387 } else {
7388 Py_DECREF(pyobj_ret);
7389 ret = 0;
7392 LIBVIRT_RELEASE_THREAD_STATE;
7393 return ret;
7396 static PyObject *
7397 libvirt_virConnectNetworkEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
7398 PyObject *args)
7400 PyObject *pyobj_conn; /* virConnectPtr */
7401 PyObject *pyobj_net;
7402 PyObject *pyobj_cbData; /* hash of callback data */
7403 int eventID;
7404 virConnectPtr conn;
7405 int ret = 0;
7406 virConnectNetworkEventGenericCallback cb = NULL;
7407 virNetworkPtr net;
7409 if (!PyArg_ParseTuple(args,
7410 (char *) "OOiO:virConnectNetworkEventRegisterAny",
7411 &pyobj_conn, &pyobj_net, &eventID, &pyobj_cbData))
7412 return NULL;
7414 DEBUG("libvirt_virConnectNetworkEventRegister(%p %p %d %p) called\n",
7415 pyobj_conn, pyobj_net, eventID, pyobj_cbData);
7416 conn = PyvirConnect_Get(pyobj_conn);
7417 if (pyobj_net == Py_None)
7418 net = NULL;
7419 else
7420 net = PyvirNetwork_Get(pyobj_net);
7422 switch ((virNetworkEventID) eventID) {
7423 case VIR_NETWORK_EVENT_ID_LIFECYCLE:
7424 cb = VIR_NETWORK_EVENT_CALLBACK(libvirt_virConnectNetworkEventLifecycleCallback);
7425 break;
7427 case VIR_NETWORK_EVENT_ID_LAST:
7428 break;
7431 if (!cb) {
7432 return VIR_PY_INT_FAIL;
7435 Py_INCREF(pyobj_cbData);
7437 LIBVIRT_BEGIN_ALLOW_THREADS;
7438 ret = virConnectNetworkEventRegisterAny(conn, net, eventID,
7439 cb, pyobj_cbData,
7440 libvirt_virConnectNetworkEventFreeFunc);
7441 LIBVIRT_END_ALLOW_THREADS;
7443 if (ret < 0) {
7444 Py_DECREF(pyobj_cbData);
7447 return libvirt_intWrap(ret);
7450 static PyObject *
7451 libvirt_virConnectNetworkEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
7452 PyObject *args)
7454 PyObject *pyobj_conn;
7455 int callbackID;
7456 virConnectPtr conn;
7457 int ret = 0;
7459 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectNetworkEventDeregister",
7460 &pyobj_conn, &callbackID))
7461 return NULL;
7463 DEBUG("libvirt_virConnectNetworkEventDeregister(%p) called\n", pyobj_conn);
7465 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7467 LIBVIRT_BEGIN_ALLOW_THREADS;
7468 ret = virConnectNetworkEventDeregisterAny(conn, callbackID);
7469 LIBVIRT_END_ALLOW_THREADS;
7471 return libvirt_intWrap(ret);
7473 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1)*/
7475 #if LIBVIR_CHECK_VERSION(0, 10, 0)
7476 static void
7477 libvirt_virConnectCloseCallbackDispatch(virConnectPtr conn ATTRIBUTE_UNUSED,
7478 int reason,
7479 void *opaque)
7481 PyObject *pyobj_cbData = (PyObject*)opaque;
7482 PyObject *pyobj_ret;
7483 PyObject *pyobj_conn;
7484 PyObject *dictKey;
7486 LIBVIRT_ENSURE_THREAD_STATE;
7488 Py_INCREF(pyobj_cbData);
7490 dictKey = libvirt_constcharPtrWrap("conn");
7491 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7492 Py_DECREF(dictKey);
7494 /* Call the Callback Dispatcher */
7495 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7496 (char*)"_dispatchCloseCallback",
7497 (char*)"iO",
7498 reason,
7499 pyobj_cbData);
7501 Py_DECREF(pyobj_cbData);
7503 if (!pyobj_ret) {
7504 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7505 PyErr_Print();
7506 } else {
7507 Py_DECREF(pyobj_ret);
7510 LIBVIRT_RELEASE_THREAD_STATE;
7513 static PyObject *
7514 libvirt_virConnectRegisterCloseCallback(PyObject *self ATTRIBUTE_UNUSED,
7515 PyObject *args)
7517 PyObject *pyobj_conn; /* virConnectPtr */
7518 PyObject *pyobj_cbData; /* hash of callback data */
7519 virConnectPtr conn;
7520 int ret = 0;
7522 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectRegisterCloseCallback",
7523 &pyobj_conn, &pyobj_cbData))
7524 return NULL;
7526 DEBUG("libvirt_virConnectRegisterCloseCallback(%p %p) called\n",
7527 pyobj_conn, pyobj_cbData);
7528 conn = PyvirConnect_Get(pyobj_conn);
7530 Py_INCREF(pyobj_cbData);
7532 LIBVIRT_BEGIN_ALLOW_THREADS;
7533 ret = virConnectRegisterCloseCallback(conn,
7534 libvirt_virConnectCloseCallbackDispatch,
7535 pyobj_cbData,
7536 libvirt_virConnectDomainEventFreeFunc);
7537 LIBVIRT_END_ALLOW_THREADS;
7539 if (ret < 0) {
7540 Py_DECREF(pyobj_cbData);
7543 return libvirt_intWrap(ret);
7546 static PyObject *
7547 libvirt_virConnectUnregisterCloseCallback(PyObject * self ATTRIBUTE_UNUSED,
7548 PyObject * args)
7550 PyObject *pyobj_conn;
7551 virConnectPtr conn;
7552 int ret = 0;
7554 if (!PyArg_ParseTuple(args, (char *) "O:virConnectUnregisterCloseCallback",
7555 &pyobj_conn))
7556 return NULL;
7558 DEBUG("libvirt_virConnectDomainEventUnregister(%p) called\n",
7559 pyobj_conn);
7561 conn = PyvirConnect_Get(pyobj_conn);
7563 LIBVIRT_BEGIN_ALLOW_THREADS;
7564 ret = virConnectUnregisterCloseCallback(conn,
7565 libvirt_virConnectCloseCallbackDispatch);
7566 LIBVIRT_END_ALLOW_THREADS;
7568 return libvirt_intWrap(ret);
7570 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
7572 static void
7573 libvirt_virStreamEventFreeFunc(void *opaque)
7575 PyObject *pyobj_stream = (PyObject*)opaque;
7576 LIBVIRT_ENSURE_THREAD_STATE;
7577 Py_DECREF(pyobj_stream);
7578 LIBVIRT_RELEASE_THREAD_STATE;
7581 static void
7582 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED,
7583 int events,
7584 void *opaque)
7586 PyObject *pyobj_cbData = (PyObject *)opaque;
7587 PyObject *pyobj_stream;
7588 PyObject *pyobj_ret;
7589 PyObject *dictKey;
7591 LIBVIRT_ENSURE_THREAD_STATE;
7593 Py_INCREF(pyobj_cbData);
7594 dictKey = libvirt_constcharPtrWrap("stream");
7595 pyobj_stream = PyDict_GetItem(pyobj_cbData, dictKey);
7596 Py_DECREF(dictKey);
7598 /* Call the pure python dispatcher */
7599 pyobj_ret = PyObject_CallMethod(pyobj_stream,
7600 (char *)"_dispatchStreamEventCallback",
7601 (char *)"iO",
7602 events, pyobj_cbData);
7604 Py_DECREF(pyobj_cbData);
7606 if (!pyobj_ret) {
7607 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7608 PyErr_Print();
7609 } else {
7610 Py_DECREF(pyobj_ret);
7613 LIBVIRT_RELEASE_THREAD_STATE;
7616 static PyObject *
7617 libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
7618 PyObject *args)
7620 PyObject *pyobj_stream;
7621 PyObject *pyobj_cbData;
7622 virStreamPtr stream;
7623 virStreamEventCallback cb = libvirt_virStreamEventCallback;
7624 int ret;
7625 int events;
7627 if (!PyArg_ParseTuple(args, (char *) "OiO:virStreamEventAddCallback",
7628 &pyobj_stream, &events, &pyobj_cbData))
7629 return NULL;
7631 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
7632 pyobj_stream, events, pyobj_cbData);
7633 stream = PyvirStream_Get(pyobj_stream);
7635 Py_INCREF(pyobj_cbData);
7637 LIBVIRT_BEGIN_ALLOW_THREADS;
7638 ret = virStreamEventAddCallback(stream, events, cb, pyobj_cbData,
7639 libvirt_virStreamEventFreeFunc);
7640 LIBVIRT_END_ALLOW_THREADS;
7642 if (ret < 0) {
7643 Py_DECREF(pyobj_cbData);
7646 return libvirt_intWrap(ret);
7649 static PyObject *
7650 libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
7651 PyObject *args)
7653 PyObject *pyobj_stream;
7654 PyObject *rv;
7655 virStreamPtr stream;
7656 char *buf = NULL;
7657 int ret;
7658 int nbytes;
7660 if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
7661 &pyobj_stream, &nbytes)) {
7662 return NULL;
7664 stream = PyvirStream_Get(pyobj_stream);
7666 if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0)
7667 return PyErr_NoMemory();
7669 LIBVIRT_BEGIN_ALLOW_THREADS;
7670 ret = virStreamRecv(stream, buf, nbytes);
7671 LIBVIRT_END_ALLOW_THREADS;
7673 buf[ret > -1 ? ret : 0] = '\0';
7674 DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
7676 if (ret == -2)
7677 return libvirt_intWrap(ret);
7678 if (ret < 0)
7679 return VIR_PY_NONE;
7680 rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
7681 VIR_FREE(buf);
7682 return rv;
7685 static PyObject *
7686 libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
7687 PyObject *args)
7689 PyObject *pyobj_stream;
7690 PyObject *pyobj_data;
7691 virStreamPtr stream;
7692 char *data;
7693 Py_ssize_t datalen;
7694 int ret;
7696 if (!PyArg_ParseTuple(args, (char *) "OO:virStreamSend",
7697 &pyobj_stream, &pyobj_data))
7698 return NULL;
7700 stream = PyvirStream_Get(pyobj_stream);
7701 libvirt_charPtrSizeUnwrap(pyobj_data, &data, &datalen);
7703 LIBVIRT_BEGIN_ALLOW_THREADS;
7704 ret = virStreamSend(stream, data, datalen);
7705 LIBVIRT_END_ALLOW_THREADS;
7707 DEBUG("StreamSend ret=%d\n", ret);
7709 return libvirt_intWrap(ret);
7712 static PyObject *
7713 libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
7714 PyObject *args)
7716 virDomainPtr domain;
7717 PyObject *pyobj_domain;
7718 PyObject *pyobj_list;
7719 int codeset;
7720 int holdtime;
7721 unsigned int flags;
7722 int ret;
7723 ssize_t i;
7724 unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
7725 unsigned int nkeycodes;
7727 if (!PyArg_ParseTuple(args, (char *)"OiiOII:virDomainSendKey",
7728 &pyobj_domain, &codeset, &holdtime, &pyobj_list,
7729 &nkeycodes, &flags))
7730 return NULL;
7732 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7734 if (!PyList_Check(pyobj_list)) {
7735 return VIR_PY_INT_FAIL;
7738 if (nkeycodes != PyList_Size(pyobj_list) ||
7739 nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
7740 return VIR_PY_INT_FAIL;
7743 for (i = 0; i < nkeycodes; i++) {
7744 if (libvirt_uintUnwrap(PyList_GetItem(pyobj_list, i), &keycodes[i]) < 0)
7745 return NULL;
7748 LIBVIRT_BEGIN_ALLOW_THREADS;
7749 ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
7750 LIBVIRT_END_ALLOW_THREADS;
7752 DEBUG("virDomainSendKey ret=%d\n", ret);
7754 return libvirt_intWrap(ret);
7757 #if LIBVIR_CHECK_VERSION(1, 0, 3)
7758 static PyObject *
7759 libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED,
7760 PyObject *args)
7762 PyObject *pyobj_domain;
7763 virDomainPtr domain;
7764 unsigned int flags;
7765 unsigned long long cacheSize;
7766 int rc;
7768 if (!PyArg_ParseTuple(args,
7769 (char *) "OI:virDomainMigrateGetCompressionCache",
7770 &pyobj_domain, &flags))
7771 return NULL;
7773 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7775 LIBVIRT_BEGIN_ALLOW_THREADS;
7776 rc = virDomainMigrateGetCompressionCache(domain, &cacheSize, flags);
7777 LIBVIRT_END_ALLOW_THREADS;
7779 if (rc < 0)
7780 return VIR_PY_NONE;
7782 return libvirt_ulonglongWrap(cacheSize);
7784 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
7786 static PyObject *
7787 libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED,
7788 PyObject *args)
7790 int c_retval;
7791 unsigned long bandwidth;
7792 virDomainPtr domain;
7793 PyObject *pyobj_domain;
7794 unsigned int flags = 0;
7796 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainMigrateGetMaxSpeed",
7797 &pyobj_domain, &flags))
7798 return NULL;
7800 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7802 LIBVIRT_BEGIN_ALLOW_THREADS;
7803 c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, flags);
7804 LIBVIRT_END_ALLOW_THREADS;
7806 if (c_retval < 0)
7807 return VIR_PY_INT_FAIL;
7809 return libvirt_ulongWrap(bandwidth);
7812 #if LIBVIR_CHECK_VERSION(3, 7, 0)
7813 static PyObject *
7814 libvirt_virDomainMigrateGetMaxDowntime(PyObject *self ATTRIBUTE_UNUSED,
7815 PyObject *args)
7817 PyObject *pyobj_domain;
7818 virDomainPtr domain;
7819 unsigned int flags;
7820 unsigned long long downtime;
7821 int rc;
7823 if (!PyArg_ParseTuple(args,
7824 (char *) "OI:virDomainMigrateGetMaxDowntime",
7825 &pyobj_domain, &flags))
7826 return NULL;
7828 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7830 LIBVIRT_BEGIN_ALLOW_THREADS;
7831 rc = virDomainMigrateGetMaxDowntime(domain, &downtime, flags);
7832 LIBVIRT_END_ALLOW_THREADS;
7834 if (rc < 0)
7835 return VIR_PY_NONE;
7837 return libvirt_ulonglongWrap(downtime);
7839 #endif /* LIBVIR_CHECK_VERSION(3, 7, 0) */
7841 #if LIBVIR_CHECK_VERSION(1, 1, 0)
7842 static virPyTypedParamsHint virPyDomainMigrate3Params[] = {
7843 # ifdef VIR_MIGRATE_PARAM_URI
7844 { VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING },
7845 # endif
7846 # ifdef VIR_MIGRATE_PARAM_DEST_NAME
7847 { VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING },
7848 # endif
7849 # ifdef VIR_MIGRATE_PARAM_DEST_XML
7850 { VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING },
7851 # endif
7852 # ifdef VIR_MIGRATE_PARAM_PERSIST_XML
7853 { VIR_MIGRATE_PARAM_PERSIST_XML, VIR_TYPED_PARAM_STRING },
7854 # endif
7855 # ifdef VIR_MIGRATE_PARAM_BANDWIDTH
7856 { VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG },
7857 # endif
7858 # ifdef VIR_MIGRATE_PARAM_GRAPHICS_URI
7859 { VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING },
7860 # endif
7861 # ifdef VIR_MIGRATE_PARAM_LISTEN_ADDRESS
7862 { VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING },
7863 # endif
7864 # ifdef VIR_MIGRATE_PARAM_MIGRATE_DISKS
7865 { VIR_MIGRATE_PARAM_MIGRATE_DISKS, VIR_TYPED_PARAM_STRING },
7866 # endif
7867 # ifdef VIR_MIGRATE_PARAM_DISKS_PORT
7868 { VIR_MIGRATE_PARAM_DISKS_PORT, VIR_TYPED_PARAM_INT },
7869 # endif
7870 # ifdef VIR_MIGRATE_PARAM_COMPRESSION
7871 { VIR_MIGRATE_PARAM_COMPRESSION, VIR_TYPED_PARAM_STRING },
7872 # endif
7873 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL
7874 { VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL, VIR_TYPED_PARAM_INT },
7875 # endif
7876 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS
7877 { VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS, VIR_TYPED_PARAM_INT },
7878 # endif
7879 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS
7880 { VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS, VIR_TYPED_PARAM_INT },
7881 # endif
7882 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE
7883 { VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE, VIR_TYPED_PARAM_ULLONG },
7884 # endif
7885 # ifdef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL
7886 { VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL, VIR_TYPED_PARAM_INT },
7887 # endif
7888 # ifdef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT
7889 { VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT, VIR_TYPED_PARAM_INT },
7890 # endif
7894 static PyObject *
7895 libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
7896 PyObject *args)
7898 PyObject *pyobj_domain;
7899 virDomainPtr domain;
7900 PyObject *pyobj_dconn;
7901 virConnectPtr dconn;
7902 PyObject *dict;
7903 unsigned int flags;
7904 virTypedParameterPtr params;
7905 int nparams = 0;
7906 virDomainPtr ddom = NULL;
7908 if (!PyArg_ParseTuple(args, (char *) "OOOI:virDomainMigrate3",
7909 &pyobj_domain, &pyobj_dconn, &dict, &flags))
7910 return NULL;
7912 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7913 dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);
7915 if (!PyDict_Check(dict)) {
7916 PyErr_Format(PyExc_TypeError, "migration params must be a dictionary");
7917 return NULL;
7920 if (virPyDictToTypedParams(dict, &params, &nparams,
7921 virPyDomainMigrate3Params,
7922 VIR_N_ELEMENTS(virPyDomainMigrate3Params)) < 0) {
7923 return NULL;
7926 LIBVIRT_BEGIN_ALLOW_THREADS;
7927 ddom = virDomainMigrate3(domain, dconn, params, nparams, flags);
7928 LIBVIRT_END_ALLOW_THREADS;
7930 virTypedParamsFree(params, nparams);
7931 return libvirt_virDomainPtrWrap(ddom);
7934 static PyObject *
7935 libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,
7936 PyObject *args)
7938 PyObject *pyobj_domain;
7939 virDomainPtr domain;
7940 char *dconnuri;
7941 PyObject *dict;
7942 unsigned int flags;
7943 virTypedParameterPtr params;
7944 int nparams;
7945 int ret = -1;
7947 if (!PyArg_ParseTuple(args, (char *) "OzOI:virDomainMigrate3",
7948 &pyobj_domain, &dconnuri, &dict, &flags))
7949 return NULL;
7951 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7953 if (!PyDict_Check(dict)) {
7954 PyErr_Format(PyExc_TypeError, "migration params must be a dictionary");
7955 return NULL;
7958 if (virPyDictToTypedParams(dict, &params, &nparams,
7959 virPyDomainMigrate3Params,
7960 VIR_N_ELEMENTS(virPyDomainMigrate3Params)) < 0) {
7961 return NULL;
7964 LIBVIRT_BEGIN_ALLOW_THREADS;
7965 ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
7966 LIBVIRT_END_ALLOW_THREADS;
7968 virTypedParamsFree(params, nparams);
7969 return libvirt_intWrap(ret);
7971 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
7973 static PyObject *
7974 libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED,
7975 PyObject *args)
7977 PyObject *py_retval = NULL;
7978 int c_retval;
7979 virDomainPtr domain;
7980 PyObject *pyobj_domain;
7981 const char *disk;
7982 unsigned long long offset;
7983 size_t size;
7984 char *buf;
7985 unsigned int flags;
7987 if (!PyArg_ParseTuple(args, (char *)"OzKkI:virDomainBlockPeek",
7988 &pyobj_domain, &disk, &offset, &size, &flags))
7989 return NULL;
7991 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7993 if (VIR_ALLOC_N(buf, size) < 0)
7994 return PyErr_NoMemory();
7996 LIBVIRT_BEGIN_ALLOW_THREADS;
7997 c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags);
7998 LIBVIRT_END_ALLOW_THREADS;
8000 if (c_retval < 0) {
8001 py_retval = VIR_PY_NONE;
8002 goto cleanup;
8005 py_retval = libvirt_charPtrSizeWrap(buf, size);
8007 cleanup:
8008 VIR_FREE(buf);
8009 return py_retval;
8012 static PyObject *
8013 libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED,
8014 PyObject *args)
8016 PyObject *py_retval = NULL;
8017 int c_retval;
8018 virDomainPtr domain;
8019 PyObject *pyobj_domain;
8020 unsigned long long start;
8021 size_t size;
8022 char *buf;
8023 unsigned int flags;
8025 if (!PyArg_ParseTuple(args, (char *)"OKkI:virDomainMemoryPeek",
8026 &pyobj_domain, &start, &size, &flags))
8027 return NULL;
8029 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8031 if (VIR_ALLOC_N(buf, size) < 0)
8032 return PyErr_NoMemory();
8034 LIBVIRT_BEGIN_ALLOW_THREADS;
8035 c_retval = virDomainMemoryPeek(domain, start, size, buf, flags);
8036 LIBVIRT_END_ALLOW_THREADS;
8038 if (c_retval < 0) {
8039 py_retval = VIR_PY_NONE;
8040 goto cleanup;
8043 py_retval = libvirt_charPtrSizeWrap(buf, size);
8045 cleanup:
8046 VIR_FREE(buf);
8047 return py_retval;
8050 #if LIBVIR_CHECK_VERSION(0, 10, 2)
8051 static PyObject *
8052 libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
8053 PyObject *args)
8055 virConnectPtr conn;
8056 PyObject *pyobj_conn, *info;
8057 PyObject *ret = NULL;
8058 int i_retval;
8059 int nparams = 0;
8060 Py_ssize_t size = 0;
8061 unsigned int flags;
8062 virTypedParameterPtr params = NULL, new_params = NULL;
8064 if (!PyArg_ParseTuple(args,
8065 (char *)"OOI:virNodeSetMemoryParameters",
8066 &pyobj_conn, &info, &flags))
8067 return NULL;
8068 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8070 if ((size = PyDict_Size(info)) < 0)
8071 return NULL;
8073 if (size == 0) {
8074 PyErr_Format(PyExc_LookupError,
8075 "Need non-empty dictionary to set attributes");
8076 return NULL;
8079 LIBVIRT_BEGIN_ALLOW_THREADS;
8080 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
8081 LIBVIRT_END_ALLOW_THREADS;
8083 if (i_retval < 0)
8084 return VIR_PY_INT_FAIL;
8086 if (nparams == 0) {
8087 PyErr_Format(PyExc_LookupError,
8088 "no settable attributes");
8089 return NULL;
8092 if (VIR_ALLOC_N(params, nparams) < 0)
8093 return PyErr_NoMemory();
8095 LIBVIRT_BEGIN_ALLOW_THREADS;
8096 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
8097 LIBVIRT_END_ALLOW_THREADS;
8099 if (i_retval < 0) {
8100 ret = VIR_PY_INT_FAIL;
8101 goto cleanup;
8104 new_params = setPyVirTypedParameter(info, params, nparams);
8105 if (!new_params)
8106 goto cleanup;
8108 LIBVIRT_BEGIN_ALLOW_THREADS;
8109 i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
8110 LIBVIRT_END_ALLOW_THREADS;
8112 if (i_retval < 0) {
8113 ret = VIR_PY_INT_FAIL;
8114 goto cleanup;
8117 ret = VIR_PY_INT_SUCCESS;
8119 cleanup:
8120 virTypedParamsFree(params, nparams);
8121 virTypedParamsFree(new_params, size);
8122 return ret;
8125 static PyObject *
8126 libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
8127 PyObject *args)
8129 virConnectPtr conn;
8130 PyObject *pyobj_conn;
8131 PyObject *ret = NULL;
8132 int i_retval;
8133 int nparams = 0;
8134 unsigned int flags;
8135 virTypedParameterPtr params;
8137 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetMemoryParameters",
8138 &pyobj_conn, &flags))
8139 return NULL;
8140 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8142 LIBVIRT_BEGIN_ALLOW_THREADS;
8143 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
8144 LIBVIRT_END_ALLOW_THREADS;
8146 if (i_retval < 0)
8147 return VIR_PY_NONE;
8149 if (!nparams)
8150 return PyDict_New();
8152 if (VIR_ALLOC_N(params, nparams) < 0)
8153 return PyErr_NoMemory();
8155 LIBVIRT_BEGIN_ALLOW_THREADS;
8156 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
8157 LIBVIRT_END_ALLOW_THREADS;
8159 if (i_retval < 0) {
8160 ret = VIR_PY_NONE;
8161 goto cleanup;
8164 ret = getPyVirTypedParameter(params, nparams);
8166 cleanup:
8167 virTypedParamsFree(params, nparams);
8168 return ret;
8170 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
8172 #if LIBVIR_CHECK_VERSION(1, 0, 0)
8173 static PyObject *
8174 libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
8175 PyObject *args)
8177 virConnectPtr conn;
8178 PyObject *pyobj_conn;
8179 PyObject *ret = NULL;
8180 PyObject *pycpumap = NULL;
8181 int i_retval;
8182 unsigned char *cpumap = NULL;
8183 unsigned int online = 0;
8184 unsigned int flags;
8185 ssize_t i;
8187 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetCPUMap",
8188 &pyobj_conn, &flags))
8189 return NULL;
8190 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8192 LIBVIRT_BEGIN_ALLOW_THREADS;
8193 i_retval = virNodeGetCPUMap(conn, &cpumap, &online, flags);
8194 LIBVIRT_END_ALLOW_THREADS;
8196 if (i_retval < 0)
8197 return VIR_PY_NONE;
8199 if ((ret = PyTuple_New(3)) == NULL)
8200 goto error;
8202 /* 0: number of CPUs */
8203 VIR_PY_TUPLE_SET_GOTO(ret, 0, libvirt_intWrap(i_retval), error);
8205 /* 1: CPU map */
8206 if ((pycpumap = PyList_New(i_retval)) == NULL)
8207 goto error;
8209 VIR_PY_TUPLE_SET_GOTO(ret, 1, pycpumap, error);
8211 for (i = 0; i < i_retval; i++)
8212 VIR_PY_LIST_SET_GOTO(pycpumap, i,
8213 PyBool_FromLong(VIR_CPU_USED(cpumap, i)), error);
8215 /* 2: number of online CPUs */
8216 VIR_PY_TUPLE_SET_GOTO(ret, 2, libvirt_uintWrap(online), error);
8218 cleanup:
8219 VIR_FREE(cpumap);
8220 return ret;
8222 error:
8223 Py_CLEAR(ret);
8224 goto cleanup;
8226 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
8229 #if LIBVIR_CHECK_VERSION(1, 1, 1)
8230 static PyObject *
8231 libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED,
8232 PyObject *args)
8234 PyObject *py_retval = NULL;
8235 int c_retval;
8236 virDomainPtr domain;
8237 PyObject *pyobj_domain;
8238 PyObject *pyobj_files;
8239 unsigned int flags;
8240 unsigned int nfiles;
8241 int *files = NULL;
8242 ssize_t i;
8244 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainCreateWithFiles",
8245 &pyobj_domain, &pyobj_files, &flags))
8246 return NULL;
8247 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8249 nfiles = PyList_Size(pyobj_files);
8251 if (VIR_ALLOC_N(files, nfiles) < 0)
8252 return PyErr_NoMemory();
8254 for (i = 0; i < nfiles; i++) {
8255 PyObject *pyfd;
8256 int fd;
8258 pyfd = PyList_GetItem(pyobj_files, i);
8260 if (libvirt_intUnwrap(pyfd, &fd) < 0)
8261 goto cleanup;
8263 files[i] = fd;
8266 LIBVIRT_BEGIN_ALLOW_THREADS;
8267 c_retval = virDomainCreateWithFiles(domain, nfiles, files, flags);
8268 LIBVIRT_END_ALLOW_THREADS;
8270 py_retval = libvirt_intWrap((int) c_retval);
8272 cleanup:
8273 VIR_FREE(files);
8274 return py_retval;
8278 static PyObject *
8279 libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED,
8280 PyObject *args)
8282 PyObject *py_retval = NULL;
8283 virDomainPtr c_retval;
8284 virConnectPtr conn;
8285 PyObject *pyobj_conn;
8286 char * xmlDesc;
8287 PyObject *pyobj_files;
8288 unsigned int flags;
8289 unsigned int nfiles;
8290 int *files = NULL;
8291 ssize_t i;
8293 if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainCreateXMLWithFiles",
8294 &pyobj_conn, &xmlDesc, &pyobj_files, &flags))
8295 return NULL;
8296 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8298 nfiles = PyList_Size(pyobj_files);
8300 if (VIR_ALLOC_N(files, nfiles) < 0)
8301 return PyErr_NoMemory();
8303 for (i = 0; i < nfiles; i++) {
8304 PyObject *pyfd;
8305 int fd;
8307 pyfd = PyList_GetItem(pyobj_files, i);
8309 if (libvirt_intUnwrap(pyfd, &fd) < 0)
8310 goto cleanup;
8312 files[i] = fd;
8315 LIBVIRT_BEGIN_ALLOW_THREADS;
8316 c_retval = virDomainCreateXMLWithFiles(conn, xmlDesc, nfiles, files, flags);
8317 LIBVIRT_END_ALLOW_THREADS;
8319 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
8321 cleanup:
8322 VIR_FREE(files);
8323 return py_retval;
8325 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
8328 #if LIBVIR_CHECK_VERSION(1, 2, 5)
8329 static PyObject *
8330 libvirt_virDomainFSFreeze(PyObject *self ATTRIBUTE_UNUSED,
8331 PyObject *args)
8333 PyObject *py_retval = NULL;
8334 int c_retval;
8335 virDomainPtr domain;
8336 PyObject *pyobj_domain;
8337 PyObject *pyobj_list;
8338 unsigned int flags;
8339 unsigned int nmountpoints = 0;
8340 char **mountpoints = NULL;
8341 ssize_t i = 0, j;
8343 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSFreeze",
8344 &pyobj_domain, &pyobj_list, &flags))
8345 return NULL;
8346 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8348 if (PyList_Check(pyobj_list)) {
8349 nmountpoints = PyList_Size(pyobj_list);
8351 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
8352 return PyErr_NoMemory();
8354 for (i = 0; i < nmountpoints; i++) {
8355 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
8356 mountpoints+i) < 0)
8357 goto cleanup;
8361 LIBVIRT_BEGIN_ALLOW_THREADS;
8362 c_retval = virDomainFSFreeze(domain, (const char **) mountpoints,
8363 nmountpoints, flags);
8364 LIBVIRT_END_ALLOW_THREADS;
8366 py_retval = libvirt_intWrap(c_retval);
8368 cleanup:
8369 for (j = 0 ; j < i ; j++)
8370 VIR_FREE(mountpoints[j]);
8371 VIR_FREE(mountpoints);
8372 return py_retval;
8376 static PyObject *
8377 libvirt_virDomainFSThaw(PyObject *self ATTRIBUTE_UNUSED,
8378 PyObject *args)
8380 PyObject *py_retval = NULL;
8381 int c_retval;
8382 virDomainPtr domain;
8383 PyObject *pyobj_domain;
8384 PyObject *pyobj_list;
8385 unsigned int flags;
8386 unsigned int nmountpoints = 0;
8387 char **mountpoints = NULL;
8388 ssize_t i = 0, j;
8390 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSThaw",
8391 &pyobj_domain, &pyobj_list, &flags))
8392 return NULL;
8393 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8395 if (PyList_Check(pyobj_list)) {
8396 nmountpoints = PyList_Size(pyobj_list);
8398 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
8399 return PyErr_NoMemory();
8401 for (i = 0; i < nmountpoints; i++) {
8402 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
8403 mountpoints+i) < 0)
8404 goto cleanup;
8408 LIBVIRT_BEGIN_ALLOW_THREADS;
8409 c_retval = virDomainFSThaw(domain, (const char **) mountpoints,
8410 nmountpoints, flags);
8411 LIBVIRT_END_ALLOW_THREADS;
8413 py_retval = libvirt_intWrap(c_retval);
8415 cleanup:
8416 for (j = 0 ; j < i ; j++)
8417 VIR_FREE(mountpoints[j]);
8418 VIR_FREE(mountpoints);
8419 return py_retval;
8422 static PyObject *
8423 libvirt_virDomainGetTime(PyObject *self ATTRIBUTE_UNUSED,
8424 PyObject *args)
8426 PyObject *py_retval = NULL;
8427 PyObject *dict = NULL;
8428 PyObject *pyobj_domain;
8429 virDomainPtr domain;
8430 long long seconds;
8431 unsigned int nseconds;
8432 unsigned int flags;
8433 int c_retval;
8435 if (!PyArg_ParseTuple(args, (char*)"OI:virDomainGetTime",
8436 &pyobj_domain, &flags))
8437 return NULL;
8438 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8440 if (!(dict = PyDict_New()))
8441 goto cleanup;
8443 LIBVIRT_BEGIN_ALLOW_THREADS;
8444 c_retval = virDomainGetTime(domain, &seconds, &nseconds, flags);
8445 LIBVIRT_END_ALLOW_THREADS;
8447 if (c_retval < 0) {
8448 py_retval = VIR_PY_NONE;
8449 goto cleanup;
8452 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("seconds"),
8453 libvirt_longlongWrap(seconds), cleanup);
8454 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("nseconds"),
8455 libvirt_longlongWrap(nseconds), cleanup);
8457 py_retval = dict;
8458 dict = NULL;
8459 cleanup:
8460 Py_XDECREF(dict);
8461 return py_retval;
8465 static PyObject *
8466 libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED,
8467 PyObject *args)
8469 PyObject *pyobj_domain;
8470 PyObject *pyobj_seconds;
8471 PyObject *pyobj_nseconds;
8472 PyObject *py_dict;
8473 virDomainPtr domain;
8474 long long seconds = 0;
8475 unsigned int nseconds = 0;
8476 unsigned int flags;
8477 ssize_t py_dict_size = 0;
8478 int c_retval;
8480 if (!PyArg_ParseTuple(args, (char*)"OOI:virDomainSetTime",
8481 &pyobj_domain, &py_dict, &flags))
8482 return NULL;
8483 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8485 if (PyDict_Check(py_dict)) {
8486 py_dict_size = PyDict_Size(py_dict);
8487 if ((pyobj_seconds = PyDict_GetItemString(py_dict, "seconds"))) {
8488 if (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)
8489 return NULL;
8490 } else {
8491 PyErr_Format(PyExc_LookupError, "Dictionary must contains 'seconds'");
8492 return NULL;
8495 if ((pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds"))) {
8496 if (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)
8497 return NULL;
8498 } else if (py_dict_size > 1) {
8499 PyErr_Format(PyExc_LookupError, "Dictionary contains unknown key");
8500 return NULL;
8502 } else if (py_dict != Py_None || !flags) {
8503 PyErr_Format(PyExc_TypeError, "time must be a dictionary "
8504 "or None with flags set");
8505 return NULL;
8508 LIBVIRT_BEGIN_ALLOW_THREADS;
8509 c_retval = virDomainSetTime(domain, seconds, nseconds, flags);
8510 LIBVIRT_END_ALLOW_THREADS;
8512 return libvirt_intWrap(c_retval);
8514 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
8517 #if LIBVIR_CHECK_VERSION(1, 2, 6)
8518 static PyObject *
8519 libvirt_virNodeGetFreePages(PyObject *self ATTRIBUTE_UNUSED,
8520 PyObject *args)
8522 PyObject *py_retval = NULL;
8523 PyObject *pyobj_conn;
8524 PyObject *pyobj_pagesize;
8525 PyObject *pyobj_counts = NULL;
8526 virConnectPtr conn;
8527 unsigned int *pages = NULL;
8528 int startCell;
8529 unsigned int cellCount;
8530 unsigned int flags;
8531 unsigned long long *counts = NULL;
8532 int c_retval;
8533 ssize_t pyobj_pagesize_size, i, j;
8535 if (!PyArg_ParseTuple(args, (char *)"OOiII:virNodeGetFreePages",
8536 &pyobj_conn, &pyobj_pagesize, &startCell,
8537 &cellCount, &flags))
8538 return NULL;
8540 if (!PyList_Check(pyobj_pagesize)) {
8541 PyErr_Format(PyExc_TypeError, "pagesize must be list");
8542 return NULL;
8545 if (cellCount == 0) {
8546 PyErr_Format(PyExc_LookupError, "cellCount must not be zero");
8547 return NULL;
8550 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8552 pyobj_pagesize_size = PyList_Size(pyobj_pagesize);
8553 if (VIR_ALLOC_N(pages, pyobj_pagesize_size) < 0 ||
8554 VIR_ALLOC_N(counts, pyobj_pagesize_size * cellCount) < 0) {
8555 PyErr_NoMemory();
8556 goto cleanup;
8559 if (!(pyobj_counts = PyDict_New()))
8560 goto cleanup;
8562 for (i = 0; i < pyobj_pagesize_size; i++) {
8563 PyObject *tmp = PyList_GetItem(pyobj_pagesize, i);
8565 if (libvirt_uintUnwrap(tmp, &pages[i]) < 0)
8566 goto cleanup;
8569 LIBVIRT_BEGIN_ALLOW_THREADS;
8570 c_retval = virNodeGetFreePages(conn,
8571 pyobj_pagesize_size, pages,
8572 startCell, cellCount,
8573 counts, flags);
8574 LIBVIRT_END_ALLOW_THREADS;
8576 if (c_retval < 0) {
8577 py_retval = VIR_PY_NONE;
8578 goto cleanup;
8581 for (i = 0; i < c_retval;) {
8582 PyObject *per_node = NULL;
8584 if (!(per_node = PyDict_New()))
8585 goto cleanup;
8587 VIR_PY_DICT_SET_GOTO(pyobj_counts,
8588 libvirt_intWrap(startCell + i/pyobj_pagesize_size),
8589 per_node, cleanup);
8591 for (j = 0; j < pyobj_pagesize_size; j ++)
8592 VIR_PY_DICT_SET_GOTO(per_node, libvirt_intWrap(pages[j]),
8593 libvirt_intWrap(counts[i + j]), cleanup);
8595 i += pyobj_pagesize_size;
8598 py_retval = pyobj_counts;
8599 pyobj_counts = NULL;
8600 cleanup:
8601 Py_XDECREF(pyobj_counts);
8602 VIR_FREE(pages);
8603 VIR_FREE(counts);
8604 return py_retval;
8608 static PyObject *
8609 libvirt_virNetworkGetDHCPLeases(PyObject *self ATTRIBUTE_UNUSED,
8610 PyObject *args)
8612 PyObject *py_retval = NULL;
8613 PyObject *py_lease = NULL;
8614 virNetworkPtr network;
8615 PyObject *pyobj_network;
8616 unsigned int flags;
8617 virNetworkDHCPLeasePtr *leases = NULL;
8618 int leases_count;
8619 char *mac = NULL;
8620 ssize_t i;
8622 if (!PyArg_ParseTuple(args, (char *) "OzI:virNetworkGetDHCPLeases",
8623 &pyobj_network, &mac, &flags))
8624 return NULL;
8626 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
8628 LIBVIRT_BEGIN_ALLOW_THREADS;
8629 leases_count = virNetworkGetDHCPLeases(network, mac, &leases, flags);
8630 LIBVIRT_END_ALLOW_THREADS;
8632 if (leases_count < 0) {
8633 py_retval = VIR_PY_NONE;
8634 goto cleanup;
8637 if (!(py_retval = PyList_New(leases_count)))
8638 goto error;
8640 for (i = 0; i < leases_count; i++) {
8641 virNetworkDHCPLeasePtr lease = leases[i];
8643 if ((py_lease = PyDict_New()) == NULL)
8644 goto error;
8646 VIR_PY_LIST_SET_GOTO(py_retval, i, py_lease, error);
8648 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("iface"),
8649 libvirt_charPtrWrap(lease->iface), error);
8650 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("expirytime"),
8651 libvirt_longlongWrap(lease->expirytime), error);
8652 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("type"),
8653 libvirt_intWrap(lease->type), error);
8654 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("mac"),
8655 libvirt_charPtrWrap(lease->mac), error);
8656 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("ipaddr"),
8657 libvirt_charPtrWrap(lease->ipaddr), error);
8658 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("prefix"),
8659 libvirt_uintWrap(lease->prefix), error);
8660 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("hostname"),
8661 libvirt_charPtrWrap(lease->hostname), error);
8662 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("clientid"),
8663 libvirt_charPtrWrap(lease->clientid), error);
8664 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("iaid"),
8665 libvirt_charPtrWrap(lease->iaid), error);
8668 cleanup:
8669 if (leases_count > 0)
8670 for (i = 0; i < leases_count; i++)
8671 virNetworkDHCPLeaseFree(leases[i]);
8672 VIR_FREE(leases);
8674 return py_retval;
8676 error:
8677 Py_CLEAR(py_retval);
8678 goto cleanup;
8681 #endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
8683 #if LIBVIR_CHECK_VERSION(1, 2, 8)
8685 static PyObject *
8686 convertDomainStatsRecord(virDomainStatsRecordPtr *records,
8687 int nrecords)
8689 PyObject *py_retval;
8690 PyObject *py_record;
8691 PyObject *py_record_stats = NULL;
8692 virDomainPtr dom = NULL;
8693 ssize_t i;
8695 if (!(py_retval = PyList_New(nrecords)))
8696 return NULL;
8698 for (i = 0; i < nrecords; i++) {
8699 if (!(py_record = PyTuple_New(2)))
8700 goto error;
8702 VIR_PY_LIST_SET_GOTO(py_retval, i, py_record, error);
8704 dom = records[i]->dom;
8705 virDomainRef(dom);
8706 VIR_PY_TUPLE_SET_GOTO(py_record, 0,
8707 libvirt_virDomainPtrWrap(dom),
8708 error);
8709 dom = NULL;
8711 if (!(py_record_stats = getPyVirTypedParameter(records[i]->params,
8712 records[i]->nparams)))
8713 goto error;
8714 VIR_PY_TUPLE_SET_GOTO(py_record, 1, py_record_stats, error);
8718 return py_retval;
8720 error:
8721 if (dom)
8722 virDomainFree(dom);
8723 Py_XDECREF(py_retval);
8724 return NULL;
8728 static PyObject *
8729 libvirt_virConnectGetAllDomainStats(PyObject *self ATTRIBUTE_UNUSED,
8730 PyObject *args)
8732 PyObject *pyobj_conn;
8733 PyObject *py_retval;
8734 virConnectPtr conn;
8735 virDomainStatsRecordPtr *records;
8736 int nrecords;
8737 unsigned int flags;
8738 unsigned int stats;
8740 if (!PyArg_ParseTuple(args, (char *)"OII:virConnectGetAllDomainStats",
8741 &pyobj_conn, &stats, &flags))
8742 return NULL;
8743 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8745 LIBVIRT_BEGIN_ALLOW_THREADS;
8746 nrecords = virConnectGetAllDomainStats(conn, stats, &records, flags);
8747 LIBVIRT_END_ALLOW_THREADS;
8749 if (nrecords < 0)
8750 return VIR_PY_NONE;
8752 py_retval = convertDomainStatsRecord(records, nrecords);
8754 virDomainStatsRecordListFree(records);
8756 return py_retval;
8760 static PyObject *
8761 libvirt_virDomainListGetStats(PyObject *self ATTRIBUTE_UNUSED,
8762 PyObject *args)
8764 PyObject *pyobj_conn;
8765 PyObject *py_retval;
8766 PyObject *py_domlist;
8767 virDomainStatsRecordPtr *records = NULL;
8768 virDomainPtr *doms = NULL;
8769 int nrecords;
8770 int ndoms;
8771 ssize_t i;
8772 unsigned int flags;
8773 unsigned int stats;
8775 if (!PyArg_ParseTuple(args, (char *)"OOII:virDomainListGetStats",
8776 &pyobj_conn, &py_domlist, &stats, &flags))
8777 return NULL;
8779 if (PyList_Check(py_domlist)) {
8780 ndoms = PyList_Size(py_domlist);
8782 if (VIR_ALLOC_N(doms, ndoms + 1) < 0)
8783 return PyErr_NoMemory();
8785 for (i = 0; i < ndoms; i++)
8786 doms[i] = PyvirDomain_Get(PyList_GetItem(py_domlist, i));
8789 LIBVIRT_BEGIN_ALLOW_THREADS;
8790 nrecords = virDomainListGetStats(doms, stats, &records, flags);
8791 LIBVIRT_END_ALLOW_THREADS;
8793 if (nrecords < 0) {
8794 py_retval = VIR_PY_NONE;
8795 goto cleanup;
8798 py_retval = convertDomainStatsRecord(records, nrecords);
8800 cleanup:
8801 virDomainStatsRecordListFree(records);
8802 VIR_FREE(doms);
8804 return py_retval;
8808 static virPyTypedParamsHint virPyDomainBlockCopyParams[] = {
8809 { VIR_DOMAIN_BLOCK_COPY_BANDWIDTH, VIR_TYPED_PARAM_ULLONG },
8810 { VIR_DOMAIN_BLOCK_COPY_GRANULARITY, VIR_TYPED_PARAM_UINT },
8811 { VIR_DOMAIN_BLOCK_COPY_BUF_SIZE, VIR_TYPED_PARAM_ULLONG },
8815 static PyObject *
8816 libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED,
8817 PyObject *args)
8819 PyObject *pyobj_dom = NULL;
8820 PyObject *pyobj_dict = NULL;
8822 virDomainPtr dom;
8823 char *disk = NULL;
8824 char *destxml = NULL;
8825 virTypedParameterPtr params = NULL;
8826 int nparams = 0;
8827 unsigned int flags = 0;
8828 int c_retval;
8830 if (!PyArg_ParseTuple(args, (char *) "Ozz|OI:virDomainBlockCopy",
8831 &pyobj_dom, &disk, &destxml, &pyobj_dict, &flags))
8832 return NULL;
8834 if (PyDict_Check(pyobj_dict)) {
8835 if (virPyDictToTypedParams(pyobj_dict, &params, &nparams,
8836 virPyDomainBlockCopyParams,
8837 VIR_N_ELEMENTS(virPyDomainBlockCopyParams)) < 0) {
8838 return NULL;
8840 } else if (pyobj_dict != Py_None) {
8841 PyErr_Format(PyExc_TypeError, "block params must be a dictionary");
8842 return NULL;
8845 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
8847 LIBVIRT_BEGIN_ALLOW_THREADS;
8848 c_retval = virDomainBlockCopy(dom, disk, destxml, params, nparams, flags);
8849 LIBVIRT_END_ALLOW_THREADS;
8851 virTypedParamsFree(params, nparams);
8852 return libvirt_intWrap(c_retval);
8855 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
8857 #if LIBVIR_CHECK_VERSION(1, 2, 9)
8858 static PyObject *
8859 libvirt_virNodeAllocPages(PyObject *self ATTRIBUTE_UNUSED,
8860 PyObject *args)
8862 PyObject *pyobj_conn;
8863 PyObject *pyobj_pages;
8864 Py_ssize_t size = 0;
8865 Py_ssize_t pos = 0;
8866 PyObject *key, *value;
8867 virConnectPtr conn;
8868 unsigned int npages = 0;
8869 unsigned int *pageSizes = NULL;
8870 unsigned long long *pageCounts = NULL;
8871 int startCell = -1;
8872 unsigned int cellCount = 1;
8873 unsigned int flags = VIR_NODE_ALLOC_PAGES_ADD;
8874 int c_retval;
8876 if (!PyArg_ParseTuple(args, (char *)"OOiII:virNodeAllocPages",
8877 &pyobj_conn, &pyobj_pages,
8878 &startCell, &cellCount, &flags))
8879 return NULL;
8880 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8882 if ((size = PyDict_Size(pyobj_pages)) < 0)
8883 return NULL;
8885 if (size == 0) {
8886 PyErr_Format(PyExc_LookupError,
8887 "Need non-empty dictionary to pages attribute");
8888 return NULL;
8891 if (VIR_ALLOC_N(pageSizes, size) < 0 ||
8892 VIR_ALLOC_N(pageCounts, size) < 0) {
8893 PyErr_NoMemory();
8894 goto error;
8897 while (PyDict_Next(pyobj_pages, &pos, &key, &value)) {
8898 if (libvirt_uintUnwrap(key, &pageSizes[npages]) < 0 ||
8899 libvirt_ulonglongUnwrap(value, &pageCounts[npages]) < 0)
8900 goto error;
8901 npages++;
8904 LIBVIRT_BEGIN_ALLOW_THREADS;
8905 c_retval = virNodeAllocPages(conn, npages, pageSizes,
8906 pageCounts, startCell, cellCount, flags);
8907 LIBVIRT_END_ALLOW_THREADS;
8909 VIR_FREE(pageSizes);
8910 VIR_FREE(pageCounts);
8912 return libvirt_intWrap(c_retval);
8914 error:
8915 VIR_FREE(pageSizes);
8916 VIR_FREE(pageCounts);
8917 return NULL;
8919 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
8921 #if LIBVIR_CHECK_VERSION(1, 2, 11)
8923 static PyObject *
8924 libvirt_virDomainGetFSInfo(PyObject *self ATTRIBUTE_UNUSED,
8925 PyObject *args)
8927 virDomainPtr domain;
8928 PyObject *pyobj_domain;
8929 unsigned int flags;
8930 virDomainFSInfoPtr *fsinfo = NULL;
8931 int c_retval, i;
8932 size_t j;
8933 PyObject *py_retval = NULL;
8935 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetFSInfo",
8936 &pyobj_domain, &flags))
8937 return NULL;
8938 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8940 LIBVIRT_BEGIN_ALLOW_THREADS;
8941 c_retval = virDomainGetFSInfo(domain, &fsinfo, flags);
8942 LIBVIRT_END_ALLOW_THREADS;
8944 if (c_retval < 0) {
8945 py_retval = VIR_PY_NONE;
8946 goto cleanup;
8949 /* convert to a Python list */
8950 if ((py_retval = PyList_New(c_retval)) == NULL)
8951 goto error;
8953 for (i = 0; i < c_retval; i++) {
8954 virDomainFSInfoPtr fs = fsinfo[i];
8955 PyObject *info, *alias;
8957 if (fs == NULL)
8958 goto error;
8960 info = PyTuple_New(4);
8961 if (info == NULL)
8962 goto error;
8964 VIR_PY_LIST_SET_GOTO(py_retval, i, info, error);
8966 VIR_PY_TUPLE_SET_GOTO(info, 0,
8967 libvirt_constcharPtrWrap(fs->mountpoint), error);
8968 VIR_PY_TUPLE_SET_GOTO(info, 1,
8969 libvirt_constcharPtrWrap(fs->name), error);
8970 VIR_PY_TUPLE_SET_GOTO(info, 2,
8971 libvirt_constcharPtrWrap(fs->fstype), error);
8973 alias = PyList_New(0);
8974 if (alias == NULL)
8975 goto error;
8976 VIR_PY_TUPLE_SET_GOTO(info, 3, alias, error);
8978 for (j = 0; j < fs->ndevAlias; j++)
8979 VIR_PY_LIST_APPEND_GOTO(alias,
8980 libvirt_constcharPtrWrap(fs->devAlias[j]),
8981 error);
8984 cleanup:
8985 if (c_retval > 0)
8986 for (i = 0; i < c_retval; i++)
8987 virDomainFSInfoFree(fsinfo[i]);
8988 VIR_FREE(fsinfo);
8989 return py_retval;
8991 error:
8992 Py_CLEAR(py_retval);
8993 goto cleanup;
8996 #endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
8998 #if LIBVIR_CHECK_VERSION(1, 3, 3)
8999 static PyObject *
9000 libvirt_virDomainGetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
9001 PyObject *args)
9003 PyObject *pyobj_domain;
9004 virDomainPtr domain;
9005 virTypedParameterPtr params = NULL;
9006 int nparams = 0;
9007 PyObject *dict = NULL;
9008 unsigned int flags;
9009 int rc;
9011 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetPerfEvents",
9012 &pyobj_domain, &flags))
9013 return NULL;
9014 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9016 LIBVIRT_BEGIN_ALLOW_THREADS;
9017 rc = virDomainGetPerfEvents(domain, &params, &nparams, flags);
9018 LIBVIRT_END_ALLOW_THREADS;
9020 if (rc < 0)
9021 return VIR_PY_NONE;
9023 if (!(dict = getPyVirTypedParameter(params, nparams)))
9024 goto cleanup;
9026 cleanup:
9027 virTypedParamsFree(params, nparams);
9028 return dict;
9031 static PyObject *
9032 libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
9033 PyObject *args)
9035 virDomainPtr domain;
9036 PyObject *pyobj_domain, *info;
9037 PyObject *ret = NULL;
9038 int i_retval;
9039 int nparams = 0;
9040 Py_ssize_t size = 0;
9041 unsigned int flags;
9042 virTypedParameterPtr params = NULL, new_params = NULL;
9044 if (!PyArg_ParseTuple(args,
9045 (char *)"OOI:virDomainSetPerfEvents",
9046 &pyobj_domain, &info, &flags))
9047 return NULL;
9048 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9050 if ((size = PyDict_Size(info)) < 0)
9051 return NULL;
9053 if (size == 0) {
9054 PyErr_Format(PyExc_LookupError,
9055 "Need non-empty dictionary to set attributes");
9056 return NULL;
9059 LIBVIRT_BEGIN_ALLOW_THREADS;
9060 i_retval = virDomainGetPerfEvents(domain, &params, &nparams, flags);
9061 LIBVIRT_END_ALLOW_THREADS;
9063 if (i_retval < 0)
9064 return VIR_PY_INT_FAIL;
9066 if (nparams == 0) {
9067 PyErr_Format(PyExc_LookupError,
9068 "Domain has no settable attributes");
9069 return NULL;
9072 new_params = setPyVirTypedParameter(info, params, nparams);
9073 if (!new_params)
9074 goto cleanup;
9076 LIBVIRT_BEGIN_ALLOW_THREADS;
9077 i_retval = virDomainSetPerfEvents(domain, new_params, size, flags);
9078 LIBVIRT_END_ALLOW_THREADS;
9080 if (i_retval < 0) {
9081 ret = VIR_PY_INT_FAIL;
9082 goto cleanup;
9085 ret = VIR_PY_INT_SUCCESS;
9087 cleanup:
9088 virTypedParamsFree(params, nparams);
9089 virTypedParamsFree(new_params, size);
9090 return ret;
9092 #endif /* LIBVIR_CHECK_VERSION(1, 3, 3) */
9094 #if LIBVIR_CHECK_VERSION(2, 0, 0)
9095 static void
9096 libvirt_virConnectStoragePoolEventFreeFunc(void *opaque)
9098 PyObject *pyobj_conn = (PyObject*)opaque;
9099 LIBVIRT_ENSURE_THREAD_STATE;
9100 Py_DECREF(pyobj_conn);
9101 LIBVIRT_RELEASE_THREAD_STATE;
9104 static int
9105 libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9106 virStoragePoolPtr pool,
9107 int event,
9108 int detail,
9109 void *opaque)
9111 PyObject *pyobj_cbData = (PyObject*)opaque;
9112 PyObject *pyobj_pool;
9113 PyObject *pyobj_ret = NULL;
9114 PyObject *pyobj_conn;
9115 PyObject *dictKey;
9116 int ret = -1;
9118 LIBVIRT_ENSURE_THREAD_STATE;
9120 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9121 goto cleanup;
9122 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9123 Py_DECREF(dictKey);
9125 /* Create a python instance of this virStoragePoolPtr */
9126 virStoragePoolRef(pool);
9127 if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
9128 virStoragePoolFree(pool);
9129 goto cleanup;
9131 Py_INCREF(pyobj_cbData);
9133 /* Call the Callback Dispatcher */
9134 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9135 (char*)"_dispatchStoragePoolEventLifecycleCallback",
9136 (char*)"OiiO",
9137 pyobj_pool,
9138 event,
9139 detail,
9140 pyobj_cbData);
9142 Py_DECREF(pyobj_cbData);
9143 Py_DECREF(pyobj_pool);
9145 cleanup:
9146 if (!pyobj_ret) {
9147 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9148 PyErr_Print();
9149 } else {
9150 Py_DECREF(pyobj_ret);
9151 ret = 0;
9154 LIBVIRT_RELEASE_THREAD_STATE;
9155 return ret;
9158 static int
9159 libvirt_virConnectStoragePoolEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9160 virStoragePoolPtr pool,
9161 void *opaque)
9163 PyObject *pyobj_cbData = (PyObject*)opaque;
9164 PyObject *pyobj_pool;
9165 PyObject *pyobj_ret = NULL;
9166 PyObject *pyobj_conn;
9167 PyObject *dictKey;
9168 int ret = -1;
9170 LIBVIRT_ENSURE_THREAD_STATE;
9172 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9173 goto cleanup;
9174 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9175 Py_DECREF(dictKey);
9177 /* Create a python instance of this virStoragePoolPtr */
9178 virStoragePoolRef(pool);
9179 if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
9180 virStoragePoolFree(pool);
9181 goto cleanup;
9183 Py_INCREF(pyobj_cbData);
9185 /* Call the Callback Dispatcher */
9186 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9187 (char*)"_dispatchStoragePoolEventGenericCallback",
9188 (char*)"OO",
9189 pyobj_pool,
9190 pyobj_cbData);
9192 Py_DECREF(pyobj_cbData);
9193 Py_DECREF(pyobj_pool);
9195 cleanup:
9196 if (!pyobj_ret) {
9197 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9198 PyErr_Print();
9199 } else {
9200 Py_DECREF(pyobj_ret);
9201 ret = 0;
9204 LIBVIRT_RELEASE_THREAD_STATE;
9205 return ret;
9208 static PyObject *
9209 libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9210 PyObject *args)
9212 PyObject *pyobj_conn; /* virConnectPtr */
9213 PyObject *pyobj_pool;
9214 PyObject *pyobj_cbData; /* hash of callback data */
9215 int eventID;
9216 virConnectPtr conn;
9217 int ret = 0;
9218 virConnectStoragePoolEventGenericCallback cb = NULL;
9219 virStoragePoolPtr pool;
9221 if (!PyArg_ParseTuple(args,
9222 (char *) "OOiO:virConnectStoragePoolEventRegisterAny",
9223 &pyobj_conn, &pyobj_pool, &eventID, &pyobj_cbData))
9224 return NULL;
9226 DEBUG("libvirt_virConnectStoragePoolEventRegister(%p %p %d %p) called\n",
9227 pyobj_conn, pyobj_pool, eventID, pyobj_cbData);
9228 conn = PyvirConnect_Get(pyobj_conn);
9229 if (pyobj_pool == Py_None)
9230 pool = NULL;
9231 else
9232 pool = PyvirStoragePool_Get(pyobj_pool);
9234 switch ((virStoragePoolEventID) eventID) {
9235 case VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE:
9236 cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventLifecycleCallback);
9237 break;
9239 case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
9240 cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventGenericCallback);
9241 break;
9243 case VIR_STORAGE_POOL_EVENT_ID_LAST:
9244 break;
9247 if (!cb) {
9248 return VIR_PY_INT_FAIL;
9251 Py_INCREF(pyobj_cbData);
9253 LIBVIRT_BEGIN_ALLOW_THREADS;
9254 ret = virConnectStoragePoolEventRegisterAny(conn,
9255 pool,
9256 eventID,
9258 pyobj_cbData,
9259 libvirt_virConnectStoragePoolEventFreeFunc);
9260 LIBVIRT_END_ALLOW_THREADS;
9262 if (ret < 0) {
9263 Py_DECREF(pyobj_cbData);
9266 return libvirt_intWrap(ret);
9269 static PyObject *
9270 libvirt_virConnectStoragePoolEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9271 PyObject *args)
9273 PyObject *pyobj_conn;
9274 int callbackID;
9275 virConnectPtr conn;
9276 int ret = 0;
9278 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectStoragePoolEventDeregisterAny",
9279 &pyobj_conn, &callbackID))
9280 return NULL;
9282 DEBUG("libvirt_virConnectStoragePoolEventDeregister(%p) called\n",
9283 pyobj_conn);
9285 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9287 LIBVIRT_BEGIN_ALLOW_THREADS;
9288 ret = virConnectStoragePoolEventDeregisterAny(conn, callbackID);
9289 LIBVIRT_END_ALLOW_THREADS;
9291 return libvirt_intWrap(ret);
9294 static PyObject *
9295 libvirt_virDomainGetGuestVcpus(PyObject *self ATTRIBUTE_UNUSED,
9296 PyObject *args)
9298 PyObject *pyobj_domain;
9299 virDomainPtr domain;
9300 virTypedParameterPtr params = NULL;
9301 unsigned int nparams = 0;
9302 unsigned int flags;
9303 int i_retval;
9304 PyObject *ret = NULL;
9306 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetGuestVcpus",
9307 &pyobj_domain, &flags))
9308 return NULL;
9309 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9311 LIBVIRT_BEGIN_ALLOW_THREADS;
9312 i_retval = virDomainGetGuestVcpus(domain, &params, &nparams, flags);
9313 LIBVIRT_END_ALLOW_THREADS;
9315 if (i_retval < 0) {
9316 ret = VIR_PY_NONE;
9317 goto cleanup;
9320 ret = getPyVirTypedParameter(params, nparams);
9321 cleanup:
9322 virTypedParamsFree(params, nparams);
9323 return ret;
9325 #endif /* LIBVIR_CHECK_VERSION(2, 0, 0)*/
9327 #if LIBVIR_CHECK_VERSION(2, 2, 0)
9328 static void
9329 libvirt_virConnectNodeDeviceEventFreeFunc(void *opaque)
9331 PyObject *pyobj_conn = (PyObject*)opaque;
9332 LIBVIRT_ENSURE_THREAD_STATE;
9333 Py_DECREF(pyobj_conn);
9334 LIBVIRT_RELEASE_THREAD_STATE;
9337 static int
9338 libvirt_virConnectNodeDeviceEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9339 virNodeDevicePtr dev,
9340 int event,
9341 int detail,
9342 void *opaque)
9344 PyObject *pyobj_cbData = (PyObject*)opaque;
9345 PyObject *pyobj_dev;
9346 PyObject *pyobj_ret = NULL;
9347 PyObject *pyobj_conn;
9348 PyObject *dictKey;
9349 int ret = -1;
9351 LIBVIRT_ENSURE_THREAD_STATE;
9353 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9354 goto cleanup;
9355 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9356 Py_DECREF(dictKey);
9358 /* Create a python instance of this virNodeDevicePtr */
9359 virNodeDeviceRef(dev);
9360 if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) {
9361 virNodeDeviceFree(dev);
9362 goto cleanup;
9364 Py_INCREF(pyobj_cbData);
9366 /* Call the Callback Dispatcher */
9367 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9368 (char*)"_dispatchNodeDeviceEventLifecycleCallback",
9369 (char*)"OiiO",
9370 pyobj_dev,
9371 event,
9372 detail,
9373 pyobj_cbData);
9375 Py_DECREF(pyobj_cbData);
9376 Py_DECREF(pyobj_dev);
9378 cleanup:
9379 if (!pyobj_ret) {
9380 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9381 PyErr_Print();
9382 } else {
9383 Py_DECREF(pyobj_ret);
9384 ret = 0;
9387 LIBVIRT_RELEASE_THREAD_STATE;
9388 return ret;
9391 static int
9392 libvirt_virConnectNodeDeviceEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9393 virNodeDevicePtr dev,
9394 void *opaque)
9396 PyObject *pyobj_cbData = (PyObject*)opaque;
9397 PyObject *pyobj_dev;
9398 PyObject *pyobj_ret = NULL;
9399 PyObject *pyobj_conn;
9400 PyObject *dictKey;
9401 int ret = -1;
9403 LIBVIRT_ENSURE_THREAD_STATE;
9405 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9406 goto cleanup;
9407 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9408 Py_DECREF(dictKey);
9410 /* Create a python instance of this virNodeDevicePtr */
9411 virNodeDeviceRef(dev);
9412 if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) {
9413 virNodeDeviceFree(dev);
9414 goto cleanup;
9416 Py_INCREF(pyobj_cbData);
9418 /* Call the Callback Dispatcher */
9419 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9420 (char*)"_dispatchNodeDeviceEventGenericCallback",
9421 (char*)"OO",
9422 pyobj_dev,
9423 pyobj_cbData);
9425 Py_DECREF(pyobj_cbData);
9426 Py_DECREF(pyobj_dev);
9428 cleanup:
9429 if (!pyobj_ret) {
9430 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9431 PyErr_Print();
9432 } else {
9433 Py_DECREF(pyobj_ret);
9434 ret = 0;
9437 LIBVIRT_RELEASE_THREAD_STATE;
9438 return ret;
9441 static PyObject *
9442 libvirt_virConnectNodeDeviceEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9443 PyObject *args)
9445 PyObject *pyobj_conn; /* virConnectPtr */
9446 PyObject *pyobj_dev;
9447 PyObject *pyobj_cbData; /* hash of callback data */
9448 int eventID;
9449 virConnectPtr conn;
9450 int ret = 0;
9451 virConnectNodeDeviceEventGenericCallback cb = NULL;
9452 virNodeDevicePtr dev;
9454 if (!PyArg_ParseTuple(args,
9455 (char *) "OOiO:virConnectNodeDeviceEventRegisterAny",
9456 &pyobj_conn, &pyobj_dev, &eventID, &pyobj_cbData))
9457 return NULL;
9459 DEBUG("libvirt_virConnectNodeDeviceEventRegister(%p %p %d %p) called\n",
9460 pyobj_conn, pyobj_dev, eventID, pyobj_cbData);
9461 conn = PyvirConnect_Get(pyobj_conn);
9462 if (pyobj_dev == Py_None)
9463 dev = NULL;
9464 else
9465 dev = PyvirNodeDevice_Get(pyobj_dev);
9467 switch ((virNodeDeviceEventID) eventID) {
9468 case VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE:
9469 cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventLifecycleCallback);
9470 break;
9472 case VIR_NODE_DEVICE_EVENT_ID_UPDATE:
9473 cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventGenericCallback);
9474 break;
9476 case VIR_NODE_DEVICE_EVENT_ID_LAST:
9477 break;
9480 if (!cb) {
9481 return VIR_PY_INT_FAIL;
9484 Py_INCREF(pyobj_cbData);
9486 LIBVIRT_BEGIN_ALLOW_THREADS;
9487 ret = virConnectNodeDeviceEventRegisterAny(conn,
9488 dev,
9489 eventID,
9491 pyobj_cbData,
9492 libvirt_virConnectNodeDeviceEventFreeFunc);
9493 LIBVIRT_END_ALLOW_THREADS;
9495 if (ret < 0) {
9496 Py_DECREF(pyobj_cbData);
9499 return libvirt_intWrap(ret);
9502 static PyObject *
9503 libvirt_virConnectNodeDeviceEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9504 PyObject *args)
9506 PyObject *pyobj_conn;
9507 int callbackID;
9508 virConnectPtr conn;
9509 int ret = 0;
9511 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectNodeDeviceEventDeregister",
9512 &pyobj_conn, &callbackID))
9513 return NULL;
9515 DEBUG("libvirt_virConnectNodeDeviceEventDeregister(%p) called\n",
9516 pyobj_conn);
9518 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9520 LIBVIRT_BEGIN_ALLOW_THREADS;
9521 ret = virConnectNodeDeviceEventDeregisterAny(conn, callbackID);
9522 LIBVIRT_END_ALLOW_THREADS;
9524 return libvirt_intWrap(ret);
9527 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0)*/
9529 #if LIBVIR_CHECK_VERSION(3, 0, 0)
9530 static void
9531 libvirt_virConnectSecretEventFreeFunc(void *opaque)
9533 PyObject *pyobj_conn = (PyObject*)opaque;
9534 LIBVIRT_ENSURE_THREAD_STATE;
9535 Py_DECREF(pyobj_conn);
9536 LIBVIRT_RELEASE_THREAD_STATE;
9539 static int
9540 libvirt_virConnectSecretEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9541 virSecretPtr secret,
9542 int event,
9543 int detail,
9544 void *opaque)
9546 PyObject *pyobj_cbData = (PyObject*)opaque;
9547 PyObject *pyobj_secret;
9548 PyObject *pyobj_ret = NULL;
9549 PyObject *pyobj_conn;
9550 PyObject *dictKey;
9551 int ret = -1;
9553 LIBVIRT_ENSURE_THREAD_STATE;
9555 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9556 goto cleanup;
9557 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9558 Py_DECREF(dictKey);
9560 /* Create a python instance of this virSecretPtr */
9561 virSecretRef(secret);
9562 if (!(pyobj_secret = libvirt_virSecretPtrWrap(secret))) {
9563 virSecretFree(secret);
9564 goto cleanup;
9566 Py_INCREF(pyobj_cbData);
9568 /* Call the Callback Dispatcher */
9569 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9570 (char*)"_dispatchSecretEventLifecycleCallback",
9571 (char*)"OiiO",
9572 pyobj_secret,
9573 event,
9574 detail,
9575 pyobj_cbData);
9577 Py_DECREF(pyobj_cbData);
9578 Py_DECREF(pyobj_secret);
9580 cleanup:
9581 if (!pyobj_ret) {
9582 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9583 PyErr_Print();
9584 } else {
9585 Py_DECREF(pyobj_ret);
9586 ret = 0;
9589 LIBVIRT_RELEASE_THREAD_STATE;
9590 return ret;
9593 static int
9594 libvirt_virConnectSecretEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9595 virSecretPtr secret,
9596 void *opaque)
9598 PyObject *pyobj_cbData = (PyObject*)opaque;
9599 PyObject *pyobj_secret;
9600 PyObject *pyobj_ret = NULL;
9601 PyObject *pyobj_conn;
9602 PyObject *dictKey;
9603 int ret = -1;
9605 LIBVIRT_ENSURE_THREAD_STATE;
9607 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9608 goto cleanup;
9609 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9610 Py_DECREF(dictKey);
9612 /* Create a python instance of this virSecretPtr */
9613 virSecretRef(secret);
9614 if (!(pyobj_secret = libvirt_virSecretPtrWrap(secret))) {
9615 virSecretFree(secret);
9616 goto cleanup;
9618 Py_INCREF(pyobj_cbData);
9620 /* Call the Callback Dispatcher */
9621 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9622 (char*)"_dispatchSecretEventGenericCallback",
9623 (char*)"OO",
9624 pyobj_secret,
9625 pyobj_cbData);
9627 Py_DECREF(pyobj_cbData);
9628 Py_DECREF(pyobj_secret);
9630 cleanup:
9631 if (!pyobj_ret) {
9632 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9633 PyErr_Print();
9634 } else {
9635 Py_DECREF(pyobj_ret);
9636 ret = 0;
9639 LIBVIRT_RELEASE_THREAD_STATE;
9640 return ret;
9643 static PyObject *
9644 libvirt_virConnectSecretEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9645 PyObject *args)
9647 PyObject *pyobj_conn; /* virConnectPtr */
9648 PyObject *pyobj_secret;
9649 PyObject *pyobj_cbData; /* hash of callback data */
9650 int eventID;
9651 virConnectPtr conn;
9652 int ret = 0;
9653 virConnectSecretEventGenericCallback cb = NULL;
9654 virSecretPtr secret;
9656 if (!PyArg_ParseTuple(args,
9657 (char *) "OOiO:virConnectSecretEventRegisterAny",
9658 &pyobj_conn, &pyobj_secret, &eventID, &pyobj_cbData))
9659 return NULL;
9661 DEBUG("libvirt_virConnectSecretEventRegister(%p %p %d %p) called\n",
9662 pyobj_conn, pyobj_secret, eventID, pyobj_cbData);
9663 conn = PyvirConnect_Get(pyobj_conn);
9664 if (pyobj_secret == Py_None)
9665 secret = NULL;
9666 else
9667 secret = PyvirSecret_Get(pyobj_secret);
9669 switch ((virSecretEventID) eventID) {
9670 case VIR_SECRET_EVENT_ID_LIFECYCLE:
9671 cb = VIR_SECRET_EVENT_CALLBACK(libvirt_virConnectSecretEventLifecycleCallback);
9672 break;
9674 case VIR_SECRET_EVENT_ID_VALUE_CHANGED:
9675 cb = VIR_SECRET_EVENT_CALLBACK(libvirt_virConnectSecretEventGenericCallback);
9676 break;
9678 case VIR_SECRET_EVENT_ID_LAST:
9679 break;
9682 if (!cb) {
9683 return VIR_PY_INT_FAIL;
9686 Py_INCREF(pyobj_cbData);
9688 LIBVIRT_BEGIN_ALLOW_THREADS;
9689 ret = virConnectSecretEventRegisterAny(conn, secret, eventID,
9690 cb, pyobj_cbData,
9691 libvirt_virConnectSecretEventFreeFunc);
9692 LIBVIRT_END_ALLOW_THREADS;
9694 if (ret < 0) {
9695 Py_DECREF(pyobj_cbData);
9698 return libvirt_intWrap(ret);
9701 static PyObject *
9702 libvirt_virConnectSecretEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9703 PyObject *args)
9705 PyObject *pyobj_conn;
9706 int callbackID;
9707 virConnectPtr conn;
9708 int ret = 0;
9710 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectSecretEventDeregister",
9711 &pyobj_conn, &callbackID))
9712 return NULL;
9714 DEBUG("libvirt_virConnectSecretEventDeregister(%p) called\n", pyobj_conn);
9716 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9718 LIBVIRT_BEGIN_ALLOW_THREADS;
9719 ret = virConnectSecretEventDeregisterAny(conn, callbackID);
9720 LIBVIRT_END_ALLOW_THREADS;
9722 return libvirt_intWrap(ret);
9724 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0)*/
9727 #if LIBVIR_CHECK_VERSION(3, 4, 0)
9728 static PyObject *
9729 libvirt_virStreamRecvHole(PyObject *self ATTRIBUTE_UNUSED,
9730 PyObject *args)
9732 PyObject *pyobj_stream;
9733 virStreamPtr stream;
9734 long long length = -1;
9735 unsigned int flags;
9736 int ret;
9738 if (!PyArg_ParseTuple(args, (char *) "OI:virStreamRecvHole",
9739 &pyobj_stream, &flags))
9740 return NULL;
9742 stream = PyvirStream_Get(pyobj_stream);
9744 LIBVIRT_BEGIN_ALLOW_THREADS;
9745 ret = virStreamRecvHole(stream, &length, flags);
9746 LIBVIRT_END_ALLOW_THREADS;
9748 DEBUG("StreamRecvHole ret=%d length=%lld\n", ret, length);
9750 if (ret < 0)
9751 return VIR_PY_NONE;
9753 return libvirt_longlongWrap(length);
9757 static PyObject *
9758 libvirt_virStreamSendHole(PyObject *self ATTRIBUTE_UNUSED,
9759 PyObject *args)
9761 PyObject *pyobj_stream;
9762 virStreamPtr stream;
9763 long long length;
9764 unsigned int flags;
9765 int ret;
9767 if (!PyArg_ParseTuple(args, (char *) "OLI:virStreamSendHole",
9768 &pyobj_stream, &length, &flags))
9769 return NULL;
9771 stream = PyvirStream_Get(pyobj_stream);
9773 LIBVIRT_BEGIN_ALLOW_THREADS;
9774 ret = virStreamSendHole(stream, length, flags);
9775 LIBVIRT_END_ALLOW_THREADS;
9777 DEBUG("StreamSendHole ret=%d\n", ret);
9779 return libvirt_intWrap(ret);
9783 static PyObject *
9784 libvirt_virStreamRecvFlags(PyObject *self ATTRIBUTE_UNUSED,
9785 PyObject *args)
9787 PyObject *pyobj_stream;
9788 PyObject *rv;
9789 virStreamPtr stream;
9790 char *buf = NULL;
9791 size_t nbytes;
9792 unsigned int flags;
9793 int ret;
9795 if (!PyArg_ParseTuple(args, (char *) "OkI:virStreamRecvFlags",
9796 &pyobj_stream, &nbytes, &flags))
9797 return NULL;
9799 stream = PyvirStream_Get(pyobj_stream);
9801 if (VIR_ALLOC_N(buf, nbytes + 1) < 0)
9802 return PyErr_NoMemory();
9804 LIBVIRT_BEGIN_ALLOW_THREADS;
9805 ret = virStreamRecvFlags(stream, buf, nbytes, flags);
9806 LIBVIRT_END_ALLOW_THREADS;
9808 buf[ret > -1 ? ret : 0] = '\0';
9809 DEBUG("StreamRecvFlags ret=%d strlen=%d\n", ret, (int) strlen(buf));
9811 if (ret == -2 || ret == -3)
9812 return libvirt_intWrap(ret);
9813 if (ret < 0)
9814 return VIR_PY_NONE;
9815 rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
9816 VIR_FREE(buf);
9817 return rv;
9820 #endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */
9823 #if LIBVIR_CHECK_VERSION(4, 4, 0)
9824 static PyObject *
9825 libvirt_virConnectBaselineHypervisorCPU(PyObject *self ATTRIBUTE_UNUSED,
9826 PyObject *args)
9828 virConnectPtr conn;
9829 PyObject *pyobj_conn;
9830 char *emulator;
9831 char *arch;
9832 char *machine;
9833 char *virttype;
9834 PyObject *list;
9835 unsigned int flags;
9836 char **xmlCPUs = NULL;
9837 int ncpus = 0;
9838 size_t i;
9839 char *cpu;
9840 PyObject *ret = NULL;
9842 if (!PyArg_ParseTuple(args, (char *)"OzzzzOI:virConnectBaselineHypervisorCPU",
9843 &pyobj_conn, &emulator, &arch, &machine, &virttype,
9844 &list, &flags))
9845 return NULL;
9847 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9849 if (PyList_Check(list)) {
9850 ncpus = PyList_Size(list);
9851 if (VIR_ALLOC_N(xmlCPUs, ncpus) < 0)
9852 return PyErr_NoMemory();
9854 for (i = 0; i < ncpus; i++) {
9855 if (libvirt_charPtrUnwrap(PyList_GetItem(list, i),
9856 &(xmlCPUs[i])) < 0)
9857 goto cleanup;
9861 LIBVIRT_BEGIN_ALLOW_THREADS;
9862 cpu = virConnectBaselineHypervisorCPU(conn, emulator, arch, machine, virttype,
9863 (const char **)xmlCPUs, ncpus, flags);
9864 LIBVIRT_END_ALLOW_THREADS;
9866 ret = libvirt_constcharPtrWrap(cpu);
9868 cleanup:
9869 for (i = 0; i < ncpus; i++)
9870 VIR_FREE(xmlCPUs[i]);
9871 VIR_FREE(xmlCPUs);
9872 VIR_FREE(cpu);
9874 return ret;
9876 #endif /* LIBVIR_CHECK_VERSION(4, 4, 0) */
9879 #if LIBVIR_CHECK_VERSION(4, 5, 0)
9880 static PyObject *
9881 libvirt_virDomainGetLaunchSecurityInfo(PyObject *self ATTRIBUTE_UNUSED,
9882 PyObject *args)
9884 PyObject *pyobj_dom = NULL;
9885 PyObject *ret = NULL;
9887 virDomainPtr dom = NULL;
9888 virTypedParameterPtr params = NULL;
9889 int nparams = 0;
9890 unsigned int flags = 0;
9891 int i_retval;
9893 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetLaunchSecurityInfo",
9894 &pyobj_dom, &flags))
9895 return NULL;
9896 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
9898 LIBVIRT_BEGIN_ALLOW_THREADS;
9899 i_retval = virDomainGetLaunchSecurityInfo(dom, &params, &nparams, flags);
9900 LIBVIRT_END_ALLOW_THREADS;
9902 if (i_retval < 0) {
9903 ret = VIR_PY_NONE;
9904 goto cleanup;
9907 ret = getPyVirTypedParameter(params, nparams);
9908 cleanup:
9909 virTypedParamsFree(params, nparams);
9910 return ret;
9914 static PyObject *
9915 libvirt_virNodeGetSEVInfo(PyObject *self ATTRIBUTE_UNUSED,
9916 PyObject *args)
9918 PyObject *pyobj_conn = NULL;
9919 PyObject *ret = NULL;
9921 virConnectPtr conn = NULL;
9922 virTypedParameterPtr params = NULL;
9923 int nparams = 0;
9924 unsigned int flags = 0;
9925 int i_retval;
9927 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetSEVInfo",
9928 &pyobj_conn, &flags))
9929 return NULL;
9930 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9932 LIBVIRT_BEGIN_ALLOW_THREADS;
9933 i_retval = virNodeGetSEVInfo(conn, &params, &nparams, flags);
9934 LIBVIRT_END_ALLOW_THREADS;
9936 if (i_retval < 0) {
9937 ret = VIR_PY_NONE;
9938 goto cleanup;
9941 ret = getPyVirTypedParameter(params, nparams);
9942 cleanup:
9943 virTypedParamsFree(params, nparams);
9944 return ret;
9946 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
9948 #if LIBVIR_CHECK_VERSION(5, 5, 0)
9949 static PyObject *
9950 libvirt_virNetworkPortSetParameters(PyObject *self ATTRIBUTE_UNUSED,
9951 PyObject *args)
9953 virNetworkPortPtr port;
9954 PyObject *pyobj_port, *info;
9955 PyObject *ret = NULL;
9956 int i_retval;
9957 int nparams = 0;
9958 Py_ssize_t size = 0;
9959 unsigned int flags;
9960 virTypedParameterPtr params = NULL, new_params = NULL;
9962 if (!PyArg_ParseTuple(args,
9963 (char *)"OOI:virNetworkPortSetParameters",
9964 &pyobj_port, &info, &flags))
9965 return NULL;
9966 port = (virNetworkPortPtr) PyvirNetworkPort_Get(pyobj_port);
9968 if ((size = PyDict_Size(info)) < 0)
9969 return NULL;
9971 if (size == 0) {
9972 PyErr_Format(PyExc_LookupError,
9973 "Need non-empty dictionary to set attributes");
9974 return NULL;
9977 LIBVIRT_BEGIN_ALLOW_THREADS;
9978 i_retval = virNetworkPortGetParameters(port, &params, &nparams, flags);
9979 LIBVIRT_END_ALLOW_THREADS;
9981 if (i_retval < 0)
9982 return VIR_PY_INT_FAIL;
9984 if (nparams == 0) {
9985 PyErr_Format(PyExc_LookupError,
9986 "Port has no settable attributes");
9987 return NULL;
9990 new_params = setPyVirTypedParameter(info, params, nparams);
9991 if (!new_params)
9992 goto cleanup;
9994 LIBVIRT_BEGIN_ALLOW_THREADS;
9995 i_retval = virNetworkPortSetParameters(port, new_params, size, flags);
9996 LIBVIRT_END_ALLOW_THREADS;
9998 if (i_retval < 0) {
9999 ret = VIR_PY_INT_FAIL;
10000 goto cleanup;
10003 ret = VIR_PY_INT_SUCCESS;
10005 cleanup:
10006 virTypedParamsFree(params, nparams);
10007 virTypedParamsFree(new_params, size);
10008 return ret;
10011 static PyObject *
10012 libvirt_virNetworkPortGetParameters(PyObject *self ATTRIBUTE_UNUSED,
10013 PyObject *args)
10015 PyObject *pyobj_port;
10016 virNetworkPortPtr port;
10017 virTypedParameterPtr params = NULL;
10018 int nparams = 0;
10019 PyObject *dict = NULL;
10020 unsigned int flags;
10021 int rc;
10023 if (!PyArg_ParseTuple(args, (char *) "OI:virNetworkPortGetParameters",
10024 &pyobj_port, &flags))
10025 return NULL;
10026 port = (virNetworkPortPtr) PyvirNetworkPort_Get(pyobj_port);
10028 LIBVIRT_BEGIN_ALLOW_THREADS;
10029 rc = virNetworkPortGetParameters(port, &params, &nparams, flags);
10030 LIBVIRT_END_ALLOW_THREADS;
10032 if (rc < 0)
10033 return VIR_PY_NONE;
10035 dict = getPyVirTypedParameter(params, nparams);
10037 virTypedParamsFree(params, nparams);
10038 return dict;
10040 #endif /* LIBVIR_CHECK_VERSION(5, 5, 0) */
10042 /************************************************************************
10044 * The registration stuff *
10046 ************************************************************************/
10047 static PyMethodDef libvirtMethods[] = {
10048 #include "build/libvirt-export.c"
10049 {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
10050 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL},
10051 #if LIBVIR_CHECK_VERSION(1, 1, 3)
10052 {(char *) "virConnectGetCPUModelNames", libvirt_virConnectGetCPUModelNames, METH_VARARGS, NULL},
10053 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
10054 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
10055 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
10056 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
10057 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
10058 #if LIBVIR_CHECK_VERSION(0, 9, 13)
10059 {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
10060 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
10061 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
10062 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
10063 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
10064 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
10065 #if LIBVIR_CHECK_VERSION(1, 2, 1)
10066 {(char *) "virConnectNetworkEventRegisterAny", libvirt_virConnectNetworkEventRegisterAny, METH_VARARGS, NULL},
10067 {(char *) "virConnectNetworkEventDeregisterAny", libvirt_virConnectNetworkEventDeregisterAny, METH_VARARGS, NULL},
10068 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1) */
10069 #if LIBVIR_CHECK_VERSION(0, 10, 0)
10070 {(char *) "virConnectRegisterCloseCallback", libvirt_virConnectRegisterCloseCallback, METH_VARARGS, NULL},
10071 {(char *) "virConnectUnregisterCloseCallback", libvirt_virConnectUnregisterCloseCallback, METH_VARARGS, NULL},
10072 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
10073 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
10074 {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
10075 {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
10076 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
10077 {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
10078 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
10079 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
10080 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
10081 {(char *) "virNodeGetSecurityModel", libvirt_virNodeGetSecurityModel, METH_VARARGS, NULL},
10082 {(char *) "virDomainGetSecurityLabel", libvirt_virDomainGetSecurityLabel, METH_VARARGS, NULL},
10083 #if LIBVIR_CHECK_VERSION(0, 10, 0)
10084 {(char *) "virDomainGetSecurityLabelList", libvirt_virDomainGetSecurityLabelList, METH_VARARGS, NULL},
10085 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
10086 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
10087 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
10088 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
10089 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
10090 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
10091 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
10092 {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
10093 {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
10094 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
10095 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
10096 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10097 {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
10098 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10099 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
10100 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
10101 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},
10102 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL},
10103 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
10104 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
10105 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL},
10106 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats, METH_VARARGS, NULL},
10107 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
10108 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
10109 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
10110 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
10111 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
10112 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags, METH_VARARGS, NULL},
10113 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
10114 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags, METH_VARARGS, NULL},
10115 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters, METH_VARARGS, NULL},
10116 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters, METH_VARARGS, NULL},
10117 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters, METH_VARARGS, NULL},
10118 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
10119 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
10120 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
10121 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
10122 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
10123 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
10124 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
10125 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
10126 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
10127 #if LIBVIR_CHECK_VERSION(0, 10, 0)
10128 {(char *) "virDomainGetEmulatorPinInfo", libvirt_virDomainGetEmulatorPinInfo, METH_VARARGS, NULL},
10129 {(char *) "virDomainPinEmulator", libvirt_virDomainPinEmulator, METH_VARARGS, NULL},
10130 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
10131 #if LIBVIR_CHECK_VERSION(1, 2, 14)
10132 {(char *) "virDomainGetIOThreadInfo", libvirt_virDomainGetIOThreadInfo, METH_VARARGS, NULL},
10133 {(char *) "virDomainPinIOThread", libvirt_virDomainPinIOThread, METH_VARARGS, NULL},
10134 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
10135 #if LIBVIR_CHECK_VERSION(4, 10, 0)
10136 {(char *) "virDomainSetIOThreadParams", libvirt_virDomainSetIOThreadParams, METH_VARARGS, NULL},
10137 #endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */
10138 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
10139 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
10140 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10141 {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
10142 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10143 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
10144 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
10145 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10146 {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
10147 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10148 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL},
10149 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL},
10150 #if LIBVIR_CHECK_VERSION(3, 0, 0)
10151 {(char *) "virStorageVolGetInfoFlags", libvirt_virStorageVolGetInfoFlags, METH_VARARGS, NULL},
10152 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0) */
10153 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL},
10154 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL},
10155 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL},
10156 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
10157 {(char *) "virEventAddHandle", libvirt_virEventAddHandle, METH_VARARGS, NULL},
10158 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout, METH_VARARGS, NULL},
10159 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
10160 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
10161 {(char *) "virEventInvokeFreeCallback", libvirt_virEventInvokeFreeCallback, METH_VARARGS, NULL},
10162 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
10163 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10164 {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
10165 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10166 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
10167 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
10168 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},
10169 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL},
10170 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
10171 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10172 {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL},
10173 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10174 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
10175 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
10176 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL},
10177 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
10178 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
10179 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
10180 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10181 {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
10182 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10183 #if LIBVIR_CHECK_VERSION(4, 5, 0)
10184 {(char *) "virConnectListAllNWFilterBindings", libvirt_virConnectListAllNWFilterBindings, METH_VARARGS, NULL},
10185 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
10186 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
10187 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
10188 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10189 {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
10190 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10191 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
10192 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
10193 #if LIBVIR_CHECK_VERSION(1, 0, 3)
10194 {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL},
10195 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
10196 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
10197 #if LIBVIR_CHECK_VERSION(0, 9, 13)
10198 {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
10199 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
10200 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
10201 #if LIBVIR_CHECK_VERSION(0, 9, 13)
10202 {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
10203 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
10204 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
10205 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
10206 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
10207 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL},
10208 {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
10209 #if LIBVIR_CHECK_VERSION(1, 0, 3)
10210 {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL},
10211 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
10212 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
10213 #if LIBVIR_CHECK_VERSION(3, 7, 0)
10214 {(char *) "virDomainMigrateGetMaxDowntime", libvirt_virDomainMigrateGetMaxDowntime, METH_VARARGS, NULL},
10215 #endif /* LIBVIR_CHECK_VERSION(3, 7, 0) */
10216 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
10217 #if LIBVIR_CHECK_VERSION(1, 1, 0)
10218 {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL},
10219 {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL},
10220 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
10221 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
10222 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
10223 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
10224 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10225 {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
10226 {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
10227 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10228 #if LIBVIR_CHECK_VERSION(1, 0, 0)
10229 {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
10230 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
10231 #if LIBVIR_CHECK_VERSION(1, 1, 1)
10232 {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL},
10233 {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL},
10234 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
10235 #if LIBVIR_CHECK_VERSION(1, 2, 5)
10236 {(char *) "virDomainFSFreeze", libvirt_virDomainFSFreeze, METH_VARARGS, NULL},
10237 {(char *) "virDomainFSThaw", libvirt_virDomainFSThaw, METH_VARARGS, NULL},
10238 {(char *) "virDomainGetTime", libvirt_virDomainGetTime, METH_VARARGS, NULL},
10239 {(char *) "virDomainSetTime", libvirt_virDomainSetTime, METH_VARARGS, NULL},
10240 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
10241 #if LIBVIR_CHECK_VERSION(1, 2, 6)
10242 {(char *) "virNodeGetFreePages", libvirt_virNodeGetFreePages, METH_VARARGS, NULL},
10243 {(char *) "virNetworkGetDHCPLeases", libvirt_virNetworkGetDHCPLeases, METH_VARARGS, NULL},
10244 #endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
10245 #if LIBVIR_CHECK_VERSION(1, 2, 8)
10246 {(char *) "virConnectGetAllDomainStats", libvirt_virConnectGetAllDomainStats, METH_VARARGS, NULL},
10247 {(char *) "virDomainListGetStats", libvirt_virDomainListGetStats, METH_VARARGS, NULL},
10248 {(char *) "virDomainBlockCopy", libvirt_virDomainBlockCopy, METH_VARARGS, NULL},
10249 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
10250 #if LIBVIR_CHECK_VERSION(1, 2, 9)
10251 {(char *) "virNodeAllocPages", libvirt_virNodeAllocPages, METH_VARARGS, NULL},
10252 #endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
10253 #if LIBVIR_CHECK_VERSION(1, 2, 11)
10254 {(char *) "virDomainGetFSInfo", libvirt_virDomainGetFSInfo, METH_VARARGS, NULL},
10255 #endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
10256 #if LIBVIR_CHECK_VERSION(1, 2, 14)
10257 {(char *) "virDomainInterfaceAddresses", libvirt_virDomainInterfaceAddresses, METH_VARARGS, NULL},
10258 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
10259 #if LIBVIR_CHECK_VERSION(1, 3, 3)
10260 {(char *) "virDomainGetPerfEvents", libvirt_virDomainGetPerfEvents, METH_VARARGS, NULL},
10261 {(char *) "virDomainSetPerfEvents", libvirt_virDomainSetPerfEvents, METH_VARARGS, NULL},
10262 #endif /* LIBVIR_CHECK_VERSION(1, 3, 3) */
10263 #if LIBVIR_CHECK_VERSION(2, 0, 0)
10264 {(char *) "virConnectStoragePoolEventRegisterAny", libvirt_virConnectStoragePoolEventRegisterAny, METH_VARARGS, NULL},
10265 {(char *) "virConnectStoragePoolEventDeregisterAny", libvirt_virConnectStoragePoolEventDeregisterAny, METH_VARARGS, NULL},
10266 {(char *) "virDomainGetGuestVcpus", libvirt_virDomainGetGuestVcpus, METH_VARARGS, NULL},
10267 #endif /* LIBVIR_CHECK_VERSION(2, 0, 0) */
10268 #if LIBVIR_CHECK_VERSION(2, 2, 0)
10269 {(char *) "virConnectNodeDeviceEventRegisterAny", libvirt_virConnectNodeDeviceEventRegisterAny, METH_VARARGS, NULL},
10270 {(char *) "virConnectNodeDeviceEventDeregisterAny", libvirt_virConnectNodeDeviceEventDeregisterAny, METH_VARARGS, NULL},
10271 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0) */
10272 #if LIBVIR_CHECK_VERSION(3, 0, 0)
10273 {(char *) "virConnectSecretEventRegisterAny", libvirt_virConnectSecretEventRegisterAny, METH_VARARGS, NULL},
10274 {(char *) "virConnectSecretEventDeregisterAny", libvirt_virConnectSecretEventDeregisterAny, METH_VARARGS, NULL},
10275 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0) */
10276 #if LIBVIR_CHECK_VERSION(3, 4, 0)
10277 {(char *) "virStreamRecvHole", libvirt_virStreamRecvHole, METH_VARARGS, NULL},
10278 {(char *) "virStreamSendHole", libvirt_virStreamSendHole, METH_VARARGS, NULL},
10279 {(char *) "virStreamRecvFlags", libvirt_virStreamRecvFlags, METH_VARARGS, NULL},
10280 #endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */
10281 #if LIBVIR_CHECK_VERSION(4, 4, 0)
10282 {(char *) "virConnectBaselineHypervisorCPU", libvirt_virConnectBaselineHypervisorCPU, METH_VARARGS, NULL},
10283 #endif /* LIBVIR_CHECK_VERSION(4, 4, 0) */
10284 #if LIBVIR_CHECK_VERSION(4, 5, 0)
10285 {(char *) "virDomainGetLaunchSecurityInfo", libvirt_virDomainGetLaunchSecurityInfo, METH_VARARGS, NULL},
10286 {(char *) "virNodeGetSEVInfo", libvirt_virNodeGetSEVInfo, METH_VARARGS, NULL},
10287 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
10288 #if LIBVIR_CHECK_VERSION(5, 5, 0)
10289 {(char *) "virNetworkPortSetParameters", libvirt_virNetworkPortSetParameters, METH_VARARGS, NULL},
10290 {(char *) "virNetworkPortGetParameters", libvirt_virNetworkPortGetParameters, METH_VARARGS, NULL},
10291 #endif /* LIBVIR_CHECK_VERSION(5, 5, 0) */
10292 {NULL, NULL, 0, NULL}
10295 #if PY_MAJOR_VERSION > 2
10296 static struct PyModuleDef moduledef = {
10297 PyModuleDef_HEAD_INIT,
10298 # ifndef __CYGWIN__
10299 "libvirtmod",
10300 # else
10301 "cygvirtmod",
10302 # endif
10303 NULL,
10305 libvirtMethods,
10306 NULL,
10307 NULL,
10308 NULL,
10309 NULL
10312 PyObject *
10313 # ifndef __CYGWIN__
10314 PyInit_libvirtmod
10315 # else
10316 PyInit_cygvirtmod
10317 # endif
10318 (void)
10320 PyObject *module;
10322 if (virInitialize() < 0)
10323 return NULL;
10325 module = PyModule_Create(&moduledef);
10327 return module;
10329 #else /* ! PY_MAJOR_VERSION > 2 */
10330 void
10331 # ifndef __CYGWIN__
10332 initlibvirtmod
10333 # else
10334 initcygvirtmod
10335 # endif
10336 (void)
10338 if (virInitialize() < 0)
10339 return;
10341 /* initialize the python extension module */
10342 Py_InitModule((char *)
10343 # ifndef __CYGWIN__
10344 "libvirtmod",
10345 # else
10346 "cygvirtmod",
10347 # endif
10348 libvirtMethods);
10350 #endif /* ! PY_MAJOR_VERSION > 2 */