fix leak in memoryStats with older python
[libvirt-python/ericb.git] / libvirt-override.c
blob8fd856b27b3ae519206875570ea80747c6d8877b
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-2014 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
54 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
55 is so common that we encapsulate it here. Now, each use is simply
56 return VIR_PY_NONE; */
57 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
58 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
59 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
61 static char *py_str(PyObject *obj)
63 PyObject *str = PyObject_Str(obj);
64 char *ret;
65 if (!str) {
66 PyErr_Print();
67 PyErr_Clear();
68 return NULL;
70 libvirt_charPtrUnwrap(str, &ret);
71 return ret;
74 /* Helper function to convert a virTypedParameter output array into a
75 * Python dictionary for return to the user. Return NULL on failure,
76 * after raising a python exception. */
77 static PyObject *
78 getPyVirTypedParameter(const virTypedParameter *params, int nparams)
80 PyObject *key, *val, *info;
81 size_t i;
83 if ((info = PyDict_New()) == NULL)
84 return NULL;
86 for (i = 0; i < nparams; i++) {
87 switch (params[i].type) {
88 case VIR_TYPED_PARAM_INT:
89 val = libvirt_intWrap(params[i].value.i);
90 break;
92 case VIR_TYPED_PARAM_UINT:
93 val = libvirt_intWrap(params[i].value.ui);
94 break;
96 case VIR_TYPED_PARAM_LLONG:
97 val = libvirt_longlongWrap(params[i].value.l);
98 break;
100 case VIR_TYPED_PARAM_ULLONG:
101 val = libvirt_ulonglongWrap(params[i].value.ul);
102 break;
104 case VIR_TYPED_PARAM_DOUBLE:
105 val = PyFloat_FromDouble(params[i].value.d);
106 break;
108 case VIR_TYPED_PARAM_BOOLEAN:
109 val = PyBool_FromLong(params[i].value.b);
110 break;
112 case VIR_TYPED_PARAM_STRING:
113 val = libvirt_constcharPtrWrap(params[i].value.s);
114 break;
116 default:
117 /* Possible if a newer server has a bug and sent stuff we
118 * don't recognize. */
119 PyErr_Format(PyExc_LookupError,
120 "Type value \"%d\" not recognized",
121 params[i].type);
122 val = NULL;
123 break;
126 key = libvirt_constcharPtrWrap(params[i].field);
127 if (!key || !val)
128 goto cleanup;
130 if (PyDict_SetItem(info, key, val) < 0) {
131 Py_DECREF(info);
132 goto cleanup;
135 Py_DECREF(key);
136 Py_DECREF(val);
138 return info;
140 cleanup:
141 Py_XDECREF(key);
142 Py_XDECREF(val);
143 return NULL;
146 /* Allocate a new typed parameter array with the same contents and
147 * length as info, and using the array params of length nparams as
148 * hints on what types to use when creating the new array. The caller
149 * must clear the array before freeing it. Return NULL on failure,
150 * after raising a python exception. */
151 static virTypedParameterPtr ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
152 setPyVirTypedParameter(PyObject *info,
153 const virTypedParameter *params, int nparams)
155 PyObject *key, *value;
156 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
157 int pos = 0;
158 #else
159 Py_ssize_t pos = 0;
160 #endif
161 virTypedParameterPtr temp = NULL, ret = NULL;
162 Py_ssize_t size;
163 size_t i;
165 if ((size = PyDict_Size(info)) < 0)
166 return NULL;
168 /* Libvirt APIs use NULL array and 0 size as a special case;
169 * setting should have at least one parameter. */
170 if (size == 0) {
171 PyErr_Format(PyExc_LookupError, "Dictionary must not be empty");
172 return NULL;
175 if (VIR_ALLOC_N(ret, size) < 0) {
176 PyErr_NoMemory();
177 return NULL;
180 temp = &ret[0];
181 while (PyDict_Next(info, &pos, &key, &value)) {
182 char *keystr = NULL;
184 if (libvirt_charPtrUnwrap(key, &keystr) < 0 ||
185 keystr == NULL)
186 goto cleanup;
188 for (i = 0; i < nparams; i++) {
189 if (STREQ(params[i].field, keystr))
190 break;
192 if (i == nparams) {
193 PyErr_Format(PyExc_LookupError,
194 "Attribute name \"%s\" could not be recognized",
195 keystr);
196 VIR_FREE(keystr);
197 goto cleanup;
200 strncpy(temp->field, keystr, VIR_TYPED_PARAM_FIELD_LENGTH - 1);
201 temp->type = params[i].type;
202 VIR_FREE(keystr);
204 switch (params[i].type) {
205 case VIR_TYPED_PARAM_INT:
206 if (libvirt_intUnwrap(value, &temp->value.i) < 0)
207 goto cleanup;
208 break;
210 case VIR_TYPED_PARAM_UINT:
211 if (libvirt_uintUnwrap(value, &temp->value.ui) < 0)
212 goto cleanup;
213 break;
215 case VIR_TYPED_PARAM_LLONG:
216 if (libvirt_longlongUnwrap(value, &temp->value.l) < 0)
217 goto cleanup;
218 break;
220 case VIR_TYPED_PARAM_ULLONG:
221 if (libvirt_ulonglongUnwrap(value, &temp->value.ul) < 0)
222 goto cleanup;
223 break;
225 case VIR_TYPED_PARAM_DOUBLE:
226 if (libvirt_doubleUnwrap(value, &temp->value.d) < 0)
227 goto cleanup;
228 break;
230 case VIR_TYPED_PARAM_BOOLEAN:
232 bool b;
233 if (libvirt_boolUnwrap(value, &b) < 0)
234 goto cleanup;
235 temp->value.b = b;
236 break;
238 case VIR_TYPED_PARAM_STRING:
240 char *string_val;
241 if (libvirt_charPtrUnwrap(value, &string_val) < 0 ||
242 !string_val)
243 goto cleanup;
244 temp->value.s = string_val;
245 break;
248 default:
249 /* Possible if a newer server has a bug and sent stuff we
250 * don't recognize. */
251 PyErr_Format(PyExc_LookupError,
252 "Type value \"%d\" not recognized",
253 params[i].type);
254 goto cleanup;
257 temp++;
259 return ret;
261 cleanup:
262 virTypedParamsFree(ret, size);
263 return NULL;
266 /* While these appeared in libvirt in 1.0.2, we only
267 * need them in the python from 1.1.0 onwards */
268 #if LIBVIR_CHECK_VERSION(1, 1, 0)
269 typedef struct {
270 const char *name;
271 int type;
272 } virPyTypedParamsHint;
273 typedef virPyTypedParamsHint *virPyTypedParamsHintPtr;
275 # if PY_MAJOR_VERSION > 2
276 # define libvirt_PyString_Check PyUnicode_Check
277 # else
278 # define libvirt_PyString_Check PyString_Check
279 # endif
281 /* Automatically convert dict into type parameters based on types reported
282 * by python. All integer types are converted into LLONG (in case of a negative
283 * value) or ULLONG (in case of a positive value). If you need different
284 * handling, use @hints to explicitly specify what types should be used for
285 * specific parameters.
287 static int
288 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
289 virPyDictToTypedParams(PyObject *dict,
290 virTypedParameterPtr *ret_params,
291 int *ret_nparams,
292 virPyTypedParamsHintPtr hints,
293 int nhints)
295 PyObject *key;
296 PyObject *value;
297 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
298 int pos = 0;
299 #else
300 Py_ssize_t pos = 0;
301 #endif
302 virTypedParameterPtr params = NULL;
303 size_t i;
304 int n = 0;
305 int max = 0;
306 int ret = -1;
307 char *keystr = NULL;
309 *ret_params = NULL;
310 *ret_nparams = 0;
312 if (PyDict_Size(dict) < 0)
313 return -1;
315 while (PyDict_Next(dict, &pos, &key, &value)) {
316 int type = -1;
318 if (libvirt_charPtrUnwrap(key, &keystr) < 0 ||
319 !keystr)
320 goto cleanup;
322 for (i = 0; i < nhints; i++) {
323 if (STREQ(hints[i].name, keystr)) {
324 type = hints[i].type;
325 break;
329 if (type == -1) {
330 if (libvirt_PyString_Check(value)) {
331 type = VIR_TYPED_PARAM_STRING;
332 } else if (PyBool_Check(value)) {
333 type = VIR_TYPED_PARAM_BOOLEAN;
334 } else if (PyLong_Check(value)) {
335 unsigned long long ull = PyLong_AsUnsignedLongLong(value);
336 if (ull == (unsigned long long) -1 && PyErr_Occurred())
337 type = VIR_TYPED_PARAM_LLONG;
338 else
339 type = VIR_TYPED_PARAM_ULLONG;
340 #if PY_MAJOR_VERSION < 3
341 } else if (PyInt_Check(value)) {
342 if (PyInt_AS_LONG(value) < 0)
343 type = VIR_TYPED_PARAM_LLONG;
344 else
345 type = VIR_TYPED_PARAM_ULLONG;
346 #endif
347 } else if (PyFloat_Check(value)) {
348 type = VIR_TYPED_PARAM_DOUBLE;
352 if (type == -1) {
353 PyErr_Format(PyExc_TypeError,
354 "Unknown type of \"%s\" field", keystr);
355 goto cleanup;
358 switch ((virTypedParameterType) type) {
359 case VIR_TYPED_PARAM_INT:
361 int val;
362 if (libvirt_intUnwrap(value, &val) < 0 ||
363 virTypedParamsAddInt(&params, &n, &max, keystr, val) < 0)
364 goto cleanup;
365 break;
367 case VIR_TYPED_PARAM_UINT:
369 unsigned int val;
370 if (libvirt_uintUnwrap(value, &val) < 0 ||
371 virTypedParamsAddUInt(&params, &n, &max, keystr, val) < 0)
372 goto cleanup;
373 break;
375 case VIR_TYPED_PARAM_LLONG:
377 long long val;
378 if (libvirt_longlongUnwrap(value, &val) < 0 ||
379 virTypedParamsAddLLong(&params, &n, &max, keystr, val) < 0)
380 goto cleanup;
381 break;
383 case VIR_TYPED_PARAM_ULLONG:
385 unsigned long long val;
386 if (libvirt_ulonglongUnwrap(value, &val) < 0 ||
387 virTypedParamsAddULLong(&params, &n, &max, keystr, val) < 0)
388 goto cleanup;
389 break;
391 case VIR_TYPED_PARAM_DOUBLE:
393 double val;
394 if (libvirt_doubleUnwrap(value, &val) < 0 ||
395 virTypedParamsAddDouble(&params, &n, &max, keystr, val) < 0)
396 goto cleanup;
397 break;
399 case VIR_TYPED_PARAM_BOOLEAN:
401 bool val;
402 if (libvirt_boolUnwrap(value, &val) < 0 ||
403 virTypedParamsAddBoolean(&params, &n, &max, keystr, val) < 0)
404 goto cleanup;
405 break;
407 case VIR_TYPED_PARAM_STRING:
409 char *val;;
410 if (libvirt_charPtrUnwrap(value, &val) < 0 ||
411 !val ||
412 virTypedParamsAddString(&params, &n, &max, keystr, val) < 0) {
413 VIR_FREE(val);
414 goto cleanup;
416 VIR_FREE(val);
417 break;
419 case VIR_TYPED_PARAM_LAST:
420 break; /* unreachable */
422 VIR_FREE(keystr);
425 *ret_params = params;
426 *ret_nparams = n;
427 params = NULL;
428 ret = 0;
430 cleanup:
431 VIR_FREE(keystr);
432 virTypedParamsFree(params, n);
433 return ret;
435 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
439 * Utility function to retrieve the number of node CPUs present.
440 * It first tries virGetNodeCPUMap, which will return the
441 * number reliably, if available.
442 * As a fallback and for compatibility with backlevel libvirt
443 * versions virGetNodeInfo will be called to calculate the
444 * CPU number, which has the potential to return a too small
445 * number if some host CPUs are offline.
447 static int
448 getPyNodeCPUCount(virConnectPtr conn) {
449 int i_retval = -1;
450 virNodeInfo nodeinfo;
452 #if LIBVIR_CHECK_VERSION(1, 0, 0)
453 LIBVIRT_BEGIN_ALLOW_THREADS;
454 i_retval = virNodeGetCPUMap(conn, NULL, NULL, 0);
455 LIBVIRT_END_ALLOW_THREADS;
456 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
458 if (i_retval < 0) {
459 /* fallback: use nodeinfo */
460 LIBVIRT_BEGIN_ALLOW_THREADS;
461 i_retval = virNodeGetInfo(conn, &nodeinfo);
462 LIBVIRT_END_ALLOW_THREADS;
463 if (i_retval < 0)
464 goto cleanup;
466 i_retval = VIR_NODEINFO_MAXCPUS(nodeinfo);
469 cleanup:
470 return i_retval;
473 /************************************************************************
475 * Statistics *
477 ************************************************************************/
479 static PyObject *
480 libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
481 virDomainPtr domain;
482 PyObject *pyobj_domain;
483 char * path;
484 int c_retval;
485 virDomainBlockStatsStruct stats;
486 PyObject *info;
488 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats",
489 &pyobj_domain, &path))
490 return NULL;
491 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
493 LIBVIRT_BEGIN_ALLOW_THREADS;
494 c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats));
495 LIBVIRT_END_ALLOW_THREADS;
497 if (c_retval < 0)
498 return VIR_PY_NONE;
500 /* convert to a Python tuple of long objects */
501 if ((info = PyTuple_New(5)) == NULL)
502 return VIR_PY_NONE;
503 PyTuple_SetItem(info, 0, libvirt_longlongWrap(stats.rd_req));
504 PyTuple_SetItem(info, 1, libvirt_longlongWrap(stats.rd_bytes));
505 PyTuple_SetItem(info, 2, libvirt_longlongWrap(stats.wr_req));
506 PyTuple_SetItem(info, 3, libvirt_longlongWrap(stats.wr_bytes));
507 PyTuple_SetItem(info, 4, libvirt_longlongWrap(stats.errs));
508 return info;
511 static PyObject *
512 libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED,
513 PyObject *args)
515 virDomainPtr domain;
516 PyObject *pyobj_domain;
517 PyObject *ret = NULL;
518 int i_retval;
519 int nparams = 0;
520 unsigned int flags;
521 virTypedParameterPtr params;
522 const char *path;
524 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainBlockStatsFlags",
525 &pyobj_domain, &path, &flags))
526 return NULL;
527 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
529 LIBVIRT_BEGIN_ALLOW_THREADS;
530 i_retval = virDomainBlockStatsFlags(domain, path, NULL, &nparams, flags);
531 LIBVIRT_END_ALLOW_THREADS;
533 if (i_retval < 0)
534 return VIR_PY_NONE;
536 if (!nparams)
537 return PyDict_New();
539 if (VIR_ALLOC_N(params, nparams) < 0)
540 return PyErr_NoMemory();
542 LIBVIRT_BEGIN_ALLOW_THREADS;
543 i_retval = virDomainBlockStatsFlags(domain, path, params, &nparams, flags);
544 LIBVIRT_END_ALLOW_THREADS;
546 if (i_retval < 0) {
547 ret = VIR_PY_NONE;
548 goto cleanup;
551 ret = getPyVirTypedParameter(params, nparams);
553 cleanup:
554 virTypedParamsFree(params, nparams);
555 return ret;
558 static PyObject *
559 libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
561 virDomainPtr domain;
562 PyObject *pyobj_domain, *totalbool;
563 PyObject *cpu, *total;
564 PyObject *ret = NULL;
565 PyObject *error = NULL;
566 int ncpus = -1, start_cpu = 0;
567 int sumparams = 0, nparams = -1;
568 size_t i;
569 int i_retval;
570 unsigned int flags;
571 bool totalflag;
572 virTypedParameterPtr params = NULL, cpuparams;
574 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainGetCPUStats",
575 &pyobj_domain, &totalbool, &flags))
576 return NULL;
577 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
579 if (libvirt_boolUnwrap(totalbool, &totalflag) < 0)
580 return NULL;
582 if ((ret = PyList_New(0)) == NULL)
583 return NULL;
585 if (!totalflag) {
586 LIBVIRT_BEGIN_ALLOW_THREADS;
587 ncpus = virDomainGetCPUStats(domain, NULL, 0, 0, 0, flags);
588 LIBVIRT_END_ALLOW_THREADS;
590 if (ncpus < 0) {
591 error = VIR_PY_NONE;
592 goto error;
595 LIBVIRT_BEGIN_ALLOW_THREADS;
596 nparams = virDomainGetCPUStats(domain, NULL, 0, 0, 1, flags);
597 LIBVIRT_END_ALLOW_THREADS;
599 if (nparams < 0) {
600 error = VIR_PY_NONE;
601 goto error;
604 sumparams = nparams * MIN(ncpus, 128);
606 if (VIR_ALLOC_N(params, sumparams) < 0) {
607 error = PyErr_NoMemory();
608 goto error;
611 while (ncpus) {
612 int queried_ncpus = MIN(ncpus, 128);
613 if (nparams) {
615 LIBVIRT_BEGIN_ALLOW_THREADS;
616 i_retval = virDomainGetCPUStats(domain, params,
617 nparams, start_cpu, queried_ncpus, flags);
618 LIBVIRT_END_ALLOW_THREADS;
620 if (i_retval < 0) {
621 error = VIR_PY_NONE;
622 goto error;
624 } else {
625 i_retval = 0;
628 for (i = 0; i < queried_ncpus; i++) {
629 cpuparams = &params[i * nparams];
630 if ((cpu = getPyVirTypedParameter(cpuparams, i_retval)) == NULL) {
631 goto error;
634 if (PyList_Append(ret, cpu) < 0) {
635 Py_DECREF(cpu);
636 goto error;
638 Py_DECREF(cpu);
641 start_cpu += queried_ncpus;
642 ncpus -= queried_ncpus;
643 virTypedParamsClear(params, sumparams);
645 } else {
646 LIBVIRT_BEGIN_ALLOW_THREADS;
647 nparams = virDomainGetCPUStats(domain, NULL, 0, -1, 1, flags);
648 LIBVIRT_END_ALLOW_THREADS;
650 if (nparams < 0) {
651 error = VIR_PY_NONE;
652 goto error;
655 if (nparams) {
656 sumparams = nparams;
658 if (VIR_ALLOC_N(params, nparams) < 0) {
659 error = PyErr_NoMemory();
660 goto error;
663 LIBVIRT_BEGIN_ALLOW_THREADS;
664 i_retval = virDomainGetCPUStats(domain, params, nparams, -1, 1, flags);
665 LIBVIRT_END_ALLOW_THREADS;
667 if (i_retval < 0) {
668 error = VIR_PY_NONE;
669 goto error;
671 } else {
672 i_retval = 0;
675 if ((total = getPyVirTypedParameter(params, i_retval)) == NULL) {
676 goto error;
678 if (PyList_Append(ret, total) < 0) {
679 Py_DECREF(total);
680 goto error;
682 Py_DECREF(total);
685 virTypedParamsFree(params, sumparams);
686 return ret;
688 error:
689 virTypedParamsFree(params, sumparams);
690 Py_DECREF(ret);
691 return error;
694 static PyObject *
695 libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
696 virDomainPtr domain;
697 PyObject *pyobj_domain;
698 char * path;
699 int c_retval;
700 virDomainInterfaceStatsStruct stats;
701 PyObject *info;
703 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainInterfaceStats",
704 &pyobj_domain, &path))
705 return NULL;
706 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
708 LIBVIRT_BEGIN_ALLOW_THREADS;
709 c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats));
710 LIBVIRT_END_ALLOW_THREADS;
712 if (c_retval < 0)
713 return VIR_PY_NONE;
715 /* convert to a Python tuple of long objects */
716 if ((info = PyTuple_New(8)) == NULL)
717 return VIR_PY_NONE;
718 PyTuple_SetItem(info, 0, libvirt_longlongWrap(stats.rx_bytes));
719 PyTuple_SetItem(info, 1, libvirt_longlongWrap(stats.rx_packets));
720 PyTuple_SetItem(info, 2, libvirt_longlongWrap(stats.rx_errs));
721 PyTuple_SetItem(info, 3, libvirt_longlongWrap(stats.rx_drop));
722 PyTuple_SetItem(info, 4, libvirt_longlongWrap(stats.tx_bytes));
723 PyTuple_SetItem(info, 5, libvirt_longlongWrap(stats.tx_packets));
724 PyTuple_SetItem(info, 6, libvirt_longlongWrap(stats.tx_errs));
725 PyTuple_SetItem(info, 7, libvirt_longlongWrap(stats.tx_drop));
726 return info;
729 static PyObject *
730 libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
731 virDomainPtr domain;
732 PyObject *pyobj_domain;
733 unsigned int nr_stats;
734 size_t i;
735 virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
736 PyObject *info;
737 PyObject *key = NULL, *val = NULL;
739 if (!PyArg_ParseTuple(args, (char *)"O:virDomainMemoryStats", &pyobj_domain))
740 return NULL;
741 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
743 nr_stats = virDomainMemoryStats(domain, stats,
744 VIR_DOMAIN_MEMORY_STAT_NR, 0);
745 if (nr_stats == -1)
746 return VIR_PY_NONE;
748 /* convert to a Python dictionary */
749 if ((info = PyDict_New()) == NULL)
750 return VIR_PY_NONE;
752 for (i = 0; i < nr_stats; i++) {
753 switch (stats[i].tag) {
754 case VIR_DOMAIN_MEMORY_STAT_SWAP_IN:
755 key = libvirt_constcharPtrWrap("swap_in");
756 break;
757 case VIR_DOMAIN_MEMORY_STAT_SWAP_OUT:
758 key = libvirt_constcharPtrWrap("swap_out");
759 break;
760 case VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT:
761 key = libvirt_constcharPtrWrap("major_fault");
762 break;
763 case VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT:
764 key = libvirt_constcharPtrWrap("minor_fault");
765 break;
766 case VIR_DOMAIN_MEMORY_STAT_UNUSED:
767 key = libvirt_constcharPtrWrap("unused");
768 break;
769 case VIR_DOMAIN_MEMORY_STAT_AVAILABLE:
770 key = libvirt_constcharPtrWrap("available");
771 break;
772 case VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON:
773 key = libvirt_constcharPtrWrap("actual");
774 break;
775 case VIR_DOMAIN_MEMORY_STAT_RSS:
776 key = libvirt_constcharPtrWrap("rss");
777 break;
778 default:
779 continue;
781 val = libvirt_ulonglongWrap(stats[i].val);
783 if (!key || !val || PyDict_SetItem(info, key, val) < 0) {
784 Py_DECREF(info);
785 info = NULL;
786 goto cleanup;
788 Py_DECREF(key);
789 Py_DECREF(val);
790 key = NULL;
791 val = NULL;
794 cleanup:
795 Py_XDECREF(key);
796 Py_XDECREF(val);
797 return info;
800 static PyObject *
801 libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
802 PyObject *args) {
803 virDomainPtr domain;
804 PyObject *pyobj_domain, *info;
805 char *c_retval;
806 int nparams;
808 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerType",
809 &pyobj_domain))
810 return NULL;
811 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
813 LIBVIRT_BEGIN_ALLOW_THREADS;
814 c_retval = virDomainGetSchedulerType(domain, &nparams);
815 LIBVIRT_END_ALLOW_THREADS;
816 if (c_retval == NULL)
817 return VIR_PY_NONE;
819 /* convert to a Python tuple of long objects */
820 if ((info = PyTuple_New(2)) == NULL) {
821 VIR_FREE(c_retval);
822 return VIR_PY_NONE;
825 PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(c_retval));
826 PyTuple_SetItem(info, 1, libvirt_intWrap((long)nparams));
827 VIR_FREE(c_retval);
828 return info;
831 static PyObject *
832 libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
833 PyObject *args)
835 virDomainPtr domain;
836 PyObject *pyobj_domain;
837 PyObject *ret = NULL;
838 char *c_retval;
839 int i_retval;
840 int nparams = 0;
841 virTypedParameterPtr params;
843 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerParameters",
844 &pyobj_domain))
845 return NULL;
846 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
848 LIBVIRT_BEGIN_ALLOW_THREADS;
849 c_retval = virDomainGetSchedulerType(domain, &nparams);
850 LIBVIRT_END_ALLOW_THREADS;
852 if (c_retval == NULL)
853 return VIR_PY_NONE;
854 VIR_FREE(c_retval);
856 if (!nparams)
857 return PyDict_New();
859 if (VIR_ALLOC_N(params, nparams) < 0)
860 return PyErr_NoMemory();
862 LIBVIRT_BEGIN_ALLOW_THREADS;
863 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
864 LIBVIRT_END_ALLOW_THREADS;
866 if (i_retval < 0) {
867 ret = VIR_PY_NONE;
868 goto cleanup;
871 ret = getPyVirTypedParameter(params, nparams);
873 cleanup:
874 virTypedParamsFree(params, nparams);
875 return ret;
878 static PyObject *
879 libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
880 PyObject *args)
882 virDomainPtr domain;
883 PyObject *pyobj_domain;
884 PyObject *ret = NULL;
885 char *c_retval;
886 int i_retval;
887 int nparams = 0;
888 unsigned int flags;
889 virTypedParameterPtr params;
891 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetScedulerParametersFlags",
892 &pyobj_domain, &flags))
893 return NULL;
894 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
896 LIBVIRT_BEGIN_ALLOW_THREADS;
897 c_retval = virDomainGetSchedulerType(domain, &nparams);
898 LIBVIRT_END_ALLOW_THREADS;
900 if (c_retval == NULL)
901 return VIR_PY_NONE;
902 VIR_FREE(c_retval);
904 if (!nparams)
905 return PyDict_New();
907 if (VIR_ALLOC_N(params, nparams) < 0)
908 return PyErr_NoMemory();
910 LIBVIRT_BEGIN_ALLOW_THREADS;
911 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams, flags);
912 LIBVIRT_END_ALLOW_THREADS;
914 if (i_retval < 0) {
915 ret = VIR_PY_NONE;
916 goto cleanup;
919 ret = getPyVirTypedParameter(params, nparams);
921 cleanup:
922 virTypedParamsFree(params, nparams);
923 return ret;
926 static PyObject *
927 libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
928 PyObject *args)
930 virDomainPtr domain;
931 PyObject *pyobj_domain, *info;
932 PyObject *ret = NULL;
933 char *c_retval;
934 int i_retval;
935 int nparams = 0;
936 Py_ssize_t size = 0;
937 virTypedParameterPtr params = NULL, new_params = NULL;
939 if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetScedulerParameters",
940 &pyobj_domain, &info))
941 return NULL;
942 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
944 if ((size = PyDict_Size(info)) < 0)
945 return NULL;
947 if (size == 0) {
948 PyErr_Format(PyExc_LookupError,
949 "Need non-empty dictionary to set attributes");
950 return NULL;
953 LIBVIRT_BEGIN_ALLOW_THREADS;
954 c_retval = virDomainGetSchedulerType(domain, &nparams);
955 LIBVIRT_END_ALLOW_THREADS;
957 if (c_retval == NULL)
958 return VIR_PY_INT_FAIL;
959 VIR_FREE(c_retval);
961 if (nparams == 0) {
962 PyErr_Format(PyExc_LookupError,
963 "Domain has no settable attributes");
964 return NULL;
967 if (VIR_ALLOC_N(params, nparams) < 0)
968 return PyErr_NoMemory();
970 LIBVIRT_BEGIN_ALLOW_THREADS;
971 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
972 LIBVIRT_END_ALLOW_THREADS;
974 if (i_retval < 0) {
975 ret = VIR_PY_INT_FAIL;
976 goto cleanup;
979 new_params = setPyVirTypedParameter(info, params, nparams);
980 if (!new_params)
981 goto cleanup;
983 LIBVIRT_BEGIN_ALLOW_THREADS;
984 i_retval = virDomainSetSchedulerParameters(domain, new_params, size);
985 LIBVIRT_END_ALLOW_THREADS;
987 if (i_retval < 0) {
988 ret = VIR_PY_INT_FAIL;
989 goto cleanup;
992 ret = VIR_PY_INT_SUCCESS;
994 cleanup:
995 virTypedParamsFree(params, nparams);
996 virTypedParamsFree(new_params, size);
997 return ret;
1000 static PyObject *
1001 libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
1002 PyObject *args)
1004 virDomainPtr domain;
1005 PyObject *pyobj_domain, *info;
1006 PyObject *ret = NULL;
1007 char *c_retval;
1008 int i_retval;
1009 int nparams = 0;
1010 Py_ssize_t size = 0;
1011 unsigned int flags;
1012 virTypedParameterPtr params, new_params = NULL;
1014 if (!PyArg_ParseTuple(args,
1015 (char *)"OOi:virDomainSetScedulerParametersFlags",
1016 &pyobj_domain, &info, &flags))
1017 return NULL;
1018 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1020 if ((size = PyDict_Size(info)) < 0)
1021 return NULL;
1023 if (size == 0) {
1024 PyErr_Format(PyExc_LookupError,
1025 "Need non-empty dictionary to set attributes");
1026 return NULL;
1029 LIBVIRT_BEGIN_ALLOW_THREADS;
1030 c_retval = virDomainGetSchedulerType(domain, &nparams);
1031 LIBVIRT_END_ALLOW_THREADS;
1033 if (c_retval == NULL)
1034 return VIR_PY_INT_FAIL;
1035 VIR_FREE(c_retval);
1037 if (nparams == 0) {
1038 PyErr_Format(PyExc_LookupError,
1039 "Domain has no settable attributes");
1040 return NULL;
1043 if (VIR_ALLOC_N(params, nparams) < 0)
1044 return PyErr_NoMemory();
1046 LIBVIRT_BEGIN_ALLOW_THREADS;
1047 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams, flags);
1048 LIBVIRT_END_ALLOW_THREADS;
1050 if (i_retval < 0) {
1051 ret = VIR_PY_INT_FAIL;
1052 goto cleanup;
1055 new_params = setPyVirTypedParameter(info, params, nparams);
1056 if (!new_params)
1057 goto cleanup;
1059 LIBVIRT_BEGIN_ALLOW_THREADS;
1060 i_retval = virDomainSetSchedulerParametersFlags(domain, new_params, size, flags);
1061 LIBVIRT_END_ALLOW_THREADS;
1063 if (i_retval < 0) {
1064 ret = VIR_PY_INT_FAIL;
1065 goto cleanup;
1068 ret = VIR_PY_INT_SUCCESS;
1070 cleanup:
1071 virTypedParamsFree(params, nparams);
1072 virTypedParamsFree(new_params, nparams);
1073 return ret;
1076 static PyObject *
1077 libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
1078 PyObject *args)
1080 virDomainPtr domain;
1081 PyObject *pyobj_domain, *info;
1082 PyObject *ret = NULL;
1083 int i_retval;
1084 int nparams = 0;
1085 Py_ssize_t size = 0;
1086 unsigned int flags;
1087 virTypedParameterPtr params = NULL, new_params = NULL;
1089 if (!PyArg_ParseTuple(args,
1090 (char *)"OOi:virDomainSetBlkioParameters",
1091 &pyobj_domain, &info, &flags))
1092 return NULL;
1093 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1095 if ((size = PyDict_Size(info)) < 0)
1096 return NULL;
1098 if (size == 0) {
1099 PyErr_Format(PyExc_LookupError,
1100 "Need non-empty dictionary to set attributes");
1101 return NULL;
1104 LIBVIRT_BEGIN_ALLOW_THREADS;
1105 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
1106 LIBVIRT_END_ALLOW_THREADS;
1108 if (i_retval < 0)
1109 return VIR_PY_INT_FAIL;
1111 if (nparams == 0) {
1112 PyErr_Format(PyExc_LookupError,
1113 "Domain has no settable attributes");
1114 return NULL;
1117 if (VIR_ALLOC_N(params, nparams) < 0)
1118 return PyErr_NoMemory();
1120 LIBVIRT_BEGIN_ALLOW_THREADS;
1121 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, 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 = virDomainSetBlkioParameters(domain, new_params, size, flags);
1135 LIBVIRT_END_ALLOW_THREADS;
1137 if (i_retval < 0) {
1138 ret = VIR_PY_INT_FAIL;
1139 goto cleanup;
1142 ret = VIR_PY_INT_SUCCESS;
1144 cleanup:
1145 virTypedParamsFree(params, nparams);
1146 virTypedParamsFree(new_params, size);
1147 return ret;
1150 static PyObject *
1151 libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
1152 PyObject *args)
1154 virDomainPtr domain;
1155 PyObject *pyobj_domain;
1156 PyObject *ret = NULL;
1157 int i_retval;
1158 int nparams = 0;
1159 unsigned int flags;
1160 virTypedParameterPtr params;
1162 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetBlkioParameters",
1163 &pyobj_domain, &flags))
1164 return NULL;
1165 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1167 LIBVIRT_BEGIN_ALLOW_THREADS;
1168 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
1169 LIBVIRT_END_ALLOW_THREADS;
1171 if (i_retval < 0)
1172 return VIR_PY_NONE;
1174 if (!nparams)
1175 return PyDict_New();
1177 if (VIR_ALLOC_N(params, nparams) < 0)
1178 return PyErr_NoMemory();
1180 LIBVIRT_BEGIN_ALLOW_THREADS;
1181 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
1182 LIBVIRT_END_ALLOW_THREADS;
1184 if (i_retval < 0) {
1185 ret = VIR_PY_NONE;
1186 goto cleanup;
1189 ret = getPyVirTypedParameter(params, nparams);
1191 cleanup:
1192 virTypedParamsFree(params, nparams);
1193 return ret;
1196 static PyObject *
1197 libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
1198 PyObject *args)
1200 virDomainPtr domain;
1201 PyObject *pyobj_domain, *info;
1202 PyObject *ret = NULL;
1203 int i_retval;
1204 int nparams = 0;
1205 Py_ssize_t size = 0;
1206 unsigned int flags;
1207 virTypedParameterPtr params = NULL, new_params = NULL;
1209 if (!PyArg_ParseTuple(args,
1210 (char *)"OOi:virDomainSetMemoryParameters",
1211 &pyobj_domain, &info, &flags))
1212 return NULL;
1213 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1215 if ((size = PyDict_Size(info)) < 0)
1216 return NULL;
1218 if (size == 0) {
1219 PyErr_Format(PyExc_LookupError,
1220 "Need non-empty dictionary to set attributes");
1221 return NULL;
1224 LIBVIRT_BEGIN_ALLOW_THREADS;
1225 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
1226 LIBVIRT_END_ALLOW_THREADS;
1228 if (i_retval < 0)
1229 return VIR_PY_INT_FAIL;
1231 if (nparams == 0) {
1232 PyErr_Format(PyExc_LookupError,
1233 "Domain has no settable attributes");
1234 return NULL;
1237 if (VIR_ALLOC_N(params, nparams) < 0)
1238 return PyErr_NoMemory();
1240 LIBVIRT_BEGIN_ALLOW_THREADS;
1241 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
1242 LIBVIRT_END_ALLOW_THREADS;
1244 if (i_retval < 0) {
1245 ret = VIR_PY_INT_FAIL;
1246 goto cleanup;
1249 new_params = setPyVirTypedParameter(info, params, nparams);
1250 if (!new_params)
1251 goto cleanup;
1253 LIBVIRT_BEGIN_ALLOW_THREADS;
1254 i_retval = virDomainSetMemoryParameters(domain, new_params, size, flags);
1255 LIBVIRT_END_ALLOW_THREADS;
1257 if (i_retval < 0) {
1258 ret = VIR_PY_INT_FAIL;
1259 goto cleanup;
1262 ret = VIR_PY_INT_SUCCESS;
1264 cleanup:
1265 virTypedParamsFree(params, nparams);
1266 virTypedParamsFree(new_params, size);
1267 return ret;
1270 static PyObject *
1271 libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
1272 PyObject *args)
1274 virDomainPtr domain;
1275 PyObject *pyobj_domain;
1276 PyObject *ret = NULL;
1277 int i_retval;
1278 int nparams = 0;
1279 unsigned int flags;
1280 virTypedParameterPtr params;
1282 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetMemoryParameters",
1283 &pyobj_domain, &flags))
1284 return NULL;
1285 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1287 LIBVIRT_BEGIN_ALLOW_THREADS;
1288 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
1289 LIBVIRT_END_ALLOW_THREADS;
1291 if (i_retval < 0)
1292 return VIR_PY_NONE;
1294 if (!nparams)
1295 return PyDict_New();
1297 if (VIR_ALLOC_N(params, nparams) < 0)
1298 return PyErr_NoMemory();
1300 LIBVIRT_BEGIN_ALLOW_THREADS;
1301 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
1302 LIBVIRT_END_ALLOW_THREADS;
1304 if (i_retval < 0) {
1305 ret = VIR_PY_NONE;
1306 goto cleanup;
1309 ret = getPyVirTypedParameter(params, nparams);
1311 cleanup:
1312 virTypedParamsFree(params, nparams);
1313 return ret;
1316 static PyObject *
1317 libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1318 PyObject *args)
1320 virDomainPtr domain;
1321 PyObject *pyobj_domain, *info;
1322 PyObject *ret = NULL;
1323 int i_retval;
1324 int nparams = 0;
1325 Py_ssize_t size = 0;
1326 unsigned int flags;
1327 virTypedParameterPtr params = NULL, new_params = NULL;
1329 if (!PyArg_ParseTuple(args,
1330 (char *)"OOi:virDomainSetNumaParameters",
1331 &pyobj_domain, &info, &flags))
1332 return NULL;
1333 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1335 if ((size = PyDict_Size(info)) < 0)
1336 return NULL;
1338 if (size == 0) {
1339 PyErr_Format(PyExc_LookupError,
1340 "Need non-empty dictionary to set attributes");
1341 return NULL;
1344 LIBVIRT_BEGIN_ALLOW_THREADS;
1345 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1346 LIBVIRT_END_ALLOW_THREADS;
1348 if (i_retval < 0)
1349 return VIR_PY_INT_FAIL;
1351 if (nparams == 0) {
1352 PyErr_Format(PyExc_LookupError,
1353 "Domain has no settable attributes");
1354 return NULL;
1357 if (VIR_ALLOC_N(params, nparams) < 0)
1358 return PyErr_NoMemory();
1360 LIBVIRT_BEGIN_ALLOW_THREADS;
1361 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1362 LIBVIRT_END_ALLOW_THREADS;
1364 if (i_retval < 0) {
1365 ret = VIR_PY_INT_FAIL;
1366 goto cleanup;
1369 new_params = setPyVirTypedParameter(info, params, nparams);
1370 if (!new_params)
1371 goto cleanup;
1373 LIBVIRT_BEGIN_ALLOW_THREADS;
1374 i_retval = virDomainSetNumaParameters(domain, new_params, size, flags);
1375 LIBVIRT_END_ALLOW_THREADS;
1377 if (i_retval < 0) {
1378 ret = VIR_PY_INT_FAIL;
1379 goto cleanup;
1382 ret = VIR_PY_INT_SUCCESS;
1384 cleanup:
1385 virTypedParamsFree(params, nparams);
1386 virTypedParamsFree(new_params, size);
1387 return ret;
1390 static PyObject *
1391 libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1392 PyObject *args)
1394 virDomainPtr domain;
1395 PyObject *pyobj_domain;
1396 PyObject *ret = NULL;
1397 int i_retval;
1398 int nparams = 0;
1399 unsigned int flags;
1400 virTypedParameterPtr params;
1402 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetNumaParameters",
1403 &pyobj_domain, &flags))
1404 return NULL;
1405 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1407 LIBVIRT_BEGIN_ALLOW_THREADS;
1408 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1409 LIBVIRT_END_ALLOW_THREADS;
1411 if (i_retval < 0)
1412 return VIR_PY_NONE;
1414 if (!nparams)
1415 return PyDict_New();
1417 if (VIR_ALLOC_N(params, nparams) < 0)
1418 return PyErr_NoMemory();
1420 LIBVIRT_BEGIN_ALLOW_THREADS;
1421 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1422 LIBVIRT_END_ALLOW_THREADS;
1424 if (i_retval < 0) {
1425 ret = VIR_PY_NONE;
1426 goto cleanup;
1429 ret = getPyVirTypedParameter(params, nparams);
1431 cleanup:
1432 virTypedParamsFree(params, nparams);
1433 return ret;
1436 static PyObject *
1437 libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1438 PyObject *args)
1440 virDomainPtr domain;
1441 PyObject *pyobj_domain, *info;
1442 PyObject *ret = NULL;
1443 int i_retval;
1444 int nparams = 0;
1445 Py_ssize_t size = 0;
1446 unsigned int flags;
1447 const char *device = NULL;
1448 virTypedParameterPtr params = NULL, new_params = NULL;
1450 if (!PyArg_ParseTuple(args,
1451 (char *)"OzOi:virDomainSetInterfaceParameters",
1452 &pyobj_domain, &device, &info, &flags))
1453 return NULL;
1454 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1456 if ((size = PyDict_Size(info)) < 0)
1457 return NULL;
1459 if (size == 0) {
1460 PyErr_Format(PyExc_LookupError,
1461 "Need non-empty dictionary to set attributes");
1462 return NULL;
1465 LIBVIRT_BEGIN_ALLOW_THREADS;
1466 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
1467 LIBVIRT_END_ALLOW_THREADS;
1469 if (i_retval < 0)
1470 return VIR_PY_INT_FAIL;
1472 if (nparams == 0) {
1473 PyErr_Format(PyExc_LookupError,
1474 "Domain has no settable attributes");
1475 return NULL;
1478 if (VIR_ALLOC_N(params, nparams) < 0)
1479 return PyErr_NoMemory();
1481 LIBVIRT_BEGIN_ALLOW_THREADS;
1482 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
1483 LIBVIRT_END_ALLOW_THREADS;
1485 if (i_retval < 0) {
1486 ret = VIR_PY_INT_FAIL;
1487 goto cleanup;
1490 new_params = setPyVirTypedParameter(info, params, nparams);
1491 if (!new_params)
1492 goto cleanup;
1494 LIBVIRT_BEGIN_ALLOW_THREADS;
1495 i_retval = virDomainSetInterfaceParameters(domain, device, new_params, size, flags);
1496 LIBVIRT_END_ALLOW_THREADS;
1498 if (i_retval < 0) {
1499 ret = VIR_PY_INT_FAIL;
1500 goto cleanup;
1503 ret = VIR_PY_INT_SUCCESS;
1505 cleanup:
1506 virTypedParamsFree(params, nparams);
1507 virTypedParamsFree(new_params, size);
1508 return ret;
1511 static PyObject *
1512 libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1513 PyObject *args)
1515 virDomainPtr domain;
1516 PyObject *pyobj_domain;
1517 PyObject *ret = NULL;
1518 int i_retval;
1519 int nparams = 0;
1520 unsigned int flags;
1521 const char *device = NULL;
1522 virTypedParameterPtr params;
1524 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInterfaceParameters",
1525 &pyobj_domain, &device, &flags))
1526 return NULL;
1527 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1529 LIBVIRT_BEGIN_ALLOW_THREADS;
1530 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
1531 LIBVIRT_END_ALLOW_THREADS;
1533 if (i_retval < 0)
1534 return VIR_PY_NONE;
1536 if (!nparams)
1537 return PyDict_New();
1539 if (VIR_ALLOC_N(params, nparams) < 0)
1540 return PyErr_NoMemory();
1542 LIBVIRT_BEGIN_ALLOW_THREADS;
1543 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
1544 LIBVIRT_END_ALLOW_THREADS;
1546 if (i_retval < 0) {
1547 ret = VIR_PY_NONE;
1548 goto cleanup;
1551 ret = getPyVirTypedParameter(params, nparams);
1553 cleanup:
1554 virTypedParamsFree(params, nparams);
1555 return ret;
1558 static PyObject *
1559 libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
1560 PyObject *args)
1562 virDomainPtr domain;
1563 PyObject *pyobj_domain, *pyretval = NULL, *pycpuinfo = NULL, *pycpumap = NULL;
1564 PyObject *error = NULL;
1565 virDomainInfo dominfo;
1566 virVcpuInfoPtr cpuinfo = NULL;
1567 unsigned char *cpumap = NULL;
1568 size_t cpumaplen, i;
1569 int i_retval, cpunum;
1571 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
1572 &pyobj_domain))
1573 return NULL;
1574 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1576 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1577 return VIR_PY_INT_FAIL;
1579 LIBVIRT_BEGIN_ALLOW_THREADS;
1580 i_retval = virDomainGetInfo(domain, &dominfo);
1581 LIBVIRT_END_ALLOW_THREADS;
1582 if (i_retval < 0)
1583 return VIR_PY_INT_FAIL;
1585 if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0)
1586 return PyErr_NoMemory();
1588 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1589 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1590 VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) {
1591 error = PyErr_NoMemory();
1592 goto cleanup;
1595 LIBVIRT_BEGIN_ALLOW_THREADS;
1596 i_retval = virDomainGetVcpus(domain,
1597 cpuinfo, dominfo.nrVirtCpu,
1598 cpumap, cpumaplen);
1599 LIBVIRT_END_ALLOW_THREADS;
1600 if (i_retval < 0) {
1601 error = VIR_PY_INT_FAIL;
1602 goto cleanup;
1605 /* convert to a Python tuple of long objects */
1606 if ((pyretval = PyTuple_New(2)) == NULL)
1607 goto cleanup;
1608 if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
1609 goto cleanup;
1610 if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
1611 goto cleanup;
1613 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1614 PyObject *info = PyTuple_New(4);
1615 PyObject *item = NULL;
1617 if (info == NULL)
1618 goto cleanup;
1620 if ((item = libvirt_intWrap((long)cpuinfo[i].number)) == NULL ||
1621 PyTuple_SetItem(info, 0, item) < 0)
1622 goto itemError;
1624 if ((item = libvirt_intWrap((long)cpuinfo[i].state)) == NULL ||
1625 PyTuple_SetItem(info, 1, item) < 0)
1626 goto itemError;
1628 if ((item = libvirt_longlongWrap((long long)cpuinfo[i].cpuTime)) == NULL ||
1629 PyTuple_SetItem(info, 2, item) < 0)
1630 goto itemError;
1632 if ((item = libvirt_intWrap((long)cpuinfo[i].cpu)) == NULL ||
1633 PyTuple_SetItem(info, 3, item) < 0)
1634 goto itemError;
1636 if (PyList_SetItem(pycpuinfo, i, info) < 0)
1637 goto itemError;
1639 continue;
1640 itemError:
1641 Py_DECREF(info);
1642 Py_XDECREF(item);
1643 goto cleanup;
1645 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1646 PyObject *info = PyTuple_New(cpunum);
1647 size_t j;
1648 if (info == NULL)
1649 goto cleanup;
1650 for (j = 0; j < cpunum; j++) {
1651 PyObject *item = NULL;
1652 if ((item = PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, i, j))) == NULL ||
1653 PyTuple_SetItem(info, j, item) < 0) {
1654 Py_DECREF(info);
1655 Py_XDECREF(item);
1656 goto cleanup;
1659 if (PyList_SetItem(pycpumap, i, info) < 0) {
1660 Py_DECREF(info);
1661 goto cleanup;
1664 if (PyTuple_SetItem(pyretval, 0, pycpuinfo) < 0 ||
1665 PyTuple_SetItem(pyretval, 1, pycpumap) < 0)
1666 goto cleanup;
1668 VIR_FREE(cpuinfo);
1669 VIR_FREE(cpumap);
1671 return pyretval;
1673 cleanup:
1674 VIR_FREE(cpuinfo);
1675 VIR_FREE(cpumap);
1676 Py_XDECREF(pyretval);
1677 Py_XDECREF(pycpuinfo);
1678 Py_XDECREF(pycpumap);
1679 return error;
1683 static PyObject *
1684 libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
1685 PyObject *args)
1687 virDomainPtr domain;
1688 PyObject *pyobj_domain, *pycpumap;
1689 PyObject *ret = NULL;
1690 unsigned char *cpumap;
1691 int cpumaplen, vcpu, tuple_size, cpunum;
1692 size_t i;
1693 int i_retval;
1695 if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu",
1696 &pyobj_domain, &vcpu, &pycpumap))
1697 return NULL;
1698 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1700 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1701 return VIR_PY_INT_FAIL;
1703 if (PyTuple_Check(pycpumap)) {
1704 tuple_size = PyTuple_Size(pycpumap);
1705 if (tuple_size == -1)
1706 return ret;
1707 } else {
1708 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1709 return ret;
1712 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1713 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1714 return PyErr_NoMemory();
1716 for (i = 0; i < tuple_size; i++) {
1717 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1718 bool b;
1720 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1721 goto cleanup;
1723 if (b)
1724 VIR_USE_CPU(cpumap, i);
1725 else
1726 VIR_UNUSE_CPU(cpumap, i);
1729 for (; i < cpunum; i++)
1730 VIR_UNUSE_CPU(cpumap, i);
1732 LIBVIRT_BEGIN_ALLOW_THREADS;
1733 i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen);
1734 LIBVIRT_END_ALLOW_THREADS;
1736 if (i_retval < 0) {
1737 ret = VIR_PY_INT_FAIL;
1738 goto cleanup;
1740 ret = VIR_PY_INT_SUCCESS;
1742 cleanup:
1743 VIR_FREE(cpumap);
1744 return ret;
1747 static PyObject *
1748 libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED,
1749 PyObject *args)
1751 virDomainPtr domain;
1752 PyObject *pyobj_domain, *pycpumap;
1753 PyObject *ret = NULL;
1754 unsigned char *cpumap;
1755 int cpumaplen, vcpu, tuple_size, cpunum;
1756 size_t i;
1757 unsigned int flags;
1758 int i_retval;
1760 if (!PyArg_ParseTuple(args, (char *)"OiOi:virDomainPinVcpuFlags",
1761 &pyobj_domain, &vcpu, &pycpumap, &flags))
1762 return NULL;
1763 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1765 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1766 return VIR_PY_INT_FAIL;
1768 if (PyTuple_Check(pycpumap)) {
1769 tuple_size = PyTuple_Size(pycpumap);
1770 if (tuple_size == -1)
1771 return ret;
1772 } else {
1773 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1774 return ret;
1777 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1778 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1779 return PyErr_NoMemory();
1781 for (i = 0; i < tuple_size; i++) {
1782 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1783 bool b;
1785 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1786 goto cleanup;
1788 if (b)
1789 VIR_USE_CPU(cpumap, i);
1790 else
1791 VIR_UNUSE_CPU(cpumap, i);
1794 for (; i < cpunum; i++)
1795 VIR_UNUSE_CPU(cpumap, i);
1797 LIBVIRT_BEGIN_ALLOW_THREADS;
1798 i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags);
1799 LIBVIRT_END_ALLOW_THREADS;
1800 if (i_retval < 0) {
1801 ret = VIR_PY_INT_FAIL;
1802 goto cleanup;
1804 ret = VIR_PY_INT_SUCCESS;
1806 cleanup:
1807 VIR_FREE(cpumap);
1808 return ret;
1811 static PyObject *
1812 libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1813 PyObject *args) {
1814 virDomainPtr domain;
1815 PyObject *pyobj_domain, *pycpumaps = NULL;
1816 virDomainInfo dominfo;
1817 unsigned char *cpumaps = NULL;
1818 size_t cpumaplen, vcpu, pcpu;
1819 unsigned int flags;
1820 int i_retval, cpunum;
1822 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetVcpuPinInfo",
1823 &pyobj_domain, &flags))
1824 return NULL;
1825 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1827 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1828 return VIR_PY_INT_FAIL;
1830 LIBVIRT_BEGIN_ALLOW_THREADS;
1831 i_retval = virDomainGetInfo(domain, &dominfo);
1832 LIBVIRT_END_ALLOW_THREADS;
1833 if (i_retval < 0)
1834 return VIR_PY_NONE;
1836 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1837 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1838 VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0)
1839 goto cleanup;
1841 LIBVIRT_BEGIN_ALLOW_THREADS;
1842 i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu,
1843 cpumaps, cpumaplen, flags);
1844 LIBVIRT_END_ALLOW_THREADS;
1845 if (i_retval < 0)
1846 goto cleanup;
1848 if ((pycpumaps = PyList_New(dominfo.nrVirtCpu)) == NULL)
1849 goto cleanup;
1851 for (vcpu = 0; vcpu < dominfo.nrVirtCpu; vcpu++) {
1852 PyObject *mapinfo = PyTuple_New(cpunum);
1853 if (mapinfo == NULL)
1854 goto cleanup;
1856 for (pcpu = 0; pcpu < cpunum; pcpu++) {
1857 PyTuple_SetItem(mapinfo, pcpu,
1858 PyBool_FromLong(VIR_CPU_USABLE(cpumaps, cpumaplen, vcpu, pcpu)));
1860 PyList_SetItem(pycpumaps, vcpu, mapinfo);
1863 VIR_FREE(cpumaps);
1865 return pycpumaps;
1867 cleanup:
1868 VIR_FREE(cpumaps);
1870 Py_XDECREF(pycpumaps);
1872 return VIR_PY_NONE;
1876 #if LIBVIR_CHECK_VERSION(0, 10, 0)
1877 static PyObject *
1878 libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED,
1879 PyObject *args)
1881 virDomainPtr domain;
1882 PyObject *pyobj_domain, *pycpumap;
1883 unsigned char *cpumap = NULL;
1884 int cpumaplen, tuple_size, cpunum;
1885 size_t i;
1886 int i_retval;
1887 unsigned int flags;
1889 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainPinVcpu",
1890 &pyobj_domain, &pycpumap, &flags))
1891 return NULL;
1893 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1895 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1896 return VIR_PY_INT_FAIL;
1898 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1900 if (!PyTuple_Check(pycpumap)) {
1901 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1902 return NULL;
1905 if ((tuple_size = PyTuple_Size(pycpumap)) == -1)
1906 return NULL;
1908 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1909 return PyErr_NoMemory();
1911 for (i = 0; i < tuple_size; i++) {
1912 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1913 bool b;
1915 if (!flag || libvirt_boolUnwrap(flag, &b) < 0) {
1916 VIR_FREE(cpumap);
1917 return VIR_PY_INT_FAIL;
1920 if (b)
1921 VIR_USE_CPU(cpumap, i);
1922 else
1923 VIR_UNUSE_CPU(cpumap, i);
1926 for (; i < cpunum; i++)
1927 VIR_UNUSE_CPU(cpumap, i);
1929 LIBVIRT_BEGIN_ALLOW_THREADS;
1930 i_retval = virDomainPinEmulator(domain, cpumap, cpumaplen, flags);
1931 LIBVIRT_END_ALLOW_THREADS;
1933 VIR_FREE(cpumap);
1935 if (i_retval < 0)
1936 return VIR_PY_INT_FAIL;
1938 return VIR_PY_INT_SUCCESS;
1942 static PyObject *
1943 libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1944 PyObject *args)
1946 virDomainPtr domain;
1947 PyObject *pyobj_domain;
1948 PyObject *pycpumap;
1949 unsigned char *cpumap;
1950 size_t cpumaplen;
1951 size_t pcpu;
1952 unsigned int flags;
1953 int ret;
1954 int cpunum;
1956 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainEmulatorPinInfo",
1957 &pyobj_domain, &flags))
1958 return NULL;
1960 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1962 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1963 return VIR_PY_NONE;
1965 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1967 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1968 return PyErr_NoMemory();
1970 LIBVIRT_BEGIN_ALLOW_THREADS;
1971 ret = virDomainGetEmulatorPinInfo(domain, cpumap, cpumaplen, flags);
1972 LIBVIRT_END_ALLOW_THREADS;
1973 if (ret < 0) {
1974 VIR_FREE(cpumap);
1975 return VIR_PY_NONE;
1978 if (!(pycpumap = PyTuple_New(cpunum))) {
1979 VIR_FREE(cpumap);
1980 return NULL;
1983 for (pcpu = 0; pcpu < cpunum; pcpu++)
1984 PyTuple_SET_ITEM(pycpumap, pcpu,
1985 PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen,
1986 0, pcpu)));
1988 VIR_FREE(cpumap);
1989 return pycpumap;
1991 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
1994 /************************************************************************
1996 * Global error handler at the Python level *
1998 ************************************************************************/
2000 static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
2001 static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
2003 static PyObject *
2004 libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED)
2006 virError *err;
2007 PyObject *info;
2009 if ((err = virGetLastError()) == NULL)
2010 return VIR_PY_NONE;
2012 if ((info = PyTuple_New(9)) == NULL)
2013 return VIR_PY_NONE;
2014 PyTuple_SetItem(info, 0, libvirt_intWrap((long) err->code));
2015 PyTuple_SetItem(info, 1, libvirt_intWrap((long) err->domain));
2016 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
2017 PyTuple_SetItem(info, 3, libvirt_intWrap((long) err->level));
2018 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
2019 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
2020 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
2021 PyTuple_SetItem(info, 7, libvirt_intWrap((long) err->int1));
2022 PyTuple_SetItem(info, 8, libvirt_intWrap((long) err->int2));
2024 return info;
2027 static PyObject *
2028 libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2030 virError *err;
2031 PyObject *info;
2032 virConnectPtr conn;
2033 PyObject *pyobj_conn;
2035 if (!PyArg_ParseTuple(args, (char *)"O:virConGetLastError", &pyobj_conn))
2036 return NULL;
2037 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2039 LIBVIRT_BEGIN_ALLOW_THREADS;
2040 err = virConnGetLastError(conn);
2041 LIBVIRT_END_ALLOW_THREADS;
2042 if (err == NULL)
2043 return VIR_PY_NONE;
2045 if ((info = PyTuple_New(9)) == NULL)
2046 return VIR_PY_NONE;
2047 PyTuple_SetItem(info, 0, libvirt_intWrap((long) err->code));
2048 PyTuple_SetItem(info, 1, libvirt_intWrap((long) err->domain));
2049 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
2050 PyTuple_SetItem(info, 3, libvirt_intWrap((long) err->level));
2051 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
2052 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
2053 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
2054 PyTuple_SetItem(info, 7, libvirt_intWrap((long) err->int1));
2055 PyTuple_SetItem(info, 8, libvirt_intWrap((long) err->int2));
2057 return info;
2060 static void
2061 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err)
2063 PyObject *list, *info;
2064 PyObject *result;
2066 DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
2067 err->message);
2069 if ((err == NULL) || (err->code == VIR_ERR_OK))
2070 return;
2072 LIBVIRT_ENSURE_THREAD_STATE;
2074 if ((libvirt_virPythonErrorFuncHandler == NULL) ||
2075 (libvirt_virPythonErrorFuncHandler == Py_None)) {
2076 virDefaultErrorFunc(err);
2077 } else {
2078 list = PyTuple_New(2);
2079 info = PyTuple_New(9);
2080 PyTuple_SetItem(list, 0, libvirt_virPythonErrorFuncCtxt);
2081 PyTuple_SetItem(list, 1, info);
2082 Py_XINCREF(libvirt_virPythonErrorFuncCtxt);
2083 PyTuple_SetItem(info, 0, libvirt_intWrap((long) err->code));
2084 PyTuple_SetItem(info, 1, libvirt_intWrap((long) err->domain));
2085 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
2086 PyTuple_SetItem(info, 3, libvirt_intWrap((long) err->level));
2087 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
2088 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
2089 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
2090 PyTuple_SetItem(info, 7, libvirt_intWrap((long) err->int1));
2091 PyTuple_SetItem(info, 8, libvirt_intWrap((long) err->int2));
2092 /* TODO pass conn and dom if available */
2093 result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
2094 Py_XDECREF(list);
2095 Py_XDECREF(result);
2098 LIBVIRT_RELEASE_THREAD_STATE;
2101 static PyObject *
2102 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
2103 PyObject * args)
2105 PyObject *py_retval;
2106 PyObject *pyobj_f;
2107 PyObject *pyobj_ctx;
2109 if (!PyArg_ParseTuple
2110 (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f,
2111 &pyobj_ctx))
2112 return NULL;
2114 DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
2115 pyobj_f);
2117 virSetErrorFunc(NULL, libvirt_virErrorFuncHandler);
2118 if (libvirt_virPythonErrorFuncHandler != NULL) {
2119 Py_XDECREF(libvirt_virPythonErrorFuncHandler);
2121 if (libvirt_virPythonErrorFuncCtxt != NULL) {
2122 Py_XDECREF(libvirt_virPythonErrorFuncCtxt);
2125 if ((pyobj_f == Py_None) && (pyobj_ctx == Py_None)) {
2126 libvirt_virPythonErrorFuncHandler = NULL;
2127 libvirt_virPythonErrorFuncCtxt = NULL;
2128 } else {
2129 Py_XINCREF(pyobj_ctx);
2130 Py_XINCREF(pyobj_f);
2132 /* TODO: check f is a function ! */
2133 libvirt_virPythonErrorFuncHandler = pyobj_f;
2134 libvirt_virPythonErrorFuncCtxt = pyobj_ctx;
2137 py_retval = libvirt_intWrap(1);
2138 return py_retval;
2141 static int virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
2142 unsigned int ncred,
2143 void *cbdata) {
2144 PyObject *list;
2145 PyObject *pycred;
2146 PyObject *pyauth = (PyObject *)cbdata;
2147 PyObject *pycbdata;
2148 PyObject *pycb;
2149 PyObject *pyret;
2150 int ret = -1;
2151 size_t i;
2153 LIBVIRT_ENSURE_THREAD_STATE;
2155 pycb = PyList_GetItem(pyauth, 1);
2156 pycbdata = PyList_GetItem(pyauth, 2);
2158 list = PyTuple_New(2);
2159 pycred = PyTuple_New(ncred);
2160 for (i = 0; i < ncred; i++) {
2161 PyObject *pycreditem;
2162 pycreditem = PyList_New(5);
2163 Py_INCREF(Py_None);
2164 PyTuple_SetItem(pycred, i, pycreditem);
2165 PyList_SetItem(pycreditem, 0, libvirt_intWrap((long) cred[i].type));
2166 PyList_SetItem(pycreditem, 1, libvirt_constcharPtrWrap(cred[i].prompt));
2167 if (cred[i].challenge) {
2168 PyList_SetItem(pycreditem, 2, libvirt_constcharPtrWrap(cred[i].challenge));
2169 } else {
2170 Py_INCREF(Py_None);
2171 PyList_SetItem(pycreditem, 2, Py_None);
2173 if (cred[i].defresult) {
2174 PyList_SetItem(pycreditem, 3, libvirt_constcharPtrWrap(cred[i].defresult));
2175 } else {
2176 Py_INCREF(Py_None);
2177 PyList_SetItem(pycreditem, 3, Py_None);
2179 PyList_SetItem(pycreditem, 4, Py_None);
2182 PyTuple_SetItem(list, 0, pycred);
2183 Py_XINCREF(pycbdata);
2184 PyTuple_SetItem(list, 1, pycbdata);
2186 PyErr_Clear();
2187 pyret = PyEval_CallObject(pycb, list);
2188 if (PyErr_Occurred()) {
2189 PyErr_Print();
2190 goto cleanup;
2193 ret = PyLong_AsLong(pyret);
2194 if (ret == 0) {
2195 for (i = 0; i < ncred; i++) {
2196 PyObject *pycreditem;
2197 PyObject *pyresult;
2198 char *result = NULL;
2199 pycreditem = PyTuple_GetItem(pycred, i);
2200 pyresult = PyList_GetItem(pycreditem, 4);
2201 if (pyresult != Py_None)
2202 libvirt_charPtrUnwrap(pyresult, &result);
2203 if (result != NULL) {
2204 cred[i].result = result;
2205 cred[i].resultlen = strlen(result);
2206 } else {
2207 cred[i].result = NULL;
2208 cred[i].resultlen = 0;
2213 cleanup:
2214 Py_XDECREF(list);
2215 Py_XDECREF(pyret);
2217 LIBVIRT_RELEASE_THREAD_STATE;
2219 return ret;
2223 static PyObject *
2224 libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2225 PyObject *py_retval;
2226 virConnectPtr c_retval;
2227 char * name;
2228 unsigned int flags;
2229 PyObject *pyauth;
2230 PyObject *pycredcb;
2231 PyObject *pycredtype;
2232 virConnectAuth auth;
2234 memset(&auth, 0, sizeof(auth));
2235 if (!PyArg_ParseTuple(args, (char *)"zOi:virConnectOpenAuth", &name, &pyauth, &flags))
2236 return NULL;
2238 pycredtype = PyList_GetItem(pyauth, 0);
2239 pycredcb = PyList_GetItem(pyauth, 1);
2241 auth.ncredtype = PyList_Size(pycredtype);
2242 if (auth.ncredtype) {
2243 size_t i;
2244 if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0)
2245 return VIR_PY_NONE;
2246 for (i = 0; i < auth.ncredtype; i++) {
2247 PyObject *val;
2248 val = PyList_GetItem(pycredtype, i);
2249 auth.credtype[i] = (int)PyLong_AsLong(val);
2252 if (pycredcb && pycredcb != Py_None)
2253 auth.cb = virConnectCredCallbackWrapper;
2254 auth.cbdata = pyauth;
2256 LIBVIRT_BEGIN_ALLOW_THREADS;
2258 c_retval = virConnectOpenAuth(name, &auth, flags);
2259 LIBVIRT_END_ALLOW_THREADS;
2260 VIR_FREE(auth.credtype);
2261 py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval);
2262 return py_retval;
2266 /************************************************************************
2268 * Wrappers for functions where generator fails *
2270 ************************************************************************/
2272 static PyObject *
2273 libvirt_virGetVersion(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2275 char *type = NULL;
2276 unsigned long libVer, typeVer = 0;
2277 int c_retval;
2279 if (!PyArg_ParseTuple(args, (char *) "|s", &type))
2280 return NULL;
2282 LIBVIRT_BEGIN_ALLOW_THREADS;
2284 if (type == NULL)
2285 c_retval = virGetVersion(&libVer, NULL, NULL);
2286 else
2287 c_retval = virGetVersion(&libVer, type, &typeVer);
2289 LIBVIRT_END_ALLOW_THREADS;
2291 if (c_retval == -1)
2292 return VIR_PY_NONE;
2294 if (type == NULL)
2295 return libvirt_intWrap(libVer);
2296 else
2297 return Py_BuildValue((char *) "kk", libVer, typeVer);
2300 static PyObject *
2301 libvirt_virConnectGetVersion(PyObject *self ATTRIBUTE_UNUSED,
2302 PyObject *args)
2304 unsigned long hvVersion;
2305 int c_retval;
2306 virConnectPtr conn;
2307 PyObject *pyobj_conn;
2309 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetVersion",
2310 &pyobj_conn))
2311 return NULL;
2312 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2314 LIBVIRT_BEGIN_ALLOW_THREADS;
2316 c_retval = virConnectGetVersion(conn, &hvVersion);
2318 LIBVIRT_END_ALLOW_THREADS;
2320 if (c_retval == -1)
2321 return VIR_PY_INT_FAIL;
2323 return libvirt_intWrap(hvVersion);
2326 #if LIBVIR_CHECK_VERSION(1, 1, 3)
2327 static PyObject *
2328 libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED,
2329 PyObject *args)
2331 int c_retval;
2332 virConnectPtr conn;
2333 PyObject *rv = NULL, *pyobj_conn;
2334 char **models = NULL;
2335 size_t i;
2336 int flags = 0;
2337 const char *arch = NULL;
2339 if (!PyArg_ParseTuple(args, (char *)"Osi:virConnectGetCPUModelNames",
2340 &pyobj_conn, &arch, &flags))
2341 return NULL;
2342 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2344 LIBVIRT_BEGIN_ALLOW_THREADS;
2346 c_retval = virConnectGetCPUModelNames(conn, arch, &models, flags);
2348 LIBVIRT_END_ALLOW_THREADS;
2350 if (c_retval == -1)
2351 return VIR_PY_NONE;
2353 if ((rv = PyList_New(c_retval)) == NULL)
2354 goto error;
2356 for (i = 0; i < c_retval; i++) {
2357 PyObject *str;
2358 if ((str = libvirt_constcharPtrWrap(models[i])) == NULL)
2359 goto error;
2361 PyList_SET_ITEM(rv, i, str);
2364 done:
2365 if (models) {
2366 for (i = 0; i < c_retval; i++)
2367 VIR_FREE(models[i]);
2368 VIR_FREE(models);
2371 return rv;
2373 error:
2374 Py_XDECREF(rv);
2375 rv = NULL;
2376 goto done;
2378 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
2380 static PyObject *
2381 libvirt_virConnectGetLibVersion(PyObject *self ATTRIBUTE_UNUSED,
2382 PyObject *args)
2384 unsigned long libVer;
2385 int c_retval;
2386 virConnectPtr conn;
2387 PyObject *pyobj_conn;
2389 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetLibVersion",
2390 &pyobj_conn))
2391 return NULL;
2392 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2394 LIBVIRT_BEGIN_ALLOW_THREADS;
2396 c_retval = virConnectGetLibVersion(conn, &libVer);
2398 LIBVIRT_END_ALLOW_THREADS;
2400 if (c_retval == -1)
2401 return VIR_PY_INT_FAIL;
2403 return libvirt_intWrap(libVer);
2406 static PyObject *
2407 libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
2408 PyObject *args) {
2409 PyObject *py_retval;
2410 int *ids = NULL, c_retval;
2411 size_t i;
2412 virConnectPtr conn;
2413 PyObject *pyobj_conn;
2416 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDomains", &pyobj_conn))
2417 return NULL;
2418 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2420 LIBVIRT_BEGIN_ALLOW_THREADS;
2421 c_retval = virConnectNumOfDomains(conn);
2422 LIBVIRT_END_ALLOW_THREADS;
2423 if (c_retval < 0)
2424 return VIR_PY_NONE;
2426 if (c_retval) {
2427 if (VIR_ALLOC_N(ids, c_retval) < 0)
2428 return VIR_PY_NONE;
2430 LIBVIRT_BEGIN_ALLOW_THREADS;
2431 c_retval = virConnectListDomains(conn, ids, c_retval);
2432 LIBVIRT_END_ALLOW_THREADS;
2433 if (c_retval < 0) {
2434 VIR_FREE(ids);
2435 return VIR_PY_NONE;
2438 py_retval = PyList_New(c_retval);
2440 if (ids) {
2441 for (i = 0; i < c_retval; i++) {
2442 PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
2444 VIR_FREE(ids);
2447 return py_retval;
2450 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2451 static PyObject *
2452 libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
2453 PyObject *args)
2455 PyObject *pyobj_conn;
2456 PyObject *py_retval = NULL;
2457 PyObject *tmp = NULL;
2458 virConnectPtr conn;
2459 virDomainPtr *doms = NULL;
2460 int c_retval = 0;
2461 size_t i;
2462 unsigned int flags;
2464 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllDomains",
2465 &pyobj_conn, &flags))
2466 return NULL;
2467 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2469 LIBVIRT_BEGIN_ALLOW_THREADS;
2470 c_retval = virConnectListAllDomains(conn, &doms, flags);
2471 LIBVIRT_END_ALLOW_THREADS;
2472 if (c_retval < 0)
2473 return VIR_PY_NONE;
2475 if (!(py_retval = PyList_New(c_retval)))
2476 goto cleanup;
2478 for (i = 0; i < c_retval; i++) {
2479 if (!(tmp = libvirt_virDomainPtrWrap(doms[i])) ||
2480 PyList_SetItem(py_retval, i, tmp) < 0) {
2481 Py_XDECREF(tmp);
2482 Py_DECREF(py_retval);
2483 py_retval = NULL;
2484 goto cleanup;
2486 /* python steals the pointer */
2487 doms[i] = NULL;
2490 cleanup:
2491 for (i = 0; i < c_retval; i++)
2492 if (doms[i])
2493 virDomainFree(doms[i]);
2494 VIR_FREE(doms);
2495 return py_retval;
2497 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2499 static PyObject *
2500 libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
2501 PyObject *args) {
2502 PyObject *py_retval;
2503 char **names = NULL;
2504 int c_retval;
2505 size_t i;
2506 virConnectPtr conn;
2507 PyObject *pyobj_conn;
2510 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedDomains", &pyobj_conn))
2511 return NULL;
2512 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2514 LIBVIRT_BEGIN_ALLOW_THREADS;
2515 c_retval = virConnectNumOfDefinedDomains(conn);
2516 LIBVIRT_END_ALLOW_THREADS;
2517 if (c_retval < 0)
2518 return VIR_PY_NONE;
2520 if (c_retval) {
2521 if (VIR_ALLOC_N(names, c_retval) < 0)
2522 return VIR_PY_NONE;
2523 LIBVIRT_BEGIN_ALLOW_THREADS;
2524 c_retval = virConnectListDefinedDomains(conn, names, c_retval);
2525 LIBVIRT_END_ALLOW_THREADS;
2526 if (c_retval < 0) {
2527 VIR_FREE(names);
2528 return VIR_PY_NONE;
2531 py_retval = PyList_New(c_retval);
2533 if (names) {
2534 for (i = 0; i < c_retval; i++) {
2535 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2536 VIR_FREE(names[i]);
2538 VIR_FREE(names);
2541 return py_retval;
2544 static PyObject *
2545 libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
2546 PyObject *args)
2548 PyObject *py_retval;
2549 char **names = NULL;
2550 int c_retval;
2551 size_t i;
2552 virDomainPtr dom;
2553 PyObject *pyobj_dom;
2554 PyObject *pyobj_snap;
2555 unsigned int flags;
2557 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames",
2558 &pyobj_dom, &flags))
2559 return NULL;
2560 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2562 LIBVIRT_BEGIN_ALLOW_THREADS;
2563 c_retval = virDomainSnapshotNum(dom, flags);
2564 LIBVIRT_END_ALLOW_THREADS;
2565 if (c_retval < 0)
2566 return VIR_PY_NONE;
2568 if (c_retval) {
2569 if (VIR_ALLOC_N(names, c_retval) < 0)
2570 return PyErr_NoMemory();
2571 LIBVIRT_BEGIN_ALLOW_THREADS;
2572 c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
2573 LIBVIRT_END_ALLOW_THREADS;
2574 if (c_retval < 0) {
2575 VIR_FREE(names);
2576 return VIR_PY_NONE;
2579 py_retval = PyList_New(c_retval);
2580 if (!py_retval)
2581 goto cleanup;
2583 for (i = 0; i < c_retval; i++) {
2584 if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
2585 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2586 Py_XDECREF(pyobj_snap);
2587 Py_DECREF(py_retval);
2588 py_retval = NULL;
2589 goto cleanup;
2591 VIR_FREE(names[i]);
2594 cleanup:
2595 for (i = 0; i < c_retval; i++)
2596 VIR_FREE(names[i]);
2597 VIR_FREE(names);
2598 return py_retval;
2601 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2602 static PyObject *
2603 libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
2604 PyObject *args)
2606 PyObject *py_retval = NULL;
2607 virDomainSnapshotPtr *snaps = NULL;
2608 int c_retval;
2609 size_t i;
2610 virDomainPtr dom;
2611 PyObject *pyobj_dom;
2612 unsigned int flags;
2613 PyObject *pyobj_snap;
2615 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainListAllSnapshots",
2616 &pyobj_dom, &flags))
2617 return NULL;
2618 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2620 LIBVIRT_BEGIN_ALLOW_THREADS;
2621 c_retval = virDomainListAllSnapshots(dom, &snaps, flags);
2622 LIBVIRT_END_ALLOW_THREADS;
2623 if (c_retval < 0)
2624 return VIR_PY_NONE;
2626 if (!(py_retval = PyList_New(c_retval)))
2627 goto cleanup;
2629 for (i = 0; i < c_retval; i++) {
2630 if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
2631 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2632 Py_XDECREF(pyobj_snap);
2633 Py_DECREF(py_retval);
2634 py_retval = NULL;
2635 goto cleanup;
2637 snaps[i] = NULL;
2640 cleanup:
2641 for (i = 0; i < c_retval; i++)
2642 if (snaps[i])
2643 virDomainSnapshotFree(snaps[i]);
2644 VIR_FREE(snaps);
2645 return py_retval;
2647 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2649 static PyObject *
2650 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
2651 PyObject *args)
2653 PyObject *py_retval;
2654 char **names = NULL;
2655 int c_retval;
2656 size_t i;
2657 virDomainSnapshotPtr snap;
2658 PyObject *pyobj_snap;
2659 unsigned int flags;
2661 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListChildrenNames",
2662 &pyobj_snap, &flags))
2663 return NULL;
2664 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2666 LIBVIRT_BEGIN_ALLOW_THREADS;
2667 c_retval = virDomainSnapshotNumChildren(snap, flags);
2668 LIBVIRT_END_ALLOW_THREADS;
2669 if (c_retval < 0)
2670 return VIR_PY_NONE;
2672 if (c_retval) {
2673 if (VIR_ALLOC_N(names, c_retval) < 0)
2674 return PyErr_NoMemory();
2675 LIBVIRT_BEGIN_ALLOW_THREADS;
2676 c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
2677 flags);
2678 LIBVIRT_END_ALLOW_THREADS;
2679 if (c_retval < 0) {
2680 VIR_FREE(names);
2681 return VIR_PY_NONE;
2684 py_retval = PyList_New(c_retval);
2686 for (i = 0; i < c_retval; i++) {
2687 if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
2688 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2689 Py_XDECREF(pyobj_snap);
2690 Py_DECREF(py_retval);
2691 py_retval = NULL;
2692 goto cleanup;
2694 VIR_FREE(names[i]);
2697 cleanup:
2698 for (i = 0; i < c_retval; i++)
2699 VIR_FREE(names[i]);
2700 VIR_FREE(names);
2701 return py_retval;
2704 #if LIBVIR_CHECK_VERSION(0, 9, 13)
2705 static PyObject *
2706 libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2707 PyObject *args)
2709 PyObject *py_retval = NULL;
2710 virDomainSnapshotPtr *snaps = NULL;
2711 int c_retval;
2712 size_t i;
2713 virDomainSnapshotPtr parent;
2714 PyObject *pyobj_parent;
2715 unsigned int flags;
2716 PyObject *pyobj_snap;
2718 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListAllChildren",
2719 &pyobj_parent, &flags))
2720 return NULL;
2721 parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
2723 LIBVIRT_BEGIN_ALLOW_THREADS;
2724 c_retval = virDomainSnapshotListAllChildren(parent, &snaps, flags);
2725 LIBVIRT_END_ALLOW_THREADS;
2726 if (c_retval < 0)
2727 return VIR_PY_NONE;
2729 if (!(py_retval = PyList_New(c_retval)))
2730 goto cleanup;
2732 for (i = 0; i < c_retval; i++) {
2733 if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
2734 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2735 Py_XDECREF(pyobj_snap);
2736 Py_DECREF(py_retval);
2737 py_retval = NULL;
2738 goto cleanup;
2740 snaps[i] = NULL;
2743 cleanup:
2744 for (i = 0; i < c_retval; i++)
2745 if (snaps[i])
2746 virDomainSnapshotFree(snaps[i]);
2747 VIR_FREE(snaps);
2748 return py_retval;
2750 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
2752 static PyObject *
2753 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
2754 PyObject *args) {
2755 int c_retval;
2756 virDomainSnapshotPtr snap;
2757 PyObject *pyobj_snap;
2758 PyObject *pyobj_dom;
2759 unsigned int flags;
2761 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainRevertToSnapshot", &pyobj_dom, &pyobj_snap, &flags))
2762 return NULL;
2763 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2765 LIBVIRT_BEGIN_ALLOW_THREADS;
2766 c_retval = virDomainRevertToSnapshot(snap, flags);
2767 LIBVIRT_END_ALLOW_THREADS;
2768 if (c_retval < 0)
2769 return VIR_PY_INT_FAIL;
2771 return libvirt_intWrap(c_retval);
2774 static PyObject *
2775 libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2776 PyObject *py_retval;
2777 int c_retval;
2778 virDomainPtr domain;
2779 PyObject *pyobj_domain;
2780 virDomainInfo info;
2782 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_domain))
2783 return NULL;
2784 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2786 LIBVIRT_BEGIN_ALLOW_THREADS;
2787 c_retval = virDomainGetInfo(domain, &info);
2788 LIBVIRT_END_ALLOW_THREADS;
2789 if (c_retval < 0)
2790 return VIR_PY_NONE;
2791 py_retval = PyList_New(5);
2792 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
2793 PyList_SetItem(py_retval, 1, libvirt_ulongWrap(info.maxMem));
2794 PyList_SetItem(py_retval, 2, libvirt_ulongWrap(info.memory));
2795 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
2796 PyList_SetItem(py_retval, 4,
2797 libvirt_longlongWrap((unsigned long long) info.cpuTime));
2798 return py_retval;
2801 static PyObject *
2802 libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2804 PyObject *py_retval;
2805 int c_retval;
2806 virDomainPtr domain;
2807 PyObject *pyobj_domain;
2808 int state;
2809 int reason;
2810 unsigned int flags;
2812 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetState",
2813 &pyobj_domain, &flags))
2814 return NULL;
2816 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2818 LIBVIRT_BEGIN_ALLOW_THREADS;
2819 c_retval = virDomainGetState(domain, &state, &reason, flags);
2820 LIBVIRT_END_ALLOW_THREADS;
2821 if (c_retval < 0)
2822 return VIR_PY_NONE;
2824 py_retval = PyList_New(2);
2825 PyList_SetItem(py_retval, 0, libvirt_intWrap(state));
2826 PyList_SetItem(py_retval, 1, libvirt_intWrap(reason));
2827 return py_retval;
2830 static PyObject *
2831 libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2832 PyObject *py_retval;
2833 int c_retval;
2834 virDomainPtr domain;
2835 PyObject *pyobj_domain;
2836 virDomainControlInfo info;
2837 unsigned int flags;
2839 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetControlInfo",
2840 &pyobj_domain, &flags))
2841 return NULL;
2842 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2844 LIBVIRT_BEGIN_ALLOW_THREADS;
2845 c_retval = virDomainGetControlInfo(domain, &info, flags);
2846 LIBVIRT_END_ALLOW_THREADS;
2847 if (c_retval < 0)
2848 return VIR_PY_NONE;
2849 py_retval = PyList_New(3);
2850 PyList_SetItem(py_retval, 0, libvirt_intWrap(info.state));
2851 PyList_SetItem(py_retval, 1, libvirt_intWrap(info.details));
2852 PyList_SetItem(py_retval, 2, libvirt_longlongWrap(info.stateTime));
2853 return py_retval;
2856 static PyObject *
2857 libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2858 PyObject *py_retval;
2859 int c_retval;
2860 virDomainPtr domain;
2861 PyObject *pyobj_domain;
2862 virDomainBlockInfo info;
2863 const char *path;
2864 unsigned int flags;
2866 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInfo", &pyobj_domain, &path, &flags))
2867 return NULL;
2868 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2870 LIBVIRT_BEGIN_ALLOW_THREADS;
2871 c_retval = virDomainGetBlockInfo(domain, path, &info, flags);
2872 LIBVIRT_END_ALLOW_THREADS;
2873 if (c_retval < 0)
2874 return VIR_PY_NONE;
2875 py_retval = PyList_New(3);
2876 PyList_SetItem(py_retval, 0, libvirt_ulonglongWrap(info.capacity));
2877 PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.allocation));
2878 PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.physical));
2879 return py_retval;
2882 static PyObject *
2883 libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2884 PyObject *py_retval;
2885 int c_retval;
2886 virConnectPtr conn;
2887 PyObject *pyobj_conn;
2888 virNodeInfo info;
2890 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_conn))
2891 return NULL;
2892 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2894 LIBVIRT_BEGIN_ALLOW_THREADS;
2895 c_retval = virNodeGetInfo(conn, &info);
2896 LIBVIRT_END_ALLOW_THREADS;
2897 if (c_retval < 0)
2898 return VIR_PY_NONE;
2899 py_retval = PyList_New(8);
2900 PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&info.model[0]));
2901 PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.memory >> 10));
2902 PyList_SetItem(py_retval, 2, libvirt_intWrap((int) info.cpus));
2903 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.mhz));
2904 PyList_SetItem(py_retval, 4, libvirt_intWrap((int) info.nodes));
2905 PyList_SetItem(py_retval, 5, libvirt_intWrap((int) info.sockets));
2906 PyList_SetItem(py_retval, 6, libvirt_intWrap((int) info.cores));
2907 PyList_SetItem(py_retval, 7, libvirt_intWrap((int) info.threads));
2908 return py_retval;
2911 static PyObject *
2912 libvirt_virNodeGetSecurityModel(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2913 PyObject *py_retval;
2914 int c_retval;
2915 virConnectPtr conn;
2916 PyObject *pyobj_conn;
2917 virSecurityModel model;
2919 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityModel", &pyobj_conn))
2920 return NULL;
2921 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2923 LIBVIRT_BEGIN_ALLOW_THREADS;
2924 c_retval = virNodeGetSecurityModel(conn, &model);
2925 LIBVIRT_END_ALLOW_THREADS;
2926 if (c_retval < 0)
2927 return VIR_PY_NONE;
2928 py_retval = PyList_New(2);
2929 PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&model.model[0]));
2930 PyList_SetItem(py_retval, 1, libvirt_constcharPtrWrap(&model.doi[0]));
2931 return py_retval;
2934 static PyObject *
2935 libvirt_virDomainGetSecurityLabel(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2936 PyObject *py_retval;
2937 int c_retval;
2938 virDomainPtr dom;
2939 PyObject *pyobj_dom;
2940 virSecurityLabel label;
2942 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabel", &pyobj_dom))
2943 return NULL;
2944 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2946 LIBVIRT_BEGIN_ALLOW_THREADS;
2947 c_retval = virDomainGetSecurityLabel(dom, &label);
2948 LIBVIRT_END_ALLOW_THREADS;
2949 if (c_retval < 0)
2950 return VIR_PY_NONE;
2951 py_retval = PyList_New(2);
2952 PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&label.label[0]));
2953 PyList_SetItem(py_retval, 1, libvirt_boolWrap(label.enforcing));
2954 return py_retval;
2957 #if LIBVIR_CHECK_VERSION(0, 10, 0)
2958 static PyObject *
2959 libvirt_virDomainGetSecurityLabelList(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2960 PyObject *py_retval;
2961 int c_retval;
2962 virDomainPtr dom;
2963 PyObject *pyobj_dom;
2964 virSecurityLabel *labels;
2965 size_t i;
2967 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetSecurityLabel", &pyobj_dom))
2968 return NULL;
2969 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2971 LIBVIRT_BEGIN_ALLOW_THREADS;
2972 c_retval = virDomainGetSecurityLabelList(dom, &labels);
2973 LIBVIRT_END_ALLOW_THREADS;
2974 if (c_retval < 0)
2975 return VIR_PY_NONE;
2976 py_retval = PyList_New(0);
2977 for (i = 0 ; i < c_retval ; i++) {
2978 PyObject *entry = PyList_New(2);
2979 PyList_SetItem(entry, 0, libvirt_constcharPtrWrap(&labels[i].label[0]));
2980 PyList_SetItem(entry, 1, libvirt_boolWrap(labels[i].enforcing));
2981 PyList_Append(py_retval, entry);
2983 free(labels);
2984 return py_retval;
2986 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
2988 static PyObject *
2989 libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2990 PyObject *py_retval;
2991 unsigned char uuid[VIR_UUID_BUFLEN];
2992 virDomainPtr domain;
2993 PyObject *pyobj_domain;
2994 int c_retval;
2996 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
2997 return NULL;
2998 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
3000 if (domain == NULL)
3001 return VIR_PY_NONE;
3002 LIBVIRT_BEGIN_ALLOW_THREADS;
3003 c_retval = virDomainGetUUID(domain, &uuid[0]);
3004 LIBVIRT_END_ALLOW_THREADS;
3006 if (c_retval < 0)
3007 return VIR_PY_NONE;
3008 py_retval = libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3010 return py_retval;
3013 static PyObject *
3014 libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3015 PyObject *args) {
3016 PyObject *py_retval;
3017 char uuidstr[VIR_UUID_STRING_BUFLEN];
3018 virDomainPtr dom;
3019 PyObject *pyobj_dom;
3020 int c_retval;
3022 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString",
3023 &pyobj_dom))
3024 return NULL;
3025 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
3027 if (dom == NULL)
3028 return VIR_PY_NONE;
3029 LIBVIRT_BEGIN_ALLOW_THREADS;
3030 c_retval = virDomainGetUUIDString(dom, &uuidstr[0]);
3031 LIBVIRT_END_ALLOW_THREADS;
3033 if (c_retval < 0)
3034 return VIR_PY_NONE;
3036 py_retval = libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3037 return py_retval;
3040 static PyObject *
3041 libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3042 PyObject *py_retval;
3043 virDomainPtr c_retval;
3044 virConnectPtr conn;
3045 PyObject *pyobj_conn;
3046 unsigned char * uuid;
3047 int len;
3049 if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID", &pyobj_conn, &uuid, &len))
3050 return NULL;
3051 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3053 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3054 return VIR_PY_NONE;
3056 LIBVIRT_BEGIN_ALLOW_THREADS;
3057 c_retval = virDomainLookupByUUID(conn, uuid);
3058 LIBVIRT_END_ALLOW_THREADS;
3059 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
3060 return py_retval;
3064 static PyObject *
3065 libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
3066 PyObject *args) {
3067 PyObject *py_retval;
3068 char **names = NULL;
3069 int c_retval;
3070 size_t i;
3071 virConnectPtr conn;
3072 PyObject *pyobj_conn;
3075 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks", &pyobj_conn))
3076 return NULL;
3077 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3079 LIBVIRT_BEGIN_ALLOW_THREADS;
3080 c_retval = virConnectNumOfNetworks(conn);
3081 LIBVIRT_END_ALLOW_THREADS;
3082 if (c_retval < 0)
3083 return VIR_PY_NONE;
3085 if (c_retval) {
3086 if (VIR_ALLOC_N(names, c_retval) < 0)
3087 return VIR_PY_NONE;
3088 LIBVIRT_BEGIN_ALLOW_THREADS;
3089 c_retval = virConnectListNetworks(conn, names, c_retval);
3090 LIBVIRT_END_ALLOW_THREADS;
3091 if (c_retval < 0) {
3092 VIR_FREE(names);
3093 return VIR_PY_NONE;
3096 py_retval = PyList_New(c_retval);
3098 if (names) {
3099 for (i = 0; i < c_retval; i++) {
3100 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3101 VIR_FREE(names[i]);
3103 VIR_FREE(names);
3106 return py_retval;
3110 static PyObject *
3111 libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
3112 PyObject *args) {
3113 PyObject *py_retval;
3114 char **names = NULL;
3115 int c_retval;
3116 size_t i;
3117 virConnectPtr conn;
3118 PyObject *pyobj_conn;
3121 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks", &pyobj_conn))
3122 return NULL;
3123 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3125 LIBVIRT_BEGIN_ALLOW_THREADS;
3126 c_retval = virConnectNumOfDefinedNetworks(conn);
3127 LIBVIRT_END_ALLOW_THREADS;
3128 if (c_retval < 0)
3129 return VIR_PY_NONE;
3131 if (c_retval) {
3132 if (VIR_ALLOC_N(names, c_retval) < 0)
3133 return VIR_PY_NONE;
3134 LIBVIRT_BEGIN_ALLOW_THREADS;
3135 c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
3136 LIBVIRT_END_ALLOW_THREADS;
3137 if (c_retval < 0) {
3138 VIR_FREE(names);
3139 return VIR_PY_NONE;
3142 py_retval = PyList_New(c_retval);
3144 if (names) {
3145 for (i = 0; i < c_retval; i++) {
3146 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3147 VIR_FREE(names[i]);
3149 VIR_FREE(names);
3152 return py_retval;
3155 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3156 static PyObject *
3157 libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
3158 PyObject *args)
3160 PyObject *pyobj_conn;
3161 PyObject *py_retval = NULL;
3162 PyObject *tmp = NULL;
3163 virConnectPtr conn;
3164 virNetworkPtr *nets = NULL;
3165 int c_retval = 0;
3166 size_t i;
3167 unsigned int flags;
3169 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNetworks",
3170 &pyobj_conn, &flags))
3171 return NULL;
3172 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3174 LIBVIRT_BEGIN_ALLOW_THREADS;
3175 c_retval = virConnectListAllNetworks(conn, &nets, flags);
3176 LIBVIRT_END_ALLOW_THREADS;
3177 if (c_retval < 0)
3178 return VIR_PY_NONE;
3180 if (!(py_retval = PyList_New(c_retval)))
3181 goto cleanup;
3183 for (i = 0; i < c_retval; i++) {
3184 if (!(tmp = libvirt_virNetworkPtrWrap(nets[i])) ||
3185 PyList_SetItem(py_retval, i, tmp) < 0) {
3186 Py_XDECREF(tmp);
3187 Py_DECREF(py_retval);
3188 py_retval = NULL;
3189 goto cleanup;
3191 /* python steals the pointer */
3192 nets[i] = NULL;
3195 cleanup:
3196 for (i = 0; i < c_retval; i++)
3197 if (nets[i])
3198 virNetworkFree(nets[i]);
3199 VIR_FREE(nets);
3200 return py_retval;
3202 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3205 static PyObject *
3206 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3207 PyObject *py_retval;
3208 unsigned char uuid[VIR_UUID_BUFLEN];
3209 virNetworkPtr domain;
3210 PyObject *pyobj_domain;
3211 int c_retval;
3213 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain))
3214 return NULL;
3215 domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
3217 if (domain == NULL)
3218 return VIR_PY_NONE;
3219 LIBVIRT_BEGIN_ALLOW_THREADS;
3220 c_retval = virNetworkGetUUID(domain, &uuid[0]);
3221 LIBVIRT_END_ALLOW_THREADS;
3223 if (c_retval < 0)
3224 return VIR_PY_NONE;
3225 py_retval = libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3227 return py_retval;
3230 static PyObject *
3231 libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3232 PyObject *args) {
3233 PyObject *py_retval;
3234 char uuidstr[VIR_UUID_STRING_BUFLEN];
3235 virNetworkPtr net;
3236 PyObject *pyobj_net;
3237 int c_retval;
3239 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString",
3240 &pyobj_net))
3241 return NULL;
3242 net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net);
3244 if (net == NULL)
3245 return VIR_PY_NONE;
3246 LIBVIRT_BEGIN_ALLOW_THREADS;
3247 c_retval = virNetworkGetUUIDString(net, &uuidstr[0]);
3248 LIBVIRT_END_ALLOW_THREADS;
3250 if (c_retval < 0)
3251 return VIR_PY_NONE;
3253 py_retval = libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3254 return py_retval;
3257 static PyObject *
3258 libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3259 PyObject *py_retval;
3260 virNetworkPtr c_retval;
3261 virConnectPtr conn;
3262 PyObject *pyobj_conn;
3263 unsigned char * uuid;
3264 int len;
3266 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID", &pyobj_conn, &uuid, &len))
3267 return NULL;
3268 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3270 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3271 return VIR_PY_NONE;
3273 LIBVIRT_BEGIN_ALLOW_THREADS;
3274 c_retval = virNetworkLookupByUUID(conn, uuid);
3275 LIBVIRT_END_ALLOW_THREADS;
3276 py_retval = libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval);
3277 return py_retval;
3281 static PyObject *
3282 libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3283 PyObject *py_retval;
3284 int c_retval, autostart;
3285 virDomainPtr domain;
3286 PyObject *pyobj_domain;
3288 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetAutostart", &pyobj_domain))
3289 return NULL;
3291 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
3293 LIBVIRT_BEGIN_ALLOW_THREADS;
3294 c_retval = virDomainGetAutostart(domain, &autostart);
3295 LIBVIRT_END_ALLOW_THREADS;
3297 if (c_retval < 0)
3298 return VIR_PY_INT_FAIL;
3299 py_retval = libvirt_intWrap(autostart);
3300 return py_retval;
3304 static PyObject *
3305 libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3306 PyObject *py_retval;
3307 int c_retval, autostart;
3308 virNetworkPtr network;
3309 PyObject *pyobj_network;
3311 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetAutostart", &pyobj_network))
3312 return NULL;
3314 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
3316 LIBVIRT_BEGIN_ALLOW_THREADS;
3317 c_retval = virNetworkGetAutostart(network, &autostart);
3318 LIBVIRT_END_ALLOW_THREADS;
3320 if (c_retval < 0)
3321 return VIR_PY_INT_FAIL;
3322 py_retval = libvirt_intWrap(autostart);
3323 return py_retval;
3326 static PyObject *
3327 libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
3329 PyObject *py_retval;
3330 PyObject *pyobj_conn;
3331 int startCell, maxCells, c_retval;
3332 size_t i;
3333 virConnectPtr conn;
3334 unsigned long long *freeMems;
3336 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory", &pyobj_conn, &startCell, &maxCells))
3337 return NULL;
3339 if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
3340 return VIR_PY_NONE;
3342 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3343 if (VIR_ALLOC_N(freeMems, maxCells) < 0)
3344 return VIR_PY_NONE;
3346 LIBVIRT_BEGIN_ALLOW_THREADS;
3347 c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
3348 LIBVIRT_END_ALLOW_THREADS;
3350 if (c_retval < 0) {
3351 VIR_FREE(freeMems);
3352 return VIR_PY_NONE;
3354 py_retval = PyList_New(c_retval);
3355 for (i = 0; i < c_retval; i++) {
3356 PyList_SetItem(py_retval, i,
3357 libvirt_longlongWrap((long long) freeMems[i]));
3359 VIR_FREE(freeMems);
3360 return py_retval;
3363 static PyObject *
3364 libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
3366 PyObject *ret = NULL;
3367 PyObject *key = NULL;
3368 PyObject *val = NULL;
3369 PyObject *pyobj_conn;
3370 virConnectPtr conn;
3371 unsigned int flags;
3372 int cpuNum, c_retval;
3373 size_t i;
3374 int nparams = 0;
3375 virNodeCPUStatsPtr stats = NULL;
3377 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn, &cpuNum, &flags))
3378 return ret;
3379 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3381 LIBVIRT_BEGIN_ALLOW_THREADS;
3382 c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
3383 LIBVIRT_END_ALLOW_THREADS;
3384 if (c_retval < 0)
3385 return VIR_PY_NONE;
3387 if (nparams) {
3388 if (VIR_ALLOC_N(stats, nparams) < 0)
3389 return PyErr_NoMemory();
3391 LIBVIRT_BEGIN_ALLOW_THREADS;
3392 c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
3393 LIBVIRT_END_ALLOW_THREADS;
3394 if (c_retval < 0) {
3395 VIR_FREE(stats);
3396 return VIR_PY_NONE;
3400 if (!(ret = PyDict_New()))
3401 goto error;
3403 for (i = 0; i < nparams; i++) {
3404 key = libvirt_constcharPtrWrap(stats[i].field);
3405 val = libvirt_ulonglongWrap(stats[i].value);
3407 if (!key || !val || PyDict_SetItem(ret, key, val) < 0) {
3408 Py_DECREF(ret);
3409 ret = NULL;
3410 goto error;
3413 Py_DECREF(key);
3414 Py_DECREF(val);
3417 VIR_FREE(stats);
3418 return ret;
3420 error:
3421 VIR_FREE(stats);
3422 Py_XDECREF(key);
3423 Py_XDECREF(val);
3424 return ret;
3427 static PyObject *
3428 libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
3430 PyObject *ret = NULL;
3431 PyObject *key = NULL;
3432 PyObject *val = NULL;
3433 PyObject *pyobj_conn;
3434 virConnectPtr conn;
3435 unsigned int flags;
3436 int cellNum, c_retval;
3437 size_t i;
3438 int nparams = 0;
3439 virNodeMemoryStatsPtr stats = NULL;
3441 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetMemoryStats", &pyobj_conn, &cellNum, &flags))
3442 return ret;
3443 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3445 LIBVIRT_BEGIN_ALLOW_THREADS;
3446 c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
3447 LIBVIRT_END_ALLOW_THREADS;
3448 if (c_retval < 0)
3449 return VIR_PY_NONE;
3451 if (nparams) {
3452 if (VIR_ALLOC_N(stats, nparams) < 0)
3453 return PyErr_NoMemory();
3455 LIBVIRT_BEGIN_ALLOW_THREADS;
3456 c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
3457 LIBVIRT_END_ALLOW_THREADS;
3458 if (c_retval < 0) {
3459 VIR_FREE(stats);
3460 return VIR_PY_NONE;
3464 if (!(ret = PyDict_New()))
3465 goto error;
3467 for (i = 0; i < nparams; i++) {
3468 key = libvirt_constcharPtrWrap(stats[i].field);
3469 val = libvirt_ulonglongWrap(stats[i].value);
3471 if (!key || !val || PyDict_SetItem(ret, key, val) < 0) {
3472 Py_DECREF(ret);
3473 ret = NULL;
3474 goto error;
3477 Py_DECREF(key);
3478 Py_DECREF(val);
3481 VIR_FREE(stats);
3482 return ret;
3484 error:
3485 VIR_FREE(stats);
3486 Py_XDECREF(key);
3487 Py_XDECREF(val);
3488 return ret;
3491 static PyObject *
3492 libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3493 PyObject *args) {
3494 PyObject *py_retval;
3495 char **names = NULL;
3496 int c_retval;
3497 size_t i;
3498 virConnectPtr conn;
3499 PyObject *pyobj_conn;
3502 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListStoragePools", &pyobj_conn))
3503 return NULL;
3504 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3506 LIBVIRT_BEGIN_ALLOW_THREADS;
3507 c_retval = virConnectNumOfStoragePools(conn);
3508 LIBVIRT_END_ALLOW_THREADS;
3509 if (c_retval < 0)
3510 return VIR_PY_NONE;
3512 if (c_retval) {
3513 if (VIR_ALLOC_N(names, c_retval) < 0)
3514 return VIR_PY_NONE;
3515 LIBVIRT_BEGIN_ALLOW_THREADS;
3516 c_retval = virConnectListStoragePools(conn, names, c_retval);
3517 LIBVIRT_END_ALLOW_THREADS;
3518 if (c_retval < 0) {
3519 VIR_FREE(names);
3520 return VIR_PY_NONE;
3523 py_retval = PyList_New(c_retval);
3524 if (py_retval == NULL) {
3525 if (names) {
3526 for (i = 0; i < c_retval; i++)
3527 VIR_FREE(names[i]);
3528 VIR_FREE(names);
3530 return VIR_PY_NONE;
3533 if (names) {
3534 for (i = 0; i < c_retval; i++) {
3535 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3536 VIR_FREE(names[i]);
3538 VIR_FREE(names);
3541 return py_retval;
3545 static PyObject *
3546 libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3547 PyObject *args) {
3548 PyObject *py_retval;
3549 char **names = NULL;
3550 int c_retval;
3551 size_t i;
3552 virConnectPtr conn;
3553 PyObject *pyobj_conn;
3556 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedStoragePools", &pyobj_conn))
3557 return NULL;
3558 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3560 LIBVIRT_BEGIN_ALLOW_THREADS;
3561 c_retval = virConnectNumOfDefinedStoragePools(conn);
3562 LIBVIRT_END_ALLOW_THREADS;
3563 if (c_retval < 0)
3564 return VIR_PY_NONE;
3566 if (c_retval) {
3567 if (VIR_ALLOC_N(names, c_retval) < 0)
3568 return VIR_PY_NONE;
3569 LIBVIRT_BEGIN_ALLOW_THREADS;
3570 c_retval = virConnectListDefinedStoragePools(conn, names, c_retval);
3571 LIBVIRT_END_ALLOW_THREADS;
3572 if (c_retval < 0) {
3573 VIR_FREE(names);
3574 return VIR_PY_NONE;
3577 py_retval = PyList_New(c_retval);
3578 if (py_retval == NULL) {
3579 if (names) {
3580 for (i = 0; i < c_retval; i++)
3581 VIR_FREE(names[i]);
3582 VIR_FREE(names);
3584 return VIR_PY_NONE;
3587 if (names) {
3588 for (i = 0; i < c_retval; i++) {
3589 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3590 VIR_FREE(names[i]);
3592 VIR_FREE(names);
3595 return py_retval;
3598 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3599 static PyObject *
3600 libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3601 PyObject *args)
3603 PyObject *pyobj_conn;
3604 PyObject *py_retval = NULL;
3605 PyObject *tmp = NULL;
3606 virConnectPtr conn;
3607 virStoragePoolPtr *pools = NULL;
3608 int c_retval = 0;
3609 size_t i;
3610 unsigned int flags;
3612 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllStoragePools",
3613 &pyobj_conn, &flags))
3614 return NULL;
3615 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3617 LIBVIRT_BEGIN_ALLOW_THREADS;
3618 c_retval = virConnectListAllStoragePools(conn, &pools, flags);
3619 LIBVIRT_END_ALLOW_THREADS;
3620 if (c_retval < 0)
3621 return VIR_PY_NONE;
3623 if (!(py_retval = PyList_New(c_retval)))
3624 goto cleanup;
3626 for (i = 0; i < c_retval; i++) {
3627 if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i])) ||
3628 PyList_SetItem(py_retval, i, tmp) < 0) {
3629 Py_XDECREF(tmp);
3630 Py_DECREF(py_retval);
3631 py_retval = NULL;
3632 goto cleanup;
3634 /* python steals the pointer */
3635 pools[i] = NULL;
3638 cleanup:
3639 for (i = 0; i < c_retval; i++)
3640 if (pools[i])
3641 virStoragePoolFree(pools[i]);
3642 VIR_FREE(pools);
3643 return py_retval;
3645 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3647 static PyObject *
3648 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
3649 PyObject *args) {
3650 PyObject *py_retval;
3651 char **names = NULL;
3652 int c_retval;
3653 size_t i;
3654 virStoragePoolPtr pool;
3655 PyObject *pyobj_pool;
3658 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolListVolumes", &pyobj_pool))
3659 return NULL;
3660 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3662 LIBVIRT_BEGIN_ALLOW_THREADS;
3663 c_retval = virStoragePoolNumOfVolumes(pool);
3664 LIBVIRT_END_ALLOW_THREADS;
3665 if (c_retval < 0)
3666 return VIR_PY_NONE;
3668 if (c_retval) {
3669 if (VIR_ALLOC_N(names, c_retval) < 0)
3670 return VIR_PY_NONE;
3671 LIBVIRT_BEGIN_ALLOW_THREADS;
3672 c_retval = virStoragePoolListVolumes(pool, names, c_retval);
3673 LIBVIRT_END_ALLOW_THREADS;
3674 if (c_retval < 0) {
3675 VIR_FREE(names);
3676 return VIR_PY_NONE;
3679 py_retval = PyList_New(c_retval);
3680 if (py_retval == NULL) {
3681 if (names) {
3682 for (i = 0; i < c_retval; i++)
3683 VIR_FREE(names[i]);
3684 VIR_FREE(names);
3686 return VIR_PY_NONE;
3689 if (names) {
3690 for (i = 0; i < c_retval; i++) {
3691 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3692 VIR_FREE(names[i]);
3694 VIR_FREE(names);
3697 return py_retval;
3700 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3701 static PyObject *
3702 libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
3703 PyObject *args)
3705 PyObject *py_retval = NULL;
3706 PyObject *tmp = NULL;
3707 virStoragePoolPtr pool;
3708 virStorageVolPtr *vols = NULL;
3709 int c_retval = 0;
3710 size_t i;
3711 unsigned int flags;
3712 PyObject *pyobj_pool;
3714 if (!PyArg_ParseTuple(args, (char *)"Oi:virStoragePoolListAllVolumes",
3715 &pyobj_pool, &flags))
3716 return NULL;
3718 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3720 LIBVIRT_BEGIN_ALLOW_THREADS;
3721 c_retval = virStoragePoolListAllVolumes(pool, &vols, flags);
3722 LIBVIRT_END_ALLOW_THREADS;
3723 if (c_retval < 0)
3724 return VIR_PY_NONE;
3726 if (!(py_retval = PyList_New(c_retval)))
3727 goto cleanup;
3729 for (i = 0; i < c_retval; i++) {
3730 if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i])) ||
3731 PyList_SetItem(py_retval, i, tmp) < 0) {
3732 Py_XDECREF(tmp);
3733 Py_DECREF(py_retval);
3734 py_retval = NULL;
3735 goto cleanup;
3737 /* python steals the pointer */
3738 vols[i] = NULL;
3741 cleanup:
3742 for (i = 0; i < c_retval; i++)
3743 if (vols[i])
3744 virStorageVolFree(vols[i]);
3745 VIR_FREE(vols);
3746 return py_retval;
3748 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
3751 static PyObject *
3752 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3753 PyObject *py_retval;
3754 int c_retval, autostart;
3755 virStoragePoolPtr pool;
3756 PyObject *pyobj_pool;
3758 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetAutostart", &pyobj_pool))
3759 return NULL;
3761 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3763 LIBVIRT_BEGIN_ALLOW_THREADS;
3764 c_retval = virStoragePoolGetAutostart(pool, &autostart);
3765 LIBVIRT_END_ALLOW_THREADS;
3767 if (c_retval < 0)
3768 return VIR_PY_NONE;
3770 py_retval = libvirt_intWrap(autostart);
3771 return py_retval;
3774 static PyObject *
3775 libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3776 PyObject *py_retval;
3777 int c_retval;
3778 virStoragePoolPtr pool;
3779 PyObject *pyobj_pool;
3780 virStoragePoolInfo info;
3782 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetInfo", &pyobj_pool))
3783 return NULL;
3784 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3786 LIBVIRT_BEGIN_ALLOW_THREADS;
3787 c_retval = virStoragePoolGetInfo(pool, &info);
3788 LIBVIRT_END_ALLOW_THREADS;
3789 if (c_retval < 0)
3790 return VIR_PY_NONE;
3792 if ((py_retval = PyList_New(4)) == NULL)
3793 return VIR_PY_NONE;
3795 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
3796 PyList_SetItem(py_retval, 1,
3797 libvirt_longlongWrap((unsigned long long) info.capacity));
3798 PyList_SetItem(py_retval, 2,
3799 libvirt_longlongWrap((unsigned long long) info.allocation));
3800 PyList_SetItem(py_retval, 3,
3801 libvirt_longlongWrap((unsigned long long) info.available));
3802 return py_retval;
3806 static PyObject *
3807 libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3808 PyObject *py_retval;
3809 int c_retval;
3810 virStorageVolPtr pool;
3811 PyObject *pyobj_pool;
3812 virStorageVolInfo info;
3814 if (!PyArg_ParseTuple(args, (char *)"O:virStorageVolGetInfo", &pyobj_pool))
3815 return NULL;
3816 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3818 LIBVIRT_BEGIN_ALLOW_THREADS;
3819 c_retval = virStorageVolGetInfo(pool, &info);
3820 LIBVIRT_END_ALLOW_THREADS;
3821 if (c_retval < 0)
3822 return VIR_PY_NONE;
3824 if ((py_retval = PyList_New(3)) == NULL)
3825 return VIR_PY_NONE;
3826 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
3827 PyList_SetItem(py_retval, 1,
3828 libvirt_longlongWrap((unsigned long long) info.capacity));
3829 PyList_SetItem(py_retval, 2,
3830 libvirt_longlongWrap((unsigned long long) info.allocation));
3831 return py_retval;
3834 static PyObject *
3835 libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3836 PyObject *py_retval;
3837 unsigned char uuid[VIR_UUID_BUFLEN];
3838 virStoragePoolPtr pool;
3839 PyObject *pyobj_pool;
3840 int c_retval;
3842 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUID", &pyobj_pool))
3843 return NULL;
3844 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3846 if (pool == NULL)
3847 return VIR_PY_NONE;
3848 LIBVIRT_BEGIN_ALLOW_THREADS;
3849 c_retval = virStoragePoolGetUUID(pool, &uuid[0]);
3850 LIBVIRT_END_ALLOW_THREADS;
3852 if (c_retval < 0)
3853 return VIR_PY_NONE;
3855 py_retval = libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
3857 return py_retval;
3860 static PyObject *
3861 libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3862 PyObject *args) {
3863 PyObject *py_retval;
3864 char uuidstr[VIR_UUID_STRING_BUFLEN];
3865 virStoragePoolPtr pool;
3866 PyObject *pyobj_pool;
3867 int c_retval;
3869 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString", &pyobj_pool))
3870 return NULL;
3871 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3873 if (pool == NULL)
3874 return VIR_PY_NONE;
3875 LIBVIRT_BEGIN_ALLOW_THREADS;
3876 c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]);
3877 LIBVIRT_END_ALLOW_THREADS;
3879 if (c_retval < 0)
3880 return VIR_PY_NONE;
3882 py_retval = libvirt_constcharPtrWrap((char *) &uuidstr[0]);
3883 return py_retval;
3886 static PyObject *
3887 libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3888 PyObject *py_retval;
3889 virStoragePoolPtr c_retval;
3890 virConnectPtr conn;
3891 PyObject *pyobj_conn;
3892 unsigned char * uuid;
3893 int len;
3895 if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID", &pyobj_conn, &uuid, &len))
3896 return NULL;
3897 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3899 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3900 return VIR_PY_NONE;
3902 LIBVIRT_BEGIN_ALLOW_THREADS;
3903 c_retval = virStoragePoolLookupByUUID(conn, uuid);
3904 LIBVIRT_END_ALLOW_THREADS;
3905 py_retval = libvirt_virStoragePoolPtrWrap((virStoragePoolPtr) c_retval);
3906 return py_retval;
3909 static PyObject *
3910 libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
3911 PyObject *args) {
3912 PyObject *py_retval;
3913 char **names = NULL;
3914 int c_retval;
3915 size_t i;
3916 virConnectPtr conn;
3917 PyObject *pyobj_conn;
3918 char *cap;
3919 unsigned int flags;
3921 if (!PyArg_ParseTuple(args, (char *)"Ozi:virNodeListDevices",
3922 &pyobj_conn, &cap, &flags))
3923 return NULL;
3924 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3926 LIBVIRT_BEGIN_ALLOW_THREADS;
3927 c_retval = virNodeNumOfDevices(conn, cap, flags);
3928 LIBVIRT_END_ALLOW_THREADS;
3929 if (c_retval < 0)
3930 return VIR_PY_NONE;
3932 if (c_retval) {
3933 if (VIR_ALLOC_N(names, c_retval) < 0)
3934 return VIR_PY_NONE;
3935 LIBVIRT_BEGIN_ALLOW_THREADS;
3936 c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
3937 LIBVIRT_END_ALLOW_THREADS;
3938 if (c_retval < 0) {
3939 VIR_FREE(names);
3940 return VIR_PY_NONE;
3943 py_retval = PyList_New(c_retval);
3945 if (names) {
3946 for (i = 0; i < c_retval; i++) {
3947 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3948 VIR_FREE(names[i]);
3950 VIR_FREE(names);
3953 return py_retval;
3956 #if LIBVIR_CHECK_VERSION(0, 10, 2)
3957 static PyObject *
3958 libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
3959 PyObject *args)
3961 PyObject *pyobj_conn;
3962 PyObject *py_retval = NULL;
3963 PyObject *tmp = NULL;
3964 virConnectPtr conn;
3965 virNodeDevicePtr *devices = NULL;
3966 int c_retval = 0;
3967 size_t i;
3968 unsigned int flags;
3970 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNodeDevices",
3971 &pyobj_conn, &flags))
3972 return NULL;
3973 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3975 LIBVIRT_BEGIN_ALLOW_THREADS;
3976 c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
3977 LIBVIRT_END_ALLOW_THREADS;
3978 if (c_retval < 0)
3979 return VIR_PY_NONE;
3981 if (!(py_retval = PyList_New(c_retval)))
3982 goto cleanup;
3984 for (i = 0; i < c_retval; i++) {
3985 if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i])) ||
3986 PyList_SetItem(py_retval, i, tmp) < 0) {
3987 Py_XDECREF(tmp);
3988 Py_DECREF(py_retval);
3989 py_retval = NULL;
3990 goto cleanup;
3992 /* python steals the pointer */
3993 devices[i] = NULL;
3996 cleanup:
3997 for (i = 0; i < c_retval; i++)
3998 if (devices[i])
3999 virNodeDeviceFree(devices[i]);
4000 VIR_FREE(devices);
4001 return py_retval;
4003 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4005 static PyObject *
4006 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
4007 PyObject *args) {
4008 PyObject *py_retval;
4009 char **names = NULL;
4010 int c_retval;
4011 size_t i;
4012 virNodeDevicePtr dev;
4013 PyObject *pyobj_dev;
4015 if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
4016 return NULL;
4017 dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
4019 LIBVIRT_BEGIN_ALLOW_THREADS;
4020 c_retval = virNodeDeviceNumOfCaps(dev);
4021 LIBVIRT_END_ALLOW_THREADS;
4022 if (c_retval < 0)
4023 return VIR_PY_NONE;
4025 if (c_retval) {
4026 if (VIR_ALLOC_N(names, c_retval) < 0)
4027 return VIR_PY_NONE;
4028 LIBVIRT_BEGIN_ALLOW_THREADS;
4029 c_retval = virNodeDeviceListCaps(dev, names, c_retval);
4030 LIBVIRT_END_ALLOW_THREADS;
4031 if (c_retval < 0) {
4032 VIR_FREE(names);
4033 return VIR_PY_NONE;
4036 py_retval = PyList_New(c_retval);
4038 if (names) {
4039 for (i = 0; i < c_retval; i++) {
4040 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
4041 VIR_FREE(names[i]);
4043 VIR_FREE(names);
4046 return py_retval;
4049 static PyObject *
4050 libvirt_virSecretGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4051 PyObject *py_retval;
4052 unsigned char uuid[VIR_UUID_BUFLEN];
4053 virSecretPtr secret;
4054 PyObject *pyobj_secret;
4055 int c_retval;
4057 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUID", &pyobj_secret))
4058 return NULL;
4059 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4061 if (secret == NULL)
4062 return VIR_PY_NONE;
4063 LIBVIRT_BEGIN_ALLOW_THREADS;
4064 c_retval = virSecretGetUUID(secret, &uuid[0]);
4065 LIBVIRT_END_ALLOW_THREADS;
4067 if (c_retval < 0)
4068 return VIR_PY_NONE;
4069 py_retval = libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4071 return py_retval;
4074 static PyObject *
4075 libvirt_virSecretGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4076 PyObject *args) {
4077 PyObject *py_retval;
4078 char uuidstr[VIR_UUID_STRING_BUFLEN];
4079 virSecretPtr dom;
4080 PyObject *pyobj_dom;
4081 int c_retval;
4083 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUIDString",
4084 &pyobj_dom))
4085 return NULL;
4086 dom = (virSecretPtr) PyvirSecret_Get(pyobj_dom);
4088 if (dom == NULL)
4089 return VIR_PY_NONE;
4090 LIBVIRT_BEGIN_ALLOW_THREADS;
4091 c_retval = virSecretGetUUIDString(dom, &uuidstr[0]);
4092 LIBVIRT_END_ALLOW_THREADS;
4094 if (c_retval < 0)
4095 return VIR_PY_NONE;
4097 py_retval = libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4098 return py_retval;
4101 static PyObject *
4102 libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4103 PyObject *py_retval;
4104 virSecretPtr c_retval;
4105 virConnectPtr conn;
4106 PyObject *pyobj_conn;
4107 unsigned char * uuid;
4108 int len;
4110 if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID", &pyobj_conn, &uuid, &len))
4111 return NULL;
4112 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4114 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4115 return VIR_PY_NONE;
4117 LIBVIRT_BEGIN_ALLOW_THREADS;
4118 c_retval = virSecretLookupByUUID(conn, uuid);
4119 LIBVIRT_END_ALLOW_THREADS;
4120 py_retval = libvirt_virSecretPtrWrap((virSecretPtr) c_retval);
4121 return py_retval;
4125 static PyObject *
4126 libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
4127 PyObject *args) {
4128 PyObject *py_retval;
4129 char **uuids = NULL;
4130 virConnectPtr conn;
4131 int c_retval;
4132 size_t i;
4133 PyObject *pyobj_conn;
4135 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
4136 return NULL;
4137 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4139 LIBVIRT_BEGIN_ALLOW_THREADS;
4140 c_retval = virConnectNumOfSecrets(conn);
4141 LIBVIRT_END_ALLOW_THREADS;
4142 if (c_retval < 0)
4143 return VIR_PY_NONE;
4145 if (c_retval) {
4146 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4147 return VIR_PY_NONE;
4148 LIBVIRT_BEGIN_ALLOW_THREADS;
4149 c_retval = virConnectListSecrets(conn, uuids, c_retval);
4150 LIBVIRT_END_ALLOW_THREADS;
4151 if (c_retval < 0) {
4152 VIR_FREE(uuids);
4153 return VIR_PY_NONE;
4156 py_retval = PyList_New(c_retval);
4158 if (uuids) {
4159 for (i = 0; i < c_retval; i++) {
4160 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
4161 VIR_FREE(uuids[i]);
4163 VIR_FREE(uuids);
4166 return py_retval;
4169 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4170 static PyObject *
4171 libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
4172 PyObject *args)
4174 PyObject *pyobj_conn;
4175 PyObject *py_retval = NULL;
4176 PyObject *tmp = NULL;
4177 virConnectPtr conn;
4178 virSecretPtr *secrets = NULL;
4179 int c_retval = 0;
4180 size_t i;
4181 unsigned int flags;
4183 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllSecrets",
4184 &pyobj_conn, &flags))
4185 return NULL;
4186 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4188 LIBVIRT_BEGIN_ALLOW_THREADS;
4189 c_retval = virConnectListAllSecrets(conn, &secrets, flags);
4190 LIBVIRT_END_ALLOW_THREADS;
4191 if (c_retval < 0)
4192 return VIR_PY_NONE;
4194 if (!(py_retval = PyList_New(c_retval)))
4195 goto cleanup;
4197 for (i = 0; i < c_retval; i++) {
4198 if (!(tmp = libvirt_virSecretPtrWrap(secrets[i])) ||
4199 PyList_SetItem(py_retval, i, tmp) < 0) {
4200 Py_XDECREF(tmp);
4201 Py_DECREF(py_retval);
4202 py_retval = NULL;
4203 goto cleanup;
4205 /* python steals the pointer */
4206 secrets[i] = NULL;
4209 cleanup:
4210 for (i = 0; i < c_retval; i++)
4211 if (secrets[i])
4212 virSecretFree(secrets[i]);
4213 VIR_FREE(secrets);
4214 return py_retval;
4216 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4218 static PyObject *
4219 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
4220 PyObject *args) {
4221 PyObject *py_retval;
4222 unsigned char *c_retval;
4223 size_t size;
4224 virSecretPtr secret;
4225 PyObject *pyobj_secret;
4226 unsigned int flags;
4228 if (!PyArg_ParseTuple(args, (char *)"Oi:virSecretGetValue", &pyobj_secret,
4229 &flags))
4230 return NULL;
4231 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4233 LIBVIRT_BEGIN_ALLOW_THREADS;
4234 c_retval = virSecretGetValue(secret, &size, flags);
4235 LIBVIRT_END_ALLOW_THREADS;
4237 if (c_retval == NULL)
4238 return VIR_PY_NONE;
4240 py_retval = libvirt_charPtrSizeWrap((char*)c_retval, size);
4241 VIR_FREE(c_retval);
4243 return py_retval;
4246 static PyObject *
4247 libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
4248 PyObject *args) {
4249 PyObject *py_retval;
4250 int c_retval;
4251 virSecretPtr secret;
4252 PyObject *pyobj_secret;
4253 const char *value;
4254 int size;
4255 unsigned int flags;
4257 if (!PyArg_ParseTuple(args, (char *)"Oz#i:virSecretSetValue", &pyobj_secret,
4258 &value, &size, &flags))
4259 return NULL;
4260 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4262 LIBVIRT_BEGIN_ALLOW_THREADS;
4263 c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
4264 flags);
4265 LIBVIRT_END_ALLOW_THREADS;
4267 py_retval = libvirt_intWrap(c_retval);
4268 return py_retval;
4271 static PyObject *
4272 libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4273 PyObject *py_retval;
4274 unsigned char uuid[VIR_UUID_BUFLEN];
4275 virNWFilterPtr nwfilter;
4276 PyObject *pyobj_nwfilter;
4277 int c_retval;
4279 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID", &pyobj_nwfilter))
4280 return NULL;
4281 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4283 if (nwfilter == NULL)
4284 return VIR_PY_NONE;
4285 LIBVIRT_BEGIN_ALLOW_THREADS;
4286 c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
4287 LIBVIRT_END_ALLOW_THREADS;
4289 if (c_retval < 0)
4290 return VIR_PY_NONE;
4291 py_retval = libvirt_charPtrSizeWrap((char *) &uuid[0], VIR_UUID_BUFLEN);
4293 return py_retval;
4296 static PyObject *
4297 libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4298 PyObject *args) {
4299 PyObject *py_retval;
4300 char uuidstr[VIR_UUID_STRING_BUFLEN];
4301 virNWFilterPtr nwfilter;
4302 PyObject *pyobj_nwfilter;
4303 int c_retval;
4305 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
4306 &pyobj_nwfilter))
4307 return NULL;
4308 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4310 if (nwfilter == NULL)
4311 return VIR_PY_NONE;
4312 LIBVIRT_BEGIN_ALLOW_THREADS;
4313 c_retval = virNWFilterGetUUIDString(nwfilter, &uuidstr[0]);
4314 LIBVIRT_END_ALLOW_THREADS;
4316 if (c_retval < 0)
4317 return VIR_PY_NONE;
4319 py_retval = libvirt_constcharPtrWrap((char *) &uuidstr[0]);
4320 return py_retval;
4323 static PyObject *
4324 libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4325 PyObject *py_retval;
4326 virNWFilterPtr c_retval;
4327 virConnectPtr conn;
4328 PyObject *pyobj_conn;
4329 unsigned char * uuid;
4330 int len;
4332 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID", &pyobj_conn, &uuid, &len))
4333 return NULL;
4334 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4336 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4337 return VIR_PY_NONE;
4339 LIBVIRT_BEGIN_ALLOW_THREADS;
4340 c_retval = virNWFilterLookupByUUID(conn, uuid);
4341 LIBVIRT_END_ALLOW_THREADS;
4342 py_retval = libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
4343 return py_retval;
4347 static PyObject *
4348 libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4349 PyObject *args) {
4350 PyObject *py_retval;
4351 char **uuids = NULL;
4352 virConnectPtr conn;
4353 int c_retval;
4354 size_t i;
4355 PyObject *pyobj_conn;
4357 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters", &pyobj_conn))
4358 return NULL;
4359 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4361 LIBVIRT_BEGIN_ALLOW_THREADS;
4362 c_retval = virConnectNumOfNWFilters(conn);
4363 LIBVIRT_END_ALLOW_THREADS;
4364 if (c_retval < 0)
4365 return VIR_PY_NONE;
4367 if (c_retval) {
4368 if (VIR_ALLOC_N(uuids, c_retval) < 0)
4369 return VIR_PY_NONE;
4370 LIBVIRT_BEGIN_ALLOW_THREADS;
4371 c_retval = virConnectListNWFilters(conn, uuids, c_retval);
4372 LIBVIRT_END_ALLOW_THREADS;
4373 if (c_retval < 0) {
4374 VIR_FREE(uuids);
4375 return VIR_PY_NONE;
4378 py_retval = PyList_New(c_retval);
4380 if (uuids) {
4381 for (i = 0; i < c_retval; i++) {
4382 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
4383 VIR_FREE(uuids[i]);
4385 VIR_FREE(uuids);
4388 return py_retval;
4391 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4392 static PyObject *
4393 libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4394 PyObject *args)
4396 PyObject *pyobj_conn;
4397 PyObject *py_retval = NULL;
4398 PyObject *tmp = NULL;
4399 virConnectPtr conn;
4400 virNWFilterPtr *filters = NULL;
4401 int c_retval = 0;
4402 size_t i;
4403 unsigned int flags;
4405 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNWFilters",
4406 &pyobj_conn, &flags))
4407 return NULL;
4408 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4410 LIBVIRT_BEGIN_ALLOW_THREADS;
4411 c_retval = virConnectListAllNWFilters(conn, &filters, flags);
4412 LIBVIRT_END_ALLOW_THREADS;
4413 if (c_retval < 0)
4414 return VIR_PY_NONE;
4416 if (!(py_retval = PyList_New(c_retval)))
4417 goto cleanup;
4419 for (i = 0; i < c_retval; i++) {
4420 if (!(tmp = libvirt_virNWFilterPtrWrap(filters[i])) ||
4421 PyList_SetItem(py_retval, i, tmp) < 0) {
4422 Py_XDECREF(tmp);
4423 Py_DECREF(py_retval);
4424 py_retval = NULL;
4425 goto cleanup;
4427 /* python steals the pointer */
4428 filters[i] = NULL;
4431 cleanup:
4432 for (i = 0; i < c_retval; i++)
4433 if (filters[i])
4434 virNWFilterFree(filters[i]);
4435 VIR_FREE(filters);
4436 return py_retval;
4438 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4440 static PyObject *
4441 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4442 PyObject *args) {
4443 PyObject *py_retval;
4444 char **names = NULL;
4445 int c_retval;
4446 size_t i;
4447 virConnectPtr conn;
4448 PyObject *pyobj_conn;
4451 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListInterfaces", &pyobj_conn))
4452 return NULL;
4453 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4455 LIBVIRT_BEGIN_ALLOW_THREADS;
4456 c_retval = virConnectNumOfInterfaces(conn);
4457 LIBVIRT_END_ALLOW_THREADS;
4458 if (c_retval < 0)
4459 return VIR_PY_NONE;
4461 if (c_retval) {
4462 if (VIR_ALLOC_N(names, c_retval) < 0)
4463 return VIR_PY_NONE;
4464 LIBVIRT_BEGIN_ALLOW_THREADS;
4465 c_retval = virConnectListInterfaces(conn, names, c_retval);
4466 LIBVIRT_END_ALLOW_THREADS;
4467 if (c_retval < 0) {
4468 VIR_FREE(names);
4469 return VIR_PY_NONE;
4472 py_retval = PyList_New(c_retval);
4473 if (py_retval == NULL) {
4474 if (names) {
4475 for (i = 0; i < c_retval; i++)
4476 VIR_FREE(names[i]);
4477 VIR_FREE(names);
4479 return VIR_PY_NONE;
4482 if (names) {
4483 for (i = 0; i < c_retval; i++) {
4484 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
4485 VIR_FREE(names[i]);
4487 VIR_FREE(names);
4490 return py_retval;
4494 static PyObject *
4495 libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4496 PyObject *args) {
4497 PyObject *py_retval;
4498 char **names = NULL;
4499 int c_retval;
4500 size_t i;
4501 virConnectPtr conn;
4502 PyObject *pyobj_conn;
4505 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedInterfaces",
4506 &pyobj_conn))
4507 return NULL;
4508 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4510 LIBVIRT_BEGIN_ALLOW_THREADS;
4511 c_retval = virConnectNumOfDefinedInterfaces(conn);
4512 LIBVIRT_END_ALLOW_THREADS;
4513 if (c_retval < 0)
4514 return VIR_PY_NONE;
4516 if (c_retval) {
4517 if (VIR_ALLOC_N(names, c_retval) < 0)
4518 return VIR_PY_NONE;
4519 LIBVIRT_BEGIN_ALLOW_THREADS;
4520 c_retval = virConnectListDefinedInterfaces(conn, names, c_retval);
4521 LIBVIRT_END_ALLOW_THREADS;
4522 if (c_retval < 0) {
4523 VIR_FREE(names);
4524 return VIR_PY_NONE;
4527 py_retval = PyList_New(c_retval);
4528 if (py_retval == NULL) {
4529 if (names) {
4530 for (i = 0; i < c_retval; i++)
4531 VIR_FREE(names[i]);
4532 VIR_FREE(names);
4534 return VIR_PY_NONE;
4537 if (names) {
4538 for (i = 0; i < c_retval; i++) {
4539 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
4540 VIR_FREE(names[i]);
4542 VIR_FREE(names);
4545 return py_retval;
4549 #if LIBVIR_CHECK_VERSION(0, 10, 2)
4550 static PyObject *
4551 libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4552 PyObject *args)
4554 PyObject *pyobj_conn;
4555 PyObject *py_retval = NULL;
4556 PyObject *tmp = NULL;
4557 virConnectPtr conn;
4558 virInterfacePtr *ifaces = NULL;
4559 int c_retval = 0;
4560 size_t i;
4561 unsigned int flags;
4563 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllInterfaces",
4564 &pyobj_conn, &flags))
4565 return NULL;
4566 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4568 LIBVIRT_BEGIN_ALLOW_THREADS;
4569 c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
4570 LIBVIRT_END_ALLOW_THREADS;
4571 if (c_retval < 0)
4572 return VIR_PY_NONE;
4574 if (!(py_retval = PyList_New(c_retval)))
4575 goto cleanup;
4577 for (i = 0; i < c_retval; i++) {
4578 if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) ||
4579 PyList_SetItem(py_retval, i, tmp) < 0) {
4580 Py_XDECREF(tmp);
4581 Py_DECREF(py_retval);
4582 py_retval = NULL;
4583 goto cleanup;
4585 /* python steals the pointer */
4586 ifaces[i] = NULL;
4589 cleanup:
4590 for (i = 0; i < c_retval; i++)
4591 if (ifaces[i])
4592 virInterfaceFree(ifaces[i]);
4593 VIR_FREE(ifaces);
4594 return py_retval;
4596 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
4598 static PyObject *
4599 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
4600 PyObject *args) {
4601 PyObject *pyobj_conn;
4602 PyObject *list;
4603 virConnectPtr conn;
4604 unsigned int flags;
4605 char **xmlcpus = NULL;
4606 int ncpus = 0;
4607 char *base_cpu;
4608 PyObject *pybase_cpu;
4609 size_t i, j;
4611 if (!PyArg_ParseTuple(args, (char *)"OOi:virConnectBaselineCPU",
4612 &pyobj_conn, &list, &flags))
4613 return NULL;
4614 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4616 if (PyList_Check(list)) {
4617 ncpus = PyList_Size(list);
4618 if (VIR_ALLOC_N(xmlcpus, ncpus) < 0)
4619 return VIR_PY_NONE;
4621 for (i = 0; i < ncpus; i++) {
4622 if (libvirt_charPtrUnwrap(PyList_GetItem(list, i), &(xmlcpus[i])) < 0 ||
4623 xmlcpus[i] == NULL) {
4624 for (j = 0 ; j < i ; j++)
4625 VIR_FREE(xmlcpus[j]);
4626 VIR_FREE(xmlcpus);
4627 return VIR_PY_NONE;
4632 LIBVIRT_BEGIN_ALLOW_THREADS;
4633 base_cpu = virConnectBaselineCPU(conn, (const char **)xmlcpus, ncpus, flags);
4634 LIBVIRT_END_ALLOW_THREADS;
4636 for (i = 0 ; i < ncpus ; i++)
4637 VIR_FREE(xmlcpus[i]);
4638 VIR_FREE(xmlcpus);
4640 if (base_cpu == NULL)
4641 return VIR_PY_NONE;
4643 pybase_cpu = libvirt_constcharPtrWrap(base_cpu);
4644 VIR_FREE(base_cpu);
4646 if (pybase_cpu == NULL)
4647 return VIR_PY_NONE;
4649 return pybase_cpu;
4653 static PyObject *
4654 libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4655 PyObject *py_retval;
4656 int c_retval;
4657 virDomainPtr domain;
4658 PyObject *pyobj_domain;
4659 virDomainJobInfo info;
4661 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetJobInfo", &pyobj_domain))
4662 return NULL;
4663 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4665 LIBVIRT_BEGIN_ALLOW_THREADS;
4666 c_retval = virDomainGetJobInfo(domain, &info);
4667 LIBVIRT_END_ALLOW_THREADS;
4668 if (c_retval < 0)
4669 return VIR_PY_NONE;
4670 py_retval = PyList_New(12);
4671 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
4672 PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.timeElapsed));
4673 PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.timeRemaining));
4674 PyList_SetItem(py_retval, 3, libvirt_ulonglongWrap(info.dataTotal));
4675 PyList_SetItem(py_retval, 4, libvirt_ulonglongWrap(info.dataProcessed));
4676 PyList_SetItem(py_retval, 5, libvirt_ulonglongWrap(info.dataRemaining));
4677 PyList_SetItem(py_retval, 6, libvirt_ulonglongWrap(info.memTotal));
4678 PyList_SetItem(py_retval, 7, libvirt_ulonglongWrap(info.memProcessed));
4679 PyList_SetItem(py_retval, 8, libvirt_ulonglongWrap(info.memRemaining));
4680 PyList_SetItem(py_retval, 9, libvirt_ulonglongWrap(info.fileTotal));
4681 PyList_SetItem(py_retval, 10, libvirt_ulonglongWrap(info.fileProcessed));
4682 PyList_SetItem(py_retval, 11, libvirt_ulonglongWrap(info.fileRemaining));
4684 return py_retval;
4687 #if LIBVIR_CHECK_VERSION(1, 0, 3)
4688 static PyObject *
4689 libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
4691 PyObject *pyobj_domain;
4692 virDomainPtr domain;
4693 unsigned int flags;
4694 virTypedParameterPtr params = NULL;
4695 int nparams = 0;
4696 int type;
4697 PyObject *dict = NULL;
4698 int rc;
4700 if (!PyArg_ParseTuple(args, (char *) "Oi:virDomainGetJobStats",
4701 &pyobj_domain, &flags))
4702 goto cleanup;
4703 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4705 LIBVIRT_BEGIN_ALLOW_THREADS;
4706 rc = virDomainGetJobStats(domain, &type, &params, &nparams, flags);
4707 LIBVIRT_END_ALLOW_THREADS;
4708 if (rc < 0)
4709 goto cleanup;
4711 if (!(dict = getPyVirTypedParameter(params, nparams)))
4712 goto cleanup;
4714 if (PyDict_SetItem(dict, libvirt_constcharPtrWrap("type"),
4715 libvirt_intWrap(type)) < 0) {
4716 Py_DECREF(dict);
4717 dict = NULL;
4718 goto cleanup;
4721 cleanup:
4722 virTypedParamsFree(params, nparams);
4723 if (dict)
4724 return dict;
4725 else
4726 return VIR_PY_NONE;
4728 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
4730 static PyObject *
4731 libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4732 PyObject *args)
4734 virDomainPtr domain;
4735 PyObject *pyobj_domain;
4736 const char *path;
4737 unsigned int flags;
4738 virDomainBlockJobInfo info;
4739 int c_ret;
4740 PyObject *type = NULL, *bandwidth = NULL, *cur = NULL, *end = NULL;
4741 PyObject *dict;
4743 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetBlockJobInfo",
4744 &pyobj_domain, &path, &flags))
4745 return NULL;
4746 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4748 if ((dict = PyDict_New()) == NULL)
4749 return NULL;
4751 LIBVIRT_BEGIN_ALLOW_THREADS;
4752 c_ret = virDomainGetBlockJobInfo(domain, path, &info, flags);
4753 LIBVIRT_END_ALLOW_THREADS;
4755 if (c_ret == 0) {
4756 return dict;
4757 } else if (c_ret < 0) {
4758 Py_DECREF(dict);
4759 return VIR_PY_NONE;
4762 if ((type = libvirt_intWrap(info.type)) == NULL ||
4763 PyDict_SetItemString(dict, "type", type) < 0)
4764 goto error;
4765 Py_DECREF(type);
4767 if ((bandwidth = libvirt_ulongWrap(info.bandwidth)) == NULL ||
4768 PyDict_SetItemString(dict, "bandwidth", bandwidth) < 0)
4769 goto error;
4770 Py_DECREF(bandwidth);
4772 if ((cur = libvirt_ulonglongWrap(info.cur)) == NULL ||
4773 PyDict_SetItemString(dict, "cur", cur) < 0)
4774 goto error;
4775 Py_DECREF(cur);
4777 if ((end = libvirt_ulonglongWrap(info.end)) == NULL ||
4778 PyDict_SetItemString(dict, "end", end) < 0)
4779 goto error;
4780 Py_DECREF(end);
4782 return dict;
4784 error:
4785 Py_DECREF(dict);
4786 Py_XDECREF(type);
4787 Py_XDECREF(bandwidth);
4788 Py_XDECREF(cur);
4789 Py_XDECREF(end);
4790 return NULL;
4793 static PyObject *
4794 libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4795 PyObject *args)
4797 virDomainPtr domain;
4798 PyObject *pyobj_domain, *info;
4799 PyObject *ret = NULL;
4800 int i_retval;
4801 int nparams = 0;
4802 Py_ssize_t size = 0;
4803 const char *disk;
4804 unsigned int flags;
4805 virTypedParameterPtr params = NULL, new_params = NULL;
4807 if (!PyArg_ParseTuple(args, (char *)"OzOi:virDomainSetBlockIoTune",
4808 &pyobj_domain, &disk, &info, &flags))
4809 return NULL;
4810 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4812 if ((size = PyDict_Size(info)) < 0)
4813 return NULL;
4815 if (size == 0) {
4816 PyErr_Format(PyExc_LookupError,
4817 "Need non-empty dictionary to set attributes");
4818 return NULL;
4821 LIBVIRT_BEGIN_ALLOW_THREADS;
4822 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4823 LIBVIRT_END_ALLOW_THREADS;
4825 if (i_retval < 0)
4826 return VIR_PY_INT_FAIL;
4828 if (nparams == 0) {
4829 PyErr_Format(PyExc_LookupError,
4830 "Domain has no settable attributes");
4831 return NULL;
4834 if (VIR_ALLOC_N(params, nparams) < 0)
4835 return PyErr_NoMemory();
4837 LIBVIRT_BEGIN_ALLOW_THREADS;
4838 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4839 LIBVIRT_END_ALLOW_THREADS;
4841 if (i_retval < 0) {
4842 ret = VIR_PY_INT_FAIL;
4843 goto cleanup;
4846 new_params = setPyVirTypedParameter(info, params, nparams);
4847 if (!new_params)
4848 goto cleanup;
4850 LIBVIRT_BEGIN_ALLOW_THREADS;
4851 i_retval = virDomainSetBlockIoTune(domain, disk, new_params, size, flags);
4852 LIBVIRT_END_ALLOW_THREADS;
4854 if (i_retval < 0) {
4855 ret = VIR_PY_INT_FAIL;
4856 goto cleanup;
4859 ret = VIR_PY_INT_SUCCESS;
4861 cleanup:
4862 virTypedParamsFree(params, nparams);
4863 virTypedParamsFree(new_params, size);
4864 return ret;
4867 static PyObject *
4868 libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4869 PyObject *args)
4871 virDomainPtr domain;
4872 PyObject *pyobj_domain;
4873 PyObject *ret = NULL;
4874 int i_retval;
4875 int nparams = 0;
4876 const char *disk;
4877 unsigned int flags;
4878 virTypedParameterPtr params;
4880 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetBlockIoTune",
4881 &pyobj_domain, &disk, &flags))
4882 return NULL;
4883 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4885 LIBVIRT_BEGIN_ALLOW_THREADS;
4886 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4887 LIBVIRT_END_ALLOW_THREADS;
4889 if (i_retval < 0)
4890 return VIR_PY_NONE;
4892 if (!nparams)
4893 return PyDict_New();
4895 if (VIR_ALLOC_N(params, nparams) < 0)
4896 return PyErr_NoMemory();
4898 LIBVIRT_BEGIN_ALLOW_THREADS;
4899 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4900 LIBVIRT_END_ALLOW_THREADS;
4902 if (i_retval < 0) {
4903 ret = VIR_PY_NONE;
4904 goto cleanup;
4907 ret = getPyVirTypedParameter(params, nparams);
4909 cleanup:
4910 virTypedParamsFree(params, nparams);
4911 return ret;
4914 static PyObject *
4915 libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED,
4916 PyObject *args)
4918 PyObject *py_retval = VIR_PY_NONE;
4919 virDomainPtr domain;
4920 PyObject *pyobj_domain;
4921 unsigned int flags;
4922 virDomainDiskErrorPtr disks = NULL;
4923 unsigned int ndisks;
4924 int count;
4925 size_t i;
4927 if (!PyArg_ParseTuple(args, (char *) "Oi:virDomainGetDiskErrors",
4928 &pyobj_domain, &flags))
4929 return NULL;
4931 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4933 if ((count = virDomainGetDiskErrors(domain, NULL, 0, 0)) < 0)
4934 return VIR_PY_NONE;
4935 ndisks = count;
4937 if (ndisks) {
4938 if (VIR_ALLOC_N(disks, ndisks) < 0)
4939 return VIR_PY_NONE;
4941 LIBVIRT_BEGIN_ALLOW_THREADS;
4942 count = virDomainGetDiskErrors(domain, disks, ndisks, 0);
4943 LIBVIRT_END_ALLOW_THREADS;
4945 if (count < 0)
4946 goto cleanup;
4949 if (!(py_retval = PyDict_New()))
4950 goto cleanup;
4952 for (i = 0; i < count; i++) {
4953 PyDict_SetItem(py_retval,
4954 libvirt_constcharPtrWrap(disks[i].disk),
4955 libvirt_intWrap(disks[i].error));
4958 cleanup:
4959 if (disks) {
4960 for (i = 0; i < count; i++)
4961 VIR_FREE(disks[i].disk);
4962 VIR_FREE(disks);
4964 return py_retval;
4967 /*******************************************
4968 * Helper functions to avoid importing modules
4969 * for every callback
4970 *******************************************/
4971 static PyObject *libvirt_module = NULL;
4972 static PyObject *libvirt_dict = NULL;
4974 static PyObject *
4975 getLibvirtModuleObject(void) {
4976 if (libvirt_module)
4977 return libvirt_module;
4979 // PyImport_ImportModule returns a new reference
4980 /* Bogus (char *) cast for RHEL-5 python API brokenness */
4981 libvirt_module = PyImport_ImportModule((char *)"libvirt");
4982 if (!libvirt_module) {
4983 DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
4984 PyErr_Print();
4985 return NULL;
4988 return libvirt_module;
4991 static PyObject *
4992 getLibvirtDictObject(void) {
4993 if (libvirt_dict)
4994 return libvirt_dict;
4996 // PyModule_GetDict returns a borrowed reference
4997 libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
4998 if (!libvirt_dict) {
4999 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
5000 PyErr_Print();
5001 return NULL;
5004 Py_INCREF(libvirt_dict);
5005 return libvirt_dict;
5009 static PyObject *
5010 libvirt_lookupPythonFunc(const char *funcname)
5012 PyObject *python_cb;
5014 /* Lookup the python callback */
5015 python_cb = PyDict_GetItemString(getLibvirtDictObject(), funcname);
5017 if (!python_cb) {
5018 DEBUG("%s: Error finding %s\n", __FUNCTION__, funcname);
5019 PyErr_Print();
5020 PyErr_Clear();
5021 return NULL;
5024 if (!PyCallable_Check(python_cb)) {
5025 DEBUG("%s: %s is not callable\n", __FUNCTION__, funcname);
5026 return NULL;
5029 return python_cb;
5032 /*******************************************
5033 * Domain Events
5034 *******************************************/
5036 static int
5037 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5038 virDomainPtr dom,
5039 int event,
5040 int detail,
5041 void *opaque)
5043 PyObject *pyobj_ret = NULL;
5045 PyObject *pyobj_conn = (PyObject*)opaque;
5046 PyObject *pyobj_dom;
5048 int ret = -1;
5050 LIBVIRT_ENSURE_THREAD_STATE;
5052 /* Create a python instance of this virDomainPtr */
5053 virDomainRef(dom);
5054 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5055 virDomainFree(dom);
5056 goto cleanup;
5059 /* Call the Callback Dispatcher */
5060 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5061 (char*)"_dispatchDomainEventCallbacks",
5062 (char*)"Oii",
5063 pyobj_dom,
5064 event, detail);
5066 Py_DECREF(pyobj_dom);
5068 cleanup:
5069 if (!pyobj_ret) {
5070 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5071 PyErr_Print();
5072 } else {
5073 Py_DECREF(pyobj_ret);
5074 ret = 0;
5077 LIBVIRT_RELEASE_THREAD_STATE;
5078 return ret;
5081 static PyObject *
5082 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject *self,
5083 PyObject *args)
5085 PyObject *py_retval; /* return value */
5086 PyObject *pyobj_conn; /* virConnectPtr */
5087 PyObject *pyobj_conn_inst; /* virConnect Python object */
5089 virConnectPtr conn;
5090 int ret = 0;
5092 if (!PyArg_ParseTuple
5093 (args, (char *) "OO:virConnectDomainEventRegister",
5094 &pyobj_conn, &pyobj_conn_inst)) {
5095 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
5096 return VIR_PY_INT_FAIL;
5099 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
5100 pyobj_conn, pyobj_conn_inst);
5101 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5103 Py_INCREF(pyobj_conn_inst);
5105 LIBVIRT_BEGIN_ALLOW_THREADS;
5107 ret = virConnectDomainEventRegister(conn,
5108 libvirt_virConnectDomainEventCallback,
5109 pyobj_conn_inst, NULL);
5111 LIBVIRT_END_ALLOW_THREADS;
5113 py_retval = libvirt_intWrap(ret);
5114 return py_retval;
5117 static PyObject *
5118 libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject *self,
5119 PyObject *args)
5121 PyObject *py_retval;
5122 PyObject *pyobj_conn;
5123 PyObject *pyobj_conn_inst;
5125 virConnectPtr conn;
5126 int ret = 0;
5128 if (!PyArg_ParseTuple
5129 (args, (char *) "OO:virConnectDomainEventDeregister",
5130 &pyobj_conn, &pyobj_conn_inst))
5131 return NULL;
5133 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
5135 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5137 LIBVIRT_BEGIN_ALLOW_THREADS;
5139 ret = virConnectDomainEventDeregister(conn, libvirt_virConnectDomainEventCallback);
5141 LIBVIRT_END_ALLOW_THREADS;
5143 Py_DECREF(pyobj_conn_inst);
5144 py_retval = libvirt_intWrap(ret);
5145 return py_retval;
5148 /*******************************************
5149 * Event Impl
5150 *******************************************/
5151 static PyObject *addHandleObj;
5152 static char *addHandleName;
5153 static PyObject *updateHandleObj;
5154 static char *updateHandleName;
5155 static PyObject *removeHandleObj;
5156 static char *removeHandleName;
5157 static PyObject *addTimeoutObj;
5158 static char *addTimeoutName;
5159 static PyObject *updateTimeoutObj;
5160 static char *updateTimeoutName;
5161 static PyObject *removeTimeoutObj;
5162 static char *removeTimeoutName;
5164 #define NAME(fn) ( fn ## Name ? fn ## Name : # fn )
5166 static int
5167 libvirt_virEventAddHandleFunc (int fd,
5168 int event,
5169 virEventHandleCallback cb,
5170 void *opaque,
5171 virFreeCallback ff)
5173 PyObject *result;
5174 PyObject *python_cb;
5175 PyObject *cb_obj;
5176 PyObject *ff_obj;
5177 PyObject *opaque_obj;
5178 PyObject *cb_args;
5179 PyObject *pyobj_args;
5180 int retval = -1;
5182 LIBVIRT_ENSURE_THREAD_STATE;
5184 /* Lookup the python callback */
5185 python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
5186 if (!python_cb) {
5187 goto cleanup;
5189 Py_INCREF(python_cb);
5191 /* create tuple for cb */
5192 cb_obj = libvirt_virEventHandleCallbackWrap(cb);
5193 ff_obj = libvirt_virFreeCallbackWrap(ff);
5194 opaque_obj = libvirt_virVoidPtrWrap(opaque);
5196 cb_args = PyTuple_New(3);
5197 PyTuple_SetItem(cb_args, 0, cb_obj);
5198 PyTuple_SetItem(cb_args, 1, opaque_obj);
5199 PyTuple_SetItem(cb_args, 2, ff_obj);
5201 pyobj_args = PyTuple_New(4);
5202 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd));
5203 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event));
5204 PyTuple_SetItem(pyobj_args, 2, python_cb);
5205 PyTuple_SetItem(pyobj_args, 3, cb_args);
5207 result = PyEval_CallObject(addHandleObj, pyobj_args);
5208 if (!result) {
5209 PyErr_Print();
5210 PyErr_Clear();
5211 } else {
5212 libvirt_intUnwrap(result, &retval);
5215 Py_XDECREF(result);
5216 Py_DECREF(pyobj_args);
5218 cleanup:
5219 LIBVIRT_RELEASE_THREAD_STATE;
5221 return retval;
5224 static void
5225 libvirt_virEventUpdateHandleFunc(int watch, int event)
5227 PyObject *result;
5228 PyObject *pyobj_args;
5230 LIBVIRT_ENSURE_THREAD_STATE;
5232 pyobj_args = PyTuple_New(2);
5233 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch));
5234 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event));
5236 result = PyEval_CallObject(updateHandleObj, pyobj_args);
5237 if (!result) {
5238 PyErr_Print();
5239 PyErr_Clear();
5242 Py_XDECREF(result);
5243 Py_DECREF(pyobj_args);
5245 LIBVIRT_RELEASE_THREAD_STATE;
5249 static int
5250 libvirt_virEventRemoveHandleFunc(int watch)
5252 PyObject *result;
5253 PyObject *pyobj_args;
5254 PyObject *opaque;
5255 PyObject *ff;
5256 int retval = -1;
5257 virFreeCallback cff;
5259 LIBVIRT_ENSURE_THREAD_STATE;
5261 pyobj_args = PyTuple_New(1);
5262 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch));
5264 result = PyEval_CallObject(removeHandleObj, pyobj_args);
5265 if (!result) {
5266 PyErr_Print();
5267 PyErr_Clear();
5268 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
5269 DEBUG("%s: %s must return opaque obj registered with %s"
5270 "to avoid leaking libvirt memory\n",
5271 __FUNCTION__, NAME(removeHandle), NAME(addHandle));
5272 } else {
5273 opaque = PyTuple_GetItem(result, 1);
5274 ff = PyTuple_GetItem(result, 2);
5275 cff = PyvirFreeCallback_Get(ff);
5276 if (cff)
5277 (*cff)(PyvirVoidPtr_Get(opaque));
5278 retval = 0;
5281 Py_XDECREF(result);
5282 Py_DECREF(pyobj_args);
5284 LIBVIRT_RELEASE_THREAD_STATE;
5286 return retval;
5290 static int
5291 libvirt_virEventAddTimeoutFunc(int timeout,
5292 virEventTimeoutCallback cb,
5293 void *opaque,
5294 virFreeCallback ff)
5296 PyObject *result;
5298 PyObject *python_cb;
5300 PyObject *cb_obj;
5301 PyObject *ff_obj;
5302 PyObject *opaque_obj;
5303 PyObject *cb_args;
5304 PyObject *pyobj_args;
5305 int retval = -1;
5307 LIBVIRT_ENSURE_THREAD_STATE;
5309 /* Lookup the python callback */
5310 python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
5311 if (!python_cb) {
5312 goto cleanup;
5314 Py_INCREF(python_cb);
5316 /* create tuple for cb */
5317 cb_obj = libvirt_virEventTimeoutCallbackWrap(cb);
5318 ff_obj = libvirt_virFreeCallbackWrap(ff);
5319 opaque_obj = libvirt_virVoidPtrWrap(opaque);
5321 cb_args = PyTuple_New(3);
5322 PyTuple_SetItem(cb_args, 0, cb_obj);
5323 PyTuple_SetItem(cb_args, 1, opaque_obj);
5324 PyTuple_SetItem(cb_args, 2, ff_obj);
5326 pyobj_args = PyTuple_New(3);
5328 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timeout));
5329 PyTuple_SetItem(pyobj_args, 1, python_cb);
5330 PyTuple_SetItem(pyobj_args, 2, cb_args);
5332 result = PyEval_CallObject(addTimeoutObj, pyobj_args);
5333 if (!result) {
5334 PyErr_Print();
5335 PyErr_Clear();
5336 } else {
5337 libvirt_intUnwrap(result, &retval);
5340 Py_XDECREF(result);
5341 Py_DECREF(pyobj_args);
5343 cleanup:
5344 LIBVIRT_RELEASE_THREAD_STATE;
5345 return retval;
5348 static void
5349 libvirt_virEventUpdateTimeoutFunc(int timer, int timeout)
5351 PyObject *result = NULL;
5352 PyObject *pyobj_args;
5354 LIBVIRT_ENSURE_THREAD_STATE;
5356 pyobj_args = PyTuple_New(2);
5357 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer));
5358 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(timeout));
5360 result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
5361 if (!result) {
5362 PyErr_Print();
5363 PyErr_Clear();
5366 Py_XDECREF(result);
5367 Py_DECREF(pyobj_args);
5369 LIBVIRT_RELEASE_THREAD_STATE;
5372 static int
5373 libvirt_virEventRemoveTimeoutFunc(int timer)
5375 PyObject *result = NULL;
5376 PyObject *pyobj_args;
5377 PyObject *opaque;
5378 PyObject *ff;
5379 int retval = -1;
5380 virFreeCallback cff;
5382 LIBVIRT_ENSURE_THREAD_STATE;
5384 pyobj_args = PyTuple_New(1);
5385 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer));
5387 result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
5388 if (!result) {
5389 PyErr_Print();
5390 PyErr_Clear();
5391 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
5392 DEBUG("%s: %s must return opaque obj registered with %s"
5393 "to avoid leaking libvirt memory\n",
5394 __FUNCTION__, NAME(removeTimeout), NAME(addTimeout));
5395 } else {
5396 opaque = PyTuple_GetItem(result, 1);
5397 ff = PyTuple_GetItem(result, 2);
5398 cff = PyvirFreeCallback_Get(ff);
5399 if (cff)
5400 (*cff)(PyvirVoidPtr_Get(opaque));
5401 retval = 0;
5404 Py_XDECREF(result);
5405 Py_DECREF(pyobj_args);
5407 LIBVIRT_RELEASE_THREAD_STATE;
5409 return retval;
5412 static PyObject *
5413 libvirt_virEventRegisterImpl(ATTRIBUTE_UNUSED PyObject * self,
5414 PyObject * args)
5416 /* Unref the previously-registered impl (if any) */
5417 Py_XDECREF(addHandleObj);
5418 Py_XDECREF(updateHandleObj);
5419 Py_XDECREF(removeHandleObj);
5420 Py_XDECREF(addTimeoutObj);
5421 Py_XDECREF(updateTimeoutObj);
5422 Py_XDECREF(removeTimeoutObj);
5423 VIR_FREE(addHandleName);
5424 VIR_FREE(updateHandleName);
5425 VIR_FREE(removeHandleName);
5426 VIR_FREE(addTimeoutName);
5427 VIR_FREE(updateTimeoutName);
5428 VIR_FREE(removeTimeoutName);
5430 /* Parse and check arguments */
5431 if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
5432 &addHandleObj, &updateHandleObj,
5433 &removeHandleObj, &addTimeoutObj,
5434 &updateTimeoutObj, &removeTimeoutObj) ||
5435 !PyCallable_Check(addHandleObj) ||
5436 !PyCallable_Check(updateHandleObj) ||
5437 !PyCallable_Check(removeHandleObj) ||
5438 !PyCallable_Check(addTimeoutObj) ||
5439 !PyCallable_Check(updateTimeoutObj) ||
5440 !PyCallable_Check(removeTimeoutObj))
5441 return VIR_PY_INT_FAIL;
5443 /* Get argument string representations (for error reporting) */
5444 addHandleName = py_str(addHandleObj);
5445 updateHandleName = py_str(updateHandleObj);
5446 removeHandleName = py_str(removeHandleObj);
5447 addTimeoutName = py_str(addTimeoutObj);
5448 updateTimeoutName = py_str(updateTimeoutObj);
5449 removeTimeoutName = py_str(removeTimeoutObj);
5451 /* Inc refs since we're holding on to these objects until
5452 * the next call (if any) to this function.
5454 Py_INCREF(addHandleObj);
5455 Py_INCREF(updateHandleObj);
5456 Py_INCREF(removeHandleObj);
5457 Py_INCREF(addTimeoutObj);
5458 Py_INCREF(updateTimeoutObj);
5459 Py_INCREF(removeTimeoutObj);
5461 LIBVIRT_BEGIN_ALLOW_THREADS;
5463 /* Now register our C EventImpl, which will dispatch
5464 * to the Python callbacks passed in as args.
5466 virEventRegisterImpl(libvirt_virEventAddHandleFunc,
5467 libvirt_virEventUpdateHandleFunc,
5468 libvirt_virEventRemoveHandleFunc,
5469 libvirt_virEventAddTimeoutFunc,
5470 libvirt_virEventUpdateTimeoutFunc,
5471 libvirt_virEventRemoveTimeoutFunc);
5473 LIBVIRT_END_ALLOW_THREADS;
5475 return VIR_PY_INT_SUCCESS;
5478 static PyObject *
5479 libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
5480 PyObject *args)
5482 int watch, fd, event;
5483 PyObject *py_f;
5484 PyObject *py_opaque;
5485 virEventHandleCallback cb;
5486 void *opaque;
5488 if (!PyArg_ParseTuple
5489 (args, (char *) "iiiOO:virEventInvokeHandleCallback",
5490 &watch, &fd, &event, &py_f, &py_opaque
5492 return VIR_PY_INT_FAIL;
5494 cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
5495 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5497 if (cb) {
5498 LIBVIRT_BEGIN_ALLOW_THREADS;
5499 cb(watch, fd, event, opaque);
5500 LIBVIRT_END_ALLOW_THREADS;
5503 return VIR_PY_INT_SUCCESS;
5506 static PyObject *
5507 libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
5508 PyObject *args)
5510 int timer;
5511 PyObject *py_f;
5512 PyObject *py_opaque;
5513 virEventTimeoutCallback cb;
5514 void *opaque;
5516 if (!PyArg_ParseTuple
5517 (args, (char *) "iOO:virEventInvokeTimeoutCallback",
5518 &timer, &py_f, &py_opaque
5520 return VIR_PY_INT_FAIL;
5522 cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
5523 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5524 if (cb) {
5525 LIBVIRT_BEGIN_ALLOW_THREADS;
5526 cb(timer, opaque);
5527 LIBVIRT_END_ALLOW_THREADS;
5530 return VIR_PY_INT_SUCCESS;
5533 static void
5534 libvirt_virEventHandleCallback(int watch,
5535 int fd,
5536 int events,
5537 void *opaque)
5539 PyObject *pyobj_cbData = (PyObject *)opaque;
5540 PyObject *pyobj_ret;
5541 PyObject *python_cb;
5543 LIBVIRT_ENSURE_THREAD_STATE;
5545 /* Lookup the python callback */
5546 python_cb = libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
5547 if (!python_cb) {
5548 goto cleanup;
5551 Py_INCREF(pyobj_cbData);
5553 /* Call the pure python dispatcher */
5554 pyobj_ret = PyObject_CallFunction(python_cb,
5555 (char *)"iiiO",
5556 watch, fd, events, pyobj_cbData);
5558 Py_DECREF(pyobj_cbData);
5560 if (!pyobj_ret) {
5561 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5562 PyErr_Print();
5563 } else {
5564 Py_DECREF(pyobj_ret);
5567 cleanup:
5568 LIBVIRT_RELEASE_THREAD_STATE;
5571 static PyObject *
5572 libvirt_virEventAddHandle(PyObject *self ATTRIBUTE_UNUSED,
5573 PyObject *args)
5575 PyObject *py_retval;
5576 PyObject *pyobj_cbData;
5577 virEventHandleCallback cb = libvirt_virEventHandleCallback;
5578 int events;
5579 int fd;
5580 int ret;
5582 if (!PyArg_ParseTuple(args, (char *) "iiO:virEventAddHandle",
5583 &fd, &events, &pyobj_cbData)) {
5584 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
5585 return VIR_PY_INT_FAIL;
5588 Py_INCREF(pyobj_cbData);
5590 LIBVIRT_BEGIN_ALLOW_THREADS;
5591 ret = virEventAddHandle(fd, events, cb, pyobj_cbData, NULL);
5592 LIBVIRT_END_ALLOW_THREADS;
5594 if (ret < 0) {
5595 Py_DECREF(pyobj_cbData);
5598 py_retval = libvirt_intWrap(ret);
5599 return py_retval;
5602 static void
5603 libvirt_virEventTimeoutCallback(int timer,
5604 void *opaque)
5606 PyObject *pyobj_cbData = (PyObject *)opaque;
5607 PyObject *pyobj_ret;
5608 PyObject *python_cb;
5610 LIBVIRT_ENSURE_THREAD_STATE;
5612 /* Lookup the python callback */
5613 python_cb = libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
5614 if (!python_cb) {
5615 goto cleanup;
5618 Py_INCREF(pyobj_cbData);
5620 /* Call the pure python dispatcher */
5621 pyobj_ret = PyObject_CallFunction(python_cb,
5622 (char *)"iO",
5623 timer, pyobj_cbData);
5625 Py_DECREF(pyobj_cbData);
5627 if (!pyobj_ret) {
5628 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5629 PyErr_Print();
5630 } else {
5631 Py_DECREF(pyobj_ret);
5634 cleanup:
5635 LIBVIRT_RELEASE_THREAD_STATE;
5638 static PyObject *
5639 libvirt_virEventAddTimeout(PyObject *self ATTRIBUTE_UNUSED,
5640 PyObject *args)
5642 PyObject *py_retval;
5643 PyObject *pyobj_cbData;
5644 virEventTimeoutCallback cb = libvirt_virEventTimeoutCallback;
5645 int timeout;
5646 int ret;
5648 if (!PyArg_ParseTuple(args, (char *) "iO:virEventAddTimeout",
5649 &timeout, &pyobj_cbData)) {
5650 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
5651 return VIR_PY_INT_FAIL;
5654 Py_INCREF(pyobj_cbData);
5656 LIBVIRT_BEGIN_ALLOW_THREADS;
5657 ret = virEventAddTimeout(timeout, cb, pyobj_cbData, NULL);
5658 LIBVIRT_END_ALLOW_THREADS;
5660 if (ret < 0) {
5661 Py_DECREF(pyobj_cbData);
5664 py_retval = libvirt_intWrap(ret);
5665 return py_retval;
5668 static void
5669 libvirt_virConnectDomainEventFreeFunc(void *opaque)
5671 PyObject *pyobj_conn = (PyObject*)opaque;
5672 LIBVIRT_ENSURE_THREAD_STATE;
5673 Py_DECREF(pyobj_conn);
5674 LIBVIRT_RELEASE_THREAD_STATE;
5677 static int
5678 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5679 virDomainPtr dom,
5680 int event,
5681 int detail,
5682 void *opaque)
5684 PyObject *pyobj_cbData = (PyObject*)opaque;
5685 PyObject *pyobj_dom;
5686 PyObject *pyobj_ret = NULL;
5687 PyObject *pyobj_conn;
5688 PyObject *dictKey;
5689 int ret = -1;
5691 LIBVIRT_ENSURE_THREAD_STATE;
5693 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5694 goto cleanup;
5695 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5696 Py_DECREF(dictKey);
5698 /* Create a python instance of this virDomainPtr */
5699 virDomainRef(dom);
5700 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5701 virDomainFree(dom);
5702 goto cleanup;
5704 Py_INCREF(pyobj_cbData);
5706 /* Call the Callback Dispatcher */
5707 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5708 (char*)"_dispatchDomainEventLifecycleCallback",
5709 (char*)"OiiO",
5710 pyobj_dom,
5711 event, detail,
5712 pyobj_cbData);
5714 Py_DECREF(pyobj_cbData);
5715 Py_DECREF(pyobj_dom);
5717 cleanup:
5718 if (!pyobj_ret) {
5719 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5720 PyErr_Print();
5721 } else {
5722 Py_DECREF(pyobj_ret);
5723 ret = 0;
5726 LIBVIRT_RELEASE_THREAD_STATE;
5727 return ret;
5730 static int
5731 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5732 virDomainPtr dom,
5733 void *opaque)
5735 PyObject *pyobj_cbData = (PyObject*)opaque;
5736 PyObject *pyobj_dom;
5737 PyObject *pyobj_ret = NULL;
5738 PyObject *pyobj_conn;
5739 PyObject *dictKey;
5740 int ret = -1;
5742 LIBVIRT_ENSURE_THREAD_STATE;
5744 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5745 goto cleanup;
5746 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5747 Py_DECREF(dictKey);
5749 /* Create a python instance of this virDomainPtr */
5750 virDomainRef(dom);
5751 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5752 virDomainFree(dom);
5753 goto cleanup;
5755 Py_INCREF(pyobj_cbData);
5757 /* Call the Callback Dispatcher */
5758 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5759 (char*)"_dispatchDomainEventGenericCallback",
5760 (char*)"OO",
5761 pyobj_dom, pyobj_cbData);
5763 Py_DECREF(pyobj_cbData);
5764 Py_DECREF(pyobj_dom);
5766 cleanup:
5767 if (!pyobj_ret) {
5768 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5769 PyErr_Print();
5770 } else {
5771 Py_DECREF(pyobj_ret);
5772 ret = 0;
5775 LIBVIRT_RELEASE_THREAD_STATE;
5776 return ret;
5779 static int
5780 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5781 virDomainPtr dom,
5782 long long utcoffset,
5783 void *opaque)
5785 PyObject *pyobj_cbData = (PyObject*)opaque;
5786 PyObject *pyobj_dom;
5787 PyObject *pyobj_ret = NULL;
5788 PyObject *pyobj_conn;
5789 PyObject *dictKey;
5790 int ret = -1;
5792 LIBVIRT_ENSURE_THREAD_STATE;
5794 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5795 goto cleanup;
5796 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5797 Py_DECREF(dictKey);
5799 /* Create a python instance of this virDomainPtr */
5800 virDomainRef(dom);
5801 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5802 virDomainFree(dom);
5803 goto cleanup;
5805 Py_INCREF(pyobj_cbData);
5807 /* Call the Callback Dispatcher */
5808 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5809 (char*)"_dispatchDomainEventRTCChangeCallback",
5810 (char*)"OLO",
5811 pyobj_dom,
5812 (PY_LONG_LONG)utcoffset,
5813 pyobj_cbData);
5815 Py_DECREF(pyobj_cbData);
5816 Py_DECREF(pyobj_dom);
5818 cleanup:
5819 if (!pyobj_ret) {
5820 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5821 PyErr_Print();
5822 } else {
5823 Py_DECREF(pyobj_ret);
5824 ret = 0;
5827 LIBVIRT_RELEASE_THREAD_STATE;
5828 return ret;
5831 static int
5832 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5833 virDomainPtr dom,
5834 int action,
5835 void *opaque)
5837 PyObject *pyobj_cbData = (PyObject*)opaque;
5838 PyObject *pyobj_dom;
5839 PyObject *pyobj_ret = NULL;
5840 PyObject *pyobj_conn;
5841 PyObject *dictKey;
5842 int ret = -1;
5844 LIBVIRT_ENSURE_THREAD_STATE;
5846 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5847 goto cleanup;
5848 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5849 Py_DECREF(dictKey);
5851 /* Create a python instance of this virDomainPtr */
5852 virDomainRef(dom);
5853 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5854 virDomainFree(dom);
5855 goto cleanup;
5857 Py_INCREF(pyobj_cbData);
5859 /* Call the Callback Dispatcher */
5860 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5861 (char*)"_dispatchDomainEventWatchdogCallback",
5862 (char*)"OiO",
5863 pyobj_dom,
5864 action,
5865 pyobj_cbData);
5867 Py_DECREF(pyobj_cbData);
5868 Py_DECREF(pyobj_dom);
5870 cleanup:
5871 if (!pyobj_ret) {
5872 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5873 PyErr_Print();
5874 } else {
5875 Py_DECREF(pyobj_ret);
5876 ret = 0;
5879 LIBVIRT_RELEASE_THREAD_STATE;
5880 return ret;
5883 static int
5884 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5885 virDomainPtr dom,
5886 const char *srcPath,
5887 const char *devAlias,
5888 int action,
5889 void *opaque)
5891 PyObject *pyobj_cbData = (PyObject*)opaque;
5892 PyObject *pyobj_dom;
5893 PyObject *pyobj_ret = NULL;
5894 PyObject *pyobj_conn;
5895 PyObject *dictKey;
5896 int ret = -1;
5898 LIBVIRT_ENSURE_THREAD_STATE;
5900 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5901 goto cleanup;
5902 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5903 Py_DECREF(dictKey);
5905 /* Create a python instance of this virDomainPtr */
5906 virDomainRef(dom);
5907 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5908 virDomainFree(dom);
5909 goto cleanup;
5911 Py_INCREF(pyobj_cbData);
5913 /* Call the Callback Dispatcher */
5914 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5915 (char*)"_dispatchDomainEventIOErrorCallback",
5916 (char*)"OssiO",
5917 pyobj_dom,
5918 srcPath, devAlias, action,
5919 pyobj_cbData);
5921 Py_DECREF(pyobj_cbData);
5922 Py_DECREF(pyobj_dom);
5924 cleanup:
5925 if (!pyobj_ret) {
5926 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5927 PyErr_Print();
5928 } else {
5929 Py_DECREF(pyobj_ret);
5930 ret = 0;
5933 LIBVIRT_RELEASE_THREAD_STATE;
5934 return ret;
5937 static int
5938 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5939 virDomainPtr dom,
5940 const char *srcPath,
5941 const char *devAlias,
5942 int action,
5943 const char *reason,
5944 void *opaque)
5946 PyObject *pyobj_cbData = (PyObject*)opaque;
5947 PyObject *pyobj_dom;
5948 PyObject *pyobj_ret = NULL;
5949 PyObject *pyobj_conn;
5950 PyObject *dictKey;
5951 int ret = -1;
5953 LIBVIRT_ENSURE_THREAD_STATE;
5955 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
5956 goto cleanup;
5957 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5958 Py_DECREF(dictKey);
5960 /* Create a python instance of this virDomainPtr */
5961 virDomainRef(dom);
5962 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
5963 virDomainFree(dom);
5964 goto cleanup;
5966 Py_INCREF(pyobj_cbData);
5968 /* Call the Callback Dispatcher */
5969 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5970 (char*)"_dispatchDomainEventIOErrorReasonCallback",
5971 (char*)"OssisO",
5972 pyobj_dom,
5973 srcPath, devAlias, action, reason,
5974 pyobj_cbData);
5976 Py_DECREF(pyobj_cbData);
5977 Py_DECREF(pyobj_dom);
5979 cleanup:
5980 if (!pyobj_ret) {
5981 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5982 PyErr_Print();
5983 } else {
5984 Py_DECREF(pyobj_ret);
5985 ret = 0;
5988 LIBVIRT_RELEASE_THREAD_STATE;
5989 return ret;
5992 static int
5993 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5994 virDomainPtr dom,
5995 int phase,
5996 virDomainEventGraphicsAddressPtr local,
5997 virDomainEventGraphicsAddressPtr remote,
5998 const char *authScheme,
5999 virDomainEventGraphicsSubjectPtr subject,
6000 void *opaque)
6002 PyObject *pyobj_cbData = (PyObject*)opaque;
6003 PyObject *pyobj_dom;
6004 PyObject *pyobj_ret = NULL;
6005 PyObject *pyobj_conn;
6006 PyObject *dictKey;
6007 PyObject *pyobj_local;
6008 PyObject *pyobj_remote;
6009 PyObject *pyobj_subject;
6010 int ret = -1;
6011 size_t i;
6013 LIBVIRT_ENSURE_THREAD_STATE;
6015 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6016 goto cleanup;
6017 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6018 Py_DECREF(dictKey);
6020 /* Create a python instance of this virDomainPtr */
6021 virDomainRef(dom);
6022 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6023 virDomainFree(dom);
6024 goto cleanup;
6026 Py_INCREF(pyobj_cbData);
6028 /* FIXME This code should check for errors... */
6029 pyobj_local = PyDict_New();
6030 PyDict_SetItem(pyobj_local,
6031 libvirt_constcharPtrWrap("family"),
6032 libvirt_intWrap(local->family));
6033 PyDict_SetItem(pyobj_local,
6034 libvirt_constcharPtrWrap("node"),
6035 libvirt_constcharPtrWrap(local->node));
6036 PyDict_SetItem(pyobj_local,
6037 libvirt_constcharPtrWrap("service"),
6038 libvirt_constcharPtrWrap(local->service));
6040 pyobj_remote = PyDict_New();
6041 PyDict_SetItem(pyobj_remote,
6042 libvirt_constcharPtrWrap("family"),
6043 libvirt_intWrap(remote->family));
6044 PyDict_SetItem(pyobj_remote,
6045 libvirt_constcharPtrWrap("node"),
6046 libvirt_constcharPtrWrap(remote->node));
6047 PyDict_SetItem(pyobj_remote,
6048 libvirt_constcharPtrWrap("service"),
6049 libvirt_constcharPtrWrap(remote->service));
6051 pyobj_subject = PyList_New(subject->nidentity);
6052 for (i = 0; i < subject->nidentity; i++) {
6053 PyObject *pair = PyTuple_New(2);
6054 PyTuple_SetItem(pair, 0, libvirt_constcharPtrWrap(subject->identities[i].type));
6055 PyTuple_SetItem(pair, 1, libvirt_constcharPtrWrap(subject->identities[i].name));
6057 PyList_SetItem(pyobj_subject, i, pair);
6060 /* Call the Callback Dispatcher */
6061 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6062 (char*)"_dispatchDomainEventGraphicsCallback",
6063 (char*)"OiOOsOO",
6064 pyobj_dom,
6065 phase, pyobj_local, pyobj_remote,
6066 authScheme, pyobj_subject,
6067 pyobj_cbData);
6069 Py_DECREF(pyobj_cbData);
6070 Py_DECREF(pyobj_dom);
6072 cleanup:
6073 if (!pyobj_ret) {
6074 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6075 PyErr_Print();
6076 } else {
6077 Py_DECREF(pyobj_ret);
6078 ret = 0;
6081 LIBVIRT_RELEASE_THREAD_STATE;
6082 return ret;
6085 static int
6086 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6087 virDomainPtr dom,
6088 const char *path,
6089 int type,
6090 int status,
6091 void *opaque)
6093 PyObject *pyobj_cbData = (PyObject*)opaque;
6094 PyObject *pyobj_dom;
6095 PyObject *pyobj_ret = NULL;
6096 PyObject *pyobj_conn;
6097 PyObject *dictKey;
6098 int ret = -1;
6100 LIBVIRT_ENSURE_THREAD_STATE;
6102 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6103 goto cleanup;
6104 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6105 Py_DECREF(dictKey);
6107 /* Create a python instance of this virDomainPtr */
6108 virDomainRef(dom);
6109 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6110 virDomainFree(dom);
6111 goto cleanup;
6113 Py_INCREF(pyobj_cbData);
6115 /* Call the Callback Dispatcher */
6116 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6117 (char*)"_dispatchDomainEventBlockPullCallback",
6118 (char*)"OsiiO",
6119 pyobj_dom, path, type, status, pyobj_cbData);
6121 Py_DECREF(pyobj_cbData);
6122 Py_DECREF(pyobj_dom);
6124 cleanup:
6125 if (!pyobj_ret) {
6126 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6127 PyErr_Print();
6128 } else {
6129 Py_DECREF(pyobj_ret);
6130 ret = 0;
6133 LIBVIRT_RELEASE_THREAD_STATE;
6134 return ret;
6137 static int
6138 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6139 virDomainPtr dom,
6140 const char *oldSrcPath,
6141 const char *newSrcPath,
6142 const char *devAlias,
6143 int reason,
6144 void *opaque)
6146 PyObject *pyobj_cbData = (PyObject*)opaque;
6147 PyObject *pyobj_dom;
6148 PyObject *pyobj_ret = NULL;
6149 PyObject *pyobj_conn;
6150 PyObject *dictKey;
6151 int ret = -1;
6153 LIBVIRT_ENSURE_THREAD_STATE;
6155 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6156 goto cleanup;
6157 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6158 Py_DECREF(dictKey);
6160 /* Create a python instance of this virDomainPtr */
6161 virDomainRef(dom);
6162 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6163 virDomainFree(dom);
6164 goto cleanup;
6166 Py_INCREF(pyobj_cbData);
6168 /* Call the Callback Dispatcher */
6169 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6170 (char*)"_dispatchDomainEventDiskChangeCallback",
6171 (char*)"OsssiO",
6172 pyobj_dom,
6173 oldSrcPath, newSrcPath,
6174 devAlias, reason, pyobj_cbData);
6176 Py_DECREF(pyobj_cbData);
6177 Py_DECREF(pyobj_dom);
6179 cleanup:
6180 if (!pyobj_ret) {
6181 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6182 PyErr_Print();
6183 } else {
6184 Py_DECREF(pyobj_ret);
6185 ret = 0;
6188 LIBVIRT_RELEASE_THREAD_STATE;
6189 return ret;
6192 static int
6193 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6194 virDomainPtr dom,
6195 const char *devAlias,
6196 int reason,
6197 void *opaque)
6199 PyObject *pyobj_cbData = (PyObject*)opaque;
6200 PyObject *pyobj_dom;
6201 PyObject *pyobj_ret = NULL;
6202 PyObject *pyobj_conn;
6203 PyObject *dictKey;
6204 int ret = -1;
6206 LIBVIRT_ENSURE_THREAD_STATE;
6208 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6209 goto cleanup;
6210 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6211 Py_DECREF(dictKey);
6213 /* Create a python instance of this virDomainPtr */
6214 virDomainRef(dom);
6215 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6216 virDomainFree(dom);
6217 goto cleanup;
6219 Py_INCREF(pyobj_cbData);
6221 /* Call the Callback Dispatcher */
6222 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6223 (char*)"_dispatchDomainEventTrayChangeCallback",
6224 (char*)"OsiO",
6225 pyobj_dom,
6226 devAlias, reason, pyobj_cbData);
6228 Py_DECREF(pyobj_cbData);
6229 Py_DECREF(pyobj_dom);
6231 cleanup:
6232 if (!pyobj_ret) {
6233 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6234 PyErr_Print();
6235 } else {
6236 Py_DECREF(pyobj_ret);
6237 ret = 0;
6240 LIBVIRT_RELEASE_THREAD_STATE;
6241 return ret;
6244 static int
6245 libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6246 virDomainPtr dom,
6247 int reason,
6248 void *opaque)
6250 PyObject *pyobj_cbData = (PyObject*)opaque;
6251 PyObject *pyobj_dom;
6252 PyObject *pyobj_ret = NULL;
6253 PyObject *pyobj_conn;
6254 PyObject *dictKey;
6255 int ret = -1;
6257 LIBVIRT_ENSURE_THREAD_STATE;
6259 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6260 goto cleanup;
6261 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6262 Py_DECREF(dictKey);
6264 /* Create a python instance of this virDomainPtr */
6265 virDomainRef(dom);
6266 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6267 virDomainFree(dom);
6268 goto cleanup;
6270 Py_INCREF(pyobj_cbData);
6272 /* Call the Callback Dispatcher */
6273 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6274 (char*)"_dispatchDomainEventPMWakeupCallback",
6275 (char*)"OiO",
6276 pyobj_dom,
6277 reason,
6278 pyobj_cbData);
6280 Py_DECREF(pyobj_cbData);
6281 Py_DECREF(pyobj_dom);
6283 cleanup:
6284 if (!pyobj_ret) {
6285 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6286 PyErr_Print();
6287 } else {
6288 Py_DECREF(pyobj_ret);
6289 ret = 0;
6292 LIBVIRT_RELEASE_THREAD_STATE;
6293 return ret;
6296 static int
6297 libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6298 virDomainPtr dom,
6299 int reason,
6300 void *opaque)
6302 PyObject *pyobj_cbData = (PyObject*)opaque;
6303 PyObject *pyobj_dom;
6304 PyObject *pyobj_ret = NULL;
6305 PyObject *pyobj_conn;
6306 PyObject *dictKey;
6307 int ret = -1;
6309 LIBVIRT_ENSURE_THREAD_STATE;
6311 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6312 goto cleanup;
6313 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6314 Py_DECREF(dictKey);
6316 /* Create a python instance of this virDomainPtr */
6317 virDomainRef(dom);
6318 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6319 virDomainFree(dom);
6320 goto cleanup;
6322 Py_INCREF(pyobj_cbData);
6324 /* Call the Callback Dispatcher */
6325 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6326 (char*)"_dispatchDomainEventPMSuspendCallback",
6327 (char*)"OiO",
6328 pyobj_dom,
6329 reason,
6330 pyobj_cbData);
6332 Py_DECREF(pyobj_cbData);
6333 Py_DECREF(pyobj_dom);
6335 cleanup:
6336 if (!pyobj_ret) {
6337 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6338 PyErr_Print();
6339 } else {
6340 Py_DECREF(pyobj_ret);
6341 ret = 0;
6344 LIBVIRT_RELEASE_THREAD_STATE;
6345 return ret;
6349 #if LIBVIR_CHECK_VERSION(0, 10, 0)
6350 static int
6351 libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6352 virDomainPtr dom,
6353 unsigned long long actual,
6354 void *opaque)
6356 PyObject *pyobj_cbData = (PyObject*)opaque;
6357 PyObject *pyobj_dom;
6358 PyObject *pyobj_ret = NULL;
6359 PyObject *pyobj_conn;
6360 PyObject *dictKey;
6361 int ret = -1;
6363 LIBVIRT_ENSURE_THREAD_STATE;
6365 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6366 goto cleanup;
6367 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6368 Py_DECREF(dictKey);
6370 /* Create a python instance of this virDomainPtr */
6371 virDomainRef(dom);
6372 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6373 virDomainFree(dom);
6374 goto cleanup;
6376 Py_INCREF(pyobj_cbData);
6378 /* Call the Callback Dispatcher */
6379 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6380 (char*)"_dispatchDomainEventBalloonChangeCallback",
6381 (char*)"OLO",
6382 pyobj_dom,
6383 (PY_LONG_LONG)actual,
6384 pyobj_cbData);
6386 Py_DECREF(pyobj_cbData);
6387 Py_DECREF(pyobj_dom);
6389 cleanup:
6390 if (!pyobj_ret) {
6391 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6392 PyErr_Print();
6393 } else {
6394 Py_DECREF(pyobj_ret);
6395 ret = 0;
6398 LIBVIRT_RELEASE_THREAD_STATE;
6399 return ret;
6401 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
6403 #if LIBVIR_CHECK_VERSION(1, 0, 0)
6404 static int
6405 libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6406 virDomainPtr dom,
6407 int reason,
6408 void *opaque)
6410 PyObject *pyobj_cbData = (PyObject*)opaque;
6411 PyObject *pyobj_dom;
6412 PyObject *pyobj_ret = NULL;
6413 PyObject *pyobj_conn;
6414 PyObject *dictKey;
6415 int ret = -1;
6417 LIBVIRT_ENSURE_THREAD_STATE;
6419 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6420 goto cleanup;
6421 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6422 Py_DECREF(dictKey);
6424 /* Create a python instance of this virDomainPtr */
6425 virDomainRef(dom);
6426 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6427 virDomainFree(dom);
6428 goto cleanup;
6430 Py_INCREF(pyobj_cbData);
6432 /* Call the Callback Dispatcher */
6433 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6434 (char*)"_dispatchDomainEventPMSuspendDiskCallback",
6435 (char*)"OiO",
6436 pyobj_dom,
6437 reason,
6438 pyobj_cbData);
6440 Py_DECREF(pyobj_cbData);
6441 Py_DECREF(pyobj_dom);
6443 cleanup:
6444 if (!pyobj_ret) {
6445 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6446 PyErr_Print();
6447 } else {
6448 Py_DECREF(pyobj_ret);
6449 ret = 0;
6452 LIBVIRT_RELEASE_THREAD_STATE;
6453 return ret;
6455 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
6457 #if LIBVIR_CHECK_VERSION(1, 1, 1)
6458 static int
6459 libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6460 virDomainPtr dom,
6461 const char *devAlias,
6462 void *opaque)
6464 PyObject *pyobj_cbData = (PyObject*)opaque;
6465 PyObject *pyobj_dom;
6466 PyObject *pyobj_ret = NULL;
6467 PyObject *pyobj_conn;
6468 PyObject *dictKey;
6469 int ret = -1;
6471 LIBVIRT_ENSURE_THREAD_STATE;
6473 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6474 goto cleanup;
6475 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6476 Py_DECREF(dictKey);
6478 /* Create a python instance of this virDomainPtr */
6479 virDomainRef(dom);
6480 if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
6481 virDomainFree(dom);
6482 goto cleanup;
6484 Py_INCREF(pyobj_cbData);
6486 /* Call the Callback Dispatcher */
6487 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6488 (char*)"_dispatchDomainEventDeviceRemovedCallback",
6489 (char*)"OsO",
6490 pyobj_dom, devAlias, pyobj_cbData);
6492 Py_DECREF(pyobj_cbData);
6493 Py_DECREF(pyobj_dom);
6495 cleanup:
6496 if (!pyobj_ret) {
6497 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6498 PyErr_Print();
6499 } else {
6500 Py_DECREF(pyobj_ret);
6501 ret = 0;
6504 LIBVIRT_RELEASE_THREAD_STATE;
6505 return ret;
6507 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
6509 static PyObject *
6510 libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject *self,
6511 PyObject *args)
6513 PyObject *py_retval; /* return value */
6514 PyObject *pyobj_conn; /* virConnectPtr */
6515 PyObject *pyobj_dom;
6516 PyObject *pyobj_cbData; /* hash of callback data */
6517 int eventID;
6518 virConnectPtr conn;
6519 int ret = 0;
6520 virConnectDomainEventGenericCallback cb = NULL;
6521 virDomainPtr dom;
6523 if (!PyArg_ParseTuple
6524 (args, (char *) "OOiO:virConnectDomainEventRegisterAny",
6525 &pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData)) {
6526 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
6527 return VIR_PY_INT_FAIL;
6530 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
6531 pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
6532 conn = PyvirConnect_Get(pyobj_conn);
6533 if (pyobj_dom == Py_None)
6534 dom = NULL;
6535 else
6536 dom = PyvirDomain_Get(pyobj_dom);
6538 switch ((virDomainEventID) eventID) {
6539 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
6540 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback);
6541 break;
6542 case VIR_DOMAIN_EVENT_ID_REBOOT:
6543 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
6544 break;
6545 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
6546 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback);
6547 break;
6548 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
6549 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback);
6550 break;
6551 case VIR_DOMAIN_EVENT_ID_IO_ERROR:
6552 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback);
6553 break;
6554 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
6555 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback);
6556 break;
6557 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
6558 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback);
6559 break;
6560 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
6561 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
6562 break;
6563 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
6564 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback);
6565 break;
6566 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
6567 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
6568 break;
6569 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
6570 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
6571 break;
6572 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
6573 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
6574 break;
6575 case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
6576 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
6577 break;
6578 #if LIBVIR_CHECK_VERSION(0, 10, 0)
6579 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
6580 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback);
6581 break;
6582 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
6583 #if LIBVIR_CHECK_VERSION(1, 0, 0)
6584 case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
6585 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback);
6586 break;
6587 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
6588 #if LIBVIR_CHECK_VERSION(1, 1, 1)
6589 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
6590 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback);
6591 break;
6592 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
6593 case VIR_DOMAIN_EVENT_ID_LAST:
6594 break;
6597 if (!cb) {
6598 return VIR_PY_INT_FAIL;
6601 Py_INCREF(pyobj_cbData);
6603 LIBVIRT_BEGIN_ALLOW_THREADS;
6604 ret = virConnectDomainEventRegisterAny(conn, dom, eventID,
6605 cb, pyobj_cbData,
6606 libvirt_virConnectDomainEventFreeFunc);
6607 LIBVIRT_END_ALLOW_THREADS;
6609 if (ret < 0) {
6610 Py_DECREF(pyobj_cbData);
6613 py_retval = libvirt_intWrap(ret);
6614 return py_retval;
6617 static PyObject *
6618 libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject *self,
6619 PyObject *args)
6621 PyObject *py_retval;
6622 PyObject *pyobj_conn;
6623 int callbackID;
6624 virConnectPtr conn;
6625 int ret = 0;
6627 if (!PyArg_ParseTuple
6628 (args, (char *) "Oi:virConnectDomainEventDeregister",
6629 &pyobj_conn, &callbackID))
6630 return NULL;
6632 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
6634 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6636 LIBVIRT_BEGIN_ALLOW_THREADS;
6638 ret = virConnectDomainEventDeregisterAny(conn, callbackID);
6640 LIBVIRT_END_ALLOW_THREADS;
6641 py_retval = libvirt_intWrap(ret);
6642 return py_retval;
6645 #if LIBVIR_CHECK_VERSION(1, 2, 1)
6646 static void
6647 libvirt_virConnectNetworkEventFreeFunc(void *opaque)
6649 PyObject *pyobj_conn = (PyObject*)opaque;
6650 LIBVIRT_ENSURE_THREAD_STATE;
6651 Py_DECREF(pyobj_conn);
6652 LIBVIRT_RELEASE_THREAD_STATE;
6655 static int
6656 libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6657 virNetworkPtr net,
6658 int event,
6659 int detail,
6660 void *opaque)
6662 PyObject *pyobj_cbData = (PyObject*)opaque;
6663 PyObject *pyobj_net;
6664 PyObject *pyobj_ret = NULL;
6665 PyObject *pyobj_conn;
6666 PyObject *dictKey;
6667 int ret = -1;
6669 LIBVIRT_ENSURE_THREAD_STATE;
6671 if (!(dictKey = libvirt_constcharPtrWrap("conn")))
6672 goto cleanup;
6673 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6674 Py_DECREF(dictKey);
6676 /* Create a python instance of this virNetworkPtr */
6677 virNetworkRef(net);
6678 if (!(pyobj_net = libvirt_virNetworkPtrWrap(net))) {
6679 virNetworkFree(net);
6680 goto cleanup;
6682 Py_INCREF(pyobj_cbData);
6684 /* Call the Callback Dispatcher */
6685 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6686 (char*)"_dispatchNetworkEventLifecycleCallback",
6687 (char*)"OiiO",
6688 pyobj_net,
6689 event,
6690 detail,
6691 pyobj_cbData);
6693 Py_DECREF(pyobj_cbData);
6694 Py_DECREF(pyobj_net);
6696 cleanup:
6697 if (!pyobj_ret) {
6698 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6699 PyErr_Print();
6700 } else {
6701 Py_DECREF(pyobj_ret);
6702 ret = 0;
6705 LIBVIRT_RELEASE_THREAD_STATE;
6706 return ret;
6709 static PyObject *
6710 libvirt_virConnectNetworkEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
6711 PyObject *args)
6713 PyObject *py_retval; /* return value */
6714 PyObject *pyobj_conn; /* virConnectPtr */
6715 PyObject *pyobj_net;
6716 PyObject *pyobj_cbData; /* hash of callback data */
6717 int eventID;
6718 virConnectPtr conn;
6719 int ret = 0;
6720 virConnectNetworkEventGenericCallback cb = NULL;
6721 virNetworkPtr net;
6723 if (!PyArg_ParseTuple
6724 (args, (char *) "OOiO:virConnectNetworkEventRegisterAny",
6725 &pyobj_conn, &pyobj_net, &eventID, &pyobj_cbData)) {
6726 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
6727 return VIR_PY_INT_FAIL;
6730 DEBUG("libvirt_virConnectNetworkEventRegister(%p %p %d %p) called\n",
6731 pyobj_conn, pyobj_net, eventID, pyobj_cbData);
6732 conn = PyvirConnect_Get(pyobj_conn);
6733 if (pyobj_net == Py_None)
6734 net = NULL;
6735 else
6736 net = PyvirNetwork_Get(pyobj_net);
6738 switch ((virNetworkEventID) eventID) {
6739 case VIR_NETWORK_EVENT_ID_LIFECYCLE:
6740 cb = VIR_NETWORK_EVENT_CALLBACK(libvirt_virConnectNetworkEventLifecycleCallback);
6741 break;
6743 case VIR_NETWORK_EVENT_ID_LAST:
6744 break;
6747 if (!cb) {
6748 return VIR_PY_INT_FAIL;
6751 Py_INCREF(pyobj_cbData);
6753 LIBVIRT_BEGIN_ALLOW_THREADS;
6754 ret = virConnectNetworkEventRegisterAny(conn, net, eventID,
6755 cb, pyobj_cbData,
6756 libvirt_virConnectNetworkEventFreeFunc);
6757 LIBVIRT_END_ALLOW_THREADS;
6759 if (ret < 0) {
6760 Py_DECREF(pyobj_cbData);
6763 py_retval = libvirt_intWrap(ret);
6764 return py_retval;
6767 static PyObject
6768 *libvirt_virConnectNetworkEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
6769 PyObject *args)
6771 PyObject *py_retval;
6772 PyObject *pyobj_conn;
6773 int callbackID;
6774 virConnectPtr conn;
6775 int ret = 0;
6777 if (!PyArg_ParseTuple
6778 (args, (char *) "Oi:virConnectNetworkEventDeregister",
6779 &pyobj_conn, &callbackID))
6780 return NULL;
6782 DEBUG("libvirt_virConnectNetworkEventDeregister(%p) called\n", pyobj_conn);
6784 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6786 LIBVIRT_BEGIN_ALLOW_THREADS;
6788 ret = virConnectNetworkEventDeregisterAny(conn, callbackID);
6790 LIBVIRT_END_ALLOW_THREADS;
6791 py_retval = libvirt_intWrap(ret);
6792 return py_retval;
6794 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1)*/
6796 #if LIBVIR_CHECK_VERSION(0, 10, 0)
6797 static void
6798 libvirt_virConnectCloseCallbackDispatch(virConnectPtr conn ATTRIBUTE_UNUSED,
6799 int reason,
6800 void *opaque)
6802 PyObject *pyobj_cbData = (PyObject*)opaque;
6803 PyObject *pyobj_ret;
6804 PyObject *pyobj_conn;
6805 PyObject *dictKey;
6807 LIBVIRT_ENSURE_THREAD_STATE;
6809 Py_INCREF(pyobj_cbData);
6811 dictKey = libvirt_constcharPtrWrap("conn");
6812 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6813 Py_DECREF(dictKey);
6815 /* Call the Callback Dispatcher */
6816 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6817 (char*)"_dispatchCloseCallback",
6818 (char*)"iO",
6819 reason,
6820 pyobj_cbData);
6822 Py_DECREF(pyobj_cbData);
6824 if (!pyobj_ret) {
6825 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6826 PyErr_Print();
6827 } else {
6828 Py_DECREF(pyobj_ret);
6831 LIBVIRT_RELEASE_THREAD_STATE;
6834 static PyObject *
6835 libvirt_virConnectRegisterCloseCallback(ATTRIBUTE_UNUSED PyObject * self,
6836 PyObject * args)
6838 PyObject *py_retval; /* return value */
6839 PyObject *pyobj_conn; /* virConnectPtr */
6840 PyObject *pyobj_cbData; /* hash of callback data */
6841 virConnectPtr conn;
6842 int ret = 0;
6844 if (!PyArg_ParseTuple
6845 (args, (char *) "OO:virConnectRegisterCloseCallback",
6846 &pyobj_conn, &pyobj_cbData)) {
6847 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
6848 return VIR_PY_INT_FAIL;
6851 DEBUG("libvirt_virConnectRegisterCloseCallback(%p %p) called\n",
6852 pyobj_conn, pyobj_cbData);
6853 conn = PyvirConnect_Get(pyobj_conn);
6855 Py_INCREF(pyobj_cbData);
6857 LIBVIRT_BEGIN_ALLOW_THREADS;
6858 ret = virConnectRegisterCloseCallback(conn,
6859 libvirt_virConnectCloseCallbackDispatch,
6860 pyobj_cbData,
6861 libvirt_virConnectDomainEventFreeFunc);
6862 LIBVIRT_END_ALLOW_THREADS;
6864 if (ret < 0) {
6865 Py_DECREF(pyobj_cbData);
6868 py_retval = libvirt_intWrap(ret);
6869 return py_retval;
6872 static PyObject *
6873 libvirt_virConnectUnregisterCloseCallback(ATTRIBUTE_UNUSED PyObject * self,
6874 PyObject * args)
6876 PyObject *py_retval;
6877 PyObject *pyobj_conn;
6878 virConnectPtr conn;
6879 int ret = 0;
6881 if (!PyArg_ParseTuple
6882 (args, (char *) "O:virConnectDomainEventUnregister",
6883 &pyobj_conn))
6884 return NULL;
6886 DEBUG("libvirt_virConnectDomainEventUnregister(%p) called\n",
6887 pyobj_conn);
6889 conn = PyvirConnect_Get(pyobj_conn);
6891 LIBVIRT_BEGIN_ALLOW_THREADS;
6893 ret = virConnectUnregisterCloseCallback(conn,
6894 libvirt_virConnectCloseCallbackDispatch);
6896 LIBVIRT_END_ALLOW_THREADS;
6897 py_retval = libvirt_intWrap(ret);
6898 return py_retval;
6900 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
6902 static void
6903 libvirt_virStreamEventFreeFunc(void *opaque)
6905 PyObject *pyobj_stream = (PyObject*)opaque;
6906 LIBVIRT_ENSURE_THREAD_STATE;
6907 Py_DECREF(pyobj_stream);
6908 LIBVIRT_RELEASE_THREAD_STATE;
6911 static void
6912 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED,
6913 int events,
6914 void *opaque)
6916 PyObject *pyobj_cbData = (PyObject *)opaque;
6917 PyObject *pyobj_stream;
6918 PyObject *pyobj_ret;
6919 PyObject *dictKey;
6921 LIBVIRT_ENSURE_THREAD_STATE;
6923 Py_INCREF(pyobj_cbData);
6924 dictKey = libvirt_constcharPtrWrap("stream");
6925 pyobj_stream = PyDict_GetItem(pyobj_cbData, dictKey);
6926 Py_DECREF(dictKey);
6928 /* Call the pure python dispatcher */
6929 pyobj_ret = PyObject_CallMethod(pyobj_stream,
6930 (char *)"_dispatchStreamEventCallback",
6931 (char *)"iO",
6932 events, pyobj_cbData);
6934 Py_DECREF(pyobj_cbData);
6936 if (!pyobj_ret) {
6937 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6938 PyErr_Print();
6939 } else {
6940 Py_DECREF(pyobj_ret);
6943 LIBVIRT_RELEASE_THREAD_STATE;
6946 static PyObject *
6947 libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
6948 PyObject *args)
6950 PyObject *py_retval;
6951 PyObject *pyobj_stream;
6952 PyObject *pyobj_cbData;
6953 virStreamPtr stream;
6954 virStreamEventCallback cb = libvirt_virStreamEventCallback;
6955 int ret;
6956 int events;
6958 if (!PyArg_ParseTuple(args, (char *) "OiO:virStreamEventAddCallback",
6959 &pyobj_stream, &events, &pyobj_cbData)) {
6960 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6961 return VIR_PY_INT_FAIL;
6964 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
6965 pyobj_stream, events, pyobj_cbData);
6966 stream = PyvirStream_Get(pyobj_stream);
6968 Py_INCREF(pyobj_cbData);
6970 LIBVIRT_BEGIN_ALLOW_THREADS;
6971 ret = virStreamEventAddCallback(stream, events, cb, pyobj_cbData,
6972 libvirt_virStreamEventFreeFunc);
6973 LIBVIRT_END_ALLOW_THREADS;
6975 if (ret < 0) {
6976 Py_DECREF(pyobj_cbData);
6979 py_retval = libvirt_intWrap(ret);
6980 return py_retval;
6983 static PyObject *
6984 libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
6985 PyObject *args)
6987 PyObject *pyobj_stream;
6988 PyObject *rv;
6989 virStreamPtr stream;
6990 char *buf = NULL;
6991 int ret;
6992 int nbytes;
6994 if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
6995 &pyobj_stream, &nbytes)) {
6996 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6997 return VIR_PY_NONE;
6999 stream = PyvirStream_Get(pyobj_stream);
7001 if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0)
7002 return VIR_PY_NONE;
7004 LIBVIRT_BEGIN_ALLOW_THREADS;
7005 ret = virStreamRecv(stream, buf, nbytes);
7006 LIBVIRT_END_ALLOW_THREADS;
7008 buf[ret > -1 ? ret : 0] = '\0';
7009 DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
7011 if (ret == -2)
7012 return libvirt_intWrap(ret);
7013 if (ret < 0)
7014 return VIR_PY_NONE;
7015 rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
7016 VIR_FREE(buf);
7017 return rv;
7020 static PyObject *
7021 libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
7022 PyObject *args)
7024 PyObject *py_retval;
7025 PyObject *pyobj_stream;
7026 PyObject *pyobj_data;
7027 virStreamPtr stream;
7028 char *data;
7029 Py_ssize_t datalen;
7030 int ret;
7032 if (!PyArg_ParseTuple(args, (char *) "OO:virStreamRecv",
7033 &pyobj_stream, &pyobj_data)) {
7034 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
7035 return VIR_PY_INT_FAIL;
7037 stream = PyvirStream_Get(pyobj_stream);
7038 libvirt_charPtrSizeUnwrap(pyobj_data, &data, &datalen);
7040 LIBVIRT_BEGIN_ALLOW_THREADS;
7041 ret = virStreamSend(stream, data, datalen);
7042 LIBVIRT_END_ALLOW_THREADS;
7044 DEBUG("StreamSend ret=%d\n", ret);
7046 py_retval = libvirt_intWrap(ret);
7047 return py_retval;
7050 static PyObject *
7051 libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
7052 PyObject *args)
7054 PyObject *py_retval;
7055 virDomainPtr domain;
7056 PyObject *pyobj_domain;
7057 PyObject *pyobj_list;
7058 int codeset;
7059 int holdtime;
7060 unsigned int flags;
7061 int ret;
7062 size_t i;
7063 unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
7064 unsigned int nkeycodes;
7066 if (!PyArg_ParseTuple(args, (char *)"OiiOii:virDomainSendKey",
7067 &pyobj_domain, &codeset, &holdtime, &pyobj_list,
7068 &nkeycodes, &flags)) {
7069 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
7070 return VIR_PY_INT_FAIL;
7072 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7074 if (!PyList_Check(pyobj_list)) {
7075 return VIR_PY_INT_FAIL;
7078 if (nkeycodes != PyList_Size(pyobj_list) ||
7079 nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
7080 return VIR_PY_INT_FAIL;
7083 for (i = 0; i < nkeycodes; i++) {
7084 libvirt_uintUnwrap(PyList_GetItem(pyobj_list, i), &(keycodes[i]));
7087 LIBVIRT_BEGIN_ALLOW_THREADS;
7088 ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
7089 LIBVIRT_END_ALLOW_THREADS;
7091 DEBUG("virDomainSendKey ret=%d\n", ret);
7093 py_retval = libvirt_intWrap(ret);
7094 return py_retval;
7097 #if LIBVIR_CHECK_VERSION(1, 0, 3)
7098 static PyObject *
7099 libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED,
7100 PyObject *args)
7102 PyObject *pyobj_domain;
7103 virDomainPtr domain;
7104 unsigned int flags;
7105 unsigned long long cacheSize;
7106 int rc;
7108 if (!PyArg_ParseTuple(args,
7109 (char *) "Oi:virDomainMigrateGetCompressionCache",
7110 &pyobj_domain, &flags))
7111 return VIR_PY_NONE;
7113 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7115 LIBVIRT_BEGIN_ALLOW_THREADS;
7116 rc = virDomainMigrateGetCompressionCache(domain, &cacheSize, flags);
7117 LIBVIRT_END_ALLOW_THREADS;
7119 if (rc < 0)
7120 return VIR_PY_NONE;
7122 return libvirt_ulonglongWrap(cacheSize);
7124 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
7126 static PyObject *
7127 libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7128 PyObject *py_retval;
7129 int c_retval;
7130 unsigned long bandwidth;
7131 virDomainPtr domain;
7132 PyObject *pyobj_domain;
7133 unsigned int flags = 0;
7135 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainMigrateGetMaxSpeed",
7136 &pyobj_domain, &flags))
7137 return NULL;
7139 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7141 LIBVIRT_BEGIN_ALLOW_THREADS;
7142 c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, flags);
7143 LIBVIRT_END_ALLOW_THREADS;
7145 if (c_retval < 0)
7146 return VIR_PY_INT_FAIL;
7147 py_retval = libvirt_ulongWrap(bandwidth);
7148 return py_retval;
7151 #if LIBVIR_CHECK_VERSION(1, 1, 0)
7152 static PyObject *
7153 libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
7154 PyObject *args)
7156 PyObject *pyobj_domain;
7157 virDomainPtr domain;
7158 PyObject *pyobj_dconn;
7159 virConnectPtr dconn;
7160 PyObject *dict;
7161 unsigned int flags;
7162 virTypedParameterPtr params;
7163 int nparams;
7164 virDomainPtr ddom = NULL;
7166 if (!PyArg_ParseTuple(args, (char *) "OOOi:virDomainMigrate3",
7167 &pyobj_domain, &pyobj_dconn, &dict, &flags))
7168 return NULL;
7170 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7171 dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);
7173 if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
7174 return NULL;
7176 LIBVIRT_BEGIN_ALLOW_THREADS;
7177 ddom = virDomainMigrate3(domain, dconn, params, nparams, flags);
7178 LIBVIRT_END_ALLOW_THREADS;
7180 virTypedParamsFree(params, nparams);
7181 return libvirt_virDomainPtrWrap(ddom);
7184 static PyObject *
7185 libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,
7186 PyObject *args)
7188 PyObject *pyobj_domain;
7189 virDomainPtr domain;
7190 char *dconnuri;
7191 PyObject *dict;
7192 unsigned int flags;
7193 virTypedParameterPtr params;
7194 int nparams;
7195 int ret = -1;
7197 if (!PyArg_ParseTuple(args, (char *) "OzOi:virDomainMigrate3",
7198 &pyobj_domain, &dconnuri, &dict, &flags))
7199 return NULL;
7201 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7203 if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
7204 return NULL;
7206 LIBVIRT_BEGIN_ALLOW_THREADS;
7207 ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
7208 LIBVIRT_END_ALLOW_THREADS;
7210 virTypedParamsFree(params, nparams);
7211 return libvirt_intWrap(ret);
7213 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
7215 static PyObject *
7216 libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED,
7217 PyObject *args) {
7218 PyObject *py_retval = NULL;
7219 int c_retval;
7220 virDomainPtr domain;
7221 PyObject *pyobj_domain;
7222 const char *disk;
7223 unsigned long long offset;
7224 size_t size;
7225 char *buf;
7226 unsigned int flags;
7228 if (!PyArg_ParseTuple(args, (char *)"OzLni:virDomainBlockPeek", &pyobj_domain,
7229 &disk, &offset, &size, &flags))
7230 return NULL;
7232 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7234 if (VIR_ALLOC_N(buf, size) < 0)
7235 return VIR_PY_NONE;
7237 LIBVIRT_BEGIN_ALLOW_THREADS;
7238 c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags);
7239 LIBVIRT_END_ALLOW_THREADS;
7241 if (c_retval < 0) {
7242 py_retval = VIR_PY_NONE;
7243 goto cleanup;
7246 py_retval = libvirt_charPtrSizeWrap(buf, size);
7248 cleanup:
7249 VIR_FREE(buf);
7250 return py_retval;
7253 static PyObject *
7254 libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED,
7255 PyObject *args) {
7256 PyObject *py_retval = NULL;
7257 int c_retval;
7258 virDomainPtr domain;
7259 PyObject *pyobj_domain;
7260 unsigned long long start;
7261 size_t size;
7262 char *buf;
7263 unsigned int flags;
7265 if (!PyArg_ParseTuple(args, (char *)"OLni:virDomainMemoryPeek", &pyobj_domain,
7266 &start, &size, &flags))
7267 return NULL;
7269 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7271 if (VIR_ALLOC_N(buf, size) < 0)
7272 return VIR_PY_NONE;
7274 LIBVIRT_BEGIN_ALLOW_THREADS;
7275 c_retval = virDomainMemoryPeek(domain, start, size, buf, flags);
7276 LIBVIRT_END_ALLOW_THREADS;
7278 if (c_retval < 0) {
7279 py_retval = VIR_PY_NONE;
7280 goto cleanup;
7283 py_retval = libvirt_charPtrSizeWrap(buf, size);
7285 cleanup:
7286 VIR_FREE(buf);
7287 return py_retval;
7290 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7291 static PyObject *
7292 libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
7293 PyObject *args)
7295 virConnectPtr conn;
7296 PyObject *pyobj_conn, *info;
7297 PyObject *ret = NULL;
7298 int i_retval;
7299 int nparams = 0;
7300 Py_ssize_t size = 0;
7301 unsigned int flags;
7302 virTypedParameterPtr params, new_params = NULL;
7304 if (!PyArg_ParseTuple(args,
7305 (char *)"OOi:virNodeSetMemoryParameters",
7306 &pyobj_conn, &info, &flags))
7307 return NULL;
7308 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7310 if ((size = PyDict_Size(info)) < 0)
7311 return NULL;
7313 if (size == 0) {
7314 PyErr_Format(PyExc_LookupError,
7315 "Need non-empty dictionary to set attributes");
7316 return NULL;
7319 LIBVIRT_BEGIN_ALLOW_THREADS;
7320 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
7321 LIBVIRT_END_ALLOW_THREADS;
7323 if (i_retval < 0)
7324 return VIR_PY_INT_FAIL;
7326 if (nparams == 0) {
7327 PyErr_Format(PyExc_LookupError,
7328 "no settable attributes");
7329 return NULL;
7332 if (VIR_ALLOC_N(params, nparams) < 0)
7333 return PyErr_NoMemory();
7335 LIBVIRT_BEGIN_ALLOW_THREADS;
7336 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
7337 LIBVIRT_END_ALLOW_THREADS;
7339 if (i_retval < 0) {
7340 ret = VIR_PY_INT_FAIL;
7341 goto cleanup;
7344 new_params = setPyVirTypedParameter(info, params, nparams);
7345 if (!new_params)
7346 goto cleanup;
7348 LIBVIRT_BEGIN_ALLOW_THREADS;
7349 i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
7350 LIBVIRT_END_ALLOW_THREADS;
7352 if (i_retval < 0) {
7353 ret = VIR_PY_INT_FAIL;
7354 goto cleanup;
7357 ret = VIR_PY_INT_SUCCESS;
7359 cleanup:
7360 virTypedParamsFree(params, nparams);
7361 virTypedParamsFree(new_params, nparams);
7362 return ret;
7365 static PyObject *
7366 libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
7367 PyObject *args)
7369 virConnectPtr conn;
7370 PyObject *pyobj_conn;
7371 PyObject *ret = NULL;
7372 int i_retval;
7373 int nparams = 0;
7374 unsigned int flags;
7375 virTypedParameterPtr params;
7377 if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetMemoryParameters",
7378 &pyobj_conn, &flags))
7379 return NULL;
7380 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7382 LIBVIRT_BEGIN_ALLOW_THREADS;
7383 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
7384 LIBVIRT_END_ALLOW_THREADS;
7386 if (i_retval < 0)
7387 return VIR_PY_NONE;
7389 if (!nparams)
7390 return PyDict_New();
7392 if (VIR_ALLOC_N(params, nparams) < 0)
7393 return PyErr_NoMemory();
7395 LIBVIRT_BEGIN_ALLOW_THREADS;
7396 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
7397 LIBVIRT_END_ALLOW_THREADS;
7399 if (i_retval < 0) {
7400 ret = VIR_PY_NONE;
7401 goto cleanup;
7404 ret = getPyVirTypedParameter(params, nparams);
7406 cleanup:
7407 virTypedParamsFree(params, nparams);
7408 return ret;
7410 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7412 #if LIBVIR_CHECK_VERSION(1, 0, 0)
7413 static PyObject *
7414 libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
7415 PyObject *args)
7417 virConnectPtr conn;
7418 PyObject *pyobj_conn;
7419 PyObject *ret = NULL;
7420 PyObject *pycpumap = NULL;
7421 PyObject *pyused = NULL;
7422 PyObject *pycpunum = NULL;
7423 PyObject *pyonline = NULL;
7424 int i_retval;
7425 unsigned char *cpumap = NULL;
7426 unsigned int online = 0;
7427 unsigned int flags;
7428 size_t i;
7430 if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetCPUMap",
7431 &pyobj_conn, &flags))
7432 return NULL;
7433 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7435 LIBVIRT_BEGIN_ALLOW_THREADS;
7436 i_retval = virNodeGetCPUMap(conn, &cpumap, &online, flags);
7437 LIBVIRT_END_ALLOW_THREADS;
7439 if (i_retval < 0)
7440 return VIR_PY_NONE;
7442 if ((ret = PyTuple_New(3)) == NULL)
7443 goto error;
7445 /* 0: number of CPUs */
7446 if ((pycpunum = libvirt_intWrap(i_retval)) == NULL ||
7447 PyTuple_SetItem(ret, 0, pycpunum) < 0)
7448 goto error;
7450 /* 1: CPU map */
7451 if ((pycpumap = PyList_New(i_retval)) == NULL)
7452 goto error;
7454 for (i = 0; i < i_retval; i++) {
7455 if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL)
7456 goto error;
7457 if (PyList_SetItem(pycpumap, i, pyused) < 0)
7458 goto error;
7461 if (PyTuple_SetItem(ret, 1, pycpumap) < 0)
7462 goto error;
7464 /* 2: number of online CPUs */
7465 if ((pyonline = libvirt_uintWrap(online)) == NULL ||
7466 PyTuple_SetItem(ret, 2, pyonline) < 0)
7467 goto error;
7469 cleanup:
7470 VIR_FREE(cpumap);
7471 return ret;
7472 error:
7473 Py_XDECREF(ret);
7474 Py_XDECREF(pycpumap);
7475 Py_XDECREF(pyused);
7476 Py_XDECREF(pycpunum);
7477 Py_XDECREF(pyonline);
7478 ret = NULL;
7479 goto cleanup;
7481 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
7484 #if LIBVIR_CHECK_VERSION(1, 1, 1)
7485 static PyObject *
7486 libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7487 PyObject *py_retval = NULL;
7488 int c_retval;
7489 virDomainPtr domain;
7490 PyObject *pyobj_domain;
7491 PyObject *pyobj_files;
7492 unsigned int flags;
7493 unsigned int nfiles;
7494 int *files = NULL;
7495 size_t i;
7497 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainCreateWithFiles",
7498 &pyobj_domain, &pyobj_files, &flags))
7499 return NULL;
7500 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7502 nfiles = PyList_Size(pyobj_files);
7504 if (VIR_ALLOC_N(files, nfiles) < 0)
7505 return PyErr_NoMemory();
7507 for (i = 0; i < nfiles; i++) {
7508 PyObject *pyfd;
7509 int fd;
7511 pyfd = PyList_GetItem(pyobj_files, i);
7513 if (libvirt_intUnwrap(pyfd, &fd) < 0)
7514 goto cleanup;
7516 files[i] = fd;
7519 LIBVIRT_BEGIN_ALLOW_THREADS;
7520 c_retval = virDomainCreateWithFiles(domain, nfiles, files, flags);
7521 LIBVIRT_END_ALLOW_THREADS;
7522 py_retval = libvirt_intWrap((int) c_retval);
7524 cleanup:
7525 VIR_FREE(files);
7526 return py_retval;
7530 static PyObject *
7531 libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7532 PyObject *py_retval = NULL;
7533 virDomainPtr c_retval;
7534 virConnectPtr conn;
7535 PyObject *pyobj_conn;
7536 char * xmlDesc;
7537 PyObject *pyobj_files;
7538 unsigned int flags;
7539 unsigned int nfiles;
7540 int *files = NULL;
7541 size_t i;
7543 if (!PyArg_ParseTuple(args, (char *)"OzOi:virDomainCreateXMLWithFiles",
7544 &pyobj_conn, &xmlDesc, &pyobj_files, &flags))
7545 return NULL;
7546 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
7548 nfiles = PyList_Size(pyobj_files);
7550 if (VIR_ALLOC_N(files, nfiles) < 0)
7551 return PyErr_NoMemory();
7553 for (i = 0; i < nfiles; i++) {
7554 PyObject *pyfd;
7555 int fd;
7557 pyfd = PyList_GetItem(pyobj_files, i);
7559 if (libvirt_intUnwrap(pyfd, &fd) < 0)
7560 goto cleanup;
7562 files[i] = fd;
7565 LIBVIRT_BEGIN_ALLOW_THREADS;
7566 c_retval = virDomainCreateXMLWithFiles(conn, xmlDesc, nfiles, files, flags);
7567 LIBVIRT_END_ALLOW_THREADS;
7568 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
7570 cleanup:
7571 VIR_FREE(files);
7572 return py_retval;
7574 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
7577 #if LIBVIR_CHECK_VERSION(1, 2, 5)
7578 static PyObject *
7579 libvirt_virDomainFSFreeze(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7580 PyObject *py_retval = NULL;
7581 int c_retval;
7582 virDomainPtr domain;
7583 PyObject *pyobj_domain;
7584 PyObject *pyobj_list;
7585 unsigned int flags;
7586 unsigned int nmountpoints = 0;
7587 char **mountpoints = NULL;
7588 size_t i = 0, j;
7590 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainFSFreeze",
7591 &pyobj_domain, &pyobj_list, &flags))
7592 return NULL;
7593 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7595 if (PyList_Check(pyobj_list)) {
7596 nmountpoints = PyList_Size(pyobj_list);
7598 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
7599 return PyErr_NoMemory();
7601 for (i = 0; i < nmountpoints; i++) {
7602 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
7603 mountpoints+i) < 0 ||
7604 mountpoints[i] == NULL)
7605 goto cleanup;
7609 LIBVIRT_BEGIN_ALLOW_THREADS;
7610 c_retval = virDomainFSFreeze(domain, (const char **) mountpoints,
7611 nmountpoints, flags);
7612 LIBVIRT_END_ALLOW_THREADS;
7614 py_retval = libvirt_intWrap(c_retval);
7616 cleanup:
7617 for (j = 0 ; j < i ; j++)
7618 VIR_FREE(mountpoints[j]);
7619 VIR_FREE(mountpoints);
7620 return py_retval;
7624 static PyObject *
7625 libvirt_virDomainFSThaw(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7626 PyObject *py_retval = NULL;
7627 int c_retval;
7628 virDomainPtr domain;
7629 PyObject *pyobj_domain;
7630 PyObject *pyobj_list;
7631 unsigned int flags;
7632 unsigned int nmountpoints = 0;
7633 char **mountpoints = NULL;
7634 size_t i = 0, j;
7636 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainFSThaw",
7637 &pyobj_domain, &pyobj_list, &flags))
7638 return NULL;
7639 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7641 if (PyList_Check(pyobj_list)) {
7642 nmountpoints = PyList_Size(pyobj_list);
7644 if (VIR_ALLOC_N(mountpoints, nmountpoints) < 0)
7645 return PyErr_NoMemory();
7647 for (i = 0; i < nmountpoints; i++) {
7648 if (libvirt_charPtrUnwrap(PyList_GetItem(pyobj_list, i),
7649 mountpoints+i) < 0 ||
7650 mountpoints[i] == NULL)
7651 goto cleanup;
7655 LIBVIRT_BEGIN_ALLOW_THREADS;
7656 c_retval = virDomainFSThaw(domain, (const char **) mountpoints,
7657 nmountpoints, flags);
7658 LIBVIRT_END_ALLOW_THREADS;
7660 py_retval = libvirt_intWrap(c_retval);
7662 cleanup:
7663 for (j = 0 ; j < i ; j++)
7664 VIR_FREE(mountpoints[j]);
7665 VIR_FREE(mountpoints);
7666 return py_retval;
7669 static PyObject *
7670 libvirt_virDomainGetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7671 PyObject *py_retval = NULL;
7672 PyObject *dict = NULL;
7673 PyObject *pyobj_domain, *pyobj_seconds, *pyobj_nseconds;
7674 virDomainPtr domain;
7675 long long seconds;
7676 unsigned int nseconds;
7677 unsigned int flags;
7678 int c_retval;
7680 if (!PyArg_ParseTuple(args, (char*)"Oi:virDomainGetTime",
7681 &pyobj_domain, &flags))
7682 return NULL;
7683 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7685 if (!(dict = PyDict_New()))
7686 goto cleanup;
7688 LIBVIRT_BEGIN_ALLOW_THREADS;
7689 c_retval = virDomainGetTime(domain, &seconds, &nseconds, flags);
7690 LIBVIRT_END_ALLOW_THREADS;
7692 if (c_retval < 0)
7693 goto cleanup;
7695 if (!(pyobj_seconds = libvirt_longlongWrap(seconds)) ||
7696 PyDict_SetItemString(dict, "seconds", pyobj_seconds) < 0)
7697 goto cleanup;
7698 Py_DECREF(pyobj_seconds);
7700 if (!(pyobj_nseconds = libvirt_uintWrap(nseconds)) ||
7701 PyDict_SetItemString(dict, "nseconds", pyobj_nseconds) < 0)
7702 goto cleanup;
7703 Py_DECREF(pyobj_nseconds);
7705 py_retval = dict;
7706 dict = NULL;
7707 cleanup:
7708 Py_XDECREF(dict);
7709 return py_retval;
7713 static PyObject *
7714 libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
7715 PyObject *py_retval = NULL;
7716 PyObject *pyobj_domain;
7717 PyObject *py_dict;
7718 virDomainPtr domain;
7719 long long seconds = 0;
7720 unsigned int nseconds = 0;
7721 unsigned int flags;
7722 ssize_t py_dict_size;
7723 int c_retval;
7725 if (!PyArg_ParseTuple(args, (char*)"OOi:virDomainSetTime",
7726 &pyobj_domain, &py_dict, &flags))
7727 return NULL;
7728 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
7730 py_dict_size = PyDict_Size(py_dict);
7732 if (py_dict_size == 2) {
7733 PyObject *pyobj_seconds, *pyobj_nseconds;
7735 if (!(pyobj_seconds = PyDict_GetItemString(py_dict, "seconds")) ||
7736 (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)) {
7737 PyErr_Format(PyExc_LookupError, "malformed or missing 'seconds'");
7738 goto cleanup;
7741 if (!(pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds")) ||
7742 (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)) {
7743 PyErr_Format(PyExc_LookupError, "malformed or missing 'nseconds'");
7744 goto cleanup;
7746 } else if (py_dict_size > 0) {
7747 PyErr_Format(PyExc_LookupError, "Dictionary must contain "
7748 "'seconds' and 'nseconds'");
7749 goto cleanup;
7752 LIBVIRT_BEGIN_ALLOW_THREADS;
7753 c_retval = virDomainSetTime(domain, seconds, nseconds, flags);
7754 LIBVIRT_END_ALLOW_THREADS;
7756 py_retval = libvirt_intWrap(c_retval);
7758 cleanup:
7759 return py_retval;
7761 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
7763 /************************************************************************
7765 * The registration stuff *
7767 ************************************************************************/
7768 static PyMethodDef libvirtMethods[] = {
7769 #include "build/libvirt-export.c"
7770 {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
7771 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL},
7772 #if LIBVIR_CHECK_VERSION(1, 1, 3)
7773 {(char *) "virConnectGetCPUModelNames", libvirt_virConnectGetCPUModelNames, METH_VARARGS, NULL},
7774 #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */
7775 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
7776 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
7777 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
7778 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
7779 #if LIBVIR_CHECK_VERSION(0, 9, 13)
7780 {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
7781 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
7782 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
7783 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
7784 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
7785 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
7786 #if LIBVIR_CHECK_VERSION(1, 2, 1)
7787 {(char *) "virConnectNetworkEventRegisterAny", libvirt_virConnectNetworkEventRegisterAny, METH_VARARGS, NULL},
7788 {(char *) "virConnectNetworkEventDeregisterAny", libvirt_virConnectNetworkEventDeregisterAny, METH_VARARGS, NULL},
7789 #endif /* LIBVIR_CHECK_VERSION(1, 2, 1) */
7790 #if LIBVIR_CHECK_VERSION(0, 10, 0)
7791 {(char *) "virConnectRegisterCloseCallback", libvirt_virConnectRegisterCloseCallback, METH_VARARGS, NULL},
7792 {(char *) "virConnectUnregisterCloseCallback", libvirt_virConnectUnregisterCloseCallback, METH_VARARGS, NULL},
7793 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
7794 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
7795 {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
7796 {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
7797 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
7798 {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
7799 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
7800 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
7801 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
7802 {(char *) "virNodeGetSecurityModel", libvirt_virNodeGetSecurityModel, METH_VARARGS, NULL},
7803 {(char *) "virDomainGetSecurityLabel", libvirt_virDomainGetSecurityLabel, METH_VARARGS, NULL},
7804 #if LIBVIR_CHECK_VERSION(0, 10, 0)
7805 {(char *) "virDomainGetSecurityLabelList", libvirt_virDomainGetSecurityLabelList, METH_VARARGS, NULL},
7806 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
7807 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
7808 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
7809 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
7810 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
7811 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
7812 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
7813 {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
7814 {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
7815 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
7816 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
7817 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7818 {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
7819 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7820 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
7821 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
7822 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},
7823 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL},
7824 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
7825 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
7826 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL},
7827 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats, METH_VARARGS, NULL},
7828 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
7829 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
7830 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
7831 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
7832 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
7833 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags, METH_VARARGS, NULL},
7834 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
7835 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags, METH_VARARGS, NULL},
7836 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters, METH_VARARGS, NULL},
7837 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters, METH_VARARGS, NULL},
7838 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters, METH_VARARGS, NULL},
7839 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
7840 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
7841 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
7842 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
7843 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
7844 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
7845 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
7846 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
7847 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
7848 #if LIBVIR_CHECK_VERSION(0, 10, 0)
7849 {(char *) "virDomainGetEmulatorPinInfo", libvirt_virDomainGetEmulatorPinInfo, METH_VARARGS, NULL},
7850 {(char *) "virDomainPinEmulator", libvirt_virDomainPinEmulator, METH_VARARGS, NULL},
7851 #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
7852 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
7853 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
7854 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7855 {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
7856 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7857 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
7858 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
7859 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7860 {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
7861 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7862 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL},
7863 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL},
7864 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL},
7865 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL},
7866 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL},
7867 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
7868 {(char *) "virEventAddHandle", libvirt_virEventAddHandle, METH_VARARGS, NULL},
7869 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout, METH_VARARGS, NULL},
7870 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
7871 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
7872 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
7873 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7874 {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
7875 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7876 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
7877 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
7878 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},
7879 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL},
7880 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
7881 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7882 {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL},
7883 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7884 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
7885 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
7886 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL},
7887 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
7888 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
7889 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
7890 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7891 {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
7892 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7893 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
7894 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
7895 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7896 {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
7897 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7898 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
7899 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
7900 #if LIBVIR_CHECK_VERSION(1, 0, 3)
7901 {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL},
7902 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
7903 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
7904 #if LIBVIR_CHECK_VERSION(0, 9, 13)
7905 {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
7906 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
7907 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
7908 #if LIBVIR_CHECK_VERSION(0, 9, 13)
7909 {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
7910 #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */
7911 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
7912 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
7913 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
7914 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL},
7915 {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
7916 #if LIBVIR_CHECK_VERSION(1, 0, 3)
7917 {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL},
7918 #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
7919 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
7920 #if LIBVIR_CHECK_VERSION(1, 1, 0)
7921 {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL},
7922 {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL},
7923 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
7924 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
7925 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
7926 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
7927 #if LIBVIR_CHECK_VERSION(0, 10, 2)
7928 {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
7929 {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
7930 #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */
7931 #if LIBVIR_CHECK_VERSION(1, 0, 0)
7932 {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
7933 #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */
7934 #if LIBVIR_CHECK_VERSION(1, 1, 1)
7935 {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL},
7936 {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL},
7937 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
7938 #if LIBVIR_CHECK_VERSION(1, 2, 5)
7939 {(char *) "virDomainFSFreeze", libvirt_virDomainFSFreeze, METH_VARARGS, NULL},
7940 {(char *) "virDomainFSThaw", libvirt_virDomainFSThaw, METH_VARARGS, NULL},
7941 {(char *) "virDomainGetTime", libvirt_virDomainGetTime, METH_VARARGS, NULL},
7942 {(char *) "virDomainSetTime", libvirt_virDomainSetTime, METH_VARARGS, NULL},
7943 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
7944 {NULL, NULL, 0, NULL}
7947 #if PY_MAJOR_VERSION > 2
7948 static struct PyModuleDef moduledef = {
7949 PyModuleDef_HEAD_INIT,
7950 # ifndef __CYGWIN__
7951 "libvirtmod",
7952 # else
7953 "cygvirtmod",
7954 # endif
7955 NULL,
7957 libvirtMethods,
7958 NULL,
7959 NULL,
7960 NULL,
7961 NULL
7964 PyObject *
7965 # ifndef __CYGWIN__
7966 PyInit_libvirtmod
7967 # else
7968 PyInit_cygvirtmod
7969 # endif
7970 (void)
7972 PyObject *module;
7974 if (virInitialize() < 0)
7975 return NULL;
7977 module = PyModule_Create(&moduledef);
7979 return module;
7981 #else /* ! PY_MAJOR_VERSION > 2 */
7982 void
7983 # ifndef __CYGWIN__
7984 initlibvirtmod
7985 # else
7986 initcygvirtmod
7987 # endif
7988 (void)
7990 if (virInitialize() < 0)
7991 return;
7993 /* initialize the python extension module */
7994 Py_InitModule((char *)
7995 # ifndef __CYGWIN__
7996 "libvirtmod",
7997 # else
7998 "cygvirtmod",
7999 # endif
8000 libvirtMethods);
8002 #endif /* ! PY_MAJOR_VERSION > 2 */