Add virDomainCheckpoint APIs
[libvirt-python/ericb.git] / libvirt-override.c
blob42f81983d1c6c90fde069015357a905f9981a483
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 #if LIBVIR_CHECK_VERSION(5, 6, 0)
2329 static PyObject *
2330 libvirt_virDomainListAllCheckpoints(PyObject *self ATTRIBUTE_UNUSED,
2331 PyObject *args)
2333 PyObject *py_retval = NULL;
2334 virDomainCheckpointPtr *chks = NULL;
2335 int c_retval;
2336 ssize_t i;
2337 virDomainPtr dom;
2338 PyObject *pyobj_dom;
2339 unsigned int flags;
2341 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainListAllCheckpoints",
2342 &pyobj_dom, &flags))
2343 return NULL;
2344 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2346 LIBVIRT_BEGIN_ALLOW_THREADS;
2347 c_retval = virDomainListAllCheckpoints(dom, &chks, flags);
2348 LIBVIRT_END_ALLOW_THREADS;
2350 if (c_retval < 0)
2351 return VIR_PY_NONE;
2353 if (!(py_retval = PyList_New(c_retval)))
2354 goto cleanup;
2356 for (i = 0; i < c_retval; i++) {
2357 VIR_PY_LIST_SET_GOTO(py_retval, i,
2358 libvirt_virDomainCheckpointPtrWrap(chks[i]), error);
2359 chks[i] = NULL;
2362 cleanup:
2363 for (i = 0; i < c_retval; i++)
2364 if (chks[i])
2365 virDomainCheckpointFree(chks[i]);
2366 VIR_FREE(chks);
2367 return py_retval;
2369 error:
2370 Py_CLEAR(py_retval);
2371 goto cleanup;
2374 static PyObject *
2375 libvirt_virDomainCheckpointListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2376 PyObject *args)
2378 PyObject *py_retval = NULL;
2379 virDomainCheckpointPtr *chks = NULL;
2380 int c_retval;
2381 ssize_t i;
2382 virDomainCheckpointPtr parent;
2383 PyObject *pyobj_parent;
2384 unsigned int flags;
2386 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainCheckpointListAllChildren",
2387 &pyobj_parent, &flags))
2388 return NULL;
2389 parent = (virDomainCheckpointPtr) PyvirDomainCheckpoint_Get(pyobj_parent);
2391 LIBVIRT_BEGIN_ALLOW_THREADS;
2392 c_retval = virDomainCheckpointListAllChildren(parent, &chks, flags);
2393 LIBVIRT_END_ALLOW_THREADS;
2395 if (c_retval < 0)
2396 return VIR_PY_NONE;
2398 if (!(py_retval = PyList_New(c_retval)))
2399 goto cleanup;
2401 for (i = 0; i < c_retval; i++) {
2402 VIR_PY_LIST_SET_GOTO(py_retval, i,
2403 libvirt_virDomainCheckpointPtrWrap(chks[i]), error);
2404 chks[i] = NULL;
2407 cleanup:
2408 for (i = 0; i < c_retval; i++)
2409 if (chks[i])
2410 virDomainCheckpointFree(chks[i]);
2411 VIR_FREE(chks);
2412 return py_retval;
2414 error:
2415 Py_CLEAR(py_retval);
2416 goto cleanup;
2418 #endif /* LIBVIR_CHECK_VERSION(5, 6, 0) */
2420 static PyObject *
2421 libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
2422 PyObject *args)
2424 PyObject *py_retval;
2425 char **names = NULL;
2426 int c_retval;
2427 ssize_t i;
2428 virDomainPtr dom;
2429 PyObject *pyobj_dom;
2430 unsigned int flags;
2432 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListNames",
2433 &pyobj_dom, &flags))
2434 return NULL;
2435 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2437 LIBVIRT_BEGIN_ALLOW_THREADS;
2438 c_retval = virDomainSnapshotNum(dom, flags);
2439 LIBVIRT_END_ALLOW_THREADS;
2441 if (c_retval < 0)
2442 return VIR_PY_NONE;
2444 if (c_retval) {
2445 if (VIR_ALLOC_N(names, c_retval) < 0)
2446 return PyErr_NoMemory();
2448 LIBVIRT_BEGIN_ALLOW_THREADS;
2449 c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
2450 LIBVIRT_END_ALLOW_THREADS;
2452 if (c_retval < 0) {
2453 py_retval = VIR_PY_NONE;
2454 goto cleanup;
2457 py_retval = PyList_New(c_retval);
2458 if (!py_retval)
2459 goto cleanup;
2461 for (i = 0; i < c_retval; i++)
2462 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_constcharPtrWrap(names[i]), error);
2464 cleanup:
2465 if (c_retval > 0)
2466 for (i = 0; i < c_retval; i++)
2467 VIR_FREE(names[i]);
2468 VIR_FREE(names);
2469 return py_retval;
2471 error:
2472 Py_CLEAR(py_retval);
2473 goto cleanup;
2476 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2477 static PyObject *
2478 libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
2479 PyObject *args)
2481 PyObject *py_retval = NULL;
2482 virDomainSnapshotPtr *snaps = NULL;
2483 int c_retval;
2484 ssize_t i;
2485 virDomainPtr dom;
2486 PyObject *pyobj_dom;
2487 unsigned int flags;
2489 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainListAllSnapshots",
2490 &pyobj_dom, &flags))
2491 return NULL;
2492 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2494 LIBVIRT_BEGIN_ALLOW_THREADS;
2495 c_retval = virDomainListAllSnapshots(dom, &snaps, flags);
2496 LIBVIRT_END_ALLOW_THREADS;
2498 if (c_retval < 0)
2499 return VIR_PY_NONE;
2501 if (!(py_retval = PyList_New(c_retval)))
2502 goto cleanup;
2504 for (i = 0; i < c_retval; i++) {
2505 VIR_PY_LIST_SET_GOTO(py_retval, i,
2506 libvirt_virDomainSnapshotPtrWrap(snaps[i]), error);
2507 snaps[i] = NULL;
2510 cleanup:
2511 for (i = 0; i < c_retval; i++)
2512 if (snaps[i])
2513 virDomainSnapshotFree(snaps[i]);
2514 VIR_FREE(snaps);
2515 return py_retval;
2517 error:
2518 Py_CLEAR(py_retval);
2519 goto cleanup;
2521 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2523 static PyObject *
2524 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
2525 PyObject *args)
2527 PyObject *py_retval;
2528 char **names = NULL;
2529 int c_retval;
2530 ssize_t i;
2531 virDomainSnapshotPtr snap;
2532 PyObject *pyobj_snap;
2533 unsigned int flags;
2535 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListChildrenNames",
2536 &pyobj_snap, &flags))
2537 return NULL;
2538 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2540 LIBVIRT_BEGIN_ALLOW_THREADS;
2541 c_retval = virDomainSnapshotNumChildren(snap, flags);
2542 LIBVIRT_END_ALLOW_THREADS;
2544 if (c_retval < 0)
2545 return VIR_PY_NONE;
2547 if (c_retval) {
2548 if (VIR_ALLOC_N(names, c_retval) < 0)
2549 return PyErr_NoMemory();
2551 LIBVIRT_BEGIN_ALLOW_THREADS;
2552 c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
2553 flags);
2554 LIBVIRT_END_ALLOW_THREADS;
2556 if (c_retval < 0) {
2557 py_retval = VIR_PY_NONE;
2558 goto cleanup;
2562 if ((py_retval = PyList_New(c_retval)) == NULL)
2563 goto cleanup;
2565 for (i = 0; i < c_retval; i++)
2566 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_constcharPtrWrap(names[i]), error);
2568 cleanup:
2569 if (c_retval > 0)
2570 for (i = 0; i < c_retval; i++)
2571 VIR_FREE(names[i]);
2572 VIR_FREE(names);
2573 return py_retval;
2575 error:
2576 Py_CLEAR(py_retval);
2577 goto cleanup;
2580 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2581 static PyObject *
2582 libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2583 PyObject *args)
2585 PyObject *py_retval = NULL;
2586 virDomainSnapshotPtr *snaps = NULL;
2587 int c_retval;
2588 ssize_t i;
2589 virDomainSnapshotPtr parent;
2590 PyObject *pyobj_parent;
2591 unsigned int flags;
2593 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainSnapshotListAllChildren",
2594 &pyobj_parent, &flags))
2595 return NULL;
2596 parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
2598 LIBVIRT_BEGIN_ALLOW_THREADS;
2599 c_retval = virDomainSnapshotListAllChildren(parent, &snaps, flags);
2600 LIBVIRT_END_ALLOW_THREADS;
2602 if (c_retval < 0)
2603 return VIR_PY_NONE;
2605 if (!(py_retval = PyList_New(c_retval)))
2606 goto cleanup;
2608 for (i = 0; i < c_retval; i++) {
2609 VIR_PY_LIST_SET_GOTO(py_retval, i,
2610 libvirt_virDomainSnapshotPtrWrap(snaps[i]), error);
2611 snaps[i] = NULL;
2614 cleanup:
2615 for (i = 0; i < c_retval; i++)
2616 if (snaps[i])
2617 virDomainSnapshotFree(snaps[i]);
2618 VIR_FREE(snaps);
2619 return py_retval;
2621 error:
2622 Py_CLEAR(py_retval);
2623 goto cleanup;
2625 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2627 static PyObject *
2628 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
2629 PyObject *args)
2631 int c_retval;
2632 virDomainSnapshotPtr snap;
2633 PyObject *pyobj_snap;
2634 PyObject *pyobj_dom;
2635 unsigned int flags;
2637 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainRevertToSnapshot",
2638 &pyobj_dom, &pyobj_snap, &flags))
2639 return NULL;
2640 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2642 LIBVIRT_BEGIN_ALLOW_THREADS;
2643 c_retval = virDomainRevertToSnapshot(snap, flags);
2644 LIBVIRT_END_ALLOW_THREADS;
2646 if (c_retval < 0)
2647 return VIR_PY_INT_FAIL;
2649 return libvirt_intWrap(c_retval);
2652 static PyObject *
2653 libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED,
2654 PyObject *args)
2656 PyObject *py_retval;
2657 int c_retval;
2658 virDomainPtr domain;
2659 PyObject *pyobj_domain;
2660 virDomainInfo info;
2662 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_domain))
2663 return NULL;
2664 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2666 LIBVIRT_BEGIN_ALLOW_THREADS;
2667 c_retval = virDomainGetInfo(domain, &info);
2668 LIBVIRT_END_ALLOW_THREADS;
2670 if (c_retval < 0)
2671 return VIR_PY_NONE;
2673 if ((py_retval = PyList_New(5)) == NULL)
2674 return NULL;
2676 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap((int) info.state), error);
2677 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_ulongWrap(info.maxMem), error);
2678 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_ulongWrap(info.memory), error);
2679 VIR_PY_LIST_SET_GOTO(py_retval, 3,
2680 libvirt_intWrap((int) info.nrVirtCpu), error);
2681 VIR_PY_LIST_SET_GOTO(py_retval, 4,
2682 libvirt_ulonglongWrap(info.cpuTime), error);
2684 return py_retval;
2686 error:
2687 Py_XDECREF(py_retval);
2688 return NULL;
2691 static PyObject *
2692 libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED,
2693 PyObject *args)
2695 PyObject *py_retval;
2696 int c_retval;
2697 virDomainPtr domain;
2698 PyObject *pyobj_domain;
2699 int state;
2700 int reason;
2701 unsigned int flags;
2703 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetState",
2704 &pyobj_domain, &flags))
2705 return NULL;
2707 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2709 LIBVIRT_BEGIN_ALLOW_THREADS;
2710 c_retval = virDomainGetState(domain, &state, &reason, flags);
2711 LIBVIRT_END_ALLOW_THREADS;
2713 if (c_retval < 0)
2714 return VIR_PY_NONE;
2716 if ((py_retval = PyList_New(2)) == NULL)
2717 return NULL;
2719 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap(state), error);
2720 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_intWrap(reason), error);
2722 return py_retval;
2724 error:
2725 Py_XDECREF(py_retval);
2726 return NULL;
2729 static PyObject *
2730 libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED,
2731 PyObject *args)
2733 PyObject *py_retval;
2734 int c_retval;
2735 virDomainPtr domain;
2736 PyObject *pyobj_domain;
2737 virDomainControlInfo info;
2738 unsigned int flags;
2740 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetControlInfo",
2741 &pyobj_domain, &flags))
2742 return NULL;
2743 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2745 LIBVIRT_BEGIN_ALLOW_THREADS;
2746 c_retval = virDomainGetControlInfo(domain, &info, flags);
2747 LIBVIRT_END_ALLOW_THREADS;
2749 if (c_retval < 0)
2750 return VIR_PY_NONE;
2752 if ((py_retval = PyList_New(3)) == NULL)
2753 return NULL;
2755 VIR_PY_LIST_SET_GOTO(py_retval, 0, libvirt_intWrap(info.state), error);
2756 VIR_PY_LIST_SET_GOTO(py_retval, 1, libvirt_intWrap(info.details), error);
2757 VIR_PY_LIST_SET_GOTO(py_retval, 2,
2758 libvirt_ulonglongWrap(info.stateTime), error);
2760 return py_retval;
2762 error:
2763 Py_XDECREF(py_retval);
2764 return NULL;
2767 static PyObject *
2768 libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED,
2769 PyObject *args)
2771 PyObject *py_retval;
2772 int c_retval;
2773 virDomainPtr domain;
2774 PyObject *pyobj_domain;
2775 virDomainBlockInfo info;
2776 const char *path;
2777 unsigned int flags;
2779 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockInfo",
2780 &pyobj_domain, &path, &flags))
2781 return NULL;
2782 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2784 LIBVIRT_BEGIN_ALLOW_THREADS;
2785 c_retval = virDomainGetBlockInfo(domain, path, &info, flags);
2786 LIBVIRT_END_ALLOW_THREADS;
2788 if (c_retval < 0)
2789 return VIR_PY_NONE;
2791 if ((py_retval = PyList_New(3)) == NULL)
2792 return NULL;
2794 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2795 libvirt_ulonglongWrap(info.capacity), error);
2796 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2797 libvirt_ulonglongWrap(info.allocation), error);
2798 VIR_PY_LIST_SET_GOTO(py_retval, 2,
2799 libvirt_ulonglongWrap(info.physical), error);
2801 return py_retval;
2803 error:
2804 Py_XDECREF(py_retval);
2805 return NULL;
2808 static PyObject *
2809 libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED,
2810 PyObject *args)
2812 PyObject *py_retval;
2813 int c_retval;
2814 virConnectPtr conn;
2815 PyObject *pyobj_conn;
2816 virNodeInfo info;
2818 if (!PyArg_ParseTuple(args, (char *)"O:virNodeGetInfo", &pyobj_conn))
2819 return NULL;
2820 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2822 LIBVIRT_BEGIN_ALLOW_THREADS;
2823 c_retval = virNodeGetInfo(conn, &info);
2824 LIBVIRT_END_ALLOW_THREADS;
2826 if (c_retval < 0)
2827 return VIR_PY_NONE;
2829 if ((py_retval = PyList_New(8)) == NULL)
2830 return NULL;
2832 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2833 libvirt_constcharPtrWrap(&info.model[0]), error);
2834 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2835 libvirt_longWrap((long) info.memory >> 10), error);
2836 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_intWrap((int) info.cpus), error);
2837 VIR_PY_LIST_SET_GOTO(py_retval, 3, libvirt_intWrap((int) info.mhz), error);
2838 VIR_PY_LIST_SET_GOTO(py_retval, 4, libvirt_intWrap((int) info.nodes), error);
2839 VIR_PY_LIST_SET_GOTO(py_retval, 5, libvirt_intWrap((int) info.sockets), error);
2840 VIR_PY_LIST_SET_GOTO(py_retval, 6, libvirt_intWrap((int) info.cores), error);
2841 VIR_PY_LIST_SET_GOTO(py_retval, 7, libvirt_intWrap((int) info.threads), error);
2843 return py_retval;
2845 error:
2846 Py_XDECREF(py_retval);
2847 return NULL;
2850 static PyObject *
2851 libvirt_virNodeGetSecurityModel(PyObject *self ATTRIBUTE_UNUSED,
2852 PyObject *args)
2854 PyObject *py_retval;
2855 int c_retval;
2856 virConnectPtr conn;
2857 PyObject *pyobj_conn;
2858 virSecurityModel model;
2860 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityModel",
2861 &pyobj_conn))
2862 return NULL;
2863 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2865 LIBVIRT_BEGIN_ALLOW_THREADS;
2866 c_retval = virNodeGetSecurityModel(conn, &model);
2867 LIBVIRT_END_ALLOW_THREADS;
2869 if (c_retval < 0)
2870 return VIR_PY_NONE;
2872 if ((py_retval = PyList_New(2)) == NULL)
2873 return NULL;
2875 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2876 libvirt_constcharPtrWrap(&model.model[0]), error);
2877 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2878 libvirt_constcharPtrWrap(&model.doi[0]), error);
2880 return py_retval;
2882 error:
2883 Py_XDECREF(py_retval);
2884 return NULL;
2887 static PyObject *
2888 libvirt_virDomainGetSecurityLabel(PyObject *self ATTRIBUTE_UNUSED,
2889 PyObject *args)
2891 PyObject *py_retval;
2892 int c_retval;
2893 virDomainPtr dom;
2894 PyObject *pyobj_dom;
2895 virSecurityLabel label;
2897 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabel",
2898 &pyobj_dom))
2899 return NULL;
2900 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2902 LIBVIRT_BEGIN_ALLOW_THREADS;
2903 c_retval = virDomainGetSecurityLabel(dom, &label);
2904 LIBVIRT_END_ALLOW_THREADS;
2906 if (c_retval < 0)
2907 return VIR_PY_NONE;
2909 if ((py_retval = PyList_New(2)) == NULL)
2910 return NULL;
2912 VIR_PY_LIST_SET_GOTO(py_retval, 0,
2913 libvirt_constcharPtrWrap(&label.label[0]), error);
2914 VIR_PY_LIST_SET_GOTO(py_retval, 1,
2915 libvirt_boolWrap(label.enforcing), error);
2917 return py_retval;
2919 error:
2920 Py_XDECREF(py_retval);
2921 return NULL;
2924 #if LIBVIR_CHECK_VERSION(0, 10, 0)
2925 static PyObject *
2926 libvirt_virDomainGetSecurityLabelList(PyObject *self ATTRIBUTE_UNUSED,
2927 PyObject *args)
2929 PyObject *py_retval;
2930 int c_retval;
2931 virDomainPtr dom;
2932 PyObject *pyobj_dom;
2933 virSecurityLabel *labels = NULL;
2934 ssize_t i;
2936 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabelList",
2937 &pyobj_dom))
2938 return NULL;
2940 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2942 LIBVIRT_BEGIN_ALLOW_THREADS;
2943 c_retval = virDomainGetSecurityLabelList(dom, &labels);
2944 LIBVIRT_END_ALLOW_THREADS;
2946 if (c_retval < 0)
2947 return VIR_PY_NONE;
2949 if (!(py_retval = PyList_New(0)))
2950 goto error;
2952 for (i = 0 ; i < c_retval ; i++) {
2953 PyObject *entry;
2955 if (!(entry = PyList_New(2)))
2956 goto error;
2958 VIR_PY_LIST_APPEND_GOTO(py_retval, entry, error);
2960 VIR_PY_LIST_SET_GOTO(entry, 0,
2961 libvirt_constcharPtrWrap(&labels[i].label[0]),
2962 error);
2963 VIR_PY_LIST_SET_GOTO(entry, 1,
2964 libvirt_boolWrap(labels[i].enforcing), error);
2967 cleanup:
2968 VIR_FREE(labels);
2969 return py_retval;
2971 error:
2972 Py_CLEAR(py_retval);
2973 goto cleanup;
2975 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
2977 static PyObject *
2978 libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED,
2979 PyObject *args)
2981 unsigned char uuid[VIR_UUID_BUFLEN];
2982 virDomainPtr domain;
2983 PyObject *pyobj_domain;
2984 int c_retval;
2986 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
2987 return NULL;
2988 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2990 if (domain == NULL)
2991 return VIR_PY_NONE;
2993 LIBVIRT_BEGIN_ALLOW_THREADS;
2994 c_retval = virDomainGetUUID(domain, &uuid[0]);
2995 LIBVIRT_END_ALLOW_THREADS;
2997 if (c_retval < 0)
2998 return VIR_PY_NONE;
3000 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3003 static PyObject *
3004 libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3005 PyObject *args)
3007 char uuidstr[VIR_UUID_STRING_BUFLEN];
3008 virDomainPtr dom;
3009 PyObject *pyobj_dom;
3010 int c_retval;
3012 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString",
3013 &pyobj_dom))
3014 return NULL;
3015 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
3017 if (dom == NULL)
3018 return VIR_PY_NONE;
3020 LIBVIRT_BEGIN_ALLOW_THREADS;
3021 c_retval = virDomainGetUUIDString(dom, &uuidstr[0]);
3022 LIBVIRT_END_ALLOW_THREADS;
3024 if (c_retval < 0)
3025 return VIR_PY_NONE;
3027 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3030 static PyObject *
3031 libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3032 PyObject *args)
3034 virDomainPtr c_retval;
3035 virConnectPtr conn;
3036 PyObject *pyobj_conn;
3037 unsigned char * uuid;
3038 int len;
3040 if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID",
3041 &pyobj_conn, &uuid, &len))
3042 return NULL;
3043 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3045 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3046 return VIR_PY_NONE;
3048 LIBVIRT_BEGIN_ALLOW_THREADS;
3049 c_retval = virDomainLookupByUUID(conn, uuid);
3050 LIBVIRT_END_ALLOW_THREADS;
3052 return libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
3056 static PyObject *
3057 libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
3058 PyObject *args)
3060 PyObject *py_retval;
3061 char **names = NULL;
3062 int c_retval;
3063 ssize_t i;
3064 virConnectPtr conn;
3065 PyObject *pyobj_conn;
3068 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks",
3069 &pyobj_conn))
3070 return NULL;
3071 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3073 LIBVIRT_BEGIN_ALLOW_THREADS;
3074 c_retval = virConnectNumOfNetworks(conn);
3075 LIBVIRT_END_ALLOW_THREADS;
3077 if (c_retval < 0)
3078 return VIR_PY_NONE;
3080 if (c_retval) {
3081 if (VIR_ALLOC_N(names, c_retval) < 0)
3082 return PyErr_NoMemory();
3084 LIBVIRT_BEGIN_ALLOW_THREADS;
3085 c_retval = virConnectListNetworks(conn, names, c_retval);
3086 LIBVIRT_END_ALLOW_THREADS;
3088 if (c_retval < 0) {
3089 py_retval = VIR_PY_NONE;
3090 goto cleanup;
3094 if ((py_retval = PyList_New(c_retval)) == NULL)
3095 goto cleanup;
3097 if (names)
3098 for (i = 0; i < c_retval; i++)
3099 VIR_PY_LIST_SET_GOTO(py_retval, i,
3100 libvirt_constcharPtrWrap(names[i]), error);
3102 cleanup:
3103 if (c_retval > 0)
3104 for (i = 0; i < c_retval; i++)
3105 VIR_FREE(names[i]);
3106 VIR_FREE(names);
3107 return py_retval;
3109 error:
3110 Py_CLEAR(py_retval);
3111 goto cleanup;
3115 static PyObject *
3116 libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
3117 PyObject *args)
3119 PyObject *py_retval;
3120 char **names = NULL;
3121 int c_retval;
3122 ssize_t i;
3123 virConnectPtr conn;
3124 PyObject *pyobj_conn;
3127 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks",
3128 &pyobj_conn))
3129 return NULL;
3130 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3132 LIBVIRT_BEGIN_ALLOW_THREADS;
3133 c_retval = virConnectNumOfDefinedNetworks(conn);
3134 LIBVIRT_END_ALLOW_THREADS;
3136 if (c_retval < 0)
3137 return VIR_PY_NONE;
3139 if (c_retval) {
3140 if (VIR_ALLOC_N(names, c_retval) < 0)
3141 return PyErr_NoMemory();
3143 LIBVIRT_BEGIN_ALLOW_THREADS;
3144 c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
3145 LIBVIRT_END_ALLOW_THREADS;
3147 if (c_retval < 0) {
3148 py_retval = VIR_PY_NONE;
3149 goto cleanup;
3153 if ((py_retval = PyList_New(c_retval)) == NULL)
3154 goto cleanup;
3156 for (i = 0; i < c_retval; i++)
3157 VIR_PY_LIST_SET_GOTO(py_retval, i,
3158 libvirt_constcharPtrWrap(names[i]), error);
3160 cleanup:
3161 if (c_retval > 0)
3162 for (i = 0; i < c_retval; i++)
3163 VIR_FREE(names[i]);
3164 VIR_FREE(names);
3165 return py_retval;
3167 error:
3168 Py_CLEAR(py_retval);
3169 goto cleanup;
3172 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3173 static PyObject *
3174 libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
3175 PyObject *args)
3177 PyObject *pyobj_conn;
3178 PyObject *py_retval = NULL;
3179 virConnectPtr conn;
3180 virNetworkPtr *nets = NULL;
3181 int c_retval = 0;
3182 ssize_t i;
3183 unsigned int flags;
3185 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNetworks",
3186 &pyobj_conn, &flags))
3187 return NULL;
3188 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3190 LIBVIRT_BEGIN_ALLOW_THREADS;
3191 c_retval = virConnectListAllNetworks(conn, &nets, flags);
3192 LIBVIRT_END_ALLOW_THREADS;
3194 if (c_retval < 0)
3195 return VIR_PY_NONE;
3197 if (!(py_retval = PyList_New(c_retval)))
3198 goto cleanup;
3200 for (i = 0; i < c_retval; i++) {
3201 VIR_PY_LIST_SET_GOTO(py_retval, i,
3202 libvirt_virNetworkPtrWrap(nets[i]), error);
3203 nets[i] = NULL;
3206 cleanup:
3207 for (i = 0; i < c_retval; i++)
3208 if (nets[i])
3209 virNetworkFree(nets[i]);
3210 VIR_FREE(nets);
3211 return py_retval;
3213 error:
3214 Py_CLEAR(py_retval);
3215 goto cleanup;
3217 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3220 static PyObject *
3221 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED,
3222 PyObject *args)
3224 unsigned char uuid[VIR_UUID_BUFLEN];
3225 virNetworkPtr domain;
3226 PyObject *pyobj_domain;
3227 int c_retval;
3229 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain))
3230 return NULL;
3231 domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
3233 if (domain == NULL)
3234 return VIR_PY_NONE;
3236 LIBVIRT_BEGIN_ALLOW_THREADS;
3237 c_retval = virNetworkGetUUID(domain, &uuid[0]);
3238 LIBVIRT_END_ALLOW_THREADS;
3240 if (c_retval < 0)
3241 return VIR_PY_NONE;
3243 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3246 static PyObject *
3247 libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3248 PyObject *args)
3250 char uuidstr[VIR_UUID_STRING_BUFLEN];
3251 virNetworkPtr net;
3252 PyObject *pyobj_net;
3253 int c_retval;
3255 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString",
3256 &pyobj_net))
3257 return NULL;
3258 net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net);
3260 if (net == NULL)
3261 return VIR_PY_NONE;
3263 LIBVIRT_BEGIN_ALLOW_THREADS;
3264 c_retval = virNetworkGetUUIDString(net, &uuidstr[0]);
3265 LIBVIRT_END_ALLOW_THREADS;
3267 if (c_retval < 0)
3268 return VIR_PY_NONE;
3270 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3273 static PyObject *
3274 libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3275 PyObject *args)
3277 virNetworkPtr c_retval;
3278 virConnectPtr conn;
3279 PyObject *pyobj_conn;
3280 unsigned char * uuid;
3281 int len;
3283 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID",
3284 &pyobj_conn, &uuid, &len))
3285 return NULL;
3286 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3288 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3289 return VIR_PY_NONE;
3291 LIBVIRT_BEGIN_ALLOW_THREADS;
3292 c_retval = virNetworkLookupByUUID(conn, uuid);
3293 LIBVIRT_END_ALLOW_THREADS;
3295 return libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval);
3299 static PyObject *
3300 libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3301 PyObject *args)
3303 int c_retval, autostart;
3304 virDomainPtr domain;
3305 PyObject *pyobj_domain;
3307 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetAutostart",
3308 &pyobj_domain))
3309 return NULL;
3311 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
3313 LIBVIRT_BEGIN_ALLOW_THREADS;
3314 c_retval = virDomainGetAutostart(domain, &autostart);
3315 LIBVIRT_END_ALLOW_THREADS;
3317 if (c_retval < 0)
3318 return VIR_PY_INT_FAIL;
3320 return libvirt_intWrap(autostart);
3324 static PyObject *
3325 libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3326 PyObject *args)
3328 int c_retval, autostart;
3329 virNetworkPtr network;
3330 PyObject *pyobj_network;
3332 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetAutostart",
3333 &pyobj_network))
3334 return NULL;
3336 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
3338 LIBVIRT_BEGIN_ALLOW_THREADS;
3339 c_retval = virNetworkGetAutostart(network, &autostart);
3340 LIBVIRT_END_ALLOW_THREADS;
3342 if (c_retval < 0)
3343 return VIR_PY_INT_FAIL;
3345 return libvirt_intWrap(autostart);
3348 static PyObject *
3349 libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
3350 PyObject *args)
3352 PyObject *py_retval;
3353 PyObject *pyobj_conn;
3354 int startCell, maxCells, c_retval;
3355 ssize_t i;
3356 virConnectPtr conn;
3357 unsigned long long *freeMems;
3359 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory",
3360 &pyobj_conn, &startCell, &maxCells))
3361 return NULL;
3363 if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
3364 return VIR_PY_NONE;
3366 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3367 if (VIR_ALLOC_N(freeMems, maxCells) < 0)
3368 return PyErr_NoMemory();
3370 LIBVIRT_BEGIN_ALLOW_THREADS;
3371 c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
3372 LIBVIRT_END_ALLOW_THREADS;
3374 if (c_retval < 0) {
3375 py_retval = VIR_PY_NONE;
3376 goto cleanup;
3379 if ((py_retval = PyList_New(c_retval)) == NULL)
3380 goto cleanup;
3382 for (i = 0; i < c_retval; i++)
3383 VIR_PY_LIST_SET_GOTO(py_retval, i,
3384 libvirt_ulonglongWrap(freeMems[i]), error);
3386 cleanup:
3387 VIR_FREE(freeMems);
3388 return py_retval;
3390 error:
3391 Py_CLEAR(py_retval);
3392 goto cleanup;
3395 static PyObject *
3396 libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED,
3397 PyObject *args)
3399 PyObject *ret = NULL;
3400 PyObject *key = NULL;
3401 PyObject *val = NULL;
3402 PyObject *pyobj_conn;
3403 virConnectPtr conn;
3404 unsigned int flags;
3405 int cpuNum, c_retval;
3406 ssize_t i;
3407 int nparams = 0;
3408 virNodeCPUStatsPtr stats = NULL;
3410 if (!PyArg_ParseTuple(args, (char *)"OiI:virNodeGetCPUStats",
3411 &pyobj_conn, &cpuNum, &flags))
3412 return ret;
3413 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3415 LIBVIRT_BEGIN_ALLOW_THREADS;
3416 c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
3417 LIBVIRT_END_ALLOW_THREADS;
3419 if (c_retval < 0)
3420 return VIR_PY_NONE;
3422 if (nparams) {
3423 if (VIR_ALLOC_N(stats, nparams) < 0)
3424 return PyErr_NoMemory();
3426 LIBVIRT_BEGIN_ALLOW_THREADS;
3427 c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
3428 LIBVIRT_END_ALLOW_THREADS;
3430 if (c_retval < 0) {
3431 VIR_FREE(stats);
3432 return VIR_PY_NONE;
3436 if (!(ret = PyDict_New()))
3437 goto error;
3439 for (i = 0; i < nparams; i++) {
3440 key = libvirt_constcharPtrWrap(stats[i].field);
3441 val = libvirt_ulonglongWrap(stats[i].value);
3443 VIR_PY_DICT_SET_GOTO(ret, key, val, error);
3446 cleanup:
3447 VIR_FREE(stats);
3448 return ret;
3450 error:
3451 Py_CLEAR(ret);
3452 goto cleanup;
3455 static PyObject *
3456 libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED,
3457 PyObject *args)
3459 PyObject *ret = NULL;
3460 PyObject *key = NULL;
3461 PyObject *val = NULL;
3462 PyObject *pyobj_conn;
3463 virConnectPtr conn;
3464 unsigned int flags;
3465 int cellNum, c_retval;
3466 ssize_t i;
3467 int nparams = 0;
3468 virNodeMemoryStatsPtr stats = NULL;
3470 if (!PyArg_ParseTuple(args, (char *)"OiI:virNodeGetMemoryStats",
3471 &pyobj_conn, &cellNum, &flags))
3472 return NULL;
3473 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3475 LIBVIRT_BEGIN_ALLOW_THREADS;
3476 c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
3477 LIBVIRT_END_ALLOW_THREADS;
3479 if (c_retval < 0)
3480 return VIR_PY_NONE;
3482 if (nparams) {
3483 if (VIR_ALLOC_N(stats, nparams) < 0)
3484 return PyErr_NoMemory();
3486 LIBVIRT_BEGIN_ALLOW_THREADS;
3487 c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
3488 LIBVIRT_END_ALLOW_THREADS;
3490 if (c_retval < 0) {
3491 VIR_FREE(stats);
3492 return VIR_PY_NONE;
3496 if (!(ret = PyDict_New()))
3497 goto error;
3499 for (i = 0; i < nparams; i++) {
3500 key = libvirt_constcharPtrWrap(stats[i].field);
3501 val = libvirt_ulonglongWrap(stats[i].value);
3503 VIR_PY_DICT_SET_GOTO(ret, key, val, error);
3506 cleanup:
3507 VIR_FREE(stats);
3508 return ret;
3510 error:
3511 Py_CLEAR(ret);
3512 goto cleanup;
3515 static PyObject *
3516 libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3517 PyObject *args)
3519 PyObject *py_retval;
3520 char **names = NULL;
3521 int c_retval;
3522 ssize_t i;
3523 virConnectPtr conn;
3524 PyObject *pyobj_conn;
3526 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListStoragePools",
3527 &pyobj_conn))
3528 return NULL;
3529 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3531 LIBVIRT_BEGIN_ALLOW_THREADS;
3532 c_retval = virConnectNumOfStoragePools(conn);
3533 LIBVIRT_END_ALLOW_THREADS;
3535 if (c_retval < 0)
3536 return VIR_PY_NONE;
3538 if (c_retval) {
3539 if (VIR_ALLOC_N(names, c_retval) < 0)
3540 return PyErr_NoMemory();
3542 LIBVIRT_BEGIN_ALLOW_THREADS;
3543 c_retval = virConnectListStoragePools(conn, names, c_retval);
3544 LIBVIRT_END_ALLOW_THREADS;
3546 if (c_retval < 0) {
3547 py_retval = VIR_PY_NONE;
3548 goto cleanup;
3552 if ((py_retval = PyList_New(c_retval)) == NULL)
3553 goto cleanup;
3555 for (i = 0; i < c_retval; i++)
3556 VIR_PY_LIST_SET_GOTO(py_retval, i,
3557 libvirt_constcharPtrWrap(names[i]), error);
3559 cleanup:
3560 if (c_retval > 0)
3561 for (i = 0; i < c_retval; i++)
3562 VIR_FREE(names[i]);
3563 VIR_FREE(names);
3564 return py_retval;
3566 error:
3567 Py_CLEAR(py_retval);
3568 goto cleanup;
3572 static PyObject *
3573 libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3574 PyObject *args)
3576 PyObject *py_retval;
3577 char **names = NULL;
3578 int c_retval;
3579 ssize_t i;
3580 virConnectPtr conn;
3581 PyObject *pyobj_conn;
3583 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedStoragePools",
3584 &pyobj_conn))
3585 return NULL;
3586 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3588 LIBVIRT_BEGIN_ALLOW_THREADS;
3589 c_retval = virConnectNumOfDefinedStoragePools(conn);
3590 LIBVIRT_END_ALLOW_THREADS;
3592 if (c_retval < 0)
3593 return VIR_PY_NONE;
3595 if (c_retval) {
3596 if (VIR_ALLOC_N(names, c_retval) < 0)
3597 return PyErr_NoMemory();
3599 LIBVIRT_BEGIN_ALLOW_THREADS;
3600 c_retval = virConnectListDefinedStoragePools(conn, names, c_retval);
3601 LIBVIRT_END_ALLOW_THREADS;
3603 if (c_retval < 0) {
3604 py_retval = VIR_PY_NONE;
3605 goto cleanup;
3609 if ((py_retval = PyList_New(c_retval)) == NULL)
3610 goto cleanup;
3612 if (names) {
3613 for (i = 0; i < c_retval; i++)
3614 VIR_PY_LIST_SET_GOTO(py_retval, i,
3615 libvirt_constcharPtrWrap(names[i]), error);
3618 cleanup:
3619 if (c_retval > 0)
3620 for (i = 0; i < c_retval; i++)
3621 VIR_FREE(names[i]);
3622 VIR_FREE(names);
3623 return py_retval;
3625 error:
3626 Py_CLEAR(py_retval);
3627 goto cleanup;
3630 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3631 static PyObject *
3632 libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3633 PyObject *args)
3635 PyObject *pyobj_conn;
3636 PyObject *py_retval = NULL;
3637 virConnectPtr conn;
3638 virStoragePoolPtr *pools = NULL;
3639 int c_retval = 0;
3640 ssize_t i;
3641 unsigned int flags;
3643 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllStoragePools",
3644 &pyobj_conn, &flags))
3645 return NULL;
3646 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3648 LIBVIRT_BEGIN_ALLOW_THREADS;
3649 c_retval = virConnectListAllStoragePools(conn, &pools, flags);
3650 LIBVIRT_END_ALLOW_THREADS;
3652 if (c_retval < 0)
3653 return VIR_PY_NONE;
3655 if (!(py_retval = PyList_New(c_retval)))
3656 goto cleanup;
3658 for (i = 0; i < c_retval; i++) {
3659 VIR_PY_LIST_SET_GOTO(py_retval, i,
3660 libvirt_virStoragePoolPtrWrap(pools[i]), error);
3661 /* python steals the pointer */
3662 pools[i] = NULL;
3665 cleanup:
3666 for (i = 0; i < c_retval; i++)
3667 if (pools[i])
3668 virStoragePoolFree(pools[i]);
3669 VIR_FREE(pools);
3670 return py_retval;
3672 error:
3673 Py_CLEAR(py_retval);
3674 goto cleanup;
3676 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3678 static PyObject *
3679 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
3680 PyObject *args)
3682 PyObject *py_retval;
3683 char **names = NULL;
3684 int c_retval;
3685 ssize_t i;
3686 virStoragePoolPtr pool;
3687 PyObject *pyobj_pool;
3689 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolListVolumes",
3690 &pyobj_pool))
3691 return NULL;
3692 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3694 LIBVIRT_BEGIN_ALLOW_THREADS;
3695 c_retval = virStoragePoolNumOfVolumes(pool);
3696 LIBVIRT_END_ALLOW_THREADS;
3698 if (c_retval < 0)
3699 return VIR_PY_NONE;
3701 if (c_retval) {
3702 if (VIR_ALLOC_N(names, c_retval) < 0)
3703 return PyErr_NoMemory();
3705 LIBVIRT_BEGIN_ALLOW_THREADS;
3706 c_retval = virStoragePoolListVolumes(pool, names, c_retval);
3707 LIBVIRT_END_ALLOW_THREADS;
3709 if (c_retval < 0) {
3710 py_retval = VIR_PY_NONE;
3711 goto cleanup;
3715 if ((py_retval = PyList_New(c_retval)) == NULL)
3716 goto cleanup;
3718 if (names)
3719 for (i = 0; i < c_retval; i++)
3720 VIR_PY_LIST_SET_GOTO(py_retval, i,
3721 libvirt_constcharPtrWrap(names[i]), error);
3723 cleanup:
3724 if (c_retval > 0)
3725 for (i = 0; i < c_retval; i++)
3726 VIR_FREE(names[i]);
3727 VIR_FREE(names);
3728 return py_retval;
3730 error:
3731 Py_CLEAR(py_retval);
3732 goto cleanup;
3735 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3736 static PyObject *
3737 libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
3738 PyObject *args)
3740 PyObject *py_retval = NULL;
3741 virStoragePoolPtr pool;
3742 virStorageVolPtr *vols = NULL;
3743 int c_retval = 0;
3744 ssize_t i;
3745 unsigned int flags;
3746 PyObject *pyobj_pool;
3748 if (!PyArg_ParseTuple(args, (char *)"OI:virStoragePoolListAllVolumes",
3749 &pyobj_pool, &flags))
3750 return NULL;
3752 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3754 LIBVIRT_BEGIN_ALLOW_THREADS;
3755 c_retval = virStoragePoolListAllVolumes(pool, &vols, flags);
3756 LIBVIRT_END_ALLOW_THREADS;
3758 if (c_retval < 0)
3759 return VIR_PY_NONE;
3761 if (!(py_retval = PyList_New(c_retval)))
3762 goto cleanup;
3764 for (i = 0; i < c_retval; i++) {
3765 VIR_PY_LIST_SET_GOTO(py_retval, i,
3766 libvirt_virStorageVolPtrWrap(vols[i]), error);
3767 /* python steals the pointer */
3768 vols[i] = NULL;
3771 cleanup:
3772 for (i = 0; i < c_retval; i++)
3773 if (vols[i])
3774 virStorageVolFree(vols[i]);
3775 VIR_FREE(vols);
3776 return py_retval;
3778 error:
3779 Py_CLEAR(py_retval);
3780 goto cleanup;
3782 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3785 static PyObject *
3786 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED,
3787 PyObject *args)
3789 int c_retval, autostart;
3790 virStoragePoolPtr pool;
3791 PyObject *pyobj_pool;
3793 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetAutostart",
3794 &pyobj_pool))
3795 return NULL;
3797 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3799 LIBVIRT_BEGIN_ALLOW_THREADS;
3800 c_retval = virStoragePoolGetAutostart(pool, &autostart);
3801 LIBVIRT_END_ALLOW_THREADS;
3803 if (c_retval < 0)
3804 return VIR_PY_INT_FAIL;
3806 return libvirt_intWrap(autostart);
3809 static PyObject *
3810 libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED,
3811 PyObject *args)
3813 PyObject *py_retval;
3814 int c_retval;
3815 virStoragePoolPtr pool;
3816 PyObject *pyobj_pool;
3817 virStoragePoolInfo info;
3819 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetInfo", &pyobj_pool))
3820 return NULL;
3821 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3823 LIBVIRT_BEGIN_ALLOW_THREADS;
3824 c_retval = virStoragePoolGetInfo(pool, &info);
3825 LIBVIRT_END_ALLOW_THREADS;
3827 if (c_retval < 0)
3828 return VIR_PY_NONE;
3830 if ((py_retval = PyList_New(4)) == NULL)
3831 return NULL;
3833 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3834 libvirt_intWrap((int) info.state), error);
3835 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3836 libvirt_ulonglongWrap(info.capacity), error);
3837 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3838 libvirt_ulonglongWrap(info.allocation), error);
3839 VIR_PY_LIST_SET_GOTO(py_retval, 3,
3840 libvirt_ulonglongWrap(info.available), error);
3842 return py_retval;
3844 error:
3845 Py_XDECREF(py_retval);
3846 return NULL;
3850 static PyObject *
3851 libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED,
3852 PyObject *args)
3854 PyObject *py_retval;
3855 int c_retval;
3856 virStorageVolPtr pool;
3857 PyObject *pyobj_pool;
3858 virStorageVolInfo info;
3860 if (!PyArg_ParseTuple(args, (char *)"O:virStorageVolGetInfo", &pyobj_pool))
3861 return NULL;
3862 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3864 LIBVIRT_BEGIN_ALLOW_THREADS;
3865 c_retval = virStorageVolGetInfo(pool, &info);
3866 LIBVIRT_END_ALLOW_THREADS;
3868 if (c_retval < 0)
3869 return VIR_PY_NONE;
3871 if ((py_retval = PyList_New(3)) == NULL)
3872 return NULL;
3874 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3875 libvirt_intWrap((int) info.type), error);
3876 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3877 libvirt_ulonglongWrap(info.capacity), error);
3878 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3879 libvirt_ulonglongWrap(info.allocation), error);
3881 return py_retval;
3883 error:
3884 Py_DECREF(py_retval);
3885 return NULL;
3888 #if LIBVIR_CHECK_VERSION(3, 0, 0)
3889 static PyObject *
3890 libvirt_virStorageVolGetInfoFlags(PyObject *self ATTRIBUTE_UNUSED,
3891 PyObject *args)
3893 PyObject *py_retval;
3894 int c_retval;
3895 virStorageVolPtr pool;
3896 PyObject *pyobj_pool;
3897 virStorageVolInfo info;
3898 unsigned int flags;
3900 if (!PyArg_ParseTuple(args, (char *)"OI:virStorageVolGetInfoFlags", &pyobj_pool, &flags))
3901 return NULL;
3902 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3904 LIBVIRT_BEGIN_ALLOW_THREADS;
3905 c_retval = virStorageVolGetInfoFlags(pool, &info, flags);
3906 LIBVIRT_END_ALLOW_THREADS;
3908 if (c_retval < 0)
3909 return VIR_PY_NONE;
3911 if ((py_retval = PyList_New(3)) == NULL)
3912 return NULL;
3914 VIR_PY_LIST_SET_GOTO(py_retval, 0,
3915 libvirt_intWrap((int) info.type), error);
3916 VIR_PY_LIST_SET_GOTO(py_retval, 1,
3917 libvirt_ulonglongWrap(info.capacity), error);
3918 VIR_PY_LIST_SET_GOTO(py_retval, 2,
3919 libvirt_ulonglongWrap(info.allocation), error);
3921 return py_retval;
3923 error:
3924 Py_DECREF(py_retval);
3925 return NULL;
3927 #endif
3929 static PyObject *
3930 libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED,
3931 PyObject *args)
3933 unsigned char uuid[VIR_UUID_BUFLEN];
3934 virStoragePoolPtr pool;
3935 PyObject *pyobj_pool;
3936 int c_retval;
3938 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUID", &pyobj_pool))
3939 return NULL;
3940 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3942 if (pool == NULL)
3943 return VIR_PY_NONE;
3945 LIBVIRT_BEGIN_ALLOW_THREADS;
3946 c_retval = virStoragePoolGetUUID(pool, &uuid[0]);
3947 LIBVIRT_END_ALLOW_THREADS;
3949 if (c_retval < 0)
3950 return VIR_PY_NONE;
3952 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3955 static PyObject *
3956 libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3957 PyObject *args)
3959 char uuidstr[VIR_UUID_STRING_BUFLEN];
3960 virStoragePoolPtr pool;
3961 PyObject *pyobj_pool;
3962 int c_retval;
3964 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString",
3965 &pyobj_pool))
3966 return NULL;
3967 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3969 if (pool == NULL)
3970 return VIR_PY_NONE;
3972 LIBVIRT_BEGIN_ALLOW_THREADS;
3973 c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]);
3974 LIBVIRT_END_ALLOW_THREADS;
3976 if (c_retval < 0)
3977 return VIR_PY_NONE;
3979 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3982 static PyObject *
3983 libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
3984 PyObject *args)
3986 virStoragePoolPtr c_retval;
3987 virConnectPtr conn;
3988 PyObject *pyobj_conn;
3989 unsigned char * uuid;
3990 int len;
3992 if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID",
3993 &pyobj_conn, &uuid, &len))
3994 return NULL;
3995 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3997 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3998 return VIR_PY_NONE;
4000 LIBVIRT_BEGIN_ALLOW_THREADS;
4001 c_retval = virStoragePoolLookupByUUID(conn, uuid);
4002 LIBVIRT_END_ALLOW_THREADS;
4004 return libvirt_virStoragePoolPtrWrap((virStoragePoolPtr) c_retval);
4007 static PyObject *
4008 libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
4009 PyObject *args)
4011 PyObject *py_retval;
4012 char **names = NULL;
4013 int c_retval;
4014 ssize_t i;
4015 virConnectPtr conn;
4016 PyObject *pyobj_conn;
4017 char *cap;
4018 unsigned int flags;
4020 if (!PyArg_ParseTuple(args, (char *)"OzI:virNodeListDevices",
4021 &pyobj_conn, &cap, &flags))
4022 return NULL;
4023 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4025 LIBVIRT_BEGIN_ALLOW_THREADS;
4026 c_retval = virNodeNumOfDevices(conn, cap, flags);
4027 LIBVIRT_END_ALLOW_THREADS;
4029 if (c_retval < 0)
4030 return VIR_PY_NONE;
4032 if (c_retval) {
4033 if (VIR_ALLOC_N(names, c_retval) < 0)
4034 return PyErr_NoMemory();
4036 LIBVIRT_BEGIN_ALLOW_THREADS;
4037 c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
4038 LIBVIRT_END_ALLOW_THREADS;
4040 if (c_retval < 0) {
4041 py_retval = VIR_PY_NONE;
4042 goto cleanup;
4046 if ((py_retval = PyList_New(c_retval)) == NULL)
4047 goto cleanup;
4049 if (names)
4050 for (i = 0; i < c_retval; i++)
4051 VIR_PY_LIST_SET_GOTO(py_retval, i,
4052 libvirt_constcharPtrWrap(names[i]), error);
4054 cleanup:
4055 if (c_retval > 0)
4056 for (i = 0; i < c_retval; i++)
4057 VIR_FREE(names[i]);
4058 VIR_FREE(names);
4059 return py_retval;
4061 error:
4062 Py_CLEAR(py_retval);
4063 goto cleanup;
4066 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4067 static PyObject *
4068 libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
4069 PyObject *args)
4071 PyObject *pyobj_conn;
4072 PyObject *py_retval = NULL;
4073 virConnectPtr conn;
4074 virNodeDevicePtr *devices = NULL;
4075 int c_retval = 0;
4076 ssize_t i;
4077 unsigned int flags;
4079 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNodeDevices",
4080 &pyobj_conn, &flags))
4081 return NULL;
4082 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4084 LIBVIRT_BEGIN_ALLOW_THREADS;
4085 c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
4086 LIBVIRT_END_ALLOW_THREADS;
4088 if (c_retval < 0)
4089 return VIR_PY_NONE;
4091 if (!(py_retval = PyList_New(c_retval)))
4092 goto cleanup;
4094 for (i = 0; i < c_retval; i++) {
4095 VIR_PY_LIST_SET_GOTO(py_retval, i,
4096 libvirt_virNodeDevicePtrWrap(devices[i]), error);
4097 /* python steals the pointer */
4098 devices[i] = NULL;
4101 cleanup:
4102 for (i = 0; i < c_retval; i++)
4103 if (devices[i])
4104 virNodeDeviceFree(devices[i]);
4105 VIR_FREE(devices);
4106 return py_retval;
4108 error:
4109 Py_CLEAR(py_retval);
4110 goto cleanup;
4112 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4114 static PyObject *
4115 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
4116 PyObject *args)
4118 PyObject *py_retval;
4119 char **names = NULL;
4120 int c_retval;
4121 ssize_t i;
4122 virNodeDevicePtr dev;
4123 PyObject *pyobj_dev;
4125 if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
4126 return NULL;
4127 dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
4129 LIBVIRT_BEGIN_ALLOW_THREADS;
4130 c_retval = virNodeDeviceNumOfCaps(dev);
4131 LIBVIRT_END_ALLOW_THREADS;
4133 if (c_retval < 0)
4134 return VIR_PY_NONE;
4136 if (c_retval) {
4137 if (VIR_ALLOC_N(names, c_retval) < 0)
4138 return PyErr_NoMemory();
4140 LIBVIRT_BEGIN_ALLOW_THREADS;
4141 c_retval = virNodeDeviceListCaps(dev, names, c_retval);
4142 LIBVIRT_END_ALLOW_THREADS;
4144 if (c_retval < 0) {
4145 py_retval = VIR_PY_NONE;
4146 goto cleanup;
4150 if ((py_retval = PyList_New(c_retval)) == NULL)
4151 goto cleanup;
4153 if (names)
4154 for (i = 0; i < c_retval; i++)
4155 VIR_PY_LIST_SET_GOTO(py_retval, i,
4156 libvirt_constcharPtrWrap(names[i]), error);
4158 cleanup:
4159 if (c_retval > 0)
4160 for (i = 0; i < c_retval; i++)
4161 VIR_FREE(names[i]);
4162 VIR_FREE(names);
4163 return py_retval;
4165 error:
4166 Py_CLEAR(py_retval);
4167 goto cleanup;
4170 static PyObject *
4171 libvirt_virSecretGetUUID(PyObject *self ATTRIBUTE_UNUSED,
4172 PyObject *args)
4174 unsigned char uuid[VIR_UUID_BUFLEN];
4175 virSecretPtr secret;
4176 PyObject *pyobj_secret;
4177 int c_retval;
4179 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUID", &pyobj_secret))
4180 return NULL;
4181 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4183 if (secret == NULL)
4184 return VIR_PY_NONE;
4186 LIBVIRT_BEGIN_ALLOW_THREADS;
4187 c_retval = virSecretGetUUID(secret, &uuid[0]);
4188 LIBVIRT_END_ALLOW_THREADS;
4190 if (c_retval < 0)
4191 return VIR_PY_NONE;
4193 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4196 static PyObject *
4197 libvirt_virSecretGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4198 PyObject *args)
4200 char uuidstr[VIR_UUID_STRING_BUFLEN];
4201 virSecretPtr dom;
4202 PyObject *pyobj_dom;
4203 int c_retval;
4205 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUIDString",
4206 &pyobj_dom))
4207 return NULL;
4208 dom = (virSecretPtr) PyvirSecret_Get(pyobj_dom);
4210 if (dom == NULL)
4211 return VIR_PY_NONE;
4213 LIBVIRT_BEGIN_ALLOW_THREADS;
4214 c_retval = virSecretGetUUIDString(dom, &uuidstr[0]);
4215 LIBVIRT_END_ALLOW_THREADS;
4217 if (c_retval < 0)
4218 return VIR_PY_NONE;
4220 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4223 static PyObject *
4224 libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
4225 PyObject *args)
4227 virSecretPtr c_retval;
4228 virConnectPtr conn;
4229 PyObject *pyobj_conn;
4230 unsigned char * uuid;
4231 int len;
4233 if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID",
4234 &pyobj_conn, &uuid, &len))
4235 return NULL;
4236 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4238 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4239 return VIR_PY_NONE;
4241 LIBVIRT_BEGIN_ALLOW_THREADS;
4242 c_retval = virSecretLookupByUUID(conn, uuid);
4243 LIBVIRT_END_ALLOW_THREADS;
4245 return libvirt_virSecretPtrWrap((virSecretPtr) c_retval);
4249 static PyObject *
4250 libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
4251 PyObject *args)
4253 PyObject *py_retval;
4254 char **uuids = NULL;
4255 virConnectPtr conn;
4256 int c_retval;
4257 ssize_t i;
4258 PyObject *pyobj_conn;
4260 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
4261 return NULL;
4262 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4264 LIBVIRT_BEGIN_ALLOW_THREADS;
4265 c_retval = virConnectNumOfSecrets(conn);
4266 LIBVIRT_END_ALLOW_THREADS;
4268 if (c_retval < 0)
4269 return VIR_PY_NONE;
4271 if (c_retval) {
4272 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4273 return PyErr_NoMemory();
4275 LIBVIRT_BEGIN_ALLOW_THREADS;
4276 c_retval = virConnectListSecrets(conn, uuids, c_retval);
4277 LIBVIRT_END_ALLOW_THREADS;
4279 if (c_retval < 0) {
4280 py_retval = VIR_PY_NONE;
4281 goto cleanup;
4285 if ((py_retval = PyList_New(c_retval)) == NULL)
4286 goto cleanup;
4288 if (uuids) {
4289 for (i = 0; i < c_retval; i++)
4290 VIR_PY_LIST_SET_GOTO(py_retval, i,
4291 libvirt_constcharPtrWrap(uuids[i]), error);
4294 cleanup:
4295 if (c_retval > 0)
4296 for (i = 0; i < c_retval; i++)
4297 VIR_FREE(uuids[i]);
4298 VIR_FREE(uuids);
4299 return py_retval;
4301 error:
4302 Py_CLEAR(py_retval);
4303 goto cleanup;
4306 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4307 static PyObject *
4308 libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
4309 PyObject *args)
4311 PyObject *pyobj_conn;
4312 PyObject *py_retval = NULL;
4313 virConnectPtr conn;
4314 virSecretPtr *secrets = NULL;
4315 int c_retval = 0;
4316 ssize_t i;
4317 unsigned int flags;
4319 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllSecrets",
4320 &pyobj_conn, &flags))
4321 return NULL;
4322 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4324 LIBVIRT_BEGIN_ALLOW_THREADS;
4325 c_retval = virConnectListAllSecrets(conn, &secrets, flags);
4326 LIBVIRT_END_ALLOW_THREADS;
4328 if (c_retval < 0)
4329 return VIR_PY_NONE;
4331 if (!(py_retval = PyList_New(c_retval)))
4332 goto cleanup;
4334 for (i = 0; i < c_retval; i++) {
4335 VIR_PY_LIST_SET_GOTO(py_retval, i,
4336 libvirt_virSecretPtrWrap(secrets[i]), error);
4337 /* python steals the pointer */
4338 secrets[i] = NULL;
4341 cleanup:
4342 for (i = 0; i < c_retval; i++)
4343 if (secrets[i])
4344 virSecretFree(secrets[i]);
4345 VIR_FREE(secrets);
4346 return py_retval;
4348 error:
4349 Py_CLEAR(py_retval);
4350 goto cleanup;
4352 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4354 static PyObject *
4355 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
4356 PyObject *args)
4358 PyObject *py_retval;
4359 unsigned char *c_retval;
4360 size_t size;
4361 virSecretPtr secret;
4362 PyObject *pyobj_secret;
4363 unsigned int flags;
4365 if (!PyArg_ParseTuple(args, (char *)"OI:virSecretGetValue", &pyobj_secret,
4366 &flags))
4367 return NULL;
4368 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4370 LIBVIRT_BEGIN_ALLOW_THREADS;
4371 c_retval = virSecretGetValue(secret, &size, flags);
4372 LIBVIRT_END_ALLOW_THREADS;
4374 if (c_retval == NULL)
4375 return VIR_PY_NONE;
4377 py_retval = libvirt_charPtrSizeWrap((char*)c_retval, size);
4378 VIR_FREE(c_retval);
4380 return py_retval;
4383 static PyObject *
4384 libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
4385 PyObject *args)
4387 int c_retval;
4388 virSecretPtr secret;
4389 PyObject *pyobj_secret;
4390 const char *value;
4391 int size;
4392 unsigned int flags;
4394 if (!PyArg_ParseTuple(args, (char *)"Oz#I:virSecretSetValue", &pyobj_secret,
4395 &value, &size, &flags))
4396 return NULL;
4397 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4399 LIBVIRT_BEGIN_ALLOW_THREADS;
4400 c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
4401 flags);
4402 LIBVIRT_END_ALLOW_THREADS;
4404 return libvirt_intWrap(c_retval);
4407 static PyObject *
4408 libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED,
4409 PyObject *args)
4411 unsigned char uuid[VIR_UUID_BUFLEN];
4412 virNWFilterPtr nwfilter;
4413 PyObject *pyobj_nwfilter;
4414 int c_retval;
4416 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID",
4417 &pyobj_nwfilter))
4418 return NULL;
4419 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4421 if (nwfilter == NULL)
4422 return VIR_PY_NONE;
4424 LIBVIRT_BEGIN_ALLOW_THREADS;
4425 c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
4426 LIBVIRT_END_ALLOW_THREADS;
4428 if (c_retval < 0)
4429 return VIR_PY_NONE;
4431 return libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4434 static PyObject *
4435 libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4436 PyObject *args)
4438 char uuidstr[VIR_UUID_STRING_BUFLEN];
4439 virNWFilterPtr nwfilter;
4440 PyObject *pyobj_nwfilter;
4441 int c_retval;
4443 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
4444 &pyobj_nwfilter))
4445 return NULL;
4446 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4448 if (nwfilter == NULL)
4449 return VIR_PY_NONE;
4451 LIBVIRT_BEGIN_ALLOW_THREADS;
4452 c_retval = virNWFilterGetUUIDString(nwfilter, &uuidstr[0]);
4453 LIBVIRT_END_ALLOW_THREADS;
4455 if (c_retval < 0)
4456 return VIR_PY_NONE;
4458 return libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4461 static PyObject *
4462 libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
4463 PyObject *args)
4465 virNWFilterPtr c_retval;
4466 virConnectPtr conn;
4467 PyObject *pyobj_conn;
4468 unsigned char * uuid;
4469 int len;
4471 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID",
4472 &pyobj_conn, &uuid, &len))
4473 return NULL;
4474 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4476 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4477 return VIR_PY_NONE;
4479 LIBVIRT_BEGIN_ALLOW_THREADS;
4480 c_retval = virNWFilterLookupByUUID(conn, uuid);
4481 LIBVIRT_END_ALLOW_THREADS;
4483 return libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
4487 static PyObject *
4488 libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4489 PyObject *args)
4491 PyObject *py_retval;
4492 char **uuids = NULL;
4493 virConnectPtr conn;
4494 int c_retval;
4495 ssize_t i;
4496 PyObject *pyobj_conn;
4498 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters",
4499 &pyobj_conn))
4500 return NULL;
4501 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4503 LIBVIRT_BEGIN_ALLOW_THREADS;
4504 c_retval = virConnectNumOfNWFilters(conn);
4505 LIBVIRT_END_ALLOW_THREADS;
4507 if (c_retval < 0)
4508 return VIR_PY_NONE;
4510 if (c_retval) {
4511 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4512 return PyErr_NoMemory();
4514 LIBVIRT_BEGIN_ALLOW_THREADS;
4515 c_retval = virConnectListNWFilters(conn, uuids, c_retval);
4516 LIBVIRT_END_ALLOW_THREADS;
4518 if (c_retval < 0) {
4519 py_retval = VIR_PY_NONE;
4520 goto cleanup;
4524 if ((py_retval = PyList_New(c_retval)) == NULL)
4525 goto cleanup;
4527 if (uuids)
4528 for (i = 0; i < c_retval; i++)
4529 VIR_PY_LIST_SET_GOTO(py_retval, i,
4530 libvirt_constcharPtrWrap(uuids[i]), error);
4532 cleanup:
4533 if (c_retval > 0)
4534 for (i = 0; i < c_retval; i++)
4535 VIR_FREE(uuids[i]);
4536 VIR_FREE(uuids);
4537 return py_retval;
4539 error:
4540 Py_CLEAR(py_retval);
4541 goto cleanup;
4544 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4545 static PyObject *
4546 libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4547 PyObject *args)
4549 PyObject *pyobj_conn;
4550 PyObject *py_retval = NULL;
4551 virConnectPtr conn;
4552 virNWFilterPtr *filters = NULL;
4553 int c_retval = 0;
4554 ssize_t i;
4555 unsigned int flags;
4557 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNWFilters",
4558 &pyobj_conn, &flags))
4559 return NULL;
4560 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4562 LIBVIRT_BEGIN_ALLOW_THREADS;
4563 c_retval = virConnectListAllNWFilters(conn, &filters, flags);
4564 LIBVIRT_END_ALLOW_THREADS;
4566 if (c_retval < 0)
4567 return VIR_PY_NONE;
4569 if (!(py_retval = PyList_New(c_retval)))
4570 goto cleanup;
4572 for (i = 0; i < c_retval; i++) {
4573 VIR_PY_LIST_SET_GOTO(py_retval, i,
4574 libvirt_virNWFilterPtrWrap(filters[i]), error);
4575 /* python steals the pointer */
4576 filters[i] = NULL;
4579 cleanup:
4580 for (i = 0; i < c_retval; i++)
4581 if (filters[i])
4582 virNWFilterFree(filters[i]);
4583 VIR_FREE(filters);
4584 return py_retval;
4586 error:
4587 Py_CLEAR(py_retval);
4588 goto cleanup;
4590 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4592 #if LIBVIR_CHECK_VERSION(4, 5, 0)
4593 static PyObject *
4594 libvirt_virConnectListAllNWFilterBindings(PyObject *self ATTRIBUTE_UNUSED,
4595 PyObject *args)
4597 PyObject *pyobj_conn;
4598 PyObject *py_retval = NULL;
4599 virConnectPtr conn;
4600 virNWFilterBindingPtr *bindings = NULL;
4601 int c_retval = 0;
4602 ssize_t i;
4603 unsigned int flags;
4605 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllNWFilterBindings",
4606 &pyobj_conn, &flags))
4607 return NULL;
4608 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4610 LIBVIRT_BEGIN_ALLOW_THREADS;
4611 c_retval = virConnectListAllNWFilterBindings(conn, &bindings, flags);
4612 LIBVIRT_END_ALLOW_THREADS;
4614 if (c_retval < 0)
4615 return VIR_PY_NONE;
4617 if (!(py_retval = PyList_New(c_retval)))
4618 goto cleanup;
4620 for (i = 0; i < c_retval; i++) {
4621 VIR_PY_LIST_SET_GOTO(py_retval, i,
4622 libvirt_virNWFilterBindingPtrWrap(bindings[i]), error);
4623 /* python steals the pointer */
4624 bindings[i] = NULL;
4627 cleanup:
4628 for (i = 0; i < c_retval; i++)
4629 if (bindings[i])
4630 virNWFilterBindingFree(bindings[i]);
4631 VIR_FREE(bindings);
4632 return py_retval;
4634 error:
4635 Py_CLEAR(py_retval);
4636 goto cleanup;
4638 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
4640 static PyObject *
4641 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4642 PyObject *args)
4644 PyObject *py_retval;
4645 char **names = NULL;
4646 int c_retval;
4647 ssize_t i;
4648 virConnectPtr conn;
4649 PyObject *pyobj_conn;
4652 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListInterfaces",
4653 &pyobj_conn))
4654 return NULL;
4655 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4657 LIBVIRT_BEGIN_ALLOW_THREADS;
4658 c_retval = virConnectNumOfInterfaces(conn);
4659 LIBVIRT_END_ALLOW_THREADS;
4661 if (c_retval < 0)
4662 return VIR_PY_NONE;
4664 if (c_retval) {
4665 if (VIR_ALLOC_N(names, c_retval) < 0)
4666 return PyErr_NoMemory();
4668 LIBVIRT_BEGIN_ALLOW_THREADS;
4669 c_retval = virConnectListInterfaces(conn, names, c_retval);
4670 LIBVIRT_END_ALLOW_THREADS;
4672 if (c_retval < 0) {
4673 py_retval = VIR_PY_NONE;
4674 goto cleanup;
4678 if ((py_retval = PyList_New(c_retval)) == NULL)
4679 goto cleanup;
4681 if (names)
4682 for (i = 0; i < c_retval; i++)
4683 VIR_PY_LIST_SET_GOTO(py_retval, i,
4684 libvirt_constcharPtrWrap(names[i]), error);
4686 cleanup:
4687 if (c_retval > 0)
4688 for (i = 0; i < c_retval; i++)
4689 VIR_FREE(names[i]);
4690 VIR_FREE(names);
4691 return py_retval;
4693 error:
4694 Py_CLEAR(py_retval);
4695 goto cleanup;
4699 static PyObject *
4700 libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4701 PyObject *args)
4703 PyObject *py_retval;
4704 char **names = NULL;
4705 int c_retval;
4706 ssize_t i;
4707 virConnectPtr conn;
4708 PyObject *pyobj_conn;
4711 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedInterfaces",
4712 &pyobj_conn))
4713 return NULL;
4714 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4716 LIBVIRT_BEGIN_ALLOW_THREADS;
4717 c_retval = virConnectNumOfDefinedInterfaces(conn);
4718 LIBVIRT_END_ALLOW_THREADS;
4720 if (c_retval < 0)
4721 return VIR_PY_NONE;
4723 if (c_retval) {
4724 if (VIR_ALLOC_N(names, c_retval) < 0)
4725 return PyErr_NoMemory();
4727 LIBVIRT_BEGIN_ALLOW_THREADS;
4728 c_retval = virConnectListDefinedInterfaces(conn, names, c_retval);
4729 LIBVIRT_END_ALLOW_THREADS;
4731 if (c_retval < 0) {
4732 py_retval = VIR_PY_NONE;
4733 goto cleanup;
4737 if ((py_retval = PyList_New(c_retval)) == NULL)
4738 goto cleanup;
4740 if (names) {
4741 for (i = 0; i < c_retval; i++)
4742 VIR_PY_LIST_SET_GOTO(py_retval, i,
4743 libvirt_constcharPtrWrap(names[i]), error);
4746 cleanup:
4747 if (c_retval > 0)
4748 for (i = 0; i < c_retval; i++)
4749 VIR_FREE(names[i]);
4750 VIR_FREE(names);
4751 return py_retval;
4753 error:
4754 Py_CLEAR(py_retval);
4755 goto cleanup;
4759 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4760 static PyObject *
4761 libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4762 PyObject *args)
4764 PyObject *pyobj_conn;
4765 PyObject *py_retval = NULL;
4766 virConnectPtr conn;
4767 virInterfacePtr *ifaces = NULL;
4768 int c_retval = 0;
4769 ssize_t i;
4770 unsigned int flags;
4772 if (!PyArg_ParseTuple(args, (char *)"OI:virConnectListAllInterfaces",
4773 &pyobj_conn, &flags))
4774 return NULL;
4775 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4777 LIBVIRT_BEGIN_ALLOW_THREADS;
4778 c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
4779 LIBVIRT_END_ALLOW_THREADS;
4781 if (c_retval < 0)
4782 return VIR_PY_NONE;
4784 if (!(py_retval = PyList_New(c_retval)))
4785 goto cleanup;
4787 for (i = 0; i < c_retval; i++) {
4788 VIR_PY_LIST_SET_GOTO(py_retval, i,
4789 libvirt_virInterfacePtrWrap(ifaces[i]), error);
4790 /* python steals the pointer */
4791 ifaces[i] = NULL;
4794 cleanup:
4795 for (i = 0; i < c_retval; i++)
4796 if (ifaces[i])
4797 virInterfaceFree(ifaces[i]);
4798 VIR_FREE(ifaces);
4799 return py_retval;
4801 error:
4802 Py_CLEAR(py_retval);
4803 goto cleanup;
4805 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4807 static PyObject *
4808 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
4809 PyObject *args)
4811 PyObject *pyobj_conn;
4812 PyObject *list;
4813 virConnectPtr conn;
4814 unsigned int flags;
4815 char **xmlcpus = NULL;
4816 int ncpus = 0;
4817 char *base_cpu;
4818 PyObject *pybase_cpu;
4819 ssize_t i, j;
4821 if (!PyArg_ParseTuple(args, (char *)"OOI:virConnectBaselineCPU",
4822 &pyobj_conn, &list, &flags))
4823 return NULL;
4824 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4826 if (PyList_Check(list)) {
4827 ncpus = PyList_Size(list);
4828 if (VIR_ALLOC_N(xmlcpus, ncpus) < 0)
4829 return PyErr_NoMemory();
4831 for (i = 0; i < ncpus; i++) {
4832 if (libvirt_charPtrUnwrap(PyList_GetItem(list, i),
4833 &(xmlcpus[i])) < 0) {
4834 for (j = 0 ; j < i ; j++)
4835 VIR_FREE(xmlcpus[j]);
4836 VIR_FREE(xmlcpus);
4837 return NULL;
4842 LIBVIRT_BEGIN_ALLOW_THREADS;
4843 base_cpu = virConnectBaselineCPU(conn, (const char **)xmlcpus, ncpus, flags);
4844 LIBVIRT_END_ALLOW_THREADS;
4846 for (i = 0 ; i < ncpus ; i++)
4847 VIR_FREE(xmlcpus[i]);
4848 VIR_FREE(xmlcpus);
4850 if (base_cpu == NULL)
4851 return VIR_PY_NONE;
4853 pybase_cpu = libvirt_constcharPtrWrap(base_cpu);
4854 VIR_FREE(base_cpu);
4856 return pybase_cpu;
4860 static PyObject *
4861 libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4862 PyObject *args)
4864 PyObject *py_retval;
4865 int c_retval;
4866 virDomainPtr domain;
4867 PyObject *pyobj_domain;
4868 virDomainJobInfo info;
4870 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetJobInfo", &pyobj_domain))
4871 return NULL;
4872 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4874 LIBVIRT_BEGIN_ALLOW_THREADS;
4875 c_retval = virDomainGetJobInfo(domain, &info);
4876 LIBVIRT_END_ALLOW_THREADS;
4878 if (c_retval < 0)
4879 return VIR_PY_NONE;
4881 if ((py_retval = PyList_New(12)) == NULL)
4882 return NULL;
4884 VIR_PY_LIST_SET_GOTO(py_retval, 0,
4885 libvirt_intWrap((int) info.type), error);
4886 VIR_PY_LIST_SET_GOTO(py_retval, 1,
4887 libvirt_ulonglongWrap(info.timeElapsed), error);
4888 VIR_PY_LIST_SET_GOTO(py_retval, 2,
4889 libvirt_ulonglongWrap(info.timeRemaining), error);
4890 VIR_PY_LIST_SET_GOTO(py_retval, 3,
4891 libvirt_ulonglongWrap(info.dataTotal), error);
4892 VIR_PY_LIST_SET_GOTO(py_retval, 4,
4893 libvirt_ulonglongWrap(info.dataProcessed), error);
4894 VIR_PY_LIST_SET_GOTO(py_retval, 5,
4895 libvirt_ulonglongWrap(info.dataRemaining), error);
4896 VIR_PY_LIST_SET_GOTO(py_retval, 6,
4897 libvirt_ulonglongWrap(info.memTotal), error);
4898 VIR_PY_LIST_SET_GOTO(py_retval, 7,
4899 libvirt_ulonglongWrap(info.memProcessed), error);
4900 VIR_PY_LIST_SET_GOTO(py_retval, 8,
4901 libvirt_ulonglongWrap(info.memRemaining), error);
4902 VIR_PY_LIST_SET_GOTO(py_retval, 9,
4903 libvirt_ulonglongWrap(info.fileTotal), error);
4904 VIR_PY_LIST_SET_GOTO(py_retval, 10,
4905 libvirt_ulonglongWrap(info.fileProcessed), error);
4906 VIR_PY_LIST_SET_GOTO(py_retval, 11,
4907 libvirt_ulonglongWrap(info.fileRemaining), error);
4909 return py_retval;
4911 error:
4912 Py_DECREF(py_retval);
4913 return NULL;
4916 #if LIBVIR_CHECK_VERSION(1, 0, 3)
4917 static PyObject *
4918 libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED,
4919 PyObject *args)
4921 PyObject *pyobj_domain;
4922 virDomainPtr domain;
4923 unsigned int flags;
4924 virTypedParameterPtr params = NULL;
4925 int nparams = 0;
4926 int type;
4927 PyObject *dict = NULL;
4928 int rc;
4930 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetJobStats",
4931 &pyobj_domain, &flags))
4932 return NULL;
4933 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4935 LIBVIRT_BEGIN_ALLOW_THREADS;
4936 rc = virDomainGetJobStats(domain, &type, &params, &nparams, flags);
4937 LIBVIRT_END_ALLOW_THREADS;
4939 if (rc < 0)
4940 return VIR_PY_NONE;
4942 if (!(dict = getPyVirTypedParameter(params, nparams)))
4943 goto cleanup;
4945 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("type"),
4946 libvirt_intWrap(type), error);
4948 cleanup:
4949 virTypedParamsFree(params, nparams);
4950 return dict;
4952 error:
4953 Py_CLEAR(dict);
4954 goto cleanup;
4956 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
4958 static PyObject *
4959 libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4960 PyObject *args)
4962 virDomainPtr domain;
4963 PyObject *pyobj_domain;
4964 const char *path;
4965 unsigned int flags;
4966 virDomainBlockJobInfo info;
4967 int c_ret;
4968 PyObject *dict;
4970 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockJobInfo",
4971 &pyobj_domain, &path, &flags))
4972 return NULL;
4973 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4975 LIBVIRT_BEGIN_ALLOW_THREADS;
4976 c_ret = virDomainGetBlockJobInfo(domain, path, &info, flags);
4977 LIBVIRT_END_ALLOW_THREADS;
4979 if (c_ret < 0)
4980 return VIR_PY_NONE;
4982 if ((dict = PyDict_New()) == NULL)
4983 return NULL;
4985 if (c_ret == 0)
4986 return dict;
4988 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("type"),
4989 libvirt_intWrap(info.type), error);
4990 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("bandwidth"),
4991 libvirt_ulongWrap(info.bandwidth), error);
4992 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("cur"),
4993 libvirt_ulonglongWrap(info.cur), error);
4994 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("end"),
4995 libvirt_ulonglongWrap(info.end), error);
4997 return dict;
4999 error:
5000 Py_DECREF(dict);
5001 return NULL;
5004 static PyObject *
5005 libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
5006 PyObject *args)
5008 virDomainPtr domain;
5009 PyObject *pyobj_domain, *info;
5010 PyObject *ret = NULL;
5011 int i_retval;
5012 int nparams = 0;
5013 Py_ssize_t size = 0;
5014 const char *disk;
5015 unsigned int flags;
5016 virTypedParameterPtr params = NULL, new_params = NULL;
5018 if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainSetBlockIoTune",
5019 &pyobj_domain, &disk, &info, &flags))
5020 return NULL;
5021 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5023 if ((size = PyDict_Size(info)) < 0)
5024 return NULL;
5026 if (size == 0) {
5027 PyErr_Format(PyExc_LookupError,
5028 "Need non-empty dictionary to set attributes");
5029 return NULL;
5032 LIBVIRT_BEGIN_ALLOW_THREADS;
5033 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
5034 LIBVIRT_END_ALLOW_THREADS;
5036 if (i_retval < 0)
5037 return VIR_PY_INT_FAIL;
5039 if (nparams == 0) {
5040 PyErr_Format(PyExc_LookupError,
5041 "Domain has no settable attributes");
5042 return NULL;
5045 if (VIR_ALLOC_N(params, nparams) < 0)
5046 return PyErr_NoMemory();
5048 LIBVIRT_BEGIN_ALLOW_THREADS;
5049 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
5050 LIBVIRT_END_ALLOW_THREADS;
5052 if (i_retval < 0) {
5053 ret = VIR_PY_INT_FAIL;
5054 goto cleanup;
5057 new_params = setPyVirTypedParameter(info, params, nparams);
5058 if (!new_params)
5059 goto cleanup;
5061 LIBVIRT_BEGIN_ALLOW_THREADS;
5062 i_retval = virDomainSetBlockIoTune(domain, disk, new_params, size, flags);
5063 LIBVIRT_END_ALLOW_THREADS;
5065 if (i_retval < 0) {
5066 ret = VIR_PY_INT_FAIL;
5067 goto cleanup;
5070 ret = VIR_PY_INT_SUCCESS;
5072 cleanup:
5073 virTypedParamsFree(params, nparams);
5074 virTypedParamsFree(new_params, size);
5075 return ret;
5078 static PyObject *
5079 libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
5080 PyObject *args)
5082 virDomainPtr domain;
5083 PyObject *pyobj_domain;
5084 PyObject *ret = NULL;
5085 int i_retval;
5086 int nparams = 0;
5087 const char *disk;
5088 unsigned int flags;
5089 virTypedParameterPtr params;
5091 if (!PyArg_ParseTuple(args, (char *)"OzI:virDomainGetBlockIoTune",
5092 &pyobj_domain, &disk, &flags))
5093 return NULL;
5094 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5096 LIBVIRT_BEGIN_ALLOW_THREADS;
5097 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
5098 LIBVIRT_END_ALLOW_THREADS;
5100 if (i_retval < 0)
5101 return VIR_PY_NONE;
5103 if (!nparams)
5104 return PyDict_New();
5106 if (VIR_ALLOC_N(params, nparams) < 0)
5107 return PyErr_NoMemory();
5109 LIBVIRT_BEGIN_ALLOW_THREADS;
5110 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
5111 LIBVIRT_END_ALLOW_THREADS;
5113 if (i_retval < 0) {
5114 ret = VIR_PY_NONE;
5115 goto cleanup;
5118 ret = getPyVirTypedParameter(params, nparams);
5120 cleanup:
5121 virTypedParamsFree(params, nparams);
5122 return ret;
5125 static PyObject *
5126 libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED,
5127 PyObject *args)
5129 PyObject *py_retval = VIR_PY_NONE;
5130 virDomainPtr domain;
5131 PyObject *pyobj_domain;
5132 unsigned int flags;
5133 virDomainDiskErrorPtr disks = NULL;
5134 unsigned int ndisks;
5135 int count;
5136 ssize_t i;
5138 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetDiskErrors",
5139 &pyobj_domain, &flags))
5140 return NULL;
5142 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5144 LIBVIRT_BEGIN_ALLOW_THREADS;
5145 count = virDomainGetDiskErrors(domain, NULL, 0, 0);
5146 LIBVIRT_END_ALLOW_THREADS;
5148 if (count < 0)
5149 return VIR_PY_NONE;
5150 ndisks = count;
5152 if (ndisks) {
5153 if (VIR_ALLOC_N(disks, ndisks) < 0)
5154 return PyErr_NoMemory();
5156 LIBVIRT_BEGIN_ALLOW_THREADS;
5157 count = virDomainGetDiskErrors(domain, disks, ndisks, 0);
5158 LIBVIRT_END_ALLOW_THREADS;
5160 if (count < 0) {
5161 py_retval = VIR_PY_NONE;
5162 goto cleanup;
5166 if (!(py_retval = PyDict_New()))
5167 goto cleanup;
5169 for (i = 0; i < count; i++) {
5170 VIR_PY_DICT_SET_GOTO(py_retval,
5171 libvirt_constcharPtrWrap(disks[i].disk),
5172 libvirt_intWrap(disks[i].error),
5173 error);
5176 cleanup:
5177 if (count > 0)
5178 for (i = 0; i < count; i++)
5179 VIR_FREE(disks[i].disk);
5180 VIR_FREE(disks);
5181 return py_retval;
5183 error:
5184 Py_CLEAR(py_retval);
5185 goto cleanup;
5189 #if LIBVIR_CHECK_VERSION(1, 2, 14)
5190 static PyObject *
5191 libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED,
5192 PyObject *args)
5194 PyObject *py_retval = VIR_PY_NONE;
5195 PyObject *pyobj_domain;
5196 virDomainPtr domain;
5197 virDomainInterfacePtr *ifaces = NULL;
5198 unsigned int source;
5199 unsigned int flags;
5200 int ifaces_count = 0;
5201 ssize_t i, j;
5203 if (!PyArg_ParseTuple(args, (char *) "OII:virDomainInterfaceAddresses",
5204 &pyobj_domain, &source, &flags))
5205 return NULL;
5207 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
5209 LIBVIRT_BEGIN_ALLOW_THREADS;
5210 ifaces_count = virDomainInterfaceAddresses(domain, &ifaces, source, flags);
5211 LIBVIRT_END_ALLOW_THREADS;
5213 if (ifaces_count < 0)
5214 goto cleanup;
5216 if (!(py_retval = PyDict_New()))
5217 goto error;
5219 for (i = 0; i < ifaces_count; i++) {
5220 virDomainInterfacePtr iface = ifaces[i];
5221 PyObject *py_addrs = NULL;
5222 PyObject *py_iface = NULL;
5224 if (!(py_iface = PyDict_New()))
5225 goto error;
5227 VIR_PY_DICT_SET_GOTO(py_retval, libvirt_charPtrWrap(iface->name),
5228 py_iface, error);
5230 if (iface->naddrs) {
5231 if (!(py_addrs = PyList_New(iface->naddrs))) {
5232 goto error;
5234 } else {
5235 py_addrs = VIR_PY_NONE;
5238 VIR_PY_DICT_SET_GOTO(py_iface, libvirt_constcharPtrWrap("addrs"),
5239 py_addrs, error);
5241 VIR_PY_DICT_SET_GOTO(py_iface, libvirt_constcharPtrWrap("hwaddr"),
5242 libvirt_constcharPtrWrap(iface->hwaddr), error);
5244 for (j = 0; j < iface->naddrs; j++) {
5245 virDomainIPAddressPtr addr = &(iface->addrs[j]);
5246 PyObject *py_addr = PyDict_New();
5248 if (!py_addr)
5249 goto error;
5251 VIR_PY_LIST_SET_GOTO(py_addrs, j, py_addr, error);
5253 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("addr"),
5254 libvirt_constcharPtrWrap(addr->addr), error);
5255 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("prefix"),
5256 libvirt_uintWrap(addr->prefix), error);
5257 VIR_PY_DICT_SET_GOTO(py_addr, libvirt_constcharPtrWrap("type"),
5258 libvirt_intWrap(addr->type), error);
5262 cleanup:
5263 if (ifaces && ifaces_count > 0) {
5264 for (i = 0; i < ifaces_count; i++) {
5265 virDomainInterfaceFree(ifaces[i]);
5268 VIR_FREE(ifaces);
5270 return py_retval;
5272 error:
5273 Py_CLEAR(py_retval);
5274 goto cleanup;
5276 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
5279 /*******************************************
5280 * Helper functions to avoid importing modules
5281 * for every callback
5282 *******************************************/
5283 static PyObject *libvirt_module = NULL;
5284 static PyObject *libvirt_dict = NULL;
5286 static PyObject *
5287 getLibvirtModuleObject(void)
5289 if (libvirt_module)
5290 return libvirt_module;
5292 // PyImport_ImportModule returns a new reference
5293 /* Bogus (char *) cast for RHEL-5 python API brokenness */
5294 libvirt_module = PyImport_ImportModule((char *)"libvirt");
5295 if (!libvirt_module) {
5296 DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
5297 PyErr_Print();
5298 return NULL;
5301 return libvirt_module;
5304 static PyObject *
5305 getLibvirtDictObject(void)
5307 if (libvirt_dict)
5308 return libvirt_dict;
5310 // PyModule_GetDict returns a borrowed reference
5311 libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
5312 if (!libvirt_dict) {
5313 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
5314 PyErr_Print();
5315 return NULL;
5318 Py_INCREF(libvirt_dict);
5319 return libvirt_dict;
5323 static PyObject *
5324 libvirt_lookupPythonFunc(const char *funcname)
5326 PyObject *python_cb;
5328 /* Lookup the python callback */
5329 python_cb = PyDict_GetItemString(getLibvirtDictObject(), funcname);
5331 if (!python_cb) {
5332 DEBUG("%s: Error finding %s\n", __FUNCTION__, funcname);
5333 PyErr_Print();
5334 PyErr_Clear();
5335 return NULL;
5338 if (!PyCallable_Check(python_cb)) {
5339 DEBUG("%s: %s is not callable\n", __FUNCTION__, funcname);
5340 return NULL;
5343 return python_cb;
5346 /*******************************************
5347 * Domain Events
5348 *******************************************/
5350 static int
5351 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5352 virDomainPtr dom,
5353 int event,
5354 int detail,
5355 void *opaque)
5357 PyObject *pyobj_ret = NULL;
5359 PyObject *pyobj_conn = (PyObject*)opaque;
5360 PyObject *pyobj_dom;
5362 int ret = -1;
5364 LIBVIRT_ENSURE_THREAD_STATE;
5366 /* Create a python instance of this virDomainPtr */
5367 virDomainRef(dom);
5368 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5369 virDomainFree(dom);
5370 goto cleanup;
5373 /* Call the Callback Dispatcher */
5374 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5375 (char*)"_dispatchDomainEventCallbacks",
5376 (char*)"Oii",
5377 pyobj_dom,
5378 event, detail);
5380 Py_DECREF(pyobj_dom);
5382 cleanup:
5383 if (!pyobj_ret) {
5384 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5385 PyErr_Print();
5386 } else {
5387 Py_DECREF(pyobj_ret);
5388 ret = 0;
5391 LIBVIRT_RELEASE_THREAD_STATE;
5392 return ret;
5395 static PyObject *
5396 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject *self,
5397 PyObject *args)
5399 PyObject *pyobj_conn; /* virConnectPtr */
5400 PyObject *pyobj_conn_inst; /* virConnect Python object */
5402 virConnectPtr conn;
5403 int ret = 0;
5405 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectDomainEventRegister",
5406 &pyobj_conn, &pyobj_conn_inst))
5407 return NULL;
5409 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
5410 pyobj_conn, pyobj_conn_inst);
5411 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5413 Py_INCREF(pyobj_conn_inst);
5415 LIBVIRT_BEGIN_ALLOW_THREADS;
5416 ret = virConnectDomainEventRegister(conn,
5417 libvirt_virConnectDomainEventCallback,
5418 pyobj_conn_inst, NULL);
5419 LIBVIRT_END_ALLOW_THREADS;
5421 return libvirt_intWrap(ret);
5424 static PyObject *
5425 libvirt_virConnectDomainEventDeregister(PyObject *self ATTRIBUTE_UNUSED,
5426 PyObject *args)
5428 PyObject *pyobj_conn;
5429 PyObject *pyobj_conn_inst;
5431 virConnectPtr conn;
5432 int ret = 0;
5434 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectDomainEventDeregister",
5435 &pyobj_conn, &pyobj_conn_inst))
5436 return NULL;
5438 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
5440 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5442 LIBVIRT_BEGIN_ALLOW_THREADS;
5443 ret = virConnectDomainEventDeregister(conn, libvirt_virConnectDomainEventCallback);
5444 LIBVIRT_END_ALLOW_THREADS;
5446 Py_DECREF(pyobj_conn_inst);
5447 return libvirt_intWrap(ret);
5450 /*******************************************
5451 * Event Impl
5452 *******************************************/
5453 static PyObject *addHandleObj;
5454 static PyObject *updateHandleObj;
5455 static PyObject *removeHandleObj;
5456 static PyObject *addTimeoutObj;
5457 static PyObject *updateTimeoutObj;
5458 static PyObject *removeTimeoutObj;
5460 static int
5461 libvirt_virEventAddHandleFunc(int fd,
5462 int event,
5463 virEventHandleCallback cb,
5464 void *opaque,
5465 virFreeCallback ff)
5467 PyObject *result;
5468 PyObject *python_cb = NULL;
5469 PyObject *cb_args = NULL;
5470 PyObject *pyobj_args = NULL;
5471 int retval = -1;
5473 LIBVIRT_ENSURE_THREAD_STATE;
5475 if ((pyobj_args = PyTuple_New(4)) == NULL)
5476 goto cleanup;
5478 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(fd), cleanup);
5479 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
5481 /* Lookup the python callback */
5482 python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
5483 if (!python_cb) {
5484 goto cleanup;
5486 Py_INCREF(python_cb);
5488 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, python_cb, cleanup);
5490 if ((cb_args = PyTuple_New(3)) == NULL)
5491 goto cleanup;
5493 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 3, cb_args, cleanup);
5495 /* If changing contents of the opaque object, please also change
5496 * virEventInvokeFreeCallback() in libvirt-override.py
5498 VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventHandleCallbackWrap(cb), cleanup);
5499 VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
5500 VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
5502 result = PyEval_CallObject(addHandleObj, pyobj_args);
5503 if (!result) {
5504 PyErr_Print();
5505 PyErr_Clear();
5506 } else {
5507 libvirt_intUnwrap(result, &retval);
5510 Py_XDECREF(result);
5512 cleanup:
5513 Py_XDECREF(pyobj_args);
5515 LIBVIRT_RELEASE_THREAD_STATE;
5517 return retval;
5520 static void
5521 libvirt_virEventUpdateHandleFunc(int watch,
5522 int event)
5524 PyObject *result = NULL;
5525 PyObject *pyobj_args;
5527 LIBVIRT_ENSURE_THREAD_STATE;
5529 if ((pyobj_args = PyTuple_New(2)) == NULL)
5530 goto cleanup;
5532 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
5533 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
5535 result = PyEval_CallObject(updateHandleObj, pyobj_args);
5536 if (!result) {
5537 PyErr_Print();
5538 PyErr_Clear();
5541 cleanup:
5542 Py_XDECREF(result);
5543 Py_XDECREF(pyobj_args);
5545 LIBVIRT_RELEASE_THREAD_STATE;
5549 static int
5550 libvirt_virEventRemoveHandleFunc(int watch)
5552 PyObject *result = NULL;
5553 PyObject *pyobj_args;
5554 int retval = -1;
5556 LIBVIRT_ENSURE_THREAD_STATE;
5558 if ((pyobj_args = PyTuple_New(1)) == NULL)
5559 goto cleanup;
5561 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
5563 result = PyEval_CallObject(removeHandleObj, pyobj_args);
5564 if (result) {
5565 retval = 0;
5566 } else {
5567 PyErr_Print();
5568 PyErr_Clear();
5571 cleanup:
5572 Py_XDECREF(result);
5573 Py_XDECREF(pyobj_args);
5575 LIBVIRT_RELEASE_THREAD_STATE;
5577 return retval;
5581 static int
5582 libvirt_virEventAddTimeoutFunc(int timeout,
5583 virEventTimeoutCallback cb,
5584 void *opaque,
5585 virFreeCallback ff)
5587 PyObject *result = NULL;
5588 PyObject *python_cb = NULL;
5589 PyObject *cb_args = NULL;
5590 PyObject *pyobj_args = NULL;
5591 int retval = -1;
5593 LIBVIRT_ENSURE_THREAD_STATE;
5595 if ((pyobj_args = PyTuple_New(3)) == NULL)
5596 goto cleanup;
5598 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timeout), cleanup);
5600 /* Lookup the python callback */
5601 python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
5602 if (!python_cb) {
5603 goto cleanup;
5605 Py_INCREF(python_cb);
5606 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, python_cb, cleanup);
5608 if ((cb_args = PyTuple_New(3)) == NULL)
5609 goto cleanup;
5611 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, cb_args, cleanup);
5613 /* If changing contents of the opaque object, please also change
5614 * virEventInvokeFreeCallback() in libvirt-override.py
5616 VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventTimeoutCallbackWrap(cb), cleanup);
5617 VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
5618 VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
5620 result = PyEval_CallObject(addTimeoutObj, pyobj_args);
5621 if (!result) {
5622 PyErr_Print();
5623 PyErr_Clear();
5624 } else {
5625 libvirt_intUnwrap(result, &retval);
5628 cleanup:
5629 Py_XDECREF(result);
5630 Py_XDECREF(pyobj_args);
5632 LIBVIRT_RELEASE_THREAD_STATE;
5633 return retval;
5636 static void
5637 libvirt_virEventUpdateTimeoutFunc(int timer,
5638 int timeout)
5640 PyObject *result = NULL;
5641 PyObject *pyobj_args;
5643 LIBVIRT_ENSURE_THREAD_STATE;
5645 if ((pyobj_args = PyTuple_New(2)) == NULL)
5646 goto cleanup;
5648 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
5649 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(timeout), cleanup);
5651 result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
5652 if (!result) {
5653 PyErr_Print();
5654 PyErr_Clear();
5657 cleanup:
5658 Py_XDECREF(result);
5659 Py_XDECREF(pyobj_args);
5661 LIBVIRT_RELEASE_THREAD_STATE;
5664 static int
5665 libvirt_virEventRemoveTimeoutFunc(int timer)
5667 PyObject *result = NULL;
5668 PyObject *pyobj_args;
5669 int retval = -1;
5671 LIBVIRT_ENSURE_THREAD_STATE;
5673 if ((pyobj_args = PyTuple_New(1)) == NULL)
5674 goto cleanup;
5676 VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
5678 result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
5679 if (result) {
5680 retval = 0;
5681 } else {
5682 PyErr_Print();
5683 PyErr_Clear();
5686 cleanup:
5687 Py_XDECREF(result);
5688 Py_XDECREF(pyobj_args);
5690 LIBVIRT_RELEASE_THREAD_STATE;
5692 return retval;
5695 static PyObject *
5696 libvirt_virEventRegisterImpl(PyObject *self ATTRIBUTE_UNUSED,
5697 PyObject *args)
5699 if (addHandleObj || updateHandleObj || removeHandleObj ||
5700 addTimeoutObj || updateTimeoutObj || removeTimeoutObj) {
5701 PyErr_SetString(PyExc_RuntimeError,
5702 "Event loop is already registered");
5703 return NULL;
5706 /* Parse and check arguments */
5707 if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
5708 &addHandleObj, &updateHandleObj,
5709 &removeHandleObj, &addTimeoutObj,
5710 &updateTimeoutObj, &removeTimeoutObj) ||
5711 !PyCallable_Check(addHandleObj) ||
5712 !PyCallable_Check(updateHandleObj) ||
5713 !PyCallable_Check(removeHandleObj) ||
5714 !PyCallable_Check(addTimeoutObj) ||
5715 !PyCallable_Check(updateTimeoutObj) ||
5716 !PyCallable_Check(removeTimeoutObj))
5717 return NULL;
5719 /* Inc refs since we're holding on to these objects until
5720 * the next call (if any) to this function.
5722 Py_INCREF(addHandleObj);
5723 Py_INCREF(updateHandleObj);
5724 Py_INCREF(removeHandleObj);
5725 Py_INCREF(addTimeoutObj);
5726 Py_INCREF(updateTimeoutObj);
5727 Py_INCREF(removeTimeoutObj);
5729 /* Now register our C EventImpl, which will dispatch
5730 * to the Python callbacks passed in as args.
5732 LIBVIRT_BEGIN_ALLOW_THREADS;
5733 virEventRegisterImpl(libvirt_virEventAddHandleFunc,
5734 libvirt_virEventUpdateHandleFunc,
5735 libvirt_virEventRemoveHandleFunc,
5736 libvirt_virEventAddTimeoutFunc,
5737 libvirt_virEventUpdateTimeoutFunc,
5738 libvirt_virEventRemoveTimeoutFunc);
5739 LIBVIRT_END_ALLOW_THREADS;
5741 return VIR_PY_INT_SUCCESS;
5744 static PyObject *
5745 libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
5746 PyObject *args)
5748 int watch, fd, event;
5749 PyObject *py_f;
5750 PyObject *py_opaque;
5751 virEventHandleCallback cb;
5752 void *opaque;
5754 if (!PyArg_ParseTuple(args, (char *) "iiiOO:virEventInvokeHandleCallback",
5755 &watch, &fd, &event, &py_f, &py_opaque))
5756 return NULL;
5758 cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
5759 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5761 if (cb) {
5762 LIBVIRT_BEGIN_ALLOW_THREADS;
5763 cb(watch, fd, event, opaque);
5764 LIBVIRT_END_ALLOW_THREADS;
5767 return VIR_PY_INT_SUCCESS;
5770 static PyObject *
5771 libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
5772 PyObject *args)
5774 int timer;
5775 PyObject *py_f;
5776 PyObject *py_opaque;
5777 virEventTimeoutCallback cb;
5778 void *opaque;
5780 if (!PyArg_ParseTuple(args, (char *) "iOO:virEventInvokeTimeoutCallback",
5781 &timer, &py_f, &py_opaque))
5782 return NULL;
5784 cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
5785 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5786 if (cb) {
5787 LIBVIRT_BEGIN_ALLOW_THREADS;
5788 cb(timer, opaque);
5789 LIBVIRT_END_ALLOW_THREADS;
5792 return VIR_PY_INT_SUCCESS;
5795 static PyObject *
5796 libvirt_virEventInvokeFreeCallback(PyObject *self ATTRIBUTE_UNUSED,
5797 PyObject *args)
5799 PyObject *py_f;
5800 PyObject *py_opaque;
5801 virFreeCallback cb;
5802 void *opaque;
5804 if (!PyArg_ParseTuple(args, (char *) "OO:virEventInvokeFreeCallback",
5805 &py_f, &py_opaque))
5806 return NULL;
5808 cb = (virFreeCallback) PyvirEventHandleCallback_Get(py_f);
5809 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5811 if (cb) {
5812 LIBVIRT_BEGIN_ALLOW_THREADS;
5813 cb(opaque);
5814 LIBVIRT_END_ALLOW_THREADS;
5817 return VIR_PY_INT_SUCCESS;
5820 static void
5821 libvirt_virEventHandleCallback(int watch,
5822 int fd,
5823 int events,
5824 void *opaque)
5826 PyObject *pyobj_cbData = (PyObject *)opaque;
5827 PyObject *pyobj_ret;
5828 PyObject *python_cb;
5830 LIBVIRT_ENSURE_THREAD_STATE;
5832 /* Lookup the python callback */
5833 python_cb = libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
5834 if (!python_cb) {
5835 goto cleanup;
5838 Py_INCREF(pyobj_cbData);
5840 /* Call the pure python dispatcher */
5841 pyobj_ret = PyObject_CallFunction(python_cb,
5842 (char *)"iiiO",
5843 watch, fd, events, pyobj_cbData);
5845 Py_DECREF(pyobj_cbData);
5847 if (!pyobj_ret) {
5848 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5849 PyErr_Print();
5850 } else {
5851 Py_DECREF(pyobj_ret);
5854 cleanup:
5855 LIBVIRT_RELEASE_THREAD_STATE;
5858 static PyObject *
5859 libvirt_virEventAddHandle(PyObject *self ATTRIBUTE_UNUSED,
5860 PyObject *args)
5862 PyObject *pyobj_cbData;
5863 virEventHandleCallback cb = libvirt_virEventHandleCallback;
5864 int events;
5865 int fd;
5866 int ret;
5868 if (!PyArg_ParseTuple(args, (char *) "iiO:virEventAddHandle",
5869 &fd, &events, &pyobj_cbData))
5870 return NULL;
5872 Py_INCREF(pyobj_cbData);
5874 LIBVIRT_BEGIN_ALLOW_THREADS;
5875 ret = virEventAddHandle(fd, events, cb, pyobj_cbData, NULL);
5876 LIBVIRT_END_ALLOW_THREADS;
5878 if (ret < 0) {
5879 Py_DECREF(pyobj_cbData);
5882 return libvirt_intWrap(ret);
5885 static void
5886 libvirt_virEventTimeoutCallback(int timer,
5887 void *opaque)
5889 PyObject *pyobj_cbData = (PyObject *)opaque;
5890 PyObject *pyobj_ret;
5891 PyObject *python_cb;
5893 LIBVIRT_ENSURE_THREAD_STATE;
5895 /* Lookup the python callback */
5896 python_cb = libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
5897 if (!python_cb) {
5898 goto cleanup;
5901 Py_INCREF(pyobj_cbData);
5903 /* Call the pure python dispatcher */
5904 pyobj_ret = PyObject_CallFunction(python_cb,
5905 (char *)"iO",
5906 timer, pyobj_cbData);
5908 Py_DECREF(pyobj_cbData);
5910 if (!pyobj_ret) {
5911 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5912 PyErr_Print();
5913 } else {
5914 Py_DECREF(pyobj_ret);
5917 cleanup:
5918 LIBVIRT_RELEASE_THREAD_STATE;
5921 static PyObject *
5922 libvirt_virEventAddTimeout(PyObject *self ATTRIBUTE_UNUSED,
5923 PyObject *args)
5925 PyObject *pyobj_cbData;
5926 virEventTimeoutCallback cb = libvirt_virEventTimeoutCallback;
5927 int timeout;
5928 int ret;
5930 if (!PyArg_ParseTuple(args, (char *) "iO:virEventAddTimeout",
5931 &timeout, &pyobj_cbData))
5932 return NULL;
5934 Py_INCREF(pyobj_cbData);
5936 LIBVIRT_BEGIN_ALLOW_THREADS;
5937 ret = virEventAddTimeout(timeout, cb, pyobj_cbData, NULL);
5938 LIBVIRT_END_ALLOW_THREADS;
5940 if (ret < 0) {
5941 Py_DECREF(pyobj_cbData);
5944 return libvirt_intWrap(ret);
5947 static void
5948 libvirt_virConnectDomainEventFreeFunc(void *opaque)
5950 PyObject *pyobj_conn = (PyObject*)opaque;
5951 LIBVIRT_ENSURE_THREAD_STATE;
5952 Py_DECREF(pyobj_conn);
5953 LIBVIRT_RELEASE_THREAD_STATE;
5956 static int
5957 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5958 virDomainPtr dom,
5959 int event,
5960 int detail,
5961 void *opaque)
5963 PyObject *pyobj_cbData = (PyObject*)opaque;
5964 PyObject *pyobj_dom;
5965 PyObject *pyobj_ret = NULL;
5966 PyObject *pyobj_conn;
5967 PyObject *dictKey;
5968 int ret = -1;
5970 LIBVIRT_ENSURE_THREAD_STATE;
5972 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5973 goto cleanup;
5974 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5975 Py_DECREF(dictKey);
5977 /* Create a python instance of this virDomainPtr */
5978 virDomainRef(dom);
5979 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5980 virDomainFree(dom);
5981 goto cleanup;
5983 Py_INCREF(pyobj_cbData);
5985 /* Call the Callback Dispatcher */
5986 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5987 (char*)"_dispatchDomainEventLifecycleCallback",
5988 (char*)"OiiO",
5989 pyobj_dom,
5990 event, detail,
5991 pyobj_cbData);
5993 Py_DECREF(pyobj_cbData);
5994 Py_DECREF(pyobj_dom);
5996 cleanup:
5997 if (!pyobj_ret) {
5998 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5999 PyErr_Print();
6000 } else {
6001 Py_DECREF(pyobj_ret);
6002 ret = 0;
6005 LIBVIRT_RELEASE_THREAD_STATE;
6006 return ret;
6009 static int
6010 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6011 virDomainPtr dom,
6012 void *opaque)
6014 PyObject *pyobj_cbData = (PyObject*)opaque;
6015 PyObject *pyobj_dom;
6016 PyObject *pyobj_ret = NULL;
6017 PyObject *pyobj_conn;
6018 PyObject *dictKey;
6019 int ret = -1;
6021 LIBVIRT_ENSURE_THREAD_STATE;
6023 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6024 goto cleanup;
6025 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6026 Py_DECREF(dictKey);
6028 /* Create a python instance of this virDomainPtr */
6029 virDomainRef(dom);
6030 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6031 virDomainFree(dom);
6032 goto cleanup;
6034 Py_INCREF(pyobj_cbData);
6036 /* Call the Callback Dispatcher */
6037 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6038 (char*)"_dispatchDomainEventGenericCallback",
6039 (char*)"OO",
6040 pyobj_dom, pyobj_cbData);
6042 Py_DECREF(pyobj_cbData);
6043 Py_DECREF(pyobj_dom);
6045 cleanup:
6046 if (!pyobj_ret) {
6047 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6048 PyErr_Print();
6049 } else {
6050 Py_DECREF(pyobj_ret);
6051 ret = 0;
6054 LIBVIRT_RELEASE_THREAD_STATE;
6055 return ret;
6058 static int
6059 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6060 virDomainPtr dom,
6061 long long utcoffset,
6062 void *opaque)
6064 PyObject *pyobj_cbData = (PyObject*)opaque;
6065 PyObject *pyobj_dom;
6066 PyObject *pyobj_ret = NULL;
6067 PyObject *pyobj_conn;
6068 PyObject *dictKey;
6069 int ret = -1;
6071 LIBVIRT_ENSURE_THREAD_STATE;
6073 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6074 goto cleanup;
6075 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6076 Py_DECREF(dictKey);
6078 /* Create a python instance of this virDomainPtr */
6079 virDomainRef(dom);
6080 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6081 virDomainFree(dom);
6082 goto cleanup;
6084 Py_INCREF(pyobj_cbData);
6086 /* Call the Callback Dispatcher */
6087 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6088 (char*)"_dispatchDomainEventRTCChangeCallback",
6089 (char*)"OLO",
6090 pyobj_dom,
6091 (PY_LONG_LONG)utcoffset,
6092 pyobj_cbData);
6094 Py_DECREF(pyobj_cbData);
6095 Py_DECREF(pyobj_dom);
6097 cleanup:
6098 if (!pyobj_ret) {
6099 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6100 PyErr_Print();
6101 } else {
6102 Py_DECREF(pyobj_ret);
6103 ret = 0;
6106 LIBVIRT_RELEASE_THREAD_STATE;
6107 return ret;
6110 static int
6111 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6112 virDomainPtr dom,
6113 int action,
6114 void *opaque)
6116 PyObject *pyobj_cbData = (PyObject*)opaque;
6117 PyObject *pyobj_dom;
6118 PyObject *pyobj_ret = NULL;
6119 PyObject *pyobj_conn;
6120 PyObject *dictKey;
6121 int ret = -1;
6123 LIBVIRT_ENSURE_THREAD_STATE;
6125 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6126 goto cleanup;
6127 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6128 Py_DECREF(dictKey);
6130 /* Create a python instance of this virDomainPtr */
6131 virDomainRef(dom);
6132 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6133 virDomainFree(dom);
6134 goto cleanup;
6136 Py_INCREF(pyobj_cbData);
6138 /* Call the Callback Dispatcher */
6139 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6140 (char*)"_dispatchDomainEventWatchdogCallback",
6141 (char*)"OiO",
6142 pyobj_dom,
6143 action,
6144 pyobj_cbData);
6146 Py_DECREF(pyobj_cbData);
6147 Py_DECREF(pyobj_dom);
6149 cleanup:
6150 if (!pyobj_ret) {
6151 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6152 PyErr_Print();
6153 } else {
6154 Py_DECREF(pyobj_ret);
6155 ret = 0;
6158 LIBVIRT_RELEASE_THREAD_STATE;
6159 return ret;
6162 static int
6163 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6164 virDomainPtr dom,
6165 const char *srcPath,
6166 const char *devAlias,
6167 int action,
6168 void *opaque)
6170 PyObject *pyobj_cbData = (PyObject*)opaque;
6171 PyObject *pyobj_dom;
6172 PyObject *pyobj_ret = NULL;
6173 PyObject *pyobj_conn;
6174 PyObject *dictKey;
6175 int ret = -1;
6177 LIBVIRT_ENSURE_THREAD_STATE;
6179 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6180 goto cleanup;
6181 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6182 Py_DECREF(dictKey);
6184 /* Create a python instance of this virDomainPtr */
6185 virDomainRef(dom);
6186 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6187 virDomainFree(dom);
6188 goto cleanup;
6190 Py_INCREF(pyobj_cbData);
6192 /* Call the Callback Dispatcher */
6193 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6194 (char*)"_dispatchDomainEventIOErrorCallback",
6195 (char*)"OssiO",
6196 pyobj_dom,
6197 srcPath, devAlias, action,
6198 pyobj_cbData);
6200 Py_DECREF(pyobj_cbData);
6201 Py_DECREF(pyobj_dom);
6203 cleanup:
6204 if (!pyobj_ret) {
6205 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6206 PyErr_Print();
6207 } else {
6208 Py_DECREF(pyobj_ret);
6209 ret = 0;
6212 LIBVIRT_RELEASE_THREAD_STATE;
6213 return ret;
6216 static int
6217 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6218 virDomainPtr dom,
6219 const char *srcPath,
6220 const char *devAlias,
6221 int action,
6222 const char *reason,
6223 void *opaque)
6225 PyObject *pyobj_cbData = (PyObject*)opaque;
6226 PyObject *pyobj_dom;
6227 PyObject *pyobj_ret = NULL;
6228 PyObject *pyobj_conn;
6229 PyObject *dictKey;
6230 int ret = -1;
6232 LIBVIRT_ENSURE_THREAD_STATE;
6234 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6235 goto cleanup;
6236 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6237 Py_DECREF(dictKey);
6239 /* Create a python instance of this virDomainPtr */
6240 virDomainRef(dom);
6241 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6242 virDomainFree(dom);
6243 goto cleanup;
6245 Py_INCREF(pyobj_cbData);
6247 /* Call the Callback Dispatcher */
6248 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6249 (char*)"_dispatchDomainEventIOErrorReasonCallback",
6250 (char*)"OssisO",
6251 pyobj_dom,
6252 srcPath, devAlias, action, reason,
6253 pyobj_cbData);
6255 Py_DECREF(pyobj_cbData);
6256 Py_DECREF(pyobj_dom);
6258 cleanup:
6259 if (!pyobj_ret) {
6260 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6261 PyErr_Print();
6262 } else {
6263 Py_DECREF(pyobj_ret);
6264 ret = 0;
6267 LIBVIRT_RELEASE_THREAD_STATE;
6268 return ret;
6271 static int
6272 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6273 virDomainPtr dom,
6274 int phase,
6275 virDomainEventGraphicsAddressPtr local,
6276 virDomainEventGraphicsAddressPtr remote,
6277 const char *authScheme,
6278 virDomainEventGraphicsSubjectPtr subject,
6279 void *opaque)
6281 PyObject *pyobj_cbData = (PyObject*)opaque;
6282 PyObject *pyobj_dom = NULL;
6283 PyObject *pyobj_ret = NULL;
6284 PyObject *pyobj_conn;
6285 PyObject *dictKey;
6286 PyObject *pyobj_local = NULL;
6287 PyObject *pyobj_remote = NULL;
6288 PyObject *pyobj_subject = NULL;
6289 int ret = -1;
6290 ssize_t i;
6292 LIBVIRT_ENSURE_THREAD_STATE;
6294 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6295 goto cleanup;
6296 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6297 Py_DECREF(dictKey);
6299 /* Create a python instance of this virDomainPtr */
6300 virDomainRef(dom);
6301 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6302 virDomainFree(dom);
6303 goto cleanup;
6305 Py_INCREF(pyobj_cbData);
6307 if ((pyobj_local = PyDict_New()) == NULL)
6308 goto cleanup;
6310 VIR_PY_DICT_SET_GOTO(pyobj_local,
6311 libvirt_constcharPtrWrap("family"),
6312 libvirt_intWrap(local->family),
6313 cleanup);
6314 VIR_PY_DICT_SET_GOTO(pyobj_local,
6315 libvirt_constcharPtrWrap("node"),
6316 libvirt_constcharPtrWrap(local->node),
6317 cleanup);
6318 VIR_PY_DICT_SET_GOTO(pyobj_local,
6319 libvirt_constcharPtrWrap("service"),
6320 libvirt_constcharPtrWrap(local->service),
6321 cleanup);
6323 if ((pyobj_remote = PyDict_New()) == NULL)
6324 goto cleanup;
6326 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6327 libvirt_constcharPtrWrap("family"),
6328 libvirt_intWrap(remote->family),
6329 cleanup);
6330 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6331 libvirt_constcharPtrWrap("node"),
6332 libvirt_constcharPtrWrap(remote->node),
6333 cleanup);
6334 VIR_PY_DICT_SET_GOTO(pyobj_remote,
6335 libvirt_constcharPtrWrap("service"),
6336 libvirt_constcharPtrWrap(remote->service),
6337 cleanup);
6339 if ((pyobj_subject = PyList_New(subject->nidentity)) == NULL)
6340 goto cleanup;
6342 for (i = 0; i < subject->nidentity; i++) {
6343 PyObject *pair = PyTuple_New(2);
6344 if (pair == NULL)
6345 goto cleanup;
6347 VIR_PY_LIST_SET_GOTO(pyobj_subject, i, pair, cleanup);
6349 VIR_PY_TUPLE_SET_GOTO(pair, 0,
6350 libvirt_constcharPtrWrap(subject->identities[i].type),
6351 cleanup);
6352 VIR_PY_TUPLE_SET_GOTO(pair, 1,
6353 libvirt_constcharPtrWrap(subject->identities[i].name),
6354 cleanup);
6357 /* Call the Callback Dispatcher */
6358 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6359 (char*)"_dispatchDomainEventGraphicsCallback",
6360 (char*)"OiOOsOO",
6361 pyobj_dom,
6362 phase, pyobj_local, pyobj_remote,
6363 authScheme, pyobj_subject,
6364 pyobj_cbData);
6366 cleanup:
6367 Py_DECREF(pyobj_cbData);
6368 Py_XDECREF(pyobj_dom);
6370 if (!pyobj_ret) {
6371 Py_XDECREF(pyobj_local);
6372 Py_XDECREF(pyobj_remote);
6373 Py_XDECREF(pyobj_subject);
6374 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6375 PyErr_Print();
6376 } else {
6377 Py_DECREF(pyobj_ret);
6378 ret = 0;
6381 LIBVIRT_RELEASE_THREAD_STATE;
6382 return ret;
6385 static int
6386 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6387 virDomainPtr dom,
6388 const char *disk,
6389 int type,
6390 int status,
6391 void *opaque)
6393 PyObject *pyobj_cbData = (PyObject*)opaque;
6394 PyObject *pyobj_dom;
6395 PyObject *pyobj_ret = NULL;
6396 PyObject *pyobj_conn;
6397 PyObject *dictKey;
6398 int ret = -1;
6400 LIBVIRT_ENSURE_THREAD_STATE;
6402 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6403 goto cleanup;
6404 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6405 Py_DECREF(dictKey);
6407 /* Create a python instance of this virDomainPtr */
6408 virDomainRef(dom);
6409 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6410 virDomainFree(dom);
6411 goto cleanup;
6413 Py_INCREF(pyobj_cbData);
6415 /* Call the Callback Dispatcher */
6416 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6417 (char*)"_dispatchDomainEventBlockJobCallback",
6418 (char*)"OsiiO",
6419 pyobj_dom, disk, type, status, pyobj_cbData);
6421 Py_DECREF(pyobj_cbData);
6422 Py_DECREF(pyobj_dom);
6424 cleanup:
6425 if (!pyobj_ret) {
6426 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6427 PyErr_Print();
6428 } else {
6429 Py_DECREF(pyobj_ret);
6430 ret = 0;
6433 LIBVIRT_RELEASE_THREAD_STATE;
6434 return ret;
6437 static int
6438 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6439 virDomainPtr dom,
6440 const char *oldSrcPath,
6441 const char *newSrcPath,
6442 const char *devAlias,
6443 int reason,
6444 void *opaque)
6446 PyObject *pyobj_cbData = (PyObject*)opaque;
6447 PyObject *pyobj_dom;
6448 PyObject *pyobj_ret = NULL;
6449 PyObject *pyobj_conn;
6450 PyObject *dictKey;
6451 int ret = -1;
6453 LIBVIRT_ENSURE_THREAD_STATE;
6455 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6456 goto cleanup;
6457 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6458 Py_DECREF(dictKey);
6460 /* Create a python instance of this virDomainPtr */
6461 virDomainRef(dom);
6462 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6463 virDomainFree(dom);
6464 goto cleanup;
6466 Py_INCREF(pyobj_cbData);
6468 /* Call the Callback Dispatcher */
6469 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6470 (char*)"_dispatchDomainEventDiskChangeCallback",
6471 (char*)"OsssiO",
6472 pyobj_dom,
6473 oldSrcPath, newSrcPath,
6474 devAlias, reason, pyobj_cbData);
6476 Py_DECREF(pyobj_cbData);
6477 Py_DECREF(pyobj_dom);
6479 cleanup:
6480 if (!pyobj_ret) {
6481 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6482 PyErr_Print();
6483 } else {
6484 Py_DECREF(pyobj_ret);
6485 ret = 0;
6488 LIBVIRT_RELEASE_THREAD_STATE;
6489 return ret;
6492 static int
6493 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6494 virDomainPtr dom,
6495 const char *devAlias,
6496 int reason,
6497 void *opaque)
6499 PyObject *pyobj_cbData = (PyObject*)opaque;
6500 PyObject *pyobj_dom;
6501 PyObject *pyobj_ret = NULL;
6502 PyObject *pyobj_conn;
6503 PyObject *dictKey;
6504 int ret = -1;
6506 LIBVIRT_ENSURE_THREAD_STATE;
6508 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6509 goto cleanup;
6510 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6511 Py_DECREF(dictKey);
6513 /* Create a python instance of this virDomainPtr */
6514 virDomainRef(dom);
6515 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6516 virDomainFree(dom);
6517 goto cleanup;
6519 Py_INCREF(pyobj_cbData);
6521 /* Call the Callback Dispatcher */
6522 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6523 (char*)"_dispatchDomainEventTrayChangeCallback",
6524 (char*)"OsiO",
6525 pyobj_dom,
6526 devAlias, reason, pyobj_cbData);
6528 Py_DECREF(pyobj_cbData);
6529 Py_DECREF(pyobj_dom);
6531 cleanup:
6532 if (!pyobj_ret) {
6533 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6534 PyErr_Print();
6535 } else {
6536 Py_DECREF(pyobj_ret);
6537 ret = 0;
6540 LIBVIRT_RELEASE_THREAD_STATE;
6541 return ret;
6544 static int
6545 libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6546 virDomainPtr dom,
6547 int reason,
6548 void *opaque)
6550 PyObject *pyobj_cbData = (PyObject*)opaque;
6551 PyObject *pyobj_dom;
6552 PyObject *pyobj_ret = NULL;
6553 PyObject *pyobj_conn;
6554 PyObject *dictKey;
6555 int ret = -1;
6557 LIBVIRT_ENSURE_THREAD_STATE;
6559 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6560 goto cleanup;
6561 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6562 Py_DECREF(dictKey);
6564 /* Create a python instance of this virDomainPtr */
6565 virDomainRef(dom);
6566 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6567 virDomainFree(dom);
6568 goto cleanup;
6570 Py_INCREF(pyobj_cbData);
6572 /* Call the Callback Dispatcher */
6573 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6574 (char*)"_dispatchDomainEventPMWakeupCallback",
6575 (char*)"OiO",
6576 pyobj_dom,
6577 reason,
6578 pyobj_cbData);
6580 Py_DECREF(pyobj_cbData);
6581 Py_DECREF(pyobj_dom);
6583 cleanup:
6584 if (!pyobj_ret) {
6585 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6586 PyErr_Print();
6587 } else {
6588 Py_DECREF(pyobj_ret);
6589 ret = 0;
6592 LIBVIRT_RELEASE_THREAD_STATE;
6593 return ret;
6596 static int
6597 libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6598 virDomainPtr dom,
6599 int reason,
6600 void *opaque)
6602 PyObject *pyobj_cbData = (PyObject*)opaque;
6603 PyObject *pyobj_dom;
6604 PyObject *pyobj_ret = NULL;
6605 PyObject *pyobj_conn;
6606 PyObject *dictKey;
6607 int ret = -1;
6609 LIBVIRT_ENSURE_THREAD_STATE;
6611 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6612 goto cleanup;
6613 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6614 Py_DECREF(dictKey);
6616 /* Create a python instance of this virDomainPtr */
6617 virDomainRef(dom);
6618 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6619 virDomainFree(dom);
6620 goto cleanup;
6622 Py_INCREF(pyobj_cbData);
6624 /* Call the Callback Dispatcher */
6625 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6626 (char*)"_dispatchDomainEventPMSuspendCallback",
6627 (char*)"OiO",
6628 pyobj_dom,
6629 reason,
6630 pyobj_cbData);
6632 Py_DECREF(pyobj_cbData);
6633 Py_DECREF(pyobj_dom);
6635 cleanup:
6636 if (!pyobj_ret) {
6637 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6638 PyErr_Print();
6639 } else {
6640 Py_DECREF(pyobj_ret);
6641 ret = 0;
6644 LIBVIRT_RELEASE_THREAD_STATE;
6645 return ret;
6649 #ifdef VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
6650 static int
6651 libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6652 virDomainPtr dom,
6653 unsigned long long actual,
6654 void *opaque)
6656 PyObject *pyobj_cbData = (PyObject*)opaque;
6657 PyObject *pyobj_dom;
6658 PyObject *pyobj_ret = NULL;
6659 PyObject *pyobj_conn;
6660 PyObject *dictKey;
6661 int ret = -1;
6663 LIBVIRT_ENSURE_THREAD_STATE;
6665 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6666 goto cleanup;
6667 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6668 Py_DECREF(dictKey);
6670 /* Create a python instance of this virDomainPtr */
6671 virDomainRef(dom);
6672 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6673 virDomainFree(dom);
6674 goto cleanup;
6676 Py_INCREF(pyobj_cbData);
6678 /* Call the Callback Dispatcher */
6679 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6680 (char*)"_dispatchDomainEventBalloonChangeCallback",
6681 (char*)"OLO",
6682 pyobj_dom,
6683 (PY_LONG_LONG)actual,
6684 pyobj_cbData);
6686 Py_DECREF(pyobj_cbData);
6687 Py_DECREF(pyobj_dom);
6689 cleanup:
6690 if (!pyobj_ret) {
6691 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6692 PyErr_Print();
6693 } else {
6694 Py_DECREF(pyobj_ret);
6695 ret = 0;
6698 LIBVIRT_RELEASE_THREAD_STATE;
6699 return ret;
6701 #endif /* VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE */
6703 #ifdef VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
6704 static int
6705 libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6706 virDomainPtr dom,
6707 int reason,
6708 void *opaque)
6710 PyObject *pyobj_cbData = (PyObject*)opaque;
6711 PyObject *pyobj_dom;
6712 PyObject *pyobj_ret = NULL;
6713 PyObject *pyobj_conn;
6714 PyObject *dictKey;
6715 int ret = -1;
6717 LIBVIRT_ENSURE_THREAD_STATE;
6719 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6720 goto cleanup;
6721 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6722 Py_DECREF(dictKey);
6724 /* Create a python instance of this virDomainPtr */
6725 virDomainRef(dom);
6726 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6727 virDomainFree(dom);
6728 goto cleanup;
6730 Py_INCREF(pyobj_cbData);
6732 /* Call the Callback Dispatcher */
6733 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6734 (char*)"_dispatchDomainEventPMSuspendDiskCallback",
6735 (char*)"OiO",
6736 pyobj_dom,
6737 reason,
6738 pyobj_cbData);
6740 Py_DECREF(pyobj_cbData);
6741 Py_DECREF(pyobj_dom);
6743 cleanup:
6744 if (!pyobj_ret) {
6745 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6746 PyErr_Print();
6747 } else {
6748 Py_DECREF(pyobj_ret);
6749 ret = 0;
6752 LIBVIRT_RELEASE_THREAD_STATE;
6753 return ret;
6755 #endif /* VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK */
6757 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
6758 static int
6759 libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6760 virDomainPtr dom,
6761 const char *devAlias,
6762 void *opaque)
6764 PyObject *pyobj_cbData = (PyObject*)opaque;
6765 PyObject *pyobj_dom;
6766 PyObject *pyobj_ret = NULL;
6767 PyObject *pyobj_conn;
6768 PyObject *dictKey;
6769 int ret = -1;
6771 LIBVIRT_ENSURE_THREAD_STATE;
6773 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6774 goto cleanup;
6775 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6776 Py_DECREF(dictKey);
6778 /* Create a python instance of this virDomainPtr */
6779 virDomainRef(dom);
6780 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6781 virDomainFree(dom);
6782 goto cleanup;
6784 Py_INCREF(pyobj_cbData);
6786 /* Call the Callback Dispatcher */
6787 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6788 (char*)"_dispatchDomainEventDeviceRemovedCallback",
6789 (char*)"OsO",
6790 pyobj_dom, devAlias, pyobj_cbData);
6792 Py_DECREF(pyobj_cbData);
6793 Py_DECREF(pyobj_dom);
6795 cleanup:
6796 if (!pyobj_ret) {
6797 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6798 PyErr_Print();
6799 } else {
6800 Py_DECREF(pyobj_ret);
6801 ret = 0;
6804 LIBVIRT_RELEASE_THREAD_STATE;
6805 return ret;
6807 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED */
6809 #ifdef VIR_DOMAIN_EVENT_ID_TUNABLE
6810 static int
6811 libvirt_virConnectDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6812 virDomainPtr dom,
6813 virTypedParameterPtr params,
6814 int nparams,
6815 void *opaque)
6817 PyObject *pyobj_cbData = (PyObject*)opaque;
6818 PyObject *pyobj_dom;
6819 PyObject *pyobj_ret = NULL;
6820 PyObject *pyobj_conn;
6821 PyObject *dictKey;
6822 PyObject *pyobj_dict = NULL;
6823 int ret = -1;
6825 LIBVIRT_ENSURE_THREAD_STATE;
6827 pyobj_dict = getPyVirTypedParameter(params, nparams);
6828 if (!pyobj_dict)
6829 goto cleanup;
6831 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6832 goto cleanup;
6833 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6834 Py_DECREF(dictKey);
6836 /* Create a python instance of this virDomainPtr */
6837 virDomainRef(dom);
6838 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6839 virDomainFree(dom);
6840 goto cleanup;
6842 Py_INCREF(pyobj_cbData);
6844 /* Call the Callback Dispatcher */
6845 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6846 (char*)"_dispatchDomainEventTunableCallback",
6847 (char*)"OOO",
6848 pyobj_dom, pyobj_dict, pyobj_cbData);
6850 Py_DECREF(pyobj_cbData);
6851 Py_DECREF(pyobj_dom);
6853 cleanup:
6854 if (!pyobj_ret) {
6855 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6856 PyErr_Print();
6857 } else {
6858 Py_DECREF(pyobj_ret);
6859 ret = 0;
6861 Py_XDECREF(pyobj_dict);
6863 LIBVIRT_RELEASE_THREAD_STATE;
6864 return ret;
6867 #endif /* VIR_DOMAIN_EVENT_ID_TUNABLE */
6869 #ifdef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
6870 static int
6871 libvirt_virConnectDomainEventAgentLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6872 virDomainPtr dom,
6873 int state,
6874 int reason,
6875 void *opaque)
6877 PyObject *pyobj_cbData = (PyObject*)opaque;
6878 PyObject *pyobj_dom;
6879 PyObject *pyobj_ret = NULL;
6880 PyObject *pyobj_conn;
6881 PyObject *dictKey;
6882 int ret = -1;
6884 LIBVIRT_ENSURE_THREAD_STATE;
6886 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6887 goto cleanup;
6888 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6889 Py_DECREF(dictKey);
6891 /* Create a python instance of this virDomainPtr */
6892 virDomainRef(dom);
6893 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6894 virDomainFree(dom);
6895 goto cleanup;
6897 Py_INCREF(pyobj_cbData);
6899 /* Call the Callback Dispatcher */
6900 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6901 (char*)"_dispatchDomainEventAgentLifecycleCallback",
6902 (char*)"OiiO",
6903 pyobj_dom, state, reason, pyobj_cbData);
6905 Py_DECREF(pyobj_cbData);
6906 Py_DECREF(pyobj_dom);
6908 cleanup:
6909 if (!pyobj_ret) {
6910 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6911 PyErr_Print();
6912 } else {
6913 Py_DECREF(pyobj_ret);
6914 ret = 0;
6917 LIBVIRT_RELEASE_THREAD_STATE;
6918 return ret;
6921 #endif /* VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE */
6923 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
6924 static int
6925 libvirt_virConnectDomainEventDeviceAddedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6926 virDomainPtr dom,
6927 const char *devAlias,
6928 void *opaque)
6930 PyObject *pyobj_cbData = (PyObject*)opaque;
6931 PyObject *pyobj_dom;
6932 PyObject *pyobj_ret = NULL;
6933 PyObject *pyobj_conn;
6934 PyObject *dictKey;
6935 int ret = -1;
6937 LIBVIRT_ENSURE_THREAD_STATE;
6939 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6940 goto cleanup;
6941 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6942 Py_DECREF(dictKey);
6944 /* Create a python instance of this virDomainPtr */
6945 virDomainRef(dom);
6946 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6947 virDomainFree(dom);
6948 goto cleanup;
6950 Py_INCREF(pyobj_cbData);
6952 /* Call the Callback Dispatcher */
6953 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6954 (char*)"_dispatchDomainEventDeviceAddedCallback",
6955 (char*)"OsO",
6956 pyobj_dom, devAlias, pyobj_cbData);
6958 Py_DECREF(pyobj_cbData);
6959 Py_DECREF(pyobj_dom);
6961 cleanup:
6962 if (!pyobj_ret) {
6963 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6964 PyErr_Print();
6965 } else {
6966 Py_DECREF(pyobj_ret);
6967 ret = 0;
6970 LIBVIRT_RELEASE_THREAD_STATE;
6971 return ret;
6974 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_ADDED */
6976 #ifdef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
6977 static int
6978 libvirt_virConnectDomainEventMigrationIterationCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6979 virDomainPtr dom,
6980 int iteration,
6981 void *opaque)
6983 PyObject *pyobj_cbData = (PyObject*)opaque;
6984 PyObject *pyobj_dom;
6985 PyObject *pyobj_ret = NULL;
6986 PyObject *pyobj_conn;
6987 PyObject *dictKey;
6988 int ret = -1;
6990 LIBVIRT_ENSURE_THREAD_STATE;
6992 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6993 goto cleanup;
6994 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6995 Py_DECREF(dictKey);
6997 /* Create a python instance of this virDomainPtr */
6998 virDomainRef(dom);
6999 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7000 virDomainFree(dom);
7001 goto cleanup;
7003 Py_INCREF(pyobj_cbData);
7005 /* Call the Callback Dispatcher */
7006 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7007 (char*)"_dispatchDomainEventMigrationIterationCallback",
7008 (char*)"OiO",
7009 pyobj_dom, iteration, pyobj_cbData);
7011 Py_DECREF(pyobj_cbData);
7012 Py_DECREF(pyobj_dom);
7014 cleanup:
7015 if (!pyobj_ret) {
7016 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7017 PyErr_Print();
7018 } else {
7019 Py_DECREF(pyobj_ret);
7020 ret = 0;
7023 LIBVIRT_RELEASE_THREAD_STATE;
7024 return ret;
7026 #endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
7028 #ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
7029 static int
7030 libvirt_virConnectDomainEventJobCompletedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7031 virDomainPtr dom,
7032 virTypedParameterPtr params,
7033 int nparams,
7034 void *opaque)
7036 PyObject *pyobj_cbData = (PyObject*)opaque;
7037 PyObject *pyobj_dom;
7038 PyObject *pyobj_ret = NULL;
7039 PyObject *pyobj_conn;
7040 PyObject *dictKey;
7041 PyObject *pyobj_dict = NULL;
7042 int ret = -1;
7044 LIBVIRT_ENSURE_THREAD_STATE;
7046 pyobj_dict = getPyVirTypedParameter(params, nparams);
7047 if (!pyobj_dict)
7048 goto cleanup;
7050 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7051 goto cleanup;
7052 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7053 Py_DECREF(dictKey);
7055 /* Create a python instance of this virDomainPtr */
7056 virDomainRef(dom);
7057 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7058 virDomainFree(dom);
7059 goto cleanup;
7061 Py_INCREF(pyobj_cbData);
7063 /* Call the Callback Dispatcher */
7064 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7065 (char*)"_dispatchDomainEventJobCompletedCallback",
7066 (char*)"OOO",
7067 pyobj_dom, pyobj_dict, pyobj_cbData);
7069 Py_DECREF(pyobj_cbData);
7070 Py_DECREF(pyobj_dom);
7072 cleanup:
7073 if (!pyobj_ret) {
7074 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7075 PyErr_Print();
7076 Py_XDECREF(pyobj_dict);
7077 } else {
7078 Py_DECREF(pyobj_ret);
7079 ret = 0;
7082 LIBVIRT_RELEASE_THREAD_STATE;
7083 return ret;
7085 #endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
7088 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
7089 static int
7090 libvirt_virConnectDomainEventDeviceRemovalFailedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7091 virDomainPtr dom,
7092 const char *devAlias,
7093 void *opaque)
7095 PyObject *pyobj_cbData = (PyObject*)opaque;
7096 PyObject *pyobj_dom;
7097 PyObject *pyobj_ret = NULL;
7098 PyObject *pyobj_conn;
7099 PyObject *dictKey;
7100 int ret = -1;
7102 LIBVIRT_ENSURE_THREAD_STATE;
7104 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7105 goto cleanup;
7106 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7107 Py_DECREF(dictKey);
7109 /* Create a python instance of this virDomainPtr */
7110 virDomainRef(dom);
7111 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7112 virDomainFree(dom);
7113 goto cleanup;
7115 Py_INCREF(pyobj_cbData);
7117 /* Call the Callback Dispatcher */
7118 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7119 (char*)"_dispatchDomainEventDeviceRemovalFailedCallback",
7120 (char*)"OsO",
7121 pyobj_dom, devAlias, pyobj_cbData);
7123 Py_DECREF(pyobj_cbData);
7124 Py_DECREF(pyobj_dom);
7126 cleanup:
7127 if (!pyobj_ret) {
7128 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7129 PyErr_Print();
7130 } else {
7131 Py_DECREF(pyobj_ret);
7132 ret = 0;
7135 LIBVIRT_RELEASE_THREAD_STATE;
7136 return ret;
7139 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED */
7141 #ifdef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
7142 static int
7143 libvirt_virConnectDomainEventMetadataChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7144 virDomainPtr dom,
7145 int type,
7146 const char *nsuri,
7147 void *opaque)
7149 PyObject *pyobj_cbData = (PyObject*)opaque;
7150 PyObject *pyobj_dom;
7151 PyObject *pyobj_ret = NULL;
7152 PyObject *pyobj_conn;
7153 PyObject *dictKey;
7154 int ret = -1;
7156 LIBVIRT_ENSURE_THREAD_STATE;
7158 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7159 goto cleanup;
7160 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7161 Py_DECREF(dictKey);
7163 /* Create a python instance of this virDomainPtr */
7164 virDomainRef(dom);
7165 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7166 virDomainFree(dom);
7167 goto cleanup;
7169 Py_INCREF(pyobj_cbData);
7171 /* Call the Callback Dispatcher */
7172 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7173 (char*)"_dispatchDomainEventMetadataChangeCallback",
7174 (char*)"OisO",
7175 pyobj_dom, type, nsuri, pyobj_cbData);
7177 Py_DECREF(pyobj_cbData);
7178 Py_DECREF(pyobj_dom);
7180 cleanup:
7181 if (!pyobj_ret) {
7182 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7183 PyErr_Print();
7184 } else {
7185 Py_DECREF(pyobj_ret);
7186 ret = 0;
7189 LIBVIRT_RELEASE_THREAD_STATE;
7190 return ret;
7192 #endif /* VIR_DOMAIN_EVENT_ID_METADATA_CHANGE */
7194 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
7195 static int
7196 libvirt_virConnectDomainEventBlockThresholdCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7197 virDomainPtr dom,
7198 const char *dev,
7199 const char *path,
7200 unsigned long long threshold,
7201 unsigned long long excess,
7202 void *opaque)
7204 PyObject *pyobj_cbData = (PyObject*)opaque;
7205 PyObject *pyobj_dom;
7206 PyObject *pyobj_ret = NULL;
7207 PyObject *pyobj_conn;
7208 PyObject *dictKey;
7209 int ret = -1;
7211 LIBVIRT_ENSURE_THREAD_STATE;
7213 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7214 goto cleanup;
7215 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7216 Py_DECREF(dictKey);
7218 /* Create a python instance of this virDomainPtr */
7219 virDomainRef(dom);
7220 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
7221 virDomainFree(dom);
7222 goto cleanup;
7224 Py_INCREF(pyobj_cbData);
7226 /* Call the Callback Dispatcher */
7227 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7228 (char*)"_dispatchDomainEventBlockThresholdCallback",
7229 (char*)"OssiiO",
7230 pyobj_dom, dev, path, threshold, excess,
7231 pyobj_cbData);
7233 Py_DECREF(pyobj_cbData);
7234 Py_DECREF(pyobj_dom);
7236 cleanup:
7237 if (!pyobj_ret) {
7238 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7239 PyErr_Print();
7240 } else {
7241 Py_DECREF(pyobj_ret);
7242 ret = 0;
7245 LIBVIRT_RELEASE_THREAD_STATE;
7246 return ret;
7248 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
7251 static PyObject *
7252 libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
7253 PyObject *args)
7255 PyObject *py_retval; /* return value */
7256 PyObject *pyobj_conn; /* virConnectPtr */
7257 PyObject *pyobj_dom;
7258 PyObject *pyobj_cbData; /* hash of callback data */
7259 int eventID;
7260 virConnectPtr conn;
7261 int ret = 0;
7262 virConnectDomainEventGenericCallback cb = NULL;
7263 virDomainPtr dom;
7265 if (!PyArg_ParseTuple(args,
7266 (char *) "OOiO:virConnectDomainEventRegisterAny",
7267 &pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData))
7268 return NULL;
7270 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
7271 pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
7272 conn = PyvirConnect_Get(pyobj_conn);
7273 if (pyobj_dom == Py_None)
7274 dom = NULL;
7275 else
7276 dom = PyvirDomain_Get(pyobj_dom);
7278 switch ((virDomainEventID) eventID) {
7279 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
7280 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback);
7281 break;
7282 case VIR_DOMAIN_EVENT_ID_REBOOT:
7283 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
7284 break;
7285 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
7286 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback);
7287 break;
7288 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
7289 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback);
7290 break;
7291 case VIR_DOMAIN_EVENT_ID_IO_ERROR:
7292 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback);
7293 break;
7294 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
7295 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback);
7296 break;
7297 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
7298 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback);
7299 break;
7300 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
7301 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
7302 break;
7303 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
7304 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
7305 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2:
7306 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 */
7307 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback);
7308 break;
7309 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
7310 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
7311 break;
7312 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
7313 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
7314 break;
7315 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
7316 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
7317 break;
7318 case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
7319 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
7320 break;
7321 #ifdef VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
7322 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
7323 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback);
7324 break;
7325 #endif /* VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE */
7326 #ifdef VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
7327 case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
7328 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback);
7329 break;
7330 #endif /* VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK */
7331 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
7332 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
7333 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback);
7334 break;
7335 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED */
7336 #ifdef VIR_DOMAIN_EVENT_ID_TUNABLE
7337 case VIR_DOMAIN_EVENT_ID_TUNABLE:
7338 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTunableCallback);
7339 break;
7340 #endif /* VIR_DOMAIN_EVENT_ID_TUNABLE */
7341 #ifdef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
7342 case VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE:
7343 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventAgentLifecycleCallback);
7344 break;
7345 #endif /* VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE */
7346 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
7347 case VIR_DOMAIN_EVENT_ID_DEVICE_ADDED:
7348 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceAddedCallback);
7349 break;
7350 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_ADDED */
7351 #ifdef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
7352 case VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION:
7353 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMigrationIterationCallback);
7354 break;
7355 #endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
7356 #ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
7357 case VIR_DOMAIN_EVENT_ID_JOB_COMPLETED:
7358 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventJobCompletedCallback);
7359 break;
7360 #endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
7361 #ifdef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
7362 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED:
7363 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovalFailedCallback);
7364 break;
7365 #endif /* VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED */
7366 #ifdef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
7367 case VIR_DOMAIN_EVENT_ID_METADATA_CHANGE:
7368 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMetadataChangeCallback);
7369 break;
7370 #endif /* VIR_DOMAIN_EVENT_ID_METADATA_CHANGE */
7371 #ifdef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
7372 case VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD:
7373 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockThresholdCallback);
7374 break;
7375 #endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
7376 case VIR_DOMAIN_EVENT_ID_LAST:
7377 break;
7380 if (!cb) {
7381 return VIR_PY_INT_FAIL;
7384 Py_INCREF(pyobj_cbData);
7386 LIBVIRT_BEGIN_ALLOW_THREADS;
7387 ret = virConnectDomainEventRegisterAny(conn, dom, eventID,
7388 cb, pyobj_cbData,
7389 libvirt_virConnectDomainEventFreeFunc);
7390 LIBVIRT_END_ALLOW_THREADS;
7392 if (ret < 0) {
7393 Py_DECREF(pyobj_cbData);
7396 py_retval = libvirt_intWrap(ret);
7397 return py_retval;
7400 static PyObject *
7401 libvirt_virConnectDomainEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
7402 PyObject *args)
7404 PyObject *pyobj_conn;
7405 int callbackID;
7406 virConnectPtr conn;
7407 int ret = 0;
7409 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectDomainEventDeregister",
7410 &pyobj_conn, &callbackID))
7411 return NULL;
7413 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
7415 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7417 LIBVIRT_BEGIN_ALLOW_THREADS;
7418 ret = virConnectDomainEventDeregisterAny(conn, callbackID);
7419 LIBVIRT_END_ALLOW_THREADS;
7421 return libvirt_intWrap(ret);
7424 #if LIBVIR_CHECK_VERSION(1, 2, 1)
7425 static void
7426 libvirt_virConnectNetworkEventFreeFunc(void *opaque)
7428 PyObject *pyobj_conn = (PyObject*)opaque;
7429 LIBVIRT_ENSURE_THREAD_STATE;
7430 Py_DECREF(pyobj_conn);
7431 LIBVIRT_RELEASE_THREAD_STATE;
7434 static int
7435 libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
7436 virNetworkPtr net,
7437 int event,
7438 int detail,
7439 void *opaque)
7441 PyObject *pyobj_cbData = (PyObject*)opaque;
7442 PyObject *pyobj_net;
7443 PyObject *pyobj_ret = NULL;
7444 PyObject *pyobj_conn;
7445 PyObject *dictKey;
7446 int ret = -1;
7448 LIBVIRT_ENSURE_THREAD_STATE;
7450 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
7451 goto cleanup;
7452 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7453 Py_DECREF(dictKey);
7455 /* Create a python instance of this virNetworkPtr */
7456 virNetworkRef(net);
7457 if (!(pyobj_net = libvirt_virNetworkPtrWrap(net))) {
7458 virNetworkFree(net);
7459 goto cleanup;
7461 Py_INCREF(pyobj_cbData);
7463 /* Call the Callback Dispatcher */
7464 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7465 (char*)"_dispatchNetworkEventLifecycleCallback",
7466 (char*)"OiiO",
7467 pyobj_net,
7468 event,
7469 detail,
7470 pyobj_cbData);
7472 Py_DECREF(pyobj_cbData);
7473 Py_DECREF(pyobj_net);
7475 cleanup:
7476 if (!pyobj_ret) {
7477 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7478 PyErr_Print();
7479 } else {
7480 Py_DECREF(pyobj_ret);
7481 ret = 0;
7484 LIBVIRT_RELEASE_THREAD_STATE;
7485 return ret;
7488 static PyObject *
7489 libvirt_virConnectNetworkEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
7490 PyObject *args)
7492 PyObject *pyobj_conn; /* virConnectPtr */
7493 PyObject *pyobj_net;
7494 PyObject *pyobj_cbData; /* hash of callback data */
7495 int eventID;
7496 virConnectPtr conn;
7497 int ret = 0;
7498 virConnectNetworkEventGenericCallback cb = NULL;
7499 virNetworkPtr net;
7501 if (!PyArg_ParseTuple(args,
7502 (char *) "OOiO:virConnectNetworkEventRegisterAny",
7503 &pyobj_conn, &pyobj_net, &eventID, &pyobj_cbData))
7504 return NULL;
7506 DEBUG("libvirt_virConnectNetworkEventRegister(%p %p %d %p) called\n",
7507 pyobj_conn, pyobj_net, eventID, pyobj_cbData);
7508 conn = PyvirConnect_Get(pyobj_conn);
7509 if (pyobj_net == Py_None)
7510 net = NULL;
7511 else
7512 net = PyvirNetwork_Get(pyobj_net);
7514 switch ((virNetworkEventID) eventID) {
7515 case VIR_NETWORK_EVENT_ID_LIFECYCLE:
7516 cb = VIR_NETWORK_EVENT_CALLBACK(libvirt_virConnectNetworkEventLifecycleCallback);
7517 break;
7519 case VIR_NETWORK_EVENT_ID_LAST:
7520 break;
7523 if (!cb) {
7524 return VIR_PY_INT_FAIL;
7527 Py_INCREF(pyobj_cbData);
7529 LIBVIRT_BEGIN_ALLOW_THREADS;
7530 ret = virConnectNetworkEventRegisterAny(conn, net, eventID,
7531 cb, pyobj_cbData,
7532 libvirt_virConnectNetworkEventFreeFunc);
7533 LIBVIRT_END_ALLOW_THREADS;
7535 if (ret < 0) {
7536 Py_DECREF(pyobj_cbData);
7539 return libvirt_intWrap(ret);
7542 static PyObject *
7543 libvirt_virConnectNetworkEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
7544 PyObject *args)
7546 PyObject *pyobj_conn;
7547 int callbackID;
7548 virConnectPtr conn;
7549 int ret = 0;
7551 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectNetworkEventDeregister",
7552 &pyobj_conn, &callbackID))
7553 return NULL;
7555 DEBUG("libvirt_virConnectNetworkEventDeregister(%p) called\n", pyobj_conn);
7557 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7559 LIBVIRT_BEGIN_ALLOW_THREADS;
7560 ret = virConnectNetworkEventDeregisterAny(conn, callbackID);
7561 LIBVIRT_END_ALLOW_THREADS;
7563 return libvirt_intWrap(ret);
7565 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1)*/
7567 #if LIBVIR_CHECK_VERSION(0, 10, 0)
7568 static void
7569 libvirt_virConnectCloseCallbackDispatch(virConnectPtr conn ATTRIBUTE_UNUSED,
7570 int reason,
7571 void *opaque)
7573 PyObject *pyobj_cbData = (PyObject*)opaque;
7574 PyObject *pyobj_ret;
7575 PyObject *pyobj_conn;
7576 PyObject *dictKey;
7578 LIBVIRT_ENSURE_THREAD_STATE;
7580 Py_INCREF(pyobj_cbData);
7582 dictKey = libvirt_constcharPtrWrap("conn");
7583 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
7584 Py_DECREF(dictKey);
7586 /* Call the Callback Dispatcher */
7587 pyobj_ret = PyObject_CallMethod(pyobj_conn,
7588 (char*)"_dispatchCloseCallback",
7589 (char*)"iO",
7590 reason,
7591 pyobj_cbData);
7593 Py_DECREF(pyobj_cbData);
7595 if (!pyobj_ret) {
7596 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7597 PyErr_Print();
7598 } else {
7599 Py_DECREF(pyobj_ret);
7602 LIBVIRT_RELEASE_THREAD_STATE;
7605 static PyObject *
7606 libvirt_virConnectRegisterCloseCallback(PyObject *self ATTRIBUTE_UNUSED,
7607 PyObject *args)
7609 PyObject *pyobj_conn; /* virConnectPtr */
7610 PyObject *pyobj_cbData; /* hash of callback data */
7611 virConnectPtr conn;
7612 int ret = 0;
7614 if (!PyArg_ParseTuple(args, (char *) "OO:virConnectRegisterCloseCallback",
7615 &pyobj_conn, &pyobj_cbData))
7616 return NULL;
7618 DEBUG("libvirt_virConnectRegisterCloseCallback(%p %p) called\n",
7619 pyobj_conn, pyobj_cbData);
7620 conn = PyvirConnect_Get(pyobj_conn);
7622 Py_INCREF(pyobj_cbData);
7624 LIBVIRT_BEGIN_ALLOW_THREADS;
7625 ret = virConnectRegisterCloseCallback(conn,
7626 libvirt_virConnectCloseCallbackDispatch,
7627 pyobj_cbData,
7628 libvirt_virConnectDomainEventFreeFunc);
7629 LIBVIRT_END_ALLOW_THREADS;
7631 if (ret < 0) {
7632 Py_DECREF(pyobj_cbData);
7635 return libvirt_intWrap(ret);
7638 static PyObject *
7639 libvirt_virConnectUnregisterCloseCallback(PyObject * self ATTRIBUTE_UNUSED,
7640 PyObject * args)
7642 PyObject *pyobj_conn;
7643 virConnectPtr conn;
7644 int ret = 0;
7646 if (!PyArg_ParseTuple(args, (char *) "O:virConnectUnregisterCloseCallback",
7647 &pyobj_conn))
7648 return NULL;
7650 DEBUG("libvirt_virConnectDomainEventUnregister(%p) called\n",
7651 pyobj_conn);
7653 conn = PyvirConnect_Get(pyobj_conn);
7655 LIBVIRT_BEGIN_ALLOW_THREADS;
7656 ret = virConnectUnregisterCloseCallback(conn,
7657 libvirt_virConnectCloseCallbackDispatch);
7658 LIBVIRT_END_ALLOW_THREADS;
7660 return libvirt_intWrap(ret);
7662 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
7664 static void
7665 libvirt_virStreamEventFreeFunc(void *opaque)
7667 PyObject *pyobj_stream = (PyObject*)opaque;
7668 LIBVIRT_ENSURE_THREAD_STATE;
7669 Py_DECREF(pyobj_stream);
7670 LIBVIRT_RELEASE_THREAD_STATE;
7673 static void
7674 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED,
7675 int events,
7676 void *opaque)
7678 PyObject *pyobj_cbData = (PyObject *)opaque;
7679 PyObject *pyobj_stream;
7680 PyObject *pyobj_ret;
7681 PyObject *dictKey;
7683 LIBVIRT_ENSURE_THREAD_STATE;
7685 Py_INCREF(pyobj_cbData);
7686 dictKey = libvirt_constcharPtrWrap("stream");
7687 pyobj_stream = PyDict_GetItem(pyobj_cbData, dictKey);
7688 Py_DECREF(dictKey);
7690 /* Call the pure python dispatcher */
7691 pyobj_ret = PyObject_CallMethod(pyobj_stream,
7692 (char *)"_dispatchStreamEventCallback",
7693 (char *)"iO",
7694 events, pyobj_cbData);
7696 Py_DECREF(pyobj_cbData);
7698 if (!pyobj_ret) {
7699 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
7700 PyErr_Print();
7701 } else {
7702 Py_DECREF(pyobj_ret);
7705 LIBVIRT_RELEASE_THREAD_STATE;
7708 static PyObject *
7709 libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
7710 PyObject *args)
7712 PyObject *pyobj_stream;
7713 PyObject *pyobj_cbData;
7714 virStreamPtr stream;
7715 virStreamEventCallback cb = libvirt_virStreamEventCallback;
7716 int ret;
7717 int events;
7719 if (!PyArg_ParseTuple(args, (char *) "OiO:virStreamEventAddCallback",
7720 &pyobj_stream, &events, &pyobj_cbData))
7721 return NULL;
7723 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
7724 pyobj_stream, events, pyobj_cbData);
7725 stream = PyvirStream_Get(pyobj_stream);
7727 Py_INCREF(pyobj_cbData);
7729 LIBVIRT_BEGIN_ALLOW_THREADS;
7730 ret = virStreamEventAddCallback(stream, events, cb, pyobj_cbData,
7731 libvirt_virStreamEventFreeFunc);
7732 LIBVIRT_END_ALLOW_THREADS;
7734 if (ret < 0) {
7735 Py_DECREF(pyobj_cbData);
7738 return libvirt_intWrap(ret);
7741 static PyObject *
7742 libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
7743 PyObject *args)
7745 PyObject *pyobj_stream;
7746 PyObject *rv;
7747 virStreamPtr stream;
7748 char *buf = NULL;
7749 int ret;
7750 int nbytes;
7752 if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
7753 &pyobj_stream, &nbytes)) {
7754 return NULL;
7756 stream = PyvirStream_Get(pyobj_stream);
7758 if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0)
7759 return PyErr_NoMemory();
7761 LIBVIRT_BEGIN_ALLOW_THREADS;
7762 ret = virStreamRecv(stream, buf, nbytes);
7763 LIBVIRT_END_ALLOW_THREADS;
7765 buf[ret > -1 ? ret : 0] = '\0';
7766 DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
7768 if (ret == -2)
7769 return libvirt_intWrap(ret);
7770 if (ret < 0)
7771 return VIR_PY_NONE;
7772 rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
7773 VIR_FREE(buf);
7774 return rv;
7777 static PyObject *
7778 libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
7779 PyObject *args)
7781 PyObject *pyobj_stream;
7782 PyObject *pyobj_data;
7783 virStreamPtr stream;
7784 char *data;
7785 Py_ssize_t datalen;
7786 int ret;
7788 if (!PyArg_ParseTuple(args, (char *) "OO:virStreamSend",
7789 &pyobj_stream, &pyobj_data))
7790 return NULL;
7792 stream = PyvirStream_Get(pyobj_stream);
7793 libvirt_charPtrSizeUnwrap(pyobj_data, &data, &datalen);
7795 LIBVIRT_BEGIN_ALLOW_THREADS;
7796 ret = virStreamSend(stream, data, datalen);
7797 LIBVIRT_END_ALLOW_THREADS;
7799 DEBUG("StreamSend ret=%d\n", ret);
7801 return libvirt_intWrap(ret);
7804 static PyObject *
7805 libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
7806 PyObject *args)
7808 virDomainPtr domain;
7809 PyObject *pyobj_domain;
7810 PyObject *pyobj_list;
7811 int codeset;
7812 int holdtime;
7813 unsigned int flags;
7814 int ret;
7815 ssize_t i;
7816 unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
7817 unsigned int nkeycodes;
7819 if (!PyArg_ParseTuple(args, (char *)"OiiOII:virDomainSendKey",
7820 &pyobj_domain, &codeset, &holdtime, &pyobj_list,
7821 &nkeycodes, &flags))
7822 return NULL;
7824 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7826 if (!PyList_Check(pyobj_list)) {
7827 return VIR_PY_INT_FAIL;
7830 if (nkeycodes != PyList_Size(pyobj_list) ||
7831 nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
7832 return VIR_PY_INT_FAIL;
7835 for (i = 0; i < nkeycodes; i++) {
7836 if (libvirt_uintUnwrap(PyList_GetItem(pyobj_list, i), &keycodes[i]) < 0)
7837 return NULL;
7840 LIBVIRT_BEGIN_ALLOW_THREADS;
7841 ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
7842 LIBVIRT_END_ALLOW_THREADS;
7844 DEBUG("virDomainSendKey ret=%d\n", ret);
7846 return libvirt_intWrap(ret);
7849 #if LIBVIR_CHECK_VERSION(1, 0, 3)
7850 static PyObject *
7851 libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED,
7852 PyObject *args)
7854 PyObject *pyobj_domain;
7855 virDomainPtr domain;
7856 unsigned int flags;
7857 unsigned long long cacheSize;
7858 int rc;
7860 if (!PyArg_ParseTuple(args,
7861 (char *) "OI:virDomainMigrateGetCompressionCache",
7862 &pyobj_domain, &flags))
7863 return NULL;
7865 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7867 LIBVIRT_BEGIN_ALLOW_THREADS;
7868 rc = virDomainMigrateGetCompressionCache(domain, &cacheSize, flags);
7869 LIBVIRT_END_ALLOW_THREADS;
7871 if (rc < 0)
7872 return VIR_PY_NONE;
7874 return libvirt_ulonglongWrap(cacheSize);
7876 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
7878 static PyObject *
7879 libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED,
7880 PyObject *args)
7882 int c_retval;
7883 unsigned long bandwidth;
7884 virDomainPtr domain;
7885 PyObject *pyobj_domain;
7886 unsigned int flags = 0;
7888 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainMigrateGetMaxSpeed",
7889 &pyobj_domain, &flags))
7890 return NULL;
7892 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7894 LIBVIRT_BEGIN_ALLOW_THREADS;
7895 c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, flags);
7896 LIBVIRT_END_ALLOW_THREADS;
7898 if (c_retval < 0)
7899 return VIR_PY_INT_FAIL;
7901 return libvirt_ulongWrap(bandwidth);
7904 #if LIBVIR_CHECK_VERSION(3, 7, 0)
7905 static PyObject *
7906 libvirt_virDomainMigrateGetMaxDowntime(PyObject *self ATTRIBUTE_UNUSED,
7907 PyObject *args)
7909 PyObject *pyobj_domain;
7910 virDomainPtr domain;
7911 unsigned int flags;
7912 unsigned long long downtime;
7913 int rc;
7915 if (!PyArg_ParseTuple(args,
7916 (char *) "OI:virDomainMigrateGetMaxDowntime",
7917 &pyobj_domain, &flags))
7918 return NULL;
7920 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7922 LIBVIRT_BEGIN_ALLOW_THREADS;
7923 rc = virDomainMigrateGetMaxDowntime(domain, &downtime, flags);
7924 LIBVIRT_END_ALLOW_THREADS;
7926 if (rc < 0)
7927 return VIR_PY_NONE;
7929 return libvirt_ulonglongWrap(downtime);
7931 #endif /* LIBVIR_CHECK_VERSION(3, 7, 0) */
7933 #if LIBVIR_CHECK_VERSION(1, 1, 0)
7934 static virPyTypedParamsHint virPyDomainMigrate3Params[] = {
7935 # ifdef VIR_MIGRATE_PARAM_URI
7936 { VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING },
7937 # endif
7938 # ifdef VIR_MIGRATE_PARAM_DEST_NAME
7939 { VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING },
7940 # endif
7941 # ifdef VIR_MIGRATE_PARAM_DEST_XML
7942 { VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING },
7943 # endif
7944 # ifdef VIR_MIGRATE_PARAM_PERSIST_XML
7945 { VIR_MIGRATE_PARAM_PERSIST_XML, VIR_TYPED_PARAM_STRING },
7946 # endif
7947 # ifdef VIR_MIGRATE_PARAM_BANDWIDTH
7948 { VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG },
7949 # endif
7950 # ifdef VIR_MIGRATE_PARAM_GRAPHICS_URI
7951 { VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING },
7952 # endif
7953 # ifdef VIR_MIGRATE_PARAM_LISTEN_ADDRESS
7954 { VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING },
7955 # endif
7956 # ifdef VIR_MIGRATE_PARAM_MIGRATE_DISKS
7957 { VIR_MIGRATE_PARAM_MIGRATE_DISKS, VIR_TYPED_PARAM_STRING },
7958 # endif
7959 # ifdef VIR_MIGRATE_PARAM_DISKS_PORT
7960 { VIR_MIGRATE_PARAM_DISKS_PORT, VIR_TYPED_PARAM_INT },
7961 # endif
7962 # ifdef VIR_MIGRATE_PARAM_COMPRESSION
7963 { VIR_MIGRATE_PARAM_COMPRESSION, VIR_TYPED_PARAM_STRING },
7964 # endif
7965 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL
7966 { VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL, VIR_TYPED_PARAM_INT },
7967 # endif
7968 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS
7969 { VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS, VIR_TYPED_PARAM_INT },
7970 # endif
7971 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS
7972 { VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS, VIR_TYPED_PARAM_INT },
7973 # endif
7974 # ifdef VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE
7975 { VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE, VIR_TYPED_PARAM_ULLONG },
7976 # endif
7977 # ifdef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL
7978 { VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL, VIR_TYPED_PARAM_INT },
7979 # endif
7980 # ifdef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT
7981 { VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT, VIR_TYPED_PARAM_INT },
7982 # endif
7986 static PyObject *
7987 libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
7988 PyObject *args)
7990 PyObject *pyobj_domain;
7991 virDomainPtr domain;
7992 PyObject *pyobj_dconn;
7993 virConnectPtr dconn;
7994 PyObject *dict;
7995 unsigned int flags;
7996 virTypedParameterPtr params;
7997 int nparams = 0;
7998 virDomainPtr ddom = NULL;
8000 if (!PyArg_ParseTuple(args, (char *) "OOOI:virDomainMigrate3",
8001 &pyobj_domain, &pyobj_dconn, &dict, &flags))
8002 return NULL;
8004 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8005 dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);
8007 if (!PyDict_Check(dict)) {
8008 PyErr_Format(PyExc_TypeError, "migration params must be a dictionary");
8009 return NULL;
8012 if (virPyDictToTypedParams(dict, &params, &nparams,
8013 virPyDomainMigrate3Params,
8014 VIR_N_ELEMENTS(virPyDomainMigrate3Params)) < 0) {
8015 return NULL;
8018 LIBVIRT_BEGIN_ALLOW_THREADS;
8019 ddom = virDomainMigrate3(domain, dconn, params, nparams, flags);
8020 LIBVIRT_END_ALLOW_THREADS;
8022 virTypedParamsFree(params, nparams);
8023 return libvirt_virDomainPtrWrap(ddom);
8026 static PyObject *
8027 libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,
8028 PyObject *args)
8030 PyObject *pyobj_domain;
8031 virDomainPtr domain;
8032 char *dconnuri;
8033 PyObject *dict;
8034 unsigned int flags;
8035 virTypedParameterPtr params;
8036 int nparams;
8037 int ret = -1;
8039 if (!PyArg_ParseTuple(args, (char *) "OzOI:virDomainMigrate3",
8040 &pyobj_domain, &dconnuri, &dict, &flags))
8041 return NULL;
8043 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8045 if (!PyDict_Check(dict)) {
8046 PyErr_Format(PyExc_TypeError, "migration params must be a dictionary");
8047 return NULL;
8050 if (virPyDictToTypedParams(dict, &params, &nparams,
8051 virPyDomainMigrate3Params,
8052 VIR_N_ELEMENTS(virPyDomainMigrate3Params)) < 0) {
8053 return NULL;
8056 LIBVIRT_BEGIN_ALLOW_THREADS;
8057 ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
8058 LIBVIRT_END_ALLOW_THREADS;
8060 virTypedParamsFree(params, nparams);
8061 return libvirt_intWrap(ret);
8063 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
8065 static PyObject *
8066 libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED,
8067 PyObject *args)
8069 PyObject *py_retval = NULL;
8070 int c_retval;
8071 virDomainPtr domain;
8072 PyObject *pyobj_domain;
8073 const char *disk;
8074 unsigned long long offset;
8075 size_t size;
8076 char *buf;
8077 unsigned int flags;
8079 if (!PyArg_ParseTuple(args, (char *)"OzKkI:virDomainBlockPeek",
8080 &pyobj_domain, &disk, &offset, &size, &flags))
8081 return NULL;
8083 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8085 if (VIR_ALLOC_N(buf, size) < 0)
8086 return PyErr_NoMemory();
8088 LIBVIRT_BEGIN_ALLOW_THREADS;
8089 c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags);
8090 LIBVIRT_END_ALLOW_THREADS;
8092 if (c_retval < 0) {
8093 py_retval = VIR_PY_NONE;
8094 goto cleanup;
8097 py_retval = libvirt_charPtrSizeWrap(buf, size);
8099 cleanup:
8100 VIR_FREE(buf);
8101 return py_retval;
8104 static PyObject *
8105 libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED,
8106 PyObject *args)
8108 PyObject *py_retval = NULL;
8109 int c_retval;
8110 virDomainPtr domain;
8111 PyObject *pyobj_domain;
8112 unsigned long long start;
8113 size_t size;
8114 char *buf;
8115 unsigned int flags;
8117 if (!PyArg_ParseTuple(args, (char *)"OKkI:virDomainMemoryPeek",
8118 &pyobj_domain, &start, &size, &flags))
8119 return NULL;
8121 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8123 if (VIR_ALLOC_N(buf, size) < 0)
8124 return PyErr_NoMemory();
8126 LIBVIRT_BEGIN_ALLOW_THREADS;
8127 c_retval = virDomainMemoryPeek(domain, start, size, buf, flags);
8128 LIBVIRT_END_ALLOW_THREADS;
8130 if (c_retval < 0) {
8131 py_retval = VIR_PY_NONE;
8132 goto cleanup;
8135 py_retval = libvirt_charPtrSizeWrap(buf, size);
8137 cleanup:
8138 VIR_FREE(buf);
8139 return py_retval;
8142 #if LIBVIR_CHECK_VERSION(0, 10, 2)
8143 static PyObject *
8144 libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
8145 PyObject *args)
8147 virConnectPtr conn;
8148 PyObject *pyobj_conn, *info;
8149 PyObject *ret = NULL;
8150 int i_retval;
8151 int nparams = 0;
8152 Py_ssize_t size = 0;
8153 unsigned int flags;
8154 virTypedParameterPtr params = NULL, new_params = NULL;
8156 if (!PyArg_ParseTuple(args,
8157 (char *)"OOI:virNodeSetMemoryParameters",
8158 &pyobj_conn, &info, &flags))
8159 return NULL;
8160 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8162 if ((size = PyDict_Size(info)) < 0)
8163 return NULL;
8165 if (size == 0) {
8166 PyErr_Format(PyExc_LookupError,
8167 "Need non-empty dictionary to set attributes");
8168 return NULL;
8171 LIBVIRT_BEGIN_ALLOW_THREADS;
8172 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
8173 LIBVIRT_END_ALLOW_THREADS;
8175 if (i_retval < 0)
8176 return VIR_PY_INT_FAIL;
8178 if (nparams == 0) {
8179 PyErr_Format(PyExc_LookupError,
8180 "no settable attributes");
8181 return NULL;
8184 if (VIR_ALLOC_N(params, nparams) < 0)
8185 return PyErr_NoMemory();
8187 LIBVIRT_BEGIN_ALLOW_THREADS;
8188 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
8189 LIBVIRT_END_ALLOW_THREADS;
8191 if (i_retval < 0) {
8192 ret = VIR_PY_INT_FAIL;
8193 goto cleanup;
8196 new_params = setPyVirTypedParameter(info, params, nparams);
8197 if (!new_params)
8198 goto cleanup;
8200 LIBVIRT_BEGIN_ALLOW_THREADS;
8201 i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
8202 LIBVIRT_END_ALLOW_THREADS;
8204 if (i_retval < 0) {
8205 ret = VIR_PY_INT_FAIL;
8206 goto cleanup;
8209 ret = VIR_PY_INT_SUCCESS;
8211 cleanup:
8212 virTypedParamsFree(params, nparams);
8213 virTypedParamsFree(new_params, size);
8214 return ret;
8217 static PyObject *
8218 libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
8219 PyObject *args)
8221 virConnectPtr conn;
8222 PyObject *pyobj_conn;
8223 PyObject *ret = NULL;
8224 int i_retval;
8225 int nparams = 0;
8226 unsigned int flags;
8227 virTypedParameterPtr params;
8229 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetMemoryParameters",
8230 &pyobj_conn, &flags))
8231 return NULL;
8232 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8234 LIBVIRT_BEGIN_ALLOW_THREADS;
8235 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
8236 LIBVIRT_END_ALLOW_THREADS;
8238 if (i_retval < 0)
8239 return VIR_PY_NONE;
8241 if (!nparams)
8242 return PyDict_New();
8244 if (VIR_ALLOC_N(params, nparams) < 0)
8245 return PyErr_NoMemory();
8247 LIBVIRT_BEGIN_ALLOW_THREADS;
8248 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
8249 LIBVIRT_END_ALLOW_THREADS;
8251 if (i_retval < 0) {
8252 ret = VIR_PY_NONE;
8253 goto cleanup;
8256 ret = getPyVirTypedParameter(params, nparams);
8258 cleanup:
8259 virTypedParamsFree(params, nparams);
8260 return ret;
8262 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
8264 #if LIBVIR_CHECK_VERSION(1, 0, 0)
8265 static PyObject *
8266 libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
8267 PyObject *args)
8269 virConnectPtr conn;
8270 PyObject *pyobj_conn;
8271 PyObject *ret = NULL;
8272 PyObject *pycpumap = NULL;
8273 int i_retval;
8274 unsigned char *cpumap = NULL;
8275 unsigned int online = 0;
8276 unsigned int flags;
8277 ssize_t i;
8279 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetCPUMap",
8280 &pyobj_conn, &flags))
8281 return NULL;
8282 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8284 LIBVIRT_BEGIN_ALLOW_THREADS;
8285 i_retval = virNodeGetCPUMap(conn, &cpumap, &online, flags);
8286 LIBVIRT_END_ALLOW_THREADS;
8288 if (i_retval < 0)
8289 return VIR_PY_NONE;
8291 if ((ret = PyTuple_New(3)) == NULL)
8292 goto error;
8294 /* 0: number of CPUs */
8295 VIR_PY_TUPLE_SET_GOTO(ret, 0, libvirt_intWrap(i_retval), error);
8297 /* 1: CPU map */
8298 if ((pycpumap = PyList_New(i_retval)) == NULL)
8299 goto error;
8301 VIR_PY_TUPLE_SET_GOTO(ret, 1, pycpumap, error);
8303 for (i = 0; i < i_retval; i++)
8304 VIR_PY_LIST_SET_GOTO(pycpumap, i,
8305 PyBool_FromLong(VIR_CPU_USED(cpumap, i)), error);
8307 /* 2: number of online CPUs */
8308 VIR_PY_TUPLE_SET_GOTO(ret, 2, libvirt_uintWrap(online), error);
8310 cleanup:
8311 VIR_FREE(cpumap);
8312 return ret;
8314 error:
8315 Py_CLEAR(ret);
8316 goto cleanup;
8318 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
8321 #if LIBVIR_CHECK_VERSION(1, 1, 1)
8322 static PyObject *
8323 libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED,
8324 PyObject *args)
8326 PyObject *py_retval = NULL;
8327 int c_retval;
8328 virDomainPtr domain;
8329 PyObject *pyobj_domain;
8330 PyObject *pyobj_files;
8331 unsigned int flags;
8332 unsigned int nfiles;
8333 int *files = NULL;
8334 ssize_t i;
8336 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainCreateWithFiles",
8337 &pyobj_domain, &pyobj_files, &flags))
8338 return NULL;
8339 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8341 nfiles = PyList_Size(pyobj_files);
8343 if (VIR_ALLOC_N(files, nfiles) < 0)
8344 return PyErr_NoMemory();
8346 for (i = 0; i < nfiles; i++) {
8347 PyObject *pyfd;
8348 int fd;
8350 pyfd = PyList_GetItem(pyobj_files, i);
8352 if (libvirt_intUnwrap(pyfd, &fd) < 0)
8353 goto cleanup;
8355 files[i] = fd;
8358 LIBVIRT_BEGIN_ALLOW_THREADS;
8359 c_retval = virDomainCreateWithFiles(domain, nfiles, files, flags);
8360 LIBVIRT_END_ALLOW_THREADS;
8362 py_retval = libvirt_intWrap((int) c_retval);
8364 cleanup:
8365 VIR_FREE(files);
8366 return py_retval;
8370 static PyObject *
8371 libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED,
8372 PyObject *args)
8374 PyObject *py_retval = NULL;
8375 virDomainPtr c_retval;
8376 virConnectPtr conn;
8377 PyObject *pyobj_conn;
8378 char * xmlDesc;
8379 PyObject *pyobj_files;
8380 unsigned int flags;
8381 unsigned int nfiles;
8382 int *files = NULL;
8383 ssize_t i;
8385 if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainCreateXMLWithFiles",
8386 &pyobj_conn, &xmlDesc, &pyobj_files, &flags))
8387 return NULL;
8388 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8390 nfiles = PyList_Size(pyobj_files);
8392 if (VIR_ALLOC_N(files, nfiles) < 0)
8393 return PyErr_NoMemory();
8395 for (i = 0; i < nfiles; i++) {
8396 PyObject *pyfd;
8397 int fd;
8399 pyfd = PyList_GetItem(pyobj_files, i);
8401 if (libvirt_intUnwrap(pyfd, &fd) < 0)
8402 goto cleanup;
8404 files[i] = fd;
8407 LIBVIRT_BEGIN_ALLOW_THREADS;
8408 c_retval = virDomainCreateXMLWithFiles(conn, xmlDesc, nfiles, files, flags);
8409 LIBVIRT_END_ALLOW_THREADS;
8411 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
8413 cleanup:
8414 VIR_FREE(files);
8415 return py_retval;
8417 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
8420 #if LIBVIR_CHECK_VERSION(1, 2, 5)
8421 static PyObject *
8422 libvirt_virDomainFSFreeze(PyObject *self ATTRIBUTE_UNUSED,
8423 PyObject *args)
8425 PyObject *py_retval = NULL;
8426 int c_retval;
8427 virDomainPtr domain;
8428 PyObject *pyobj_domain;
8429 PyObject *pyobj_list;
8430 unsigned int flags;
8431 unsigned int nmountpoints = 0;
8432 char **mountpoints = NULL;
8433 ssize_t i = 0, j;
8435 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSFreeze",
8436 &pyobj_domain, &pyobj_list, &flags))
8437 return NULL;
8438 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8440 if (PyList_Check(pyobj_list)) {
8441 nmountpoints = PyList_Size(pyobj_list);
8443 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
8444 return PyErr_NoMemory();
8446 for (i = 0; i < nmountpoints; i++) {
8447 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
8448 mountpoints+i) < 0)
8449 goto cleanup;
8453 LIBVIRT_BEGIN_ALLOW_THREADS;
8454 c_retval = virDomainFSFreeze(domain, (const char **) mountpoints,
8455 nmountpoints, flags);
8456 LIBVIRT_END_ALLOW_THREADS;
8458 py_retval = libvirt_intWrap(c_retval);
8460 cleanup:
8461 for (j = 0 ; j < i ; j++)
8462 VIR_FREE(mountpoints[j]);
8463 VIR_FREE(mountpoints);
8464 return py_retval;
8468 static PyObject *
8469 libvirt_virDomainFSThaw(PyObject *self ATTRIBUTE_UNUSED,
8470 PyObject *args)
8472 PyObject *py_retval = NULL;
8473 int c_retval;
8474 virDomainPtr domain;
8475 PyObject *pyobj_domain;
8476 PyObject *pyobj_list;
8477 unsigned int flags;
8478 unsigned int nmountpoints = 0;
8479 char **mountpoints = NULL;
8480 ssize_t i = 0, j;
8482 if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSThaw",
8483 &pyobj_domain, &pyobj_list, &flags))
8484 return NULL;
8485 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8487 if (PyList_Check(pyobj_list)) {
8488 nmountpoints = PyList_Size(pyobj_list);
8490 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
8491 return PyErr_NoMemory();
8493 for (i = 0; i < nmountpoints; i++) {
8494 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
8495 mountpoints+i) < 0)
8496 goto cleanup;
8500 LIBVIRT_BEGIN_ALLOW_THREADS;
8501 c_retval = virDomainFSThaw(domain, (const char **) mountpoints,
8502 nmountpoints, flags);
8503 LIBVIRT_END_ALLOW_THREADS;
8505 py_retval = libvirt_intWrap(c_retval);
8507 cleanup:
8508 for (j = 0 ; j < i ; j++)
8509 VIR_FREE(mountpoints[j]);
8510 VIR_FREE(mountpoints);
8511 return py_retval;
8514 static PyObject *
8515 libvirt_virDomainGetTime(PyObject *self ATTRIBUTE_UNUSED,
8516 PyObject *args)
8518 PyObject *py_retval = NULL;
8519 PyObject *dict = NULL;
8520 PyObject *pyobj_domain;
8521 virDomainPtr domain;
8522 long long seconds;
8523 unsigned int nseconds;
8524 unsigned int flags;
8525 int c_retval;
8527 if (!PyArg_ParseTuple(args, (char*)"OI:virDomainGetTime",
8528 &pyobj_domain, &flags))
8529 return NULL;
8530 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8532 if (!(dict = PyDict_New()))
8533 goto cleanup;
8535 LIBVIRT_BEGIN_ALLOW_THREADS;
8536 c_retval = virDomainGetTime(domain, &seconds, &nseconds, flags);
8537 LIBVIRT_END_ALLOW_THREADS;
8539 if (c_retval < 0) {
8540 py_retval = VIR_PY_NONE;
8541 goto cleanup;
8544 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("seconds"),
8545 libvirt_longlongWrap(seconds), cleanup);
8546 VIR_PY_DICT_SET_GOTO(dict, libvirt_constcharPtrWrap("nseconds"),
8547 libvirt_longlongWrap(nseconds), cleanup);
8549 py_retval = dict;
8550 dict = NULL;
8551 cleanup:
8552 Py_XDECREF(dict);
8553 return py_retval;
8557 static PyObject *
8558 libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED,
8559 PyObject *args)
8561 PyObject *pyobj_domain;
8562 PyObject *pyobj_seconds;
8563 PyObject *pyobj_nseconds;
8564 PyObject *py_dict;
8565 virDomainPtr domain;
8566 long long seconds = 0;
8567 unsigned int nseconds = 0;
8568 unsigned int flags;
8569 ssize_t py_dict_size = 0;
8570 int c_retval;
8572 if (!PyArg_ParseTuple(args, (char*)"OOI:virDomainSetTime",
8573 &pyobj_domain, &py_dict, &flags))
8574 return NULL;
8575 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
8577 if (PyDict_Check(py_dict)) {
8578 py_dict_size = PyDict_Size(py_dict);
8579 if ((pyobj_seconds = PyDict_GetItemString(py_dict, "seconds"))) {
8580 if (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)
8581 return NULL;
8582 } else {
8583 PyErr_Format(PyExc_LookupError, "Dictionary must contains 'seconds'");
8584 return NULL;
8587 if ((pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds"))) {
8588 if (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)
8589 return NULL;
8590 } else if (py_dict_size > 1) {
8591 PyErr_Format(PyExc_LookupError, "Dictionary contains unknown key");
8592 return NULL;
8594 } else if (py_dict != Py_None || !flags) {
8595 PyErr_Format(PyExc_TypeError, "time must be a dictionary "
8596 "or None with flags set");
8597 return NULL;
8600 LIBVIRT_BEGIN_ALLOW_THREADS;
8601 c_retval = virDomainSetTime(domain, seconds, nseconds, flags);
8602 LIBVIRT_END_ALLOW_THREADS;
8604 return libvirt_intWrap(c_retval);
8606 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
8609 #if LIBVIR_CHECK_VERSION(1, 2, 6)
8610 static PyObject *
8611 libvirt_virNodeGetFreePages(PyObject *self ATTRIBUTE_UNUSED,
8612 PyObject *args)
8614 PyObject *py_retval = NULL;
8615 PyObject *pyobj_conn;
8616 PyObject *pyobj_pagesize;
8617 PyObject *pyobj_counts = NULL;
8618 virConnectPtr conn;
8619 unsigned int *pages = NULL;
8620 int startCell;
8621 unsigned int cellCount;
8622 unsigned int flags;
8623 unsigned long long *counts = NULL;
8624 int c_retval;
8625 ssize_t pyobj_pagesize_size, i, j;
8627 if (!PyArg_ParseTuple(args, (char *)"OOiII:virNodeGetFreePages",
8628 &pyobj_conn, &pyobj_pagesize, &startCell,
8629 &cellCount, &flags))
8630 return NULL;
8632 if (!PyList_Check(pyobj_pagesize)) {
8633 PyErr_Format(PyExc_TypeError, "pagesize must be list");
8634 return NULL;
8637 if (cellCount == 0) {
8638 PyErr_Format(PyExc_LookupError, "cellCount must not be zero");
8639 return NULL;
8642 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8644 pyobj_pagesize_size = PyList_Size(pyobj_pagesize);
8645 if (VIR_ALLOC_N(pages, pyobj_pagesize_size) < 0 ||
8646 VIR_ALLOC_N(counts, pyobj_pagesize_size * cellCount) < 0) {
8647 PyErr_NoMemory();
8648 goto cleanup;
8651 if (!(pyobj_counts = PyDict_New()))
8652 goto cleanup;
8654 for (i = 0; i < pyobj_pagesize_size; i++) {
8655 PyObject *tmp = PyList_GetItem(pyobj_pagesize, i);
8657 if (libvirt_uintUnwrap(tmp, &pages[i]) < 0)
8658 goto cleanup;
8661 LIBVIRT_BEGIN_ALLOW_THREADS;
8662 c_retval = virNodeGetFreePages(conn,
8663 pyobj_pagesize_size, pages,
8664 startCell, cellCount,
8665 counts, flags);
8666 LIBVIRT_END_ALLOW_THREADS;
8668 if (c_retval < 0) {
8669 py_retval = VIR_PY_NONE;
8670 goto cleanup;
8673 for (i = 0; i < c_retval;) {
8674 PyObject *per_node = NULL;
8676 if (!(per_node = PyDict_New()))
8677 goto cleanup;
8679 VIR_PY_DICT_SET_GOTO(pyobj_counts,
8680 libvirt_intWrap(startCell + i/pyobj_pagesize_size),
8681 per_node, cleanup);
8683 for (j = 0; j < pyobj_pagesize_size; j ++)
8684 VIR_PY_DICT_SET_GOTO(per_node, libvirt_intWrap(pages[j]),
8685 libvirt_intWrap(counts[i + j]), cleanup);
8687 i += pyobj_pagesize_size;
8690 py_retval = pyobj_counts;
8691 pyobj_counts = NULL;
8692 cleanup:
8693 Py_XDECREF(pyobj_counts);
8694 VIR_FREE(pages);
8695 VIR_FREE(counts);
8696 return py_retval;
8700 static PyObject *
8701 libvirt_virNetworkGetDHCPLeases(PyObject *self ATTRIBUTE_UNUSED,
8702 PyObject *args)
8704 PyObject *py_retval = NULL;
8705 PyObject *py_lease = NULL;
8706 virNetworkPtr network;
8707 PyObject *pyobj_network;
8708 unsigned int flags;
8709 virNetworkDHCPLeasePtr *leases = NULL;
8710 int leases_count;
8711 char *mac = NULL;
8712 ssize_t i;
8714 if (!PyArg_ParseTuple(args, (char *) "OzI:virNetworkGetDHCPLeases",
8715 &pyobj_network, &mac, &flags))
8716 return NULL;
8718 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
8720 LIBVIRT_BEGIN_ALLOW_THREADS;
8721 leases_count = virNetworkGetDHCPLeases(network, mac, &leases, flags);
8722 LIBVIRT_END_ALLOW_THREADS;
8724 if (leases_count < 0) {
8725 py_retval = VIR_PY_NONE;
8726 goto cleanup;
8729 if (!(py_retval = PyList_New(leases_count)))
8730 goto error;
8732 for (i = 0; i < leases_count; i++) {
8733 virNetworkDHCPLeasePtr lease = leases[i];
8735 if ((py_lease = PyDict_New()) == NULL)
8736 goto error;
8738 VIR_PY_LIST_SET_GOTO(py_retval, i, py_lease, error);
8740 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("iface"),
8741 libvirt_charPtrWrap(lease->iface), error);
8742 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("expirytime"),
8743 libvirt_longlongWrap(lease->expirytime), error);
8744 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("type"),
8745 libvirt_intWrap(lease->type), error);
8746 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("mac"),
8747 libvirt_charPtrWrap(lease->mac), error);
8748 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("ipaddr"),
8749 libvirt_charPtrWrap(lease->ipaddr), error);
8750 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("prefix"),
8751 libvirt_uintWrap(lease->prefix), error);
8752 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("hostname"),
8753 libvirt_charPtrWrap(lease->hostname), error);
8754 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("clientid"),
8755 libvirt_charPtrWrap(lease->clientid), error);
8756 VIR_PY_DICT_SET_GOTO(py_lease, libvirt_constcharPtrWrap("iaid"),
8757 libvirt_charPtrWrap(lease->iaid), error);
8760 cleanup:
8761 if (leases_count > 0)
8762 for (i = 0; i < leases_count; i++)
8763 virNetworkDHCPLeaseFree(leases[i]);
8764 VIR_FREE(leases);
8766 return py_retval;
8768 error:
8769 Py_CLEAR(py_retval);
8770 goto cleanup;
8773 #endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
8775 #if LIBVIR_CHECK_VERSION(1, 2, 8)
8777 static PyObject *
8778 convertDomainStatsRecord(virDomainStatsRecordPtr *records,
8779 int nrecords)
8781 PyObject *py_retval;
8782 PyObject *py_record;
8783 PyObject *py_record_stats = NULL;
8784 virDomainPtr dom = NULL;
8785 ssize_t i;
8787 if (!(py_retval = PyList_New(nrecords)))
8788 return NULL;
8790 for (i = 0; i < nrecords; i++) {
8791 if (!(py_record = PyTuple_New(2)))
8792 goto error;
8794 VIR_PY_LIST_SET_GOTO(py_retval, i, py_record, error);
8796 dom = records[i]->dom;
8797 virDomainRef(dom);
8798 VIR_PY_TUPLE_SET_GOTO(py_record, 0,
8799 libvirt_virDomainPtrWrap(dom),
8800 error);
8801 dom = NULL;
8803 if (!(py_record_stats = getPyVirTypedParameter(records[i]->params,
8804 records[i]->nparams)))
8805 goto error;
8806 VIR_PY_TUPLE_SET_GOTO(py_record, 1, py_record_stats, error);
8810 return py_retval;
8812 error:
8813 if (dom)
8814 virDomainFree(dom);
8815 Py_XDECREF(py_retval);
8816 return NULL;
8820 static PyObject *
8821 libvirt_virConnectGetAllDomainStats(PyObject *self ATTRIBUTE_UNUSED,
8822 PyObject *args)
8824 PyObject *pyobj_conn;
8825 PyObject *py_retval;
8826 virConnectPtr conn;
8827 virDomainStatsRecordPtr *records;
8828 int nrecords;
8829 unsigned int flags;
8830 unsigned int stats;
8832 if (!PyArg_ParseTuple(args, (char *)"OII:virConnectGetAllDomainStats",
8833 &pyobj_conn, &stats, &flags))
8834 return NULL;
8835 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8837 LIBVIRT_BEGIN_ALLOW_THREADS;
8838 nrecords = virConnectGetAllDomainStats(conn, stats, &records, flags);
8839 LIBVIRT_END_ALLOW_THREADS;
8841 if (nrecords < 0)
8842 return VIR_PY_NONE;
8844 py_retval = convertDomainStatsRecord(records, nrecords);
8846 virDomainStatsRecordListFree(records);
8848 return py_retval;
8852 static PyObject *
8853 libvirt_virDomainListGetStats(PyObject *self ATTRIBUTE_UNUSED,
8854 PyObject *args)
8856 PyObject *pyobj_conn;
8857 PyObject *py_retval;
8858 PyObject *py_domlist;
8859 virDomainStatsRecordPtr *records = NULL;
8860 virDomainPtr *doms = NULL;
8861 int nrecords;
8862 int ndoms;
8863 ssize_t i;
8864 unsigned int flags;
8865 unsigned int stats;
8867 if (!PyArg_ParseTuple(args, (char *)"OOII:virDomainListGetStats",
8868 &pyobj_conn, &py_domlist, &stats, &flags))
8869 return NULL;
8871 if (PyList_Check(py_domlist)) {
8872 ndoms = PyList_Size(py_domlist);
8874 if (VIR_ALLOC_N(doms, ndoms + 1) < 0)
8875 return PyErr_NoMemory();
8877 for (i = 0; i < ndoms; i++)
8878 doms[i] = PyvirDomain_Get(PyList_GetItem(py_domlist, i));
8881 LIBVIRT_BEGIN_ALLOW_THREADS;
8882 nrecords = virDomainListGetStats(doms, stats, &records, flags);
8883 LIBVIRT_END_ALLOW_THREADS;
8885 if (nrecords < 0) {
8886 py_retval = VIR_PY_NONE;
8887 goto cleanup;
8890 py_retval = convertDomainStatsRecord(records, nrecords);
8892 cleanup:
8893 virDomainStatsRecordListFree(records);
8894 VIR_FREE(doms);
8896 return py_retval;
8900 static virPyTypedParamsHint virPyDomainBlockCopyParams[] = {
8901 { VIR_DOMAIN_BLOCK_COPY_BANDWIDTH, VIR_TYPED_PARAM_ULLONG },
8902 { VIR_DOMAIN_BLOCK_COPY_GRANULARITY, VIR_TYPED_PARAM_UINT },
8903 { VIR_DOMAIN_BLOCK_COPY_BUF_SIZE, VIR_TYPED_PARAM_ULLONG },
8907 static PyObject *
8908 libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED,
8909 PyObject *args)
8911 PyObject *pyobj_dom = NULL;
8912 PyObject *pyobj_dict = NULL;
8914 virDomainPtr dom;
8915 char *disk = NULL;
8916 char *destxml = NULL;
8917 virTypedParameterPtr params = NULL;
8918 int nparams = 0;
8919 unsigned int flags = 0;
8920 int c_retval;
8922 if (!PyArg_ParseTuple(args, (char *) "Ozz|OI:virDomainBlockCopy",
8923 &pyobj_dom, &disk, &destxml, &pyobj_dict, &flags))
8924 return NULL;
8926 if (PyDict_Check(pyobj_dict)) {
8927 if (virPyDictToTypedParams(pyobj_dict, &params, &nparams,
8928 virPyDomainBlockCopyParams,
8929 VIR_N_ELEMENTS(virPyDomainBlockCopyParams)) < 0) {
8930 return NULL;
8932 } else if (pyobj_dict != Py_None) {
8933 PyErr_Format(PyExc_TypeError, "block params must be a dictionary");
8934 return NULL;
8937 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
8939 LIBVIRT_BEGIN_ALLOW_THREADS;
8940 c_retval = virDomainBlockCopy(dom, disk, destxml, params, nparams, flags);
8941 LIBVIRT_END_ALLOW_THREADS;
8943 virTypedParamsFree(params, nparams);
8944 return libvirt_intWrap(c_retval);
8947 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
8949 #if LIBVIR_CHECK_VERSION(1, 2, 9)
8950 static PyObject *
8951 libvirt_virNodeAllocPages(PyObject *self ATTRIBUTE_UNUSED,
8952 PyObject *args)
8954 PyObject *pyobj_conn;
8955 PyObject *pyobj_pages;
8956 Py_ssize_t size = 0;
8957 Py_ssize_t pos = 0;
8958 PyObject *key, *value;
8959 virConnectPtr conn;
8960 unsigned int npages = 0;
8961 unsigned int *pageSizes = NULL;
8962 unsigned long long *pageCounts = NULL;
8963 int startCell = -1;
8964 unsigned int cellCount = 1;
8965 unsigned int flags = VIR_NODE_ALLOC_PAGES_ADD;
8966 int c_retval;
8968 if (!PyArg_ParseTuple(args, (char *)"OOiII:virNodeAllocPages",
8969 &pyobj_conn, &pyobj_pages,
8970 &startCell, &cellCount, &flags))
8971 return NULL;
8972 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
8974 if ((size = PyDict_Size(pyobj_pages)) < 0)
8975 return NULL;
8977 if (size == 0) {
8978 PyErr_Format(PyExc_LookupError,
8979 "Need non-empty dictionary to pages attribute");
8980 return NULL;
8983 if (VIR_ALLOC_N(pageSizes, size) < 0 ||
8984 VIR_ALLOC_N(pageCounts, size) < 0) {
8985 PyErr_NoMemory();
8986 goto error;
8989 while (PyDict_Next(pyobj_pages, &pos, &key, &value)) {
8990 if (libvirt_uintUnwrap(key, &pageSizes[npages]) < 0 ||
8991 libvirt_ulonglongUnwrap(value, &pageCounts[npages]) < 0)
8992 goto error;
8993 npages++;
8996 LIBVIRT_BEGIN_ALLOW_THREADS;
8997 c_retval = virNodeAllocPages(conn, npages, pageSizes,
8998 pageCounts, startCell, cellCount, flags);
8999 LIBVIRT_END_ALLOW_THREADS;
9001 VIR_FREE(pageSizes);
9002 VIR_FREE(pageCounts);
9004 return libvirt_intWrap(c_retval);
9006 error:
9007 VIR_FREE(pageSizes);
9008 VIR_FREE(pageCounts);
9009 return NULL;
9011 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
9013 #if LIBVIR_CHECK_VERSION(1, 2, 11)
9015 static PyObject *
9016 libvirt_virDomainGetFSInfo(PyObject *self ATTRIBUTE_UNUSED,
9017 PyObject *args)
9019 virDomainPtr domain;
9020 PyObject *pyobj_domain;
9021 unsigned int flags;
9022 virDomainFSInfoPtr *fsinfo = NULL;
9023 int c_retval, i;
9024 size_t j;
9025 PyObject *py_retval = NULL;
9027 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetFSInfo",
9028 &pyobj_domain, &flags))
9029 return NULL;
9030 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9032 LIBVIRT_BEGIN_ALLOW_THREADS;
9033 c_retval = virDomainGetFSInfo(domain, &fsinfo, flags);
9034 LIBVIRT_END_ALLOW_THREADS;
9036 if (c_retval < 0) {
9037 py_retval = VIR_PY_NONE;
9038 goto cleanup;
9041 /* convert to a Python list */
9042 if ((py_retval = PyList_New(c_retval)) == NULL)
9043 goto error;
9045 for (i = 0; i < c_retval; i++) {
9046 virDomainFSInfoPtr fs = fsinfo[i];
9047 PyObject *info, *alias;
9049 if (fs == NULL)
9050 goto error;
9052 info = PyTuple_New(4);
9053 if (info == NULL)
9054 goto error;
9056 VIR_PY_LIST_SET_GOTO(py_retval, i, info, error);
9058 VIR_PY_TUPLE_SET_GOTO(info, 0,
9059 libvirt_constcharPtrWrap(fs->mountpoint), error);
9060 VIR_PY_TUPLE_SET_GOTO(info, 1,
9061 libvirt_constcharPtrWrap(fs->name), error);
9062 VIR_PY_TUPLE_SET_GOTO(info, 2,
9063 libvirt_constcharPtrWrap(fs->fstype), error);
9065 alias = PyList_New(0);
9066 if (alias == NULL)
9067 goto error;
9068 VIR_PY_TUPLE_SET_GOTO(info, 3, alias, error);
9070 for (j = 0; j < fs->ndevAlias; j++)
9071 VIR_PY_LIST_APPEND_GOTO(alias,
9072 libvirt_constcharPtrWrap(fs->devAlias[j]),
9073 error);
9076 cleanup:
9077 if (c_retval > 0)
9078 for (i = 0; i < c_retval; i++)
9079 virDomainFSInfoFree(fsinfo[i]);
9080 VIR_FREE(fsinfo);
9081 return py_retval;
9083 error:
9084 Py_CLEAR(py_retval);
9085 goto cleanup;
9088 #endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
9090 #if LIBVIR_CHECK_VERSION(1, 3, 3)
9091 static PyObject *
9092 libvirt_virDomainGetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
9093 PyObject *args)
9095 PyObject *pyobj_domain;
9096 virDomainPtr domain;
9097 virTypedParameterPtr params = NULL;
9098 int nparams = 0;
9099 PyObject *dict = NULL;
9100 unsigned int flags;
9101 int rc;
9103 if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetPerfEvents",
9104 &pyobj_domain, &flags))
9105 return NULL;
9106 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9108 LIBVIRT_BEGIN_ALLOW_THREADS;
9109 rc = virDomainGetPerfEvents(domain, &params, &nparams, flags);
9110 LIBVIRT_END_ALLOW_THREADS;
9112 if (rc < 0)
9113 return VIR_PY_NONE;
9115 if (!(dict = getPyVirTypedParameter(params, nparams)))
9116 goto cleanup;
9118 cleanup:
9119 virTypedParamsFree(params, nparams);
9120 return dict;
9123 static PyObject *
9124 libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
9125 PyObject *args)
9127 virDomainPtr domain;
9128 PyObject *pyobj_domain, *info;
9129 PyObject *ret = NULL;
9130 int i_retval;
9131 int nparams = 0;
9132 Py_ssize_t size = 0;
9133 unsigned int flags;
9134 virTypedParameterPtr params = NULL, new_params = NULL;
9136 if (!PyArg_ParseTuple(args,
9137 (char *)"OOI:virDomainSetPerfEvents",
9138 &pyobj_domain, &info, &flags))
9139 return NULL;
9140 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9142 if ((size = PyDict_Size(info)) < 0)
9143 return NULL;
9145 if (size == 0) {
9146 PyErr_Format(PyExc_LookupError,
9147 "Need non-empty dictionary to set attributes");
9148 return NULL;
9151 LIBVIRT_BEGIN_ALLOW_THREADS;
9152 i_retval = virDomainGetPerfEvents(domain, &params, &nparams, flags);
9153 LIBVIRT_END_ALLOW_THREADS;
9155 if (i_retval < 0)
9156 return VIR_PY_INT_FAIL;
9158 if (nparams == 0) {
9159 PyErr_Format(PyExc_LookupError,
9160 "Domain has no settable attributes");
9161 return NULL;
9164 new_params = setPyVirTypedParameter(info, params, nparams);
9165 if (!new_params)
9166 goto cleanup;
9168 LIBVIRT_BEGIN_ALLOW_THREADS;
9169 i_retval = virDomainSetPerfEvents(domain, new_params, size, flags);
9170 LIBVIRT_END_ALLOW_THREADS;
9172 if (i_retval < 0) {
9173 ret = VIR_PY_INT_FAIL;
9174 goto cleanup;
9177 ret = VIR_PY_INT_SUCCESS;
9179 cleanup:
9180 virTypedParamsFree(params, nparams);
9181 virTypedParamsFree(new_params, size);
9182 return ret;
9184 #endif /* LIBVIR_CHECK_VERSION(1, 3, 3) */
9186 #if LIBVIR_CHECK_VERSION(2, 0, 0)
9187 static void
9188 libvirt_virConnectStoragePoolEventFreeFunc(void *opaque)
9190 PyObject *pyobj_conn = (PyObject*)opaque;
9191 LIBVIRT_ENSURE_THREAD_STATE;
9192 Py_DECREF(pyobj_conn);
9193 LIBVIRT_RELEASE_THREAD_STATE;
9196 static int
9197 libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9198 virStoragePoolPtr pool,
9199 int event,
9200 int detail,
9201 void *opaque)
9203 PyObject *pyobj_cbData = (PyObject*)opaque;
9204 PyObject *pyobj_pool;
9205 PyObject *pyobj_ret = NULL;
9206 PyObject *pyobj_conn;
9207 PyObject *dictKey;
9208 int ret = -1;
9210 LIBVIRT_ENSURE_THREAD_STATE;
9212 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9213 goto cleanup;
9214 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9215 Py_DECREF(dictKey);
9217 /* Create a python instance of this virStoragePoolPtr */
9218 virStoragePoolRef(pool);
9219 if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
9220 virStoragePoolFree(pool);
9221 goto cleanup;
9223 Py_INCREF(pyobj_cbData);
9225 /* Call the Callback Dispatcher */
9226 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9227 (char*)"_dispatchStoragePoolEventLifecycleCallback",
9228 (char*)"OiiO",
9229 pyobj_pool,
9230 event,
9231 detail,
9232 pyobj_cbData);
9234 Py_DECREF(pyobj_cbData);
9235 Py_DECREF(pyobj_pool);
9237 cleanup:
9238 if (!pyobj_ret) {
9239 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9240 PyErr_Print();
9241 } else {
9242 Py_DECREF(pyobj_ret);
9243 ret = 0;
9246 LIBVIRT_RELEASE_THREAD_STATE;
9247 return ret;
9250 static int
9251 libvirt_virConnectStoragePoolEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9252 virStoragePoolPtr pool,
9253 void *opaque)
9255 PyObject *pyobj_cbData = (PyObject*)opaque;
9256 PyObject *pyobj_pool;
9257 PyObject *pyobj_ret = NULL;
9258 PyObject *pyobj_conn;
9259 PyObject *dictKey;
9260 int ret = -1;
9262 LIBVIRT_ENSURE_THREAD_STATE;
9264 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9265 goto cleanup;
9266 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9267 Py_DECREF(dictKey);
9269 /* Create a python instance of this virStoragePoolPtr */
9270 virStoragePoolRef(pool);
9271 if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
9272 virStoragePoolFree(pool);
9273 goto cleanup;
9275 Py_INCREF(pyobj_cbData);
9277 /* Call the Callback Dispatcher */
9278 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9279 (char*)"_dispatchStoragePoolEventGenericCallback",
9280 (char*)"OO",
9281 pyobj_pool,
9282 pyobj_cbData);
9284 Py_DECREF(pyobj_cbData);
9285 Py_DECREF(pyobj_pool);
9287 cleanup:
9288 if (!pyobj_ret) {
9289 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9290 PyErr_Print();
9291 } else {
9292 Py_DECREF(pyobj_ret);
9293 ret = 0;
9296 LIBVIRT_RELEASE_THREAD_STATE;
9297 return ret;
9300 static PyObject *
9301 libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9302 PyObject *args)
9304 PyObject *pyobj_conn; /* virConnectPtr */
9305 PyObject *pyobj_pool;
9306 PyObject *pyobj_cbData; /* hash of callback data */
9307 int eventID;
9308 virConnectPtr conn;
9309 int ret = 0;
9310 virConnectStoragePoolEventGenericCallback cb = NULL;
9311 virStoragePoolPtr pool;
9313 if (!PyArg_ParseTuple(args,
9314 (char *) "OOiO:virConnectStoragePoolEventRegisterAny",
9315 &pyobj_conn, &pyobj_pool, &eventID, &pyobj_cbData))
9316 return NULL;
9318 DEBUG("libvirt_virConnectStoragePoolEventRegister(%p %p %d %p) called\n",
9319 pyobj_conn, pyobj_pool, eventID, pyobj_cbData);
9320 conn = PyvirConnect_Get(pyobj_conn);
9321 if (pyobj_pool == Py_None)
9322 pool = NULL;
9323 else
9324 pool = PyvirStoragePool_Get(pyobj_pool);
9326 switch ((virStoragePoolEventID) eventID) {
9327 case VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE:
9328 cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventLifecycleCallback);
9329 break;
9331 case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
9332 cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventGenericCallback);
9333 break;
9335 case VIR_STORAGE_POOL_EVENT_ID_LAST:
9336 break;
9339 if (!cb) {
9340 return VIR_PY_INT_FAIL;
9343 Py_INCREF(pyobj_cbData);
9345 LIBVIRT_BEGIN_ALLOW_THREADS;
9346 ret = virConnectStoragePoolEventRegisterAny(conn,
9347 pool,
9348 eventID,
9350 pyobj_cbData,
9351 libvirt_virConnectStoragePoolEventFreeFunc);
9352 LIBVIRT_END_ALLOW_THREADS;
9354 if (ret < 0) {
9355 Py_DECREF(pyobj_cbData);
9358 return libvirt_intWrap(ret);
9361 static PyObject *
9362 libvirt_virConnectStoragePoolEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9363 PyObject *args)
9365 PyObject *pyobj_conn;
9366 int callbackID;
9367 virConnectPtr conn;
9368 int ret = 0;
9370 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectStoragePoolEventDeregisterAny",
9371 &pyobj_conn, &callbackID))
9372 return NULL;
9374 DEBUG("libvirt_virConnectStoragePoolEventDeregister(%p) called\n",
9375 pyobj_conn);
9377 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9379 LIBVIRT_BEGIN_ALLOW_THREADS;
9380 ret = virConnectStoragePoolEventDeregisterAny(conn, callbackID);
9381 LIBVIRT_END_ALLOW_THREADS;
9383 return libvirt_intWrap(ret);
9386 static PyObject *
9387 libvirt_virDomainGetGuestVcpus(PyObject *self ATTRIBUTE_UNUSED,
9388 PyObject *args)
9390 PyObject *pyobj_domain;
9391 virDomainPtr domain;
9392 virTypedParameterPtr params = NULL;
9393 unsigned int nparams = 0;
9394 unsigned int flags;
9395 int i_retval;
9396 PyObject *ret = NULL;
9398 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetGuestVcpus",
9399 &pyobj_domain, &flags))
9400 return NULL;
9401 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
9403 LIBVIRT_BEGIN_ALLOW_THREADS;
9404 i_retval = virDomainGetGuestVcpus(domain, &params, &nparams, flags);
9405 LIBVIRT_END_ALLOW_THREADS;
9407 if (i_retval < 0) {
9408 ret = VIR_PY_NONE;
9409 goto cleanup;
9412 ret = getPyVirTypedParameter(params, nparams);
9413 cleanup:
9414 virTypedParamsFree(params, nparams);
9415 return ret;
9417 #endif /* LIBVIR_CHECK_VERSION(2, 0, 0)*/
9419 #if LIBVIR_CHECK_VERSION(2, 2, 0)
9420 static void
9421 libvirt_virConnectNodeDeviceEventFreeFunc(void *opaque)
9423 PyObject *pyobj_conn = (PyObject*)opaque;
9424 LIBVIRT_ENSURE_THREAD_STATE;
9425 Py_DECREF(pyobj_conn);
9426 LIBVIRT_RELEASE_THREAD_STATE;
9429 static int
9430 libvirt_virConnectNodeDeviceEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9431 virNodeDevicePtr dev,
9432 int event,
9433 int detail,
9434 void *opaque)
9436 PyObject *pyobj_cbData = (PyObject*)opaque;
9437 PyObject *pyobj_dev;
9438 PyObject *pyobj_ret = NULL;
9439 PyObject *pyobj_conn;
9440 PyObject *dictKey;
9441 int ret = -1;
9443 LIBVIRT_ENSURE_THREAD_STATE;
9445 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9446 goto cleanup;
9447 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9448 Py_DECREF(dictKey);
9450 /* Create a python instance of this virNodeDevicePtr */
9451 virNodeDeviceRef(dev);
9452 if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) {
9453 virNodeDeviceFree(dev);
9454 goto cleanup;
9456 Py_INCREF(pyobj_cbData);
9458 /* Call the Callback Dispatcher */
9459 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9460 (char*)"_dispatchNodeDeviceEventLifecycleCallback",
9461 (char*)"OiiO",
9462 pyobj_dev,
9463 event,
9464 detail,
9465 pyobj_cbData);
9467 Py_DECREF(pyobj_cbData);
9468 Py_DECREF(pyobj_dev);
9470 cleanup:
9471 if (!pyobj_ret) {
9472 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9473 PyErr_Print();
9474 } else {
9475 Py_DECREF(pyobj_ret);
9476 ret = 0;
9479 LIBVIRT_RELEASE_THREAD_STATE;
9480 return ret;
9483 static int
9484 libvirt_virConnectNodeDeviceEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9485 virNodeDevicePtr dev,
9486 void *opaque)
9488 PyObject *pyobj_cbData = (PyObject*)opaque;
9489 PyObject *pyobj_dev;
9490 PyObject *pyobj_ret = NULL;
9491 PyObject *pyobj_conn;
9492 PyObject *dictKey;
9493 int ret = -1;
9495 LIBVIRT_ENSURE_THREAD_STATE;
9497 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9498 goto cleanup;
9499 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9500 Py_DECREF(dictKey);
9502 /* Create a python instance of this virNodeDevicePtr */
9503 virNodeDeviceRef(dev);
9504 if (!(pyobj_dev = libvirt_virNodeDevicePtrWrap(dev))) {
9505 virNodeDeviceFree(dev);
9506 goto cleanup;
9508 Py_INCREF(pyobj_cbData);
9510 /* Call the Callback Dispatcher */
9511 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9512 (char*)"_dispatchNodeDeviceEventGenericCallback",
9513 (char*)"OO",
9514 pyobj_dev,
9515 pyobj_cbData);
9517 Py_DECREF(pyobj_cbData);
9518 Py_DECREF(pyobj_dev);
9520 cleanup:
9521 if (!pyobj_ret) {
9522 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9523 PyErr_Print();
9524 } else {
9525 Py_DECREF(pyobj_ret);
9526 ret = 0;
9529 LIBVIRT_RELEASE_THREAD_STATE;
9530 return ret;
9533 static PyObject *
9534 libvirt_virConnectNodeDeviceEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9535 PyObject *args)
9537 PyObject *pyobj_conn; /* virConnectPtr */
9538 PyObject *pyobj_dev;
9539 PyObject *pyobj_cbData; /* hash of callback data */
9540 int eventID;
9541 virConnectPtr conn;
9542 int ret = 0;
9543 virConnectNodeDeviceEventGenericCallback cb = NULL;
9544 virNodeDevicePtr dev;
9546 if (!PyArg_ParseTuple(args,
9547 (char *) "OOiO:virConnectNodeDeviceEventRegisterAny",
9548 &pyobj_conn, &pyobj_dev, &eventID, &pyobj_cbData))
9549 return NULL;
9551 DEBUG("libvirt_virConnectNodeDeviceEventRegister(%p %p %d %p) called\n",
9552 pyobj_conn, pyobj_dev, eventID, pyobj_cbData);
9553 conn = PyvirConnect_Get(pyobj_conn);
9554 if (pyobj_dev == Py_None)
9555 dev = NULL;
9556 else
9557 dev = PyvirNodeDevice_Get(pyobj_dev);
9559 switch ((virNodeDeviceEventID) eventID) {
9560 case VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE:
9561 cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventLifecycleCallback);
9562 break;
9564 case VIR_NODE_DEVICE_EVENT_ID_UPDATE:
9565 cb = VIR_NODE_DEVICE_EVENT_CALLBACK(libvirt_virConnectNodeDeviceEventGenericCallback);
9566 break;
9568 case VIR_NODE_DEVICE_EVENT_ID_LAST:
9569 break;
9572 if (!cb) {
9573 return VIR_PY_INT_FAIL;
9576 Py_INCREF(pyobj_cbData);
9578 LIBVIRT_BEGIN_ALLOW_THREADS;
9579 ret = virConnectNodeDeviceEventRegisterAny(conn,
9580 dev,
9581 eventID,
9583 pyobj_cbData,
9584 libvirt_virConnectNodeDeviceEventFreeFunc);
9585 LIBVIRT_END_ALLOW_THREADS;
9587 if (ret < 0) {
9588 Py_DECREF(pyobj_cbData);
9591 return libvirt_intWrap(ret);
9594 static PyObject *
9595 libvirt_virConnectNodeDeviceEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9596 PyObject *args)
9598 PyObject *pyobj_conn;
9599 int callbackID;
9600 virConnectPtr conn;
9601 int ret = 0;
9603 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectNodeDeviceEventDeregister",
9604 &pyobj_conn, &callbackID))
9605 return NULL;
9607 DEBUG("libvirt_virConnectNodeDeviceEventDeregister(%p) called\n",
9608 pyobj_conn);
9610 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9612 LIBVIRT_BEGIN_ALLOW_THREADS;
9613 ret = virConnectNodeDeviceEventDeregisterAny(conn, callbackID);
9614 LIBVIRT_END_ALLOW_THREADS;
9616 return libvirt_intWrap(ret);
9619 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0)*/
9621 #if LIBVIR_CHECK_VERSION(3, 0, 0)
9622 static void
9623 libvirt_virConnectSecretEventFreeFunc(void *opaque)
9625 PyObject *pyobj_conn = (PyObject*)opaque;
9626 LIBVIRT_ENSURE_THREAD_STATE;
9627 Py_DECREF(pyobj_conn);
9628 LIBVIRT_RELEASE_THREAD_STATE;
9631 static int
9632 libvirt_virConnectSecretEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9633 virSecretPtr secret,
9634 int event,
9635 int detail,
9636 void *opaque)
9638 PyObject *pyobj_cbData = (PyObject*)opaque;
9639 PyObject *pyobj_secret;
9640 PyObject *pyobj_ret = NULL;
9641 PyObject *pyobj_conn;
9642 PyObject *dictKey;
9643 int ret = -1;
9645 LIBVIRT_ENSURE_THREAD_STATE;
9647 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9648 goto cleanup;
9649 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9650 Py_DECREF(dictKey);
9652 /* Create a python instance of this virSecretPtr */
9653 virSecretRef(secret);
9654 if (!(pyobj_secret = libvirt_virSecretPtrWrap(secret))) {
9655 virSecretFree(secret);
9656 goto cleanup;
9658 Py_INCREF(pyobj_cbData);
9660 /* Call the Callback Dispatcher */
9661 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9662 (char*)"_dispatchSecretEventLifecycleCallback",
9663 (char*)"OiiO",
9664 pyobj_secret,
9665 event,
9666 detail,
9667 pyobj_cbData);
9669 Py_DECREF(pyobj_cbData);
9670 Py_DECREF(pyobj_secret);
9672 cleanup:
9673 if (!pyobj_ret) {
9674 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9675 PyErr_Print();
9676 } else {
9677 Py_DECREF(pyobj_ret);
9678 ret = 0;
9681 LIBVIRT_RELEASE_THREAD_STATE;
9682 return ret;
9685 static int
9686 libvirt_virConnectSecretEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
9687 virSecretPtr secret,
9688 void *opaque)
9690 PyObject *pyobj_cbData = (PyObject*)opaque;
9691 PyObject *pyobj_secret;
9692 PyObject *pyobj_ret = NULL;
9693 PyObject *pyobj_conn;
9694 PyObject *dictKey;
9695 int ret = -1;
9697 LIBVIRT_ENSURE_THREAD_STATE;
9699 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
9700 goto cleanup;
9701 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
9702 Py_DECREF(dictKey);
9704 /* Create a python instance of this virSecretPtr */
9705 virSecretRef(secret);
9706 if (!(pyobj_secret = libvirt_virSecretPtrWrap(secret))) {
9707 virSecretFree(secret);
9708 goto cleanup;
9710 Py_INCREF(pyobj_cbData);
9712 /* Call the Callback Dispatcher */
9713 pyobj_ret = PyObject_CallMethod(pyobj_conn,
9714 (char*)"_dispatchSecretEventGenericCallback",
9715 (char*)"OO",
9716 pyobj_secret,
9717 pyobj_cbData);
9719 Py_DECREF(pyobj_cbData);
9720 Py_DECREF(pyobj_secret);
9722 cleanup:
9723 if (!pyobj_ret) {
9724 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
9725 PyErr_Print();
9726 } else {
9727 Py_DECREF(pyobj_ret);
9728 ret = 0;
9731 LIBVIRT_RELEASE_THREAD_STATE;
9732 return ret;
9735 static PyObject *
9736 libvirt_virConnectSecretEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
9737 PyObject *args)
9739 PyObject *pyobj_conn; /* virConnectPtr */
9740 PyObject *pyobj_secret;
9741 PyObject *pyobj_cbData; /* hash of callback data */
9742 int eventID;
9743 virConnectPtr conn;
9744 int ret = 0;
9745 virConnectSecretEventGenericCallback cb = NULL;
9746 virSecretPtr secret;
9748 if (!PyArg_ParseTuple(args,
9749 (char *) "OOiO:virConnectSecretEventRegisterAny",
9750 &pyobj_conn, &pyobj_secret, &eventID, &pyobj_cbData))
9751 return NULL;
9753 DEBUG("libvirt_virConnectSecretEventRegister(%p %p %d %p) called\n",
9754 pyobj_conn, pyobj_secret, eventID, pyobj_cbData);
9755 conn = PyvirConnect_Get(pyobj_conn);
9756 if (pyobj_secret == Py_None)
9757 secret = NULL;
9758 else
9759 secret = PyvirSecret_Get(pyobj_secret);
9761 switch ((virSecretEventID) eventID) {
9762 case VIR_SECRET_EVENT_ID_LIFECYCLE:
9763 cb = VIR_SECRET_EVENT_CALLBACK(libvirt_virConnectSecretEventLifecycleCallback);
9764 break;
9766 case VIR_SECRET_EVENT_ID_VALUE_CHANGED:
9767 cb = VIR_SECRET_EVENT_CALLBACK(libvirt_virConnectSecretEventGenericCallback);
9768 break;
9770 case VIR_SECRET_EVENT_ID_LAST:
9771 break;
9774 if (!cb) {
9775 return VIR_PY_INT_FAIL;
9778 Py_INCREF(pyobj_cbData);
9780 LIBVIRT_BEGIN_ALLOW_THREADS;
9781 ret = virConnectSecretEventRegisterAny(conn, secret, eventID,
9782 cb, pyobj_cbData,
9783 libvirt_virConnectSecretEventFreeFunc);
9784 LIBVIRT_END_ALLOW_THREADS;
9786 if (ret < 0) {
9787 Py_DECREF(pyobj_cbData);
9790 return libvirt_intWrap(ret);
9793 static PyObject *
9794 libvirt_virConnectSecretEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
9795 PyObject *args)
9797 PyObject *pyobj_conn;
9798 int callbackID;
9799 virConnectPtr conn;
9800 int ret = 0;
9802 if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectSecretEventDeregister",
9803 &pyobj_conn, &callbackID))
9804 return NULL;
9806 DEBUG("libvirt_virConnectSecretEventDeregister(%p) called\n", pyobj_conn);
9808 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9810 LIBVIRT_BEGIN_ALLOW_THREADS;
9811 ret = virConnectSecretEventDeregisterAny(conn, callbackID);
9812 LIBVIRT_END_ALLOW_THREADS;
9814 return libvirt_intWrap(ret);
9816 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0)*/
9819 #if LIBVIR_CHECK_VERSION(3, 4, 0)
9820 static PyObject *
9821 libvirt_virStreamRecvHole(PyObject *self ATTRIBUTE_UNUSED,
9822 PyObject *args)
9824 PyObject *pyobj_stream;
9825 virStreamPtr stream;
9826 long long length = -1;
9827 unsigned int flags;
9828 int ret;
9830 if (!PyArg_ParseTuple(args, (char *) "OI:virStreamRecvHole",
9831 &pyobj_stream, &flags))
9832 return NULL;
9834 stream = PyvirStream_Get(pyobj_stream);
9836 LIBVIRT_BEGIN_ALLOW_THREADS;
9837 ret = virStreamRecvHole(stream, &length, flags);
9838 LIBVIRT_END_ALLOW_THREADS;
9840 DEBUG("StreamRecvHole ret=%d length=%lld\n", ret, length);
9842 if (ret < 0)
9843 return VIR_PY_NONE;
9845 return libvirt_longlongWrap(length);
9849 static PyObject *
9850 libvirt_virStreamSendHole(PyObject *self ATTRIBUTE_UNUSED,
9851 PyObject *args)
9853 PyObject *pyobj_stream;
9854 virStreamPtr stream;
9855 long long length;
9856 unsigned int flags;
9857 int ret;
9859 if (!PyArg_ParseTuple(args, (char *) "OLI:virStreamSendHole",
9860 &pyobj_stream, &length, &flags))
9861 return NULL;
9863 stream = PyvirStream_Get(pyobj_stream);
9865 LIBVIRT_BEGIN_ALLOW_THREADS;
9866 ret = virStreamSendHole(stream, length, flags);
9867 LIBVIRT_END_ALLOW_THREADS;
9869 DEBUG("StreamSendHole ret=%d\n", ret);
9871 return libvirt_intWrap(ret);
9875 static PyObject *
9876 libvirt_virStreamRecvFlags(PyObject *self ATTRIBUTE_UNUSED,
9877 PyObject *args)
9879 PyObject *pyobj_stream;
9880 PyObject *rv;
9881 virStreamPtr stream;
9882 char *buf = NULL;
9883 size_t nbytes;
9884 unsigned int flags;
9885 int ret;
9887 if (!PyArg_ParseTuple(args, (char *) "OkI:virStreamRecvFlags",
9888 &pyobj_stream, &nbytes, &flags))
9889 return NULL;
9891 stream = PyvirStream_Get(pyobj_stream);
9893 if (VIR_ALLOC_N(buf, nbytes + 1) < 0)
9894 return PyErr_NoMemory();
9896 LIBVIRT_BEGIN_ALLOW_THREADS;
9897 ret = virStreamRecvFlags(stream, buf, nbytes, flags);
9898 LIBVIRT_END_ALLOW_THREADS;
9900 buf[ret > -1 ? ret : 0] = '\0';
9901 DEBUG("StreamRecvFlags ret=%d strlen=%d\n", ret, (int) strlen(buf));
9903 if (ret == -2 || ret == -3)
9904 return libvirt_intWrap(ret);
9905 if (ret < 0)
9906 return VIR_PY_NONE;
9907 rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
9908 VIR_FREE(buf);
9909 return rv;
9912 #endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */
9915 #if LIBVIR_CHECK_VERSION(4, 4, 0)
9916 static PyObject *
9917 libvirt_virConnectBaselineHypervisorCPU(PyObject *self ATTRIBUTE_UNUSED,
9918 PyObject *args)
9920 virConnectPtr conn;
9921 PyObject *pyobj_conn;
9922 char *emulator;
9923 char *arch;
9924 char *machine;
9925 char *virttype;
9926 PyObject *list;
9927 unsigned int flags;
9928 char **xmlCPUs = NULL;
9929 int ncpus = 0;
9930 size_t i;
9931 char *cpu;
9932 PyObject *ret = NULL;
9934 if (!PyArg_ParseTuple(args, (char *)"OzzzzOI:virConnectBaselineHypervisorCPU",
9935 &pyobj_conn, &emulator, &arch, &machine, &virttype,
9936 &list, &flags))
9937 return NULL;
9939 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
9941 if (PyList_Check(list)) {
9942 ncpus = PyList_Size(list);
9943 if (VIR_ALLOC_N(xmlCPUs, ncpus) < 0)
9944 return PyErr_NoMemory();
9946 for (i = 0; i < ncpus; i++) {
9947 if (libvirt_charPtrUnwrap(PyList_GetItem(list, i),
9948 &(xmlCPUs[i])) < 0)
9949 goto cleanup;
9953 LIBVIRT_BEGIN_ALLOW_THREADS;
9954 cpu = virConnectBaselineHypervisorCPU(conn, emulator, arch, machine, virttype,
9955 (const char **)xmlCPUs, ncpus, flags);
9956 LIBVIRT_END_ALLOW_THREADS;
9958 ret = libvirt_constcharPtrWrap(cpu);
9960 cleanup:
9961 for (i = 0; i < ncpus; i++)
9962 VIR_FREE(xmlCPUs[i]);
9963 VIR_FREE(xmlCPUs);
9964 VIR_FREE(cpu);
9966 return ret;
9968 #endif /* LIBVIR_CHECK_VERSION(4, 4, 0) */
9971 #if LIBVIR_CHECK_VERSION(4, 5, 0)
9972 static PyObject *
9973 libvirt_virDomainGetLaunchSecurityInfo(PyObject *self ATTRIBUTE_UNUSED,
9974 PyObject *args)
9976 PyObject *pyobj_dom = NULL;
9977 PyObject *ret = NULL;
9979 virDomainPtr dom = NULL;
9980 virTypedParameterPtr params = NULL;
9981 int nparams = 0;
9982 unsigned int flags = 0;
9983 int i_retval;
9985 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainGetLaunchSecurityInfo",
9986 &pyobj_dom, &flags))
9987 return NULL;
9988 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
9990 LIBVIRT_BEGIN_ALLOW_THREADS;
9991 i_retval = virDomainGetLaunchSecurityInfo(dom, &params, &nparams, flags);
9992 LIBVIRT_END_ALLOW_THREADS;
9994 if (i_retval < 0) {
9995 ret = VIR_PY_NONE;
9996 goto cleanup;
9999 ret = getPyVirTypedParameter(params, nparams);
10000 cleanup:
10001 virTypedParamsFree(params, nparams);
10002 return ret;
10006 static PyObject *
10007 libvirt_virNodeGetSEVInfo(PyObject *self ATTRIBUTE_UNUSED,
10008 PyObject *args)
10010 PyObject *pyobj_conn = NULL;
10011 PyObject *ret = NULL;
10013 virConnectPtr conn = NULL;
10014 virTypedParameterPtr params = NULL;
10015 int nparams = 0;
10016 unsigned int flags = 0;
10017 int i_retval;
10019 if (!PyArg_ParseTuple(args, (char *)"OI:virNodeGetSEVInfo",
10020 &pyobj_conn, &flags))
10021 return NULL;
10022 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
10024 LIBVIRT_BEGIN_ALLOW_THREADS;
10025 i_retval = virNodeGetSEVInfo(conn, &params, &nparams, flags);
10026 LIBVIRT_END_ALLOW_THREADS;
10028 if (i_retval < 0) {
10029 ret = VIR_PY_NONE;
10030 goto cleanup;
10033 ret = getPyVirTypedParameter(params, nparams);
10034 cleanup:
10035 virTypedParamsFree(params, nparams);
10036 return ret;
10038 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
10040 #if LIBVIR_CHECK_VERSION(5, 5, 0)
10041 static PyObject *
10042 libvirt_virNetworkListAllPorts(PyObject *self ATTRIBUTE_UNUSED,
10043 PyObject *args)
10045 PyObject *pyobj_conn;
10046 PyObject *py_retval = NULL;
10047 virNetworkPtr conn;
10048 virNetworkPortPtr *doms = NULL;
10049 int c_retval = 0;
10050 ssize_t i;
10051 unsigned int flags;
10053 if (!PyArg_ParseTuple(args, (char *)"OI:virNetworkListAllPorts",
10054 &pyobj_conn, &flags))
10055 return NULL;
10056 conn = (virNetworkPtr) PyvirNetwork_Get(pyobj_conn);
10058 LIBVIRT_BEGIN_ALLOW_THREADS;
10059 c_retval = virNetworkListAllPorts(conn, &doms, flags);
10060 LIBVIRT_END_ALLOW_THREADS;
10062 if (c_retval < 0)
10063 return VIR_PY_NONE;
10065 if (!(py_retval = PyList_New(c_retval)))
10066 goto cleanup;
10068 for (i = 0; i < c_retval; i++) {
10069 VIR_PY_LIST_SET_GOTO(py_retval, i, libvirt_virNetworkPortPtrWrap(doms[i]), error);
10070 /* python steals the pointer */
10071 doms[i] = NULL;
10074 cleanup:
10075 for (i = 0; i < c_retval; i++)
10076 if (doms[i])
10077 virNetworkPortFree(doms[i]);
10078 VIR_FREE(doms);
10079 return py_retval;
10081 error:
10082 Py_CLEAR(py_retval);
10083 goto cleanup;
10086 static PyObject *
10087 libvirt_virNetworkPortSetParameters(PyObject *self ATTRIBUTE_UNUSED,
10088 PyObject *args)
10090 virNetworkPortPtr port;
10091 PyObject *pyobj_port, *info;
10092 PyObject *ret = NULL;
10093 int i_retval;
10094 int nparams = 0;
10095 Py_ssize_t size = 0;
10096 unsigned int flags;
10097 virTypedParameterPtr params = NULL, new_params = NULL;
10099 if (!PyArg_ParseTuple(args,
10100 (char *)"OOI:virNetworkPortSetParameters",
10101 &pyobj_port, &info, &flags))
10102 return NULL;
10103 port = (virNetworkPortPtr) PyvirNetworkPort_Get(pyobj_port);
10105 if ((size = PyDict_Size(info)) < 0)
10106 return NULL;
10108 if (size == 0) {
10109 PyErr_Format(PyExc_LookupError,
10110 "Need non-empty dictionary to set attributes");
10111 return NULL;
10114 LIBVIRT_BEGIN_ALLOW_THREADS;
10115 i_retval = virNetworkPortGetParameters(port, &params, &nparams, flags);
10116 LIBVIRT_END_ALLOW_THREADS;
10118 if (i_retval < 0)
10119 return VIR_PY_INT_FAIL;
10121 if (nparams == 0) {
10122 PyErr_Format(PyExc_LookupError,
10123 "Port has no settable attributes");
10124 return NULL;
10127 new_params = setPyVirTypedParameter(info, params, nparams);
10128 if (!new_params)
10129 goto cleanup;
10131 LIBVIRT_BEGIN_ALLOW_THREADS;
10132 i_retval = virNetworkPortSetParameters(port, new_params, size, flags);
10133 LIBVIRT_END_ALLOW_THREADS;
10135 if (i_retval < 0) {
10136 ret = VIR_PY_INT_FAIL;
10137 goto cleanup;
10140 ret = VIR_PY_INT_SUCCESS;
10142 cleanup:
10143 virTypedParamsFree(params, nparams);
10144 virTypedParamsFree(new_params, size);
10145 return ret;
10148 static PyObject *
10149 libvirt_virNetworkPortGetParameters(PyObject *self ATTRIBUTE_UNUSED,
10150 PyObject *args)
10152 PyObject *pyobj_port;
10153 virNetworkPortPtr port;
10154 virTypedParameterPtr params = NULL;
10155 int nparams = 0;
10156 PyObject *dict = NULL;
10157 unsigned int flags;
10158 int rc;
10160 if (!PyArg_ParseTuple(args, (char *) "OI:virNetworkPortGetParameters",
10161 &pyobj_port, &flags))
10162 return NULL;
10163 port = (virNetworkPortPtr) PyvirNetworkPort_Get(pyobj_port);
10165 LIBVIRT_BEGIN_ALLOW_THREADS;
10166 rc = virNetworkPortGetParameters(port, &params, &nparams, flags);
10167 LIBVIRT_END_ALLOW_THREADS;
10169 if (rc < 0)
10170 return VIR_PY_NONE;
10172 dict = getPyVirTypedParameter(params, nparams);
10174 virTypedParamsFree(params, nparams);
10175 return dict;
10177 #endif /* LIBVIR_CHECK_VERSION(5, 5, 0) */
10179 /************************************************************************
10181 * The registration stuff *
10183 ************************************************************************/
10184 static PyMethodDef libvirtMethods[] = {
10185 #include "build/libvirt-export.c"
10186 {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
10187 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL},
10188 #if LIBVIR_CHECK_VERSION(1, 1, 3)
10189 {(char *) "virConnectGetCPUModelNames", libvirt_virConnectGetCPUModelNames, METH_VARARGS, NULL},
10190 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
10191 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
10192 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
10193 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
10194 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
10195 #if LIBVIR_CHECK_VERSION(0, 9, 13)
10196 {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
10197 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
10198 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
10199 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
10200 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
10201 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
10202 #if LIBVIR_CHECK_VERSION(1, 2, 1)
10203 {(char *) "virConnectNetworkEventRegisterAny", libvirt_virConnectNetworkEventRegisterAny, METH_VARARGS, NULL},
10204 {(char *) "virConnectNetworkEventDeregisterAny", libvirt_virConnectNetworkEventDeregisterAny, METH_VARARGS, NULL},
10205 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1) */
10206 #if LIBVIR_CHECK_VERSION(0, 10, 0)
10207 {(char *) "virConnectRegisterCloseCallback", libvirt_virConnectRegisterCloseCallback, METH_VARARGS, NULL},
10208 {(char *) "virConnectUnregisterCloseCallback", libvirt_virConnectUnregisterCloseCallback, METH_VARARGS, NULL},
10209 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
10210 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
10211 {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
10212 {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
10213 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
10214 {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
10215 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
10216 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
10217 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
10218 {(char *) "virNodeGetSecurityModel", libvirt_virNodeGetSecurityModel, METH_VARARGS, NULL},
10219 {(char *) "virDomainGetSecurityLabel", libvirt_virDomainGetSecurityLabel, METH_VARARGS, NULL},
10220 #if LIBVIR_CHECK_VERSION(0, 10, 0)
10221 {(char *) "virDomainGetSecurityLabelList", libvirt_virDomainGetSecurityLabelList, METH_VARARGS, NULL},
10222 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
10223 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
10224 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
10225 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
10226 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
10227 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
10228 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
10229 {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
10230 {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
10231 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
10232 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
10233 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10234 {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
10235 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10236 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
10237 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
10238 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},
10239 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL},
10240 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
10241 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
10242 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL},
10243 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats, METH_VARARGS, NULL},
10244 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
10245 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
10246 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
10247 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
10248 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
10249 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags, METH_VARARGS, NULL},
10250 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
10251 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags, METH_VARARGS, NULL},
10252 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters, METH_VARARGS, NULL},
10253 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters, METH_VARARGS, NULL},
10254 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters, METH_VARARGS, NULL},
10255 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
10256 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
10257 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
10258 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
10259 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
10260 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
10261 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
10262 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
10263 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
10264 #if LIBVIR_CHECK_VERSION(0, 10, 0)
10265 {(char *) "virDomainGetEmulatorPinInfo", libvirt_virDomainGetEmulatorPinInfo, METH_VARARGS, NULL},
10266 {(char *) "virDomainPinEmulator", libvirt_virDomainPinEmulator, METH_VARARGS, NULL},
10267 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
10268 #if LIBVIR_CHECK_VERSION(1, 2, 14)
10269 {(char *) "virDomainGetIOThreadInfo", libvirt_virDomainGetIOThreadInfo, METH_VARARGS, NULL},
10270 {(char *) "virDomainPinIOThread", libvirt_virDomainPinIOThread, METH_VARARGS, NULL},
10271 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
10272 #if LIBVIR_CHECK_VERSION(4, 10, 0)
10273 {(char *) "virDomainSetIOThreadParams", libvirt_virDomainSetIOThreadParams, METH_VARARGS, NULL},
10274 #endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */
10275 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
10276 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
10277 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10278 {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
10279 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10280 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
10281 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
10282 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10283 {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
10284 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10285 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL},
10286 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL},
10287 #if LIBVIR_CHECK_VERSION(3, 0, 0)
10288 {(char *) "virStorageVolGetInfoFlags", libvirt_virStorageVolGetInfoFlags, METH_VARARGS, NULL},
10289 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0) */
10290 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL},
10291 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL},
10292 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL},
10293 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
10294 {(char *) "virEventAddHandle", libvirt_virEventAddHandle, METH_VARARGS, NULL},
10295 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout, METH_VARARGS, NULL},
10296 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
10297 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
10298 {(char *) "virEventInvokeFreeCallback", libvirt_virEventInvokeFreeCallback, METH_VARARGS, NULL},
10299 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
10300 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10301 {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
10302 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10303 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
10304 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
10305 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},
10306 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL},
10307 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
10308 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10309 {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL},
10310 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10311 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
10312 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
10313 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL},
10314 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
10315 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
10316 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
10317 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10318 {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
10319 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10320 #if LIBVIR_CHECK_VERSION(4, 5, 0)
10321 {(char *) "virConnectListAllNWFilterBindings", libvirt_virConnectListAllNWFilterBindings, METH_VARARGS, NULL},
10322 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
10323 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
10324 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
10325 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10326 {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
10327 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10328 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
10329 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
10330 #if LIBVIR_CHECK_VERSION(1, 0, 3)
10331 {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL},
10332 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
10333 #if LIBVIR_CHECK_VERSION(5, 6, 0)
10334 {(char *) "virDomainListAllCheckpoints", libvirt_virDomainListAllCheckpoints, METH_VARARGS, NULL},
10335 {(char *) "virDomainCheckpointListAllChildren", libvirt_virDomainCheckpointListAllChildren, METH_VARARGS, NULL},
10336 #endif /* LIBVIR_CHECK_VERSION(5, 6, 0) */
10337 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
10338 #if LIBVIR_CHECK_VERSION(0, 9, 13)
10339 {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
10340 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
10341 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
10342 #if LIBVIR_CHECK_VERSION(0, 9, 13)
10343 {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
10344 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
10345 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
10346 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
10347 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
10348 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL},
10349 {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
10350 #if LIBVIR_CHECK_VERSION(1, 0, 3)
10351 {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL},
10352 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
10353 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
10354 #if LIBVIR_CHECK_VERSION(3, 7, 0)
10355 {(char *) "virDomainMigrateGetMaxDowntime", libvirt_virDomainMigrateGetMaxDowntime, METH_VARARGS, NULL},
10356 #endif /* LIBVIR_CHECK_VERSION(3, 7, 0) */
10357 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
10358 #if LIBVIR_CHECK_VERSION(1, 1, 0)
10359 {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL},
10360 {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL},
10361 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
10362 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
10363 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
10364 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
10365 #if LIBVIR_CHECK_VERSION(0, 10, 2)
10366 {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
10367 {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
10368 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
10369 #if LIBVIR_CHECK_VERSION(1, 0, 0)
10370 {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
10371 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
10372 #if LIBVIR_CHECK_VERSION(1, 1, 1)
10373 {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL},
10374 {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL},
10375 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
10376 #if LIBVIR_CHECK_VERSION(1, 2, 5)
10377 {(char *) "virDomainFSFreeze", libvirt_virDomainFSFreeze, METH_VARARGS, NULL},
10378 {(char *) "virDomainFSThaw", libvirt_virDomainFSThaw, METH_VARARGS, NULL},
10379 {(char *) "virDomainGetTime", libvirt_virDomainGetTime, METH_VARARGS, NULL},
10380 {(char *) "virDomainSetTime", libvirt_virDomainSetTime, METH_VARARGS, NULL},
10381 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
10382 #if LIBVIR_CHECK_VERSION(1, 2, 6)
10383 {(char *) "virNodeGetFreePages", libvirt_virNodeGetFreePages, METH_VARARGS, NULL},
10384 {(char *) "virNetworkGetDHCPLeases", libvirt_virNetworkGetDHCPLeases, METH_VARARGS, NULL},
10385 #endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
10386 #if LIBVIR_CHECK_VERSION(1, 2, 8)
10387 {(char *) "virConnectGetAllDomainStats", libvirt_virConnectGetAllDomainStats, METH_VARARGS, NULL},
10388 {(char *) "virDomainListGetStats", libvirt_virDomainListGetStats, METH_VARARGS, NULL},
10389 {(char *) "virDomainBlockCopy", libvirt_virDomainBlockCopy, METH_VARARGS, NULL},
10390 #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
10391 #if LIBVIR_CHECK_VERSION(1, 2, 9)
10392 {(char *) "virNodeAllocPages", libvirt_virNodeAllocPages, METH_VARARGS, NULL},
10393 #endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
10394 #if LIBVIR_CHECK_VERSION(1, 2, 11)
10395 {(char *) "virDomainGetFSInfo", libvirt_virDomainGetFSInfo, METH_VARARGS, NULL},
10396 #endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
10397 #if LIBVIR_CHECK_VERSION(1, 2, 14)
10398 {(char *) "virDomainInterfaceAddresses", libvirt_virDomainInterfaceAddresses, METH_VARARGS, NULL},
10399 #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
10400 #if LIBVIR_CHECK_VERSION(1, 3, 3)
10401 {(char *) "virDomainGetPerfEvents", libvirt_virDomainGetPerfEvents, METH_VARARGS, NULL},
10402 {(char *) "virDomainSetPerfEvents", libvirt_virDomainSetPerfEvents, METH_VARARGS, NULL},
10403 #endif /* LIBVIR_CHECK_VERSION(1, 3, 3) */
10404 #if LIBVIR_CHECK_VERSION(2, 0, 0)
10405 {(char *) "virConnectStoragePoolEventRegisterAny", libvirt_virConnectStoragePoolEventRegisterAny, METH_VARARGS, NULL},
10406 {(char *) "virConnectStoragePoolEventDeregisterAny", libvirt_virConnectStoragePoolEventDeregisterAny, METH_VARARGS, NULL},
10407 {(char *) "virDomainGetGuestVcpus", libvirt_virDomainGetGuestVcpus, METH_VARARGS, NULL},
10408 #endif /* LIBVIR_CHECK_VERSION(2, 0, 0) */
10409 #if LIBVIR_CHECK_VERSION(2, 2, 0)
10410 {(char *) "virConnectNodeDeviceEventRegisterAny", libvirt_virConnectNodeDeviceEventRegisterAny, METH_VARARGS, NULL},
10411 {(char *) "virConnectNodeDeviceEventDeregisterAny", libvirt_virConnectNodeDeviceEventDeregisterAny, METH_VARARGS, NULL},
10412 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0) */
10413 #if LIBVIR_CHECK_VERSION(3, 0, 0)
10414 {(char *) "virConnectSecretEventRegisterAny", libvirt_virConnectSecretEventRegisterAny, METH_VARARGS, NULL},
10415 {(char *) "virConnectSecretEventDeregisterAny", libvirt_virConnectSecretEventDeregisterAny, METH_VARARGS, NULL},
10416 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0) */
10417 #if LIBVIR_CHECK_VERSION(3, 4, 0)
10418 {(char *) "virStreamRecvHole", libvirt_virStreamRecvHole, METH_VARARGS, NULL},
10419 {(char *) "virStreamSendHole", libvirt_virStreamSendHole, METH_VARARGS, NULL},
10420 {(char *) "virStreamRecvFlags", libvirt_virStreamRecvFlags, METH_VARARGS, NULL},
10421 #endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */
10422 #if LIBVIR_CHECK_VERSION(4, 4, 0)
10423 {(char *) "virConnectBaselineHypervisorCPU", libvirt_virConnectBaselineHypervisorCPU, METH_VARARGS, NULL},
10424 #endif /* LIBVIR_CHECK_VERSION(4, 4, 0) */
10425 #if LIBVIR_CHECK_VERSION(4, 5, 0)
10426 {(char *) "virDomainGetLaunchSecurityInfo", libvirt_virDomainGetLaunchSecurityInfo, METH_VARARGS, NULL},
10427 {(char *) "virNodeGetSEVInfo", libvirt_virNodeGetSEVInfo, METH_VARARGS, NULL},
10428 #endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
10429 #if LIBVIR_CHECK_VERSION(5, 5, 0)
10430 {(char *) "virNetworkListAllPorts", libvirt_virNetworkListAllPorts, METH_VARARGS, NULL},
10431 {(char *) "virNetworkPortSetParameters", libvirt_virNetworkPortSetParameters, METH_VARARGS, NULL},
10432 {(char *) "virNetworkPortGetParameters", libvirt_virNetworkPortGetParameters, METH_VARARGS, NULL},
10433 #endif /* LIBVIR_CHECK_VERSION(5, 5, 0) */
10434 {NULL, NULL, 0, NULL}
10437 #if PY_MAJOR_VERSION > 2
10438 static struct PyModuleDef moduledef = {
10439 PyModuleDef_HEAD_INIT,
10440 # ifndef __CYGWIN__
10441 "libvirtmod",
10442 # else
10443 "cygvirtmod",
10444 # endif
10445 NULL,
10447 libvirtMethods,
10448 NULL,
10449 NULL,
10450 NULL,
10451 NULL
10454 PyObject *
10455 # ifndef __CYGWIN__
10456 PyInit_libvirtmod
10457 # else
10458 PyInit_cygvirtmod
10459 # endif
10460 (void)
10462 PyObject *module;
10464 if (virInitialize() < 0)
10465 return NULL;
10467 module = PyModule_Create(&moduledef);
10469 return module;
10471 #else /* ! PY_MAJOR_VERSION > 2 */
10472 void
10473 # ifndef __CYGWIN__
10474 initlibvirtmod
10475 # else
10476 initcygvirtmod
10477 # endif
10478 (void)
10480 if (virInitialize() < 0)
10481 return;
10483 /* initialize the python extension module */
10484 Py_InitModule((char *)
10485 # ifndef __CYGWIN__
10486 "libvirtmod",
10487 # else
10488 "cygvirtmod",
10489 # endif
10490 libvirtMethods);
10492 #endif /* ! PY_MAJOR_VERSION > 2 */