python: return dictionary without value in case of no blockjob
[libvirt-python/ericb.git] / libvirt-override.c
blob01c941e0b9a0217440f3bd153480b2577fc35246
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-2013 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
12 #include <config.h>
14 /* Horrible kludge to work around even more horrible name-space pollution
15 via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
16 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
17 #undef HAVE_PTHREAD_H
19 /* We want to see *_LAST enums. */
20 #define VIR_ENUM_SENTINELS
22 #include <Python.h>
23 #include <libvirt/libvirt.h>
24 #include <libvirt/virterror.h>
25 #include "typewrappers.h"
26 #include "libvirt.h"
27 #include "viralloc.h"
28 #include "virtypedparam.h"
29 #include "ignore-value.h"
30 #include "virutil.h"
31 #include "virstring.h"
33 #ifndef __CYGWIN__
34 extern void initlibvirtmod(void);
35 #else
36 extern void initcygvirtmod(void);
37 #endif
39 #if 0
40 # define DEBUG_ERROR 1
41 #endif
43 #if DEBUG_ERROR
44 # define DEBUG(fmt, ...) \
45 printf(fmt, __VA_ARGS__)
46 #else
47 # define DEBUG(fmt, ...) \
48 do {} while (0)
49 #endif
51 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
52 is so common that we encapsulate it here. Now, each use is simply
53 return VIR_PY_NONE; */
54 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
55 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
56 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
58 /* We don't want to free() returned value. As written in doc:
59 * PyString_AsString returns pointer to 'internal buffer of string,
60 * not a copy' and 'It must not be deallocated'. */
61 static char *py_str(PyObject *obj)
63 PyObject *str = PyObject_Str(obj);
64 if (!str) {
65 PyErr_Print();
66 PyErr_Clear();
67 return NULL;
69 return PyString_AsString(str);
72 /* Helper function to convert a virTypedParameter output array into a
73 * Python dictionary for return to the user. Return NULL on failure,
74 * after raising a python exception. */
75 static PyObject *
76 getPyVirTypedParameter(const virTypedParameterPtr params, int nparams)
78 PyObject *key, *val, *info;
79 size_t i;
81 if ((info = PyDict_New()) == NULL)
82 return NULL;
84 for (i = 0; i < nparams; i++) {
85 switch (params[i].type) {
86 case VIR_TYPED_PARAM_INT:
87 val = PyInt_FromLong(params[i].value.i);
88 break;
90 case VIR_TYPED_PARAM_UINT:
91 val = PyInt_FromLong(params[i].value.ui);
92 break;
94 case VIR_TYPED_PARAM_LLONG:
95 val = PyLong_FromLongLong(params[i].value.l);
96 break;
98 case VIR_TYPED_PARAM_ULLONG:
99 val = PyLong_FromUnsignedLongLong(params[i].value.ul);
100 break;
102 case VIR_TYPED_PARAM_DOUBLE:
103 val = PyFloat_FromDouble(params[i].value.d);
104 break;
106 case VIR_TYPED_PARAM_BOOLEAN:
107 val = PyBool_FromLong(params[i].value.b);
108 break;
110 case VIR_TYPED_PARAM_STRING:
111 val = libvirt_constcharPtrWrap(params[i].value.s);
112 break;
114 default:
115 /* Possible if a newer server has a bug and sent stuff we
116 * don't recognize. */
117 PyErr_Format(PyExc_LookupError,
118 "Type value \"%d\" not recognized",
119 params[i].type);
120 val = NULL;
121 break;
124 key = libvirt_constcharPtrWrap(params[i].field);
125 if (!key || !val)
126 goto cleanup;
128 if (PyDict_SetItem(info, key, val) < 0) {
129 Py_DECREF(info);
130 goto cleanup;
133 Py_DECREF(key);
134 Py_DECREF(val);
136 return info;
138 cleanup:
139 Py_XDECREF(key);
140 Py_XDECREF(val);
141 return NULL;
144 /* Allocate a new typed parameter array with the same contents and
145 * length as info, and using the array params of length nparams as
146 * hints on what types to use when creating the new array. The caller
147 * must NOT clear the array before freeing it, as it points into info
148 * rather than allocated strings. Return NULL on failure, after
149 * raising a python exception. */
150 static virTypedParameterPtr ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
151 setPyVirTypedParameter(PyObject *info,
152 const virTypedParameterPtr params, int nparams)
154 PyObject *key, *value;
155 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
156 int pos = 0;
157 #else
158 Py_ssize_t pos = 0;
159 #endif
160 virTypedParameterPtr temp = NULL, ret = NULL;
161 Py_ssize_t size;
162 size_t i;
164 if ((size = PyDict_Size(info)) < 0)
165 return NULL;
167 /* Libvirt APIs use NULL array and 0 size as a special case;
168 * setting should have at least one parameter. */
169 if (size == 0) {
170 PyErr_Format(PyExc_LookupError, "Dictionary must not be empty");
171 return NULL;
174 if (VIR_ALLOC_N_QUIET(ret, size) < 0) {
175 PyErr_NoMemory();
176 return NULL;
179 temp = &ret[0];
180 while (PyDict_Next(info, &pos, &key, &value)) {
181 char *keystr = NULL;
183 if ((keystr = PyString_AsString(key)) == NULL)
184 goto cleanup;
186 for (i = 0; i < nparams; i++) {
187 if (STREQ(params[i].field, keystr))
188 break;
190 if (i == nparams) {
191 PyErr_Format(PyExc_LookupError,
192 "Attribute name \"%s\" could not be recognized",
193 keystr);
194 goto cleanup;
197 ignore_value(virStrcpyStatic(temp->field, keystr));
198 temp->type = params[i].type;
200 switch (params[i].type) {
201 case VIR_TYPED_PARAM_INT:
202 if (libvirt_intUnwrap(value, &temp->value.i) < 0)
203 goto cleanup;
204 break;
206 case VIR_TYPED_PARAM_UINT:
207 if (libvirt_uintUnwrap(value, &temp->value.ui) < 0)
208 goto cleanup;
209 break;
211 case VIR_TYPED_PARAM_LLONG:
212 if (libvirt_longlongUnwrap(value, &temp->value.l) < 0)
213 goto cleanup;
214 break;
216 case VIR_TYPED_PARAM_ULLONG:
217 if (libvirt_ulonglongUnwrap(value, &temp->value.ul) < 0)
218 goto cleanup;
219 break;
221 case VIR_TYPED_PARAM_DOUBLE:
222 if (libvirt_doubleUnwrap(value, &temp->value.d) < 0)
223 goto cleanup;
224 break;
226 case VIR_TYPED_PARAM_BOOLEAN:
228 bool b;
229 if (libvirt_boolUnwrap(value, &b) < 0)
230 goto cleanup;
231 temp->value.b = b;
232 break;
234 case VIR_TYPED_PARAM_STRING:
236 char *string_val = PyString_AsString(value);
237 if (!string_val)
238 goto cleanup;
239 temp->value.s = string_val;
240 break;
243 default:
244 /* Possible if a newer server has a bug and sent stuff we
245 * don't recognize. */
246 PyErr_Format(PyExc_LookupError,
247 "Type value \"%d\" not recognized",
248 params[i].type);
249 goto cleanup;
252 temp++;
254 return ret;
256 cleanup:
257 VIR_FREE(ret);
258 return NULL;
262 typedef struct {
263 const char *name;
264 int type;
265 } virPyTypedParamsHint;
266 typedef virPyTypedParamsHint *virPyTypedParamsHintPtr;
268 /* Automatically convert dict into type parameters based on types reported
269 * by python. All integer types are converted into LLONG (in case of a negative
270 * value) or ULLONG (in case of a positive value). If you need different
271 * handling, use @hints to explicitly specify what types should be used for
272 * specific parameters.
274 static int
275 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
276 virPyDictToTypedParams(PyObject *dict,
277 virTypedParameterPtr *ret_params,
278 int *ret_nparams,
279 virPyTypedParamsHintPtr hints,
280 int nhints)
282 PyObject *key;
283 PyObject *value;
284 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
285 int pos = 0;
286 #else
287 Py_ssize_t pos = 0;
288 #endif
289 virTypedParameterPtr params = NULL;
290 size_t i;
291 int n = 0;
292 int max = 0;
293 int ret = -1;
295 *ret_params = NULL;
296 *ret_nparams = 0;
298 if (PyDict_Size(dict) < 0)
299 return -1;
301 while (PyDict_Next(dict, &pos, &key, &value)) {
302 char *keystr;
303 int type = -1;
305 if (!(keystr = PyString_AsString(key)))
306 goto cleanup;
308 for (i = 0; i < nhints; i++) {
309 if (STREQ(hints[i].name, keystr)) {
310 type = hints[i].type;
311 break;
315 if (type == -1) {
316 if (PyString_Check(value)) {
317 type = VIR_TYPED_PARAM_STRING;
318 } else if (PyBool_Check(value)) {
319 type = VIR_TYPED_PARAM_BOOLEAN;
320 } else if (PyLong_Check(value)) {
321 unsigned long long ull = PyLong_AsUnsignedLongLong(value);
322 if (ull == (unsigned long long) -1 && PyErr_Occurred())
323 type = VIR_TYPED_PARAM_LLONG;
324 else
325 type = VIR_TYPED_PARAM_ULLONG;
326 } else if (PyInt_Check(value)) {
327 if (PyInt_AS_LONG(value) < 0)
328 type = VIR_TYPED_PARAM_LLONG;
329 else
330 type = VIR_TYPED_PARAM_ULLONG;
331 } else if (PyFloat_Check(value)) {
332 type = VIR_TYPED_PARAM_DOUBLE;
336 if (type == -1) {
337 PyErr_Format(PyExc_TypeError,
338 "Unknown type of \"%s\" field", keystr);
339 goto cleanup;
342 switch ((virTypedParameterType) type) {
343 case VIR_TYPED_PARAM_INT:
345 int val;
346 if (libvirt_intUnwrap(value, &val) < 0 ||
347 virTypedParamsAddInt(&params, &n, &max, keystr, val) < 0)
348 goto cleanup;
349 break;
351 case VIR_TYPED_PARAM_UINT:
353 unsigned int val;
354 if (libvirt_uintUnwrap(value, &val) < 0 ||
355 virTypedParamsAddUInt(&params, &n, &max, keystr, val) < 0)
356 goto cleanup;
357 break;
359 case VIR_TYPED_PARAM_LLONG:
361 long long val;
362 if (libvirt_longlongUnwrap(value, &val) < 0 ||
363 virTypedParamsAddLLong(&params, &n, &max, keystr, val) < 0)
364 goto cleanup;
365 break;
367 case VIR_TYPED_PARAM_ULLONG:
369 unsigned long long val;
370 if (libvirt_ulonglongUnwrap(value, &val) < 0 ||
371 virTypedParamsAddULLong(&params, &n, &max, keystr, val) < 0)
372 goto cleanup;
373 break;
375 case VIR_TYPED_PARAM_DOUBLE:
377 double val;
378 if (libvirt_doubleUnwrap(value, &val) < 0 ||
379 virTypedParamsAddDouble(&params, &n, &max, keystr, val) < 0)
380 goto cleanup;
381 break;
383 case VIR_TYPED_PARAM_BOOLEAN:
385 bool val;
386 if (libvirt_boolUnwrap(value, &val) < 0 ||
387 virTypedParamsAddBoolean(&params, &n, &max, keystr, val) < 0)
388 goto cleanup;
389 break;
391 case VIR_TYPED_PARAM_STRING:
393 char *val = PyString_AsString(value);
394 if (!val ||
395 virTypedParamsAddString(&params, &n, &max, keystr, val) < 0)
396 goto cleanup;
397 break;
399 case VIR_TYPED_PARAM_LAST:
400 break; /* unreachable */
404 *ret_params = params;
405 *ret_nparams = n;
406 params = NULL;
407 ret = 0;
409 cleanup:
410 virTypedParamsFree(params, n);
411 return ret;
416 * Utility function to retrieve the number of node CPUs present.
417 * It first tries virGetNodeCPUMap, which will return the
418 * number reliably, if available.
419 * As a fallback and for compatibility with backlevel libvirt
420 * versions virGetNodeInfo will be called to calculate the
421 * CPU number, which has the potential to return a too small
422 * number if some host CPUs are offline.
424 static int
425 getPyNodeCPUCount(virConnectPtr conn) {
426 int i_retval;
427 virNodeInfo nodeinfo;
429 LIBVIRT_BEGIN_ALLOW_THREADS;
430 i_retval = virNodeGetCPUMap(conn, NULL, NULL, 0);
431 LIBVIRT_END_ALLOW_THREADS;
433 if (i_retval < 0) {
434 /* fallback: use nodeinfo */
435 LIBVIRT_BEGIN_ALLOW_THREADS;
436 i_retval = virNodeGetInfo(conn, &nodeinfo);
437 LIBVIRT_END_ALLOW_THREADS;
438 if (i_retval < 0)
439 goto cleanup;
441 i_retval = VIR_NODEINFO_MAXCPUS(nodeinfo);
444 cleanup:
445 return i_retval;
448 /************************************************************************
450 * Statistics *
452 ************************************************************************/
454 static PyObject *
455 libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
456 virDomainPtr domain;
457 PyObject *pyobj_domain;
458 char * path;
459 int c_retval;
460 virDomainBlockStatsStruct stats;
461 PyObject *info;
463 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats",
464 &pyobj_domain,&path))
465 return NULL;
466 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
468 LIBVIRT_BEGIN_ALLOW_THREADS;
469 c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats));
470 LIBVIRT_END_ALLOW_THREADS;
472 if (c_retval < 0)
473 return VIR_PY_NONE;
475 /* convert to a Python tuple of long objects */
476 if ((info = PyTuple_New(5)) == NULL)
477 return VIR_PY_NONE;
478 PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rd_req));
479 PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rd_bytes));
480 PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.wr_req));
481 PyTuple_SetItem(info, 3, PyLong_FromLongLong(stats.wr_bytes));
482 PyTuple_SetItem(info, 4, PyLong_FromLongLong(stats.errs));
483 return info;
486 static PyObject *
487 libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED,
488 PyObject *args)
490 virDomainPtr domain;
491 PyObject *pyobj_domain;
492 PyObject *ret = NULL;
493 int i_retval;
494 int nparams = 0;
495 unsigned int flags;
496 virTypedParameterPtr params;
497 const char *path;
499 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainBlockStatsFlags",
500 &pyobj_domain, &path, &flags))
501 return NULL;
502 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
504 LIBVIRT_BEGIN_ALLOW_THREADS;
505 i_retval = virDomainBlockStatsFlags(domain, path, NULL, &nparams, flags);
506 LIBVIRT_END_ALLOW_THREADS;
508 if (i_retval < 0)
509 return VIR_PY_NONE;
511 if (!nparams)
512 return PyDict_New();
514 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
515 return PyErr_NoMemory();
517 LIBVIRT_BEGIN_ALLOW_THREADS;
518 i_retval = virDomainBlockStatsFlags(domain, path, params, &nparams, flags);
519 LIBVIRT_END_ALLOW_THREADS;
521 if (i_retval < 0) {
522 ret = VIR_PY_NONE;
523 goto cleanup;
526 ret = getPyVirTypedParameter(params, nparams);
528 cleanup:
529 virTypedParamsFree(params, nparams);
530 return ret;
533 static PyObject *
534 libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
536 virDomainPtr domain;
537 PyObject *pyobj_domain, *totalbool;
538 PyObject *cpu, *total;
539 PyObject *ret = NULL;
540 PyObject *error = NULL;
541 int ncpus = -1, start_cpu = 0;
542 int sumparams = 0, nparams = -1;
543 size_t i;
544 int i_retval;
545 unsigned int flags;
546 bool totalflag;
547 virTypedParameterPtr params = NULL, cpuparams;
549 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainGetCPUStats",
550 &pyobj_domain, &totalbool, &flags))
551 return NULL;
552 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
554 if (libvirt_boolUnwrap(totalbool, &totalflag) < 0)
555 return NULL;
557 if ((ret = PyList_New(0)) == NULL)
558 return NULL;
560 if (!totalflag) {
561 LIBVIRT_BEGIN_ALLOW_THREADS;
562 ncpus = virDomainGetCPUStats(domain, NULL, 0, 0, 0, flags);
563 LIBVIRT_END_ALLOW_THREADS;
565 if (ncpus < 0) {
566 error = VIR_PY_NONE;
567 goto error;
570 LIBVIRT_BEGIN_ALLOW_THREADS;
571 nparams = virDomainGetCPUStats(domain, NULL, 0, 0, 1, flags);
572 LIBVIRT_END_ALLOW_THREADS;
574 if (nparams < 0) {
575 error = VIR_PY_NONE;
576 goto error;
579 sumparams = nparams * MIN(ncpus, 128);
581 if (VIR_ALLOC_N_QUIET(params, sumparams) < 0) {
582 error = PyErr_NoMemory();
583 goto error;
586 while (ncpus) {
587 int queried_ncpus = MIN(ncpus, 128);
588 if (nparams) {
590 LIBVIRT_BEGIN_ALLOW_THREADS;
591 i_retval = virDomainGetCPUStats(domain, params,
592 nparams, start_cpu, queried_ncpus, flags);
593 LIBVIRT_END_ALLOW_THREADS;
595 if (i_retval < 0) {
596 error = VIR_PY_NONE;
597 goto error;
599 } else {
600 i_retval = 0;
603 for (i = 0; i < queried_ncpus; i++) {
604 cpuparams = &params[i * nparams];
605 if ((cpu = getPyVirTypedParameter(cpuparams, i_retval)) == NULL) {
606 goto error;
609 if (PyList_Append(ret, cpu) < 0) {
610 Py_DECREF(cpu);
611 goto error;
613 Py_DECREF(cpu);
616 start_cpu += queried_ncpus;
617 ncpus -= queried_ncpus;
618 virTypedParamsClear(params, sumparams);
620 } else {
621 LIBVIRT_BEGIN_ALLOW_THREADS;
622 nparams = virDomainGetCPUStats(domain, NULL, 0, -1, 1, flags);
623 LIBVIRT_END_ALLOW_THREADS;
625 if (nparams < 0) {
626 error = VIR_PY_NONE;
627 goto error;
630 if (nparams) {
631 sumparams = nparams;
633 if (VIR_ALLOC_N_QUIET(params, nparams) < 0) {
634 error = PyErr_NoMemory();
635 goto error;
638 LIBVIRT_BEGIN_ALLOW_THREADS;
639 i_retval = virDomainGetCPUStats(domain, params, nparams, -1, 1, flags);
640 LIBVIRT_END_ALLOW_THREADS;
642 if (i_retval < 0) {
643 error = VIR_PY_NONE;
644 goto error;
646 } else {
647 i_retval = 0;
650 if ((total = getPyVirTypedParameter(params, i_retval)) == NULL) {
651 goto error;
653 if (PyList_Append(ret, total) < 0) {
654 Py_DECREF(total);
655 goto error;
657 Py_DECREF(total);
660 virTypedParamsFree(params, sumparams);
661 return ret;
663 error:
664 virTypedParamsFree(params, sumparams);
665 Py_DECREF(ret);
666 return error;
669 static PyObject *
670 libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
671 virDomainPtr domain;
672 PyObject *pyobj_domain;
673 char * path;
674 int c_retval;
675 virDomainInterfaceStatsStruct stats;
676 PyObject *info;
678 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainInterfaceStats",
679 &pyobj_domain,&path))
680 return NULL;
681 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
683 LIBVIRT_BEGIN_ALLOW_THREADS;
684 c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats));
685 LIBVIRT_END_ALLOW_THREADS;
687 if (c_retval < 0)
688 return VIR_PY_NONE;
690 /* convert to a Python tuple of long objects */
691 if ((info = PyTuple_New(8)) == NULL)
692 return VIR_PY_NONE;
693 PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rx_bytes));
694 PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rx_packets));
695 PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.rx_errs));
696 PyTuple_SetItem(info, 3, PyLong_FromLongLong(stats.rx_drop));
697 PyTuple_SetItem(info, 4, PyLong_FromLongLong(stats.tx_bytes));
698 PyTuple_SetItem(info, 5, PyLong_FromLongLong(stats.tx_packets));
699 PyTuple_SetItem(info, 6, PyLong_FromLongLong(stats.tx_errs));
700 PyTuple_SetItem(info, 7, PyLong_FromLongLong(stats.tx_drop));
701 return info;
704 static PyObject *
705 libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
706 virDomainPtr domain;
707 PyObject *pyobj_domain;
708 unsigned int nr_stats;
709 size_t i;
710 virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
711 PyObject *info;
713 if (!PyArg_ParseTuple(args, (char *)"O:virDomainMemoryStats", &pyobj_domain))
714 return NULL;
715 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
717 nr_stats = virDomainMemoryStats(domain, stats,
718 VIR_DOMAIN_MEMORY_STAT_NR, 0);
719 if (nr_stats == -1)
720 return VIR_PY_NONE;
722 /* convert to a Python dictionary */
723 if ((info = PyDict_New()) == NULL)
724 return VIR_PY_NONE;
726 for (i = 0; i < nr_stats; i++) {
727 if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_SWAP_IN)
728 PyDict_SetItem(info, libvirt_constcharPtrWrap("swap_in"),
729 PyLong_FromUnsignedLongLong(stats[i].val));
730 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_SWAP_OUT)
731 PyDict_SetItem(info, libvirt_constcharPtrWrap("swap_out"),
732 PyLong_FromUnsignedLongLong(stats[i].val));
733 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT)
734 PyDict_SetItem(info, libvirt_constcharPtrWrap("major_fault"),
735 PyLong_FromUnsignedLongLong(stats[i].val));
736 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT)
737 PyDict_SetItem(info, libvirt_constcharPtrWrap("minor_fault"),
738 PyLong_FromUnsignedLongLong(stats[i].val));
739 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_UNUSED)
740 PyDict_SetItem(info, libvirt_constcharPtrWrap("unused"),
741 PyLong_FromUnsignedLongLong(stats[i].val));
742 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_AVAILABLE)
743 PyDict_SetItem(info, libvirt_constcharPtrWrap("available"),
744 PyLong_FromUnsignedLongLong(stats[i].val));
745 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON)
746 PyDict_SetItem(info, libvirt_constcharPtrWrap("actual"),
747 PyLong_FromUnsignedLongLong(stats[i].val));
748 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_RSS)
749 PyDict_SetItem(info, libvirt_constcharPtrWrap("rss"),
750 PyLong_FromUnsignedLongLong(stats[i].val));
752 return info;
755 static PyObject *
756 libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
757 PyObject *args) {
758 virDomainPtr domain;
759 PyObject *pyobj_domain, *info;
760 char *c_retval;
761 int nparams;
763 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerType",
764 &pyobj_domain))
765 return NULL;
766 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
768 LIBVIRT_BEGIN_ALLOW_THREADS;
769 c_retval = virDomainGetSchedulerType(domain, &nparams);
770 LIBVIRT_END_ALLOW_THREADS;
771 if (c_retval == NULL)
772 return VIR_PY_NONE;
774 /* convert to a Python tuple of long objects */
775 if ((info = PyTuple_New(2)) == NULL) {
776 VIR_FREE(c_retval);
777 return VIR_PY_NONE;
780 PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(c_retval));
781 PyTuple_SetItem(info, 1, PyInt_FromLong((long)nparams));
782 VIR_FREE(c_retval);
783 return info;
786 static PyObject *
787 libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
788 PyObject *args)
790 virDomainPtr domain;
791 PyObject *pyobj_domain;
792 PyObject *ret = NULL;
793 char *c_retval;
794 int i_retval;
795 int nparams = 0;
796 virTypedParameterPtr params;
798 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerParameters",
799 &pyobj_domain))
800 return NULL;
801 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
803 LIBVIRT_BEGIN_ALLOW_THREADS;
804 c_retval = virDomainGetSchedulerType(domain, &nparams);
805 LIBVIRT_END_ALLOW_THREADS;
807 if (c_retval == NULL)
808 return VIR_PY_NONE;
809 VIR_FREE(c_retval);
811 if (!nparams)
812 return PyDict_New();
814 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
815 return PyErr_NoMemory();
817 LIBVIRT_BEGIN_ALLOW_THREADS;
818 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
819 LIBVIRT_END_ALLOW_THREADS;
821 if (i_retval < 0) {
822 ret = VIR_PY_NONE;
823 goto cleanup;
826 ret = getPyVirTypedParameter(params, nparams);
828 cleanup:
829 virTypedParamsFree(params, nparams);
830 return ret;
833 static PyObject *
834 libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
835 PyObject *args)
837 virDomainPtr domain;
838 PyObject *pyobj_domain;
839 PyObject *ret = NULL;
840 char *c_retval;
841 int i_retval;
842 int nparams = 0;
843 unsigned int flags;
844 virTypedParameterPtr params;
846 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetScedulerParametersFlags",
847 &pyobj_domain, &flags))
848 return NULL;
849 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
851 LIBVIRT_BEGIN_ALLOW_THREADS;
852 c_retval = virDomainGetSchedulerType(domain, &nparams);
853 LIBVIRT_END_ALLOW_THREADS;
855 if (c_retval == NULL)
856 return VIR_PY_NONE;
857 VIR_FREE(c_retval);
859 if (!nparams)
860 return PyDict_New();
862 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
863 return PyErr_NoMemory();
865 LIBVIRT_BEGIN_ALLOW_THREADS;
866 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams, flags);
867 LIBVIRT_END_ALLOW_THREADS;
869 if (i_retval < 0) {
870 ret = VIR_PY_NONE;
871 goto cleanup;
874 ret = getPyVirTypedParameter(params, nparams);
876 cleanup:
877 virTypedParamsFree(params, nparams);
878 return ret;
881 static PyObject *
882 libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
883 PyObject *args)
885 virDomainPtr domain;
886 PyObject *pyobj_domain, *info;
887 PyObject *ret = NULL;
888 char *c_retval;
889 int i_retval;
890 int nparams = 0;
891 Py_ssize_t size = 0;
892 virTypedParameterPtr params, new_params = NULL;
894 if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetScedulerParameters",
895 &pyobj_domain, &info))
896 return NULL;
897 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
899 if ((size = PyDict_Size(info)) < 0)
900 return NULL;
902 if (size == 0) {
903 PyErr_Format(PyExc_LookupError,
904 "Need non-empty dictionary to set attributes");
905 return NULL;
908 LIBVIRT_BEGIN_ALLOW_THREADS;
909 c_retval = virDomainGetSchedulerType(domain, &nparams);
910 LIBVIRT_END_ALLOW_THREADS;
912 if (c_retval == NULL)
913 return VIR_PY_INT_FAIL;
914 VIR_FREE(c_retval);
916 if (nparams == 0) {
917 PyErr_Format(PyExc_LookupError,
918 "Domain has no settable attributes");
919 return NULL;
922 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
923 return PyErr_NoMemory();
925 LIBVIRT_BEGIN_ALLOW_THREADS;
926 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
927 LIBVIRT_END_ALLOW_THREADS;
929 if (i_retval < 0) {
930 ret = VIR_PY_INT_FAIL;
931 goto cleanup;
934 new_params = setPyVirTypedParameter(info, params, nparams);
935 if (!new_params)
936 goto cleanup;
938 LIBVIRT_BEGIN_ALLOW_THREADS;
939 i_retval = virDomainSetSchedulerParameters(domain, new_params, size);
940 LIBVIRT_END_ALLOW_THREADS;
942 if (i_retval < 0) {
943 ret = VIR_PY_INT_FAIL;
944 goto cleanup;
947 ret = VIR_PY_INT_SUCCESS;
949 cleanup:
950 virTypedParamsFree(params, nparams);
951 VIR_FREE(new_params);
952 return ret;
955 static PyObject *
956 libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
957 PyObject *args)
959 virDomainPtr domain;
960 PyObject *pyobj_domain, *info;
961 PyObject *ret = NULL;
962 char *c_retval;
963 int i_retval;
964 int nparams = 0;
965 Py_ssize_t size = 0;
966 unsigned int flags;
967 virTypedParameterPtr params, new_params = NULL;
969 if (!PyArg_ParseTuple(args,
970 (char *)"OOi:virDomainSetScedulerParametersFlags",
971 &pyobj_domain, &info, &flags))
972 return NULL;
973 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
975 if ((size = PyDict_Size(info)) < 0)
976 return NULL;
978 if (size == 0) {
979 PyErr_Format(PyExc_LookupError,
980 "Need non-empty dictionary to set attributes");
981 return NULL;
984 LIBVIRT_BEGIN_ALLOW_THREADS;
985 c_retval = virDomainGetSchedulerType(domain, &nparams);
986 LIBVIRT_END_ALLOW_THREADS;
988 if (c_retval == NULL)
989 return VIR_PY_INT_FAIL;
990 VIR_FREE(c_retval);
992 if (nparams == 0) {
993 PyErr_Format(PyExc_LookupError,
994 "Domain has no settable attributes");
995 return NULL;
998 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
999 return PyErr_NoMemory();
1001 LIBVIRT_BEGIN_ALLOW_THREADS;
1002 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams, flags);
1003 LIBVIRT_END_ALLOW_THREADS;
1005 if (i_retval < 0) {
1006 ret = VIR_PY_INT_FAIL;
1007 goto cleanup;
1010 new_params = setPyVirTypedParameter(info, params, nparams);
1011 if (!new_params)
1012 goto cleanup;
1014 LIBVIRT_BEGIN_ALLOW_THREADS;
1015 i_retval = virDomainSetSchedulerParametersFlags(domain, new_params, size, flags);
1016 LIBVIRT_END_ALLOW_THREADS;
1018 if (i_retval < 0) {
1019 ret = VIR_PY_INT_FAIL;
1020 goto cleanup;
1023 ret = VIR_PY_INT_SUCCESS;
1025 cleanup:
1026 virTypedParamsFree(params, nparams);
1027 VIR_FREE(new_params);
1028 return ret;
1031 static PyObject *
1032 libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
1033 PyObject *args)
1035 virDomainPtr domain;
1036 PyObject *pyobj_domain, *info;
1037 PyObject *ret = NULL;
1038 int i_retval;
1039 int nparams = 0;
1040 Py_ssize_t size = 0;
1041 unsigned int flags;
1042 virTypedParameterPtr params, new_params = NULL;
1044 if (!PyArg_ParseTuple(args,
1045 (char *)"OOi:virDomainSetBlkioParameters",
1046 &pyobj_domain, &info, &flags))
1047 return NULL;
1048 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1050 if ((size = PyDict_Size(info)) < 0)
1051 return NULL;
1053 if (size == 0) {
1054 PyErr_Format(PyExc_LookupError,
1055 "Need non-empty dictionary to set attributes");
1056 return NULL;
1059 LIBVIRT_BEGIN_ALLOW_THREADS;
1060 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
1061 LIBVIRT_END_ALLOW_THREADS;
1063 if (i_retval < 0)
1064 return VIR_PY_INT_FAIL;
1066 if (nparams == 0) {
1067 PyErr_Format(PyExc_LookupError,
1068 "Domain has no settable attributes");
1069 return NULL;
1072 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1073 return PyErr_NoMemory();
1075 LIBVIRT_BEGIN_ALLOW_THREADS;
1076 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
1077 LIBVIRT_END_ALLOW_THREADS;
1079 if (i_retval < 0) {
1080 ret = VIR_PY_INT_FAIL;
1081 goto cleanup;
1084 new_params = setPyVirTypedParameter(info, params, nparams);
1085 if (!new_params)
1086 goto cleanup;
1088 LIBVIRT_BEGIN_ALLOW_THREADS;
1089 i_retval = virDomainSetBlkioParameters(domain, new_params, size, flags);
1090 LIBVIRT_END_ALLOW_THREADS;
1092 if (i_retval < 0) {
1093 ret = VIR_PY_INT_FAIL;
1094 goto cleanup;
1097 ret = VIR_PY_INT_SUCCESS;
1099 cleanup:
1100 virTypedParamsFree(params, nparams);
1101 VIR_FREE(new_params);
1102 return ret;
1105 static PyObject *
1106 libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
1107 PyObject *args)
1109 virDomainPtr domain;
1110 PyObject *pyobj_domain;
1111 PyObject *ret = NULL;
1112 int i_retval;
1113 int nparams = 0;
1114 unsigned int flags;
1115 virTypedParameterPtr params;
1117 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetBlkioParameters",
1118 &pyobj_domain, &flags))
1119 return NULL;
1120 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1122 LIBVIRT_BEGIN_ALLOW_THREADS;
1123 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
1124 LIBVIRT_END_ALLOW_THREADS;
1126 if (i_retval < 0)
1127 return VIR_PY_NONE;
1129 if (!nparams)
1130 return PyDict_New();
1132 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1133 return PyErr_NoMemory();
1135 LIBVIRT_BEGIN_ALLOW_THREADS;
1136 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
1137 LIBVIRT_END_ALLOW_THREADS;
1139 if (i_retval < 0) {
1140 ret = VIR_PY_NONE;
1141 goto cleanup;
1144 ret = getPyVirTypedParameter(params, nparams);
1146 cleanup:
1147 virTypedParamsFree(params, nparams);
1148 return ret;
1151 static PyObject *
1152 libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
1153 PyObject *args)
1155 virDomainPtr domain;
1156 PyObject *pyobj_domain, *info;
1157 PyObject *ret = NULL;
1158 int i_retval;
1159 int nparams = 0;
1160 Py_ssize_t size = 0;
1161 unsigned int flags;
1162 virTypedParameterPtr params, new_params = NULL;
1164 if (!PyArg_ParseTuple(args,
1165 (char *)"OOi:virDomainSetMemoryParameters",
1166 &pyobj_domain, &info, &flags))
1167 return NULL;
1168 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1170 if ((size = PyDict_Size(info)) < 0)
1171 return NULL;
1173 if (size == 0) {
1174 PyErr_Format(PyExc_LookupError,
1175 "Need non-empty dictionary to set attributes");
1176 return NULL;
1179 LIBVIRT_BEGIN_ALLOW_THREADS;
1180 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
1181 LIBVIRT_END_ALLOW_THREADS;
1183 if (i_retval < 0)
1184 return VIR_PY_INT_FAIL;
1186 if (nparams == 0) {
1187 PyErr_Format(PyExc_LookupError,
1188 "Domain has no settable attributes");
1189 return NULL;
1192 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1193 return PyErr_NoMemory();
1195 LIBVIRT_BEGIN_ALLOW_THREADS;
1196 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
1197 LIBVIRT_END_ALLOW_THREADS;
1199 if (i_retval < 0) {
1200 ret = VIR_PY_INT_FAIL;
1201 goto cleanup;
1204 new_params = setPyVirTypedParameter(info, params, nparams);
1205 if (!new_params)
1206 goto cleanup;
1208 LIBVIRT_BEGIN_ALLOW_THREADS;
1209 i_retval = virDomainSetMemoryParameters(domain, new_params, size, flags);
1210 LIBVIRT_END_ALLOW_THREADS;
1212 if (i_retval < 0) {
1213 ret = VIR_PY_INT_FAIL;
1214 goto cleanup;
1217 ret = VIR_PY_INT_SUCCESS;
1219 cleanup:
1220 virTypedParamsFree(params, nparams);
1221 VIR_FREE(new_params);
1222 return ret;
1225 static PyObject *
1226 libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
1227 PyObject *args)
1229 virDomainPtr domain;
1230 PyObject *pyobj_domain;
1231 PyObject *ret = NULL;
1232 int i_retval;
1233 int nparams = 0;
1234 unsigned int flags;
1235 virTypedParameterPtr params;
1237 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetMemoryParameters",
1238 &pyobj_domain, &flags))
1239 return NULL;
1240 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1242 LIBVIRT_BEGIN_ALLOW_THREADS;
1243 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
1244 LIBVIRT_END_ALLOW_THREADS;
1246 if (i_retval < 0)
1247 return VIR_PY_NONE;
1249 if (!nparams)
1250 return PyDict_New();
1252 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1253 return PyErr_NoMemory();
1255 LIBVIRT_BEGIN_ALLOW_THREADS;
1256 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
1257 LIBVIRT_END_ALLOW_THREADS;
1259 if (i_retval < 0) {
1260 ret = VIR_PY_NONE;
1261 goto cleanup;
1264 ret = getPyVirTypedParameter(params, nparams);
1266 cleanup:
1267 virTypedParamsFree(params, nparams);
1268 return ret;
1271 static PyObject *
1272 libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1273 PyObject *args)
1275 virDomainPtr domain;
1276 PyObject *pyobj_domain, *info;
1277 PyObject *ret = NULL;
1278 int i_retval;
1279 int nparams = 0;
1280 Py_ssize_t size = 0;
1281 unsigned int flags;
1282 virTypedParameterPtr params, new_params = NULL;
1284 if (!PyArg_ParseTuple(args,
1285 (char *)"OOi:virDomainSetNumaParameters",
1286 &pyobj_domain, &info, &flags))
1287 return NULL;
1288 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1290 if ((size = PyDict_Size(info)) < 0)
1291 return NULL;
1293 if (size == 0) {
1294 PyErr_Format(PyExc_LookupError,
1295 "Need non-empty dictionary to set attributes");
1296 return NULL;
1299 LIBVIRT_BEGIN_ALLOW_THREADS;
1300 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1301 LIBVIRT_END_ALLOW_THREADS;
1303 if (i_retval < 0)
1304 return VIR_PY_INT_FAIL;
1306 if (nparams == 0) {
1307 PyErr_Format(PyExc_LookupError,
1308 "Domain has no settable attributes");
1309 return NULL;
1312 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1313 return PyErr_NoMemory();
1315 LIBVIRT_BEGIN_ALLOW_THREADS;
1316 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1317 LIBVIRT_END_ALLOW_THREADS;
1319 if (i_retval < 0) {
1320 ret = VIR_PY_INT_FAIL;
1321 goto cleanup;
1324 new_params = setPyVirTypedParameter(info, params, nparams);
1325 if (!new_params)
1326 goto cleanup;
1328 LIBVIRT_BEGIN_ALLOW_THREADS;
1329 i_retval = virDomainSetNumaParameters(domain, new_params, size, flags);
1330 LIBVIRT_END_ALLOW_THREADS;
1332 if (i_retval < 0) {
1333 ret = VIR_PY_INT_FAIL;
1334 goto cleanup;
1337 ret = VIR_PY_INT_SUCCESS;
1339 cleanup:
1340 virTypedParamsFree(params, nparams);
1341 VIR_FREE(new_params);
1342 return ret;
1345 static PyObject *
1346 libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1347 PyObject *args)
1349 virDomainPtr domain;
1350 PyObject *pyobj_domain;
1351 PyObject *ret = NULL;
1352 int i_retval;
1353 int nparams = 0;
1354 unsigned int flags;
1355 virTypedParameterPtr params;
1357 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetNumaParameters",
1358 &pyobj_domain, &flags))
1359 return NULL;
1360 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1362 LIBVIRT_BEGIN_ALLOW_THREADS;
1363 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1364 LIBVIRT_END_ALLOW_THREADS;
1366 if (i_retval < 0)
1367 return VIR_PY_NONE;
1369 if (!nparams)
1370 return PyDict_New();
1372 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1373 return PyErr_NoMemory();
1375 LIBVIRT_BEGIN_ALLOW_THREADS;
1376 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1377 LIBVIRT_END_ALLOW_THREADS;
1379 if (i_retval < 0) {
1380 ret = VIR_PY_NONE;
1381 goto cleanup;
1384 ret = getPyVirTypedParameter(params, nparams);
1386 cleanup:
1387 virTypedParamsFree(params, nparams);
1388 return ret;
1391 static PyObject *
1392 libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1393 PyObject *args)
1395 virDomainPtr domain;
1396 PyObject *pyobj_domain, *info;
1397 PyObject *ret = NULL;
1398 int i_retval;
1399 int nparams = 0;
1400 Py_ssize_t size = 0;
1401 unsigned int flags;
1402 const char *device = NULL;
1403 virTypedParameterPtr params, new_params = NULL;
1405 if (!PyArg_ParseTuple(args,
1406 (char *)"OzOi:virDomainSetInterfaceParameters",
1407 &pyobj_domain, &device, &info, &flags))
1408 return NULL;
1409 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1411 if ((size = PyDict_Size(info)) < 0)
1412 return NULL;
1414 if (size == 0) {
1415 PyErr_Format(PyExc_LookupError,
1416 "Need non-empty dictionary to set attributes");
1417 return NULL;
1420 LIBVIRT_BEGIN_ALLOW_THREADS;
1421 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
1422 LIBVIRT_END_ALLOW_THREADS;
1424 if (i_retval < 0)
1425 return VIR_PY_INT_FAIL;
1427 if (nparams == 0) {
1428 PyErr_Format(PyExc_LookupError,
1429 "Domain has no settable attributes");
1430 return NULL;
1433 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1434 return PyErr_NoMemory();
1436 LIBVIRT_BEGIN_ALLOW_THREADS;
1437 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
1438 LIBVIRT_END_ALLOW_THREADS;
1440 if (i_retval < 0) {
1441 ret = VIR_PY_INT_FAIL;
1442 goto cleanup;
1445 new_params = setPyVirTypedParameter(info, params, nparams);
1446 if (!new_params)
1447 goto cleanup;
1449 LIBVIRT_BEGIN_ALLOW_THREADS;
1450 i_retval = virDomainSetInterfaceParameters(domain, device, new_params, size, flags);
1451 LIBVIRT_END_ALLOW_THREADS;
1453 if (i_retval < 0) {
1454 ret = VIR_PY_INT_FAIL;
1455 goto cleanup;
1458 ret = VIR_PY_INT_SUCCESS;
1460 cleanup:
1461 virTypedParamsFree(params, nparams);
1462 VIR_FREE(new_params);
1463 return ret;
1466 static PyObject *
1467 libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1468 PyObject *args)
1470 virDomainPtr domain;
1471 PyObject *pyobj_domain;
1472 PyObject *ret = NULL;
1473 int i_retval;
1474 int nparams = 0;
1475 unsigned int flags;
1476 const char *device = NULL;
1477 virTypedParameterPtr params;
1479 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInterfaceParameters",
1480 &pyobj_domain, &device, &flags))
1481 return NULL;
1482 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1484 LIBVIRT_BEGIN_ALLOW_THREADS;
1485 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
1486 LIBVIRT_END_ALLOW_THREADS;
1488 if (i_retval < 0)
1489 return VIR_PY_NONE;
1491 if (!nparams)
1492 return PyDict_New();
1494 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
1495 return PyErr_NoMemory();
1497 LIBVIRT_BEGIN_ALLOW_THREADS;
1498 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
1499 LIBVIRT_END_ALLOW_THREADS;
1501 if (i_retval < 0) {
1502 ret = VIR_PY_NONE;
1503 goto cleanup;
1506 ret = getPyVirTypedParameter(params, nparams);
1508 cleanup:
1509 virTypedParamsFree(params, nparams);
1510 return ret;
1513 static PyObject *
1514 libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
1515 PyObject *args)
1517 virDomainPtr domain;
1518 PyObject *pyobj_domain, *pyretval = NULL, *pycpuinfo = NULL, *pycpumap = NULL;
1519 PyObject *error = NULL;
1520 virDomainInfo dominfo;
1521 virVcpuInfoPtr cpuinfo = NULL;
1522 unsigned char *cpumap = NULL;
1523 size_t cpumaplen, i;
1524 int i_retval, cpunum;
1526 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
1527 &pyobj_domain))
1528 return NULL;
1529 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1531 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1532 return VIR_PY_INT_FAIL;
1534 LIBVIRT_BEGIN_ALLOW_THREADS;
1535 i_retval = virDomainGetInfo(domain, &dominfo);
1536 LIBVIRT_END_ALLOW_THREADS;
1537 if (i_retval < 0)
1538 return VIR_PY_INT_FAIL;
1540 if (VIR_ALLOC_N_QUIET(cpuinfo, dominfo.nrVirtCpu) < 0)
1541 return PyErr_NoMemory();
1543 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1544 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1545 VIR_ALLOC_N_QUIET(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) {
1546 error = PyErr_NoMemory();
1547 goto cleanup;
1550 LIBVIRT_BEGIN_ALLOW_THREADS;
1551 i_retval = virDomainGetVcpus(domain,
1552 cpuinfo, dominfo.nrVirtCpu,
1553 cpumap, cpumaplen);
1554 LIBVIRT_END_ALLOW_THREADS;
1555 if (i_retval < 0) {
1556 error = VIR_PY_INT_FAIL;
1557 goto cleanup;
1560 /* convert to a Python tuple of long objects */
1561 if ((pyretval = PyTuple_New(2)) == NULL)
1562 goto cleanup;
1563 if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
1564 goto cleanup;
1565 if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
1566 goto cleanup;
1568 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1569 PyObject *info = PyTuple_New(4);
1570 PyObject *item = NULL;
1572 if (info == NULL)
1573 goto cleanup;
1575 if ((item = PyInt_FromLong((long)cpuinfo[i].number)) == NULL ||
1576 PyTuple_SetItem(info, 0, item) < 0)
1577 goto itemError;
1579 if ((item = PyInt_FromLong((long)cpuinfo[i].state)) == NULL ||
1580 PyTuple_SetItem(info, 1, item) < 0)
1581 goto itemError;
1583 if ((item = PyLong_FromLongLong((long long)cpuinfo[i].cpuTime)) == NULL ||
1584 PyTuple_SetItem(info, 2, item) < 0)
1585 goto itemError;
1587 if ((item = PyInt_FromLong((long)cpuinfo[i].cpu)) == NULL ||
1588 PyTuple_SetItem(info, 3, item) < 0)
1589 goto itemError;
1591 if (PyList_SetItem(pycpuinfo, i, info) < 0)
1592 goto itemError;
1594 continue;
1595 itemError:
1596 Py_DECREF(info);
1597 Py_XDECREF(item);
1598 goto cleanup;
1600 for (i = 0; i < dominfo.nrVirtCpu; i++) {
1601 PyObject *info = PyTuple_New(cpunum);
1602 size_t j;
1603 if (info == NULL)
1604 goto cleanup;
1605 for (j = 0; j < cpunum; j++) {
1606 PyObject *item = NULL;
1607 if ((item = PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, i, j))) == NULL ||
1608 PyTuple_SetItem(info, j, item) < 0) {
1609 Py_DECREF(info);
1610 Py_XDECREF(item);
1611 goto cleanup;
1614 if (PyList_SetItem(pycpumap, i, info) < 0) {
1615 Py_DECREF(info);
1616 goto cleanup;
1619 if (PyTuple_SetItem(pyretval, 0, pycpuinfo) < 0 ||
1620 PyTuple_SetItem(pyretval, 1, pycpumap) < 0)
1621 goto cleanup;
1623 VIR_FREE(cpuinfo);
1624 VIR_FREE(cpumap);
1626 return pyretval;
1628 cleanup:
1629 VIR_FREE(cpuinfo);
1630 VIR_FREE(cpumap);
1631 Py_XDECREF(pyretval);
1632 Py_XDECREF(pycpuinfo);
1633 Py_XDECREF(pycpumap);
1634 return error;
1638 static PyObject *
1639 libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
1640 PyObject *args)
1642 virDomainPtr domain;
1643 PyObject *pyobj_domain, *pycpumap;
1644 PyObject *ret = NULL;
1645 unsigned char *cpumap;
1646 int cpumaplen, vcpu, tuple_size, cpunum;
1647 size_t i;
1648 int i_retval;
1650 if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu",
1651 &pyobj_domain, &vcpu, &pycpumap))
1652 return NULL;
1653 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1655 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1656 return VIR_PY_INT_FAIL;
1658 if (PyTuple_Check(pycpumap)) {
1659 tuple_size = PyTuple_Size(pycpumap);
1660 if (tuple_size == -1)
1661 return ret;
1662 } else {
1663 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1664 return ret;
1667 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1668 if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0)
1669 return PyErr_NoMemory();
1671 for (i = 0; i < tuple_size; i++) {
1672 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1673 bool b;
1675 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1676 goto cleanup;
1678 if (b)
1679 VIR_USE_CPU(cpumap, i);
1680 else
1681 VIR_UNUSE_CPU(cpumap, i);
1684 for (; i < cpunum; i++)
1685 VIR_UNUSE_CPU(cpumap, i);
1687 LIBVIRT_BEGIN_ALLOW_THREADS;
1688 i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen);
1689 LIBVIRT_END_ALLOW_THREADS;
1691 if (i_retval < 0) {
1692 ret = VIR_PY_INT_FAIL;
1693 goto cleanup;
1695 ret = VIR_PY_INT_SUCCESS;
1697 cleanup:
1698 VIR_FREE(cpumap);
1699 return ret;
1702 static PyObject *
1703 libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED,
1704 PyObject *args)
1706 virDomainPtr domain;
1707 PyObject *pyobj_domain, *pycpumap;
1708 PyObject *ret = NULL;
1709 unsigned char *cpumap;
1710 int cpumaplen, vcpu, tuple_size, cpunum;
1711 size_t i;
1712 unsigned int flags;
1713 int i_retval;
1715 if (!PyArg_ParseTuple(args, (char *)"OiOi:virDomainPinVcpuFlags",
1716 &pyobj_domain, &vcpu, &pycpumap, &flags))
1717 return NULL;
1718 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1720 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1721 return VIR_PY_INT_FAIL;
1723 if (PyTuple_Check(pycpumap)) {
1724 tuple_size = PyTuple_Size(pycpumap);
1725 if (tuple_size == -1)
1726 return ret;
1727 } else {
1728 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1729 return ret;
1732 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1733 if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0)
1734 return PyErr_NoMemory();
1736 for (i = 0; i < tuple_size; i++) {
1737 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1738 bool b;
1740 if (!flag || libvirt_boolUnwrap(flag, &b) < 0)
1741 goto cleanup;
1743 if (b)
1744 VIR_USE_CPU(cpumap, i);
1745 else
1746 VIR_UNUSE_CPU(cpumap, i);
1749 for (; i < cpunum; i++)
1750 VIR_UNUSE_CPU(cpumap, i);
1752 LIBVIRT_BEGIN_ALLOW_THREADS;
1753 i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags);
1754 LIBVIRT_END_ALLOW_THREADS;
1755 if (i_retval < 0) {
1756 ret = VIR_PY_INT_FAIL;
1757 goto cleanup;
1759 ret = VIR_PY_INT_SUCCESS;
1761 cleanup:
1762 VIR_FREE(cpumap);
1763 return ret;
1766 static PyObject *
1767 libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1768 PyObject *args) {
1769 virDomainPtr domain;
1770 PyObject *pyobj_domain, *pycpumaps = NULL;
1771 virDomainInfo dominfo;
1772 unsigned char *cpumaps;
1773 size_t cpumaplen, vcpu, pcpu;
1774 unsigned int flags;
1775 int i_retval, cpunum;
1777 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetVcpuPinInfo",
1778 &pyobj_domain, &flags))
1779 return NULL;
1780 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1782 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1783 return VIR_PY_INT_FAIL;
1785 LIBVIRT_BEGIN_ALLOW_THREADS;
1786 i_retval = virDomainGetInfo(domain, &dominfo);
1787 LIBVIRT_END_ALLOW_THREADS;
1788 if (i_retval < 0)
1789 return VIR_PY_NONE;
1791 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1792 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1793 VIR_ALLOC_N_QUIET(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0)
1794 goto cleanup;
1796 LIBVIRT_BEGIN_ALLOW_THREADS;
1797 i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu,
1798 cpumaps, cpumaplen, flags);
1799 LIBVIRT_END_ALLOW_THREADS;
1800 if (i_retval < 0)
1801 goto cleanup;
1803 if ((pycpumaps = PyList_New(dominfo.nrVirtCpu)) == NULL)
1804 goto cleanup;
1806 for (vcpu = 0; vcpu < dominfo.nrVirtCpu; vcpu++) {
1807 PyObject *mapinfo = PyTuple_New(cpunum);
1808 if (mapinfo == NULL)
1809 goto cleanup;
1811 for (pcpu = 0; pcpu < cpunum; pcpu++) {
1812 PyTuple_SetItem(mapinfo, pcpu,
1813 PyBool_FromLong(VIR_CPU_USABLE(cpumaps, cpumaplen, vcpu, pcpu)));
1815 PyList_SetItem(pycpumaps, vcpu, mapinfo);
1818 VIR_FREE(cpumaps);
1820 return pycpumaps;
1822 cleanup:
1823 VIR_FREE(cpumaps);
1825 Py_XDECREF(pycpumaps);
1827 return VIR_PY_NONE;
1831 static PyObject *
1832 libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED,
1833 PyObject *args)
1835 virDomainPtr domain;
1836 PyObject *pyobj_domain, *pycpumap;
1837 unsigned char *cpumap = NULL;
1838 int cpumaplen, tuple_size, cpunum;
1839 size_t i;
1840 int i_retval;
1841 unsigned int flags;
1843 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainPinVcpu",
1844 &pyobj_domain, &pycpumap, &flags))
1845 return NULL;
1847 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1849 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1850 return VIR_PY_INT_FAIL;
1852 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1854 if (!PyTuple_Check(pycpumap)) {
1855 PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required");
1856 return NULL;
1859 if ((tuple_size = PyTuple_Size(pycpumap)) == -1)
1860 return NULL;
1862 if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0)
1863 return PyErr_NoMemory();
1865 for (i = 0; i < tuple_size; i++) {
1866 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1867 bool b;
1869 if (!flag || libvirt_boolUnwrap(flag, &b) < 0) {
1870 VIR_FREE(cpumap);
1871 return VIR_PY_INT_FAIL;
1874 if (b)
1875 VIR_USE_CPU(cpumap, i);
1876 else
1877 VIR_UNUSE_CPU(cpumap, i);
1880 for (; i < cpunum; i++)
1881 VIR_UNUSE_CPU(cpumap, i);
1883 LIBVIRT_BEGIN_ALLOW_THREADS;
1884 i_retval = virDomainPinEmulator(domain, cpumap, cpumaplen, flags);
1885 LIBVIRT_END_ALLOW_THREADS;
1887 VIR_FREE(cpumap);
1889 if (i_retval < 0)
1890 return VIR_PY_INT_FAIL;
1892 return VIR_PY_INT_SUCCESS;
1896 static PyObject *
1897 libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1898 PyObject *args)
1900 virDomainPtr domain;
1901 PyObject *pyobj_domain;
1902 PyObject *pycpumap;
1903 unsigned char *cpumap;
1904 size_t cpumaplen;
1905 size_t pcpu;
1906 unsigned int flags;
1907 int ret;
1908 int cpunum;
1910 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainEmulatorPinInfo",
1911 &pyobj_domain, &flags))
1912 return NULL;
1914 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1916 if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0)
1917 return VIR_PY_NONE;
1919 cpumaplen = VIR_CPU_MAPLEN(cpunum);
1921 if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0)
1922 return PyErr_NoMemory();
1924 LIBVIRT_BEGIN_ALLOW_THREADS;
1925 ret = virDomainGetEmulatorPinInfo(domain, cpumap, cpumaplen, flags);
1926 LIBVIRT_END_ALLOW_THREADS;
1927 if (ret < 0) {
1928 VIR_FREE(cpumap);
1929 return VIR_PY_NONE;
1932 if (!(pycpumap = PyTuple_New(cpunum))) {
1933 VIR_FREE(cpumap);
1934 return NULL;
1937 for (pcpu = 0; pcpu < cpunum; pcpu++)
1938 PyTuple_SET_ITEM(pycpumap, pcpu,
1939 PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen,
1940 0, pcpu)));
1942 VIR_FREE(cpumap);
1943 return pycpumap;
1947 /************************************************************************
1949 * Global error handler at the Python level *
1951 ************************************************************************/
1953 static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
1954 static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
1956 static PyObject *
1957 libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED)
1959 virError *err;
1960 PyObject *info;
1962 if ((err = virGetLastError()) == NULL)
1963 return VIR_PY_NONE;
1965 if ((info = PyTuple_New(9)) == NULL)
1966 return VIR_PY_NONE;
1967 PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code));
1968 PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain));
1969 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
1970 PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level));
1971 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
1972 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
1973 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
1974 PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1));
1975 PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2));
1977 return info;
1980 static PyObject *
1981 libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
1983 virError *err;
1984 PyObject *info;
1985 virConnectPtr conn;
1986 PyObject *pyobj_conn;
1988 if (!PyArg_ParseTuple(args, (char *)"O:virConGetLastError", &pyobj_conn))
1989 return NULL;
1990 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1992 LIBVIRT_BEGIN_ALLOW_THREADS;
1993 err = virConnGetLastError(conn);
1994 LIBVIRT_END_ALLOW_THREADS;
1995 if (err == NULL)
1996 return VIR_PY_NONE;
1998 if ((info = PyTuple_New(9)) == NULL)
1999 return VIR_PY_NONE;
2000 PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code));
2001 PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain));
2002 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
2003 PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level));
2004 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
2005 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
2006 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
2007 PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1));
2008 PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2));
2010 return info;
2013 static void
2014 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err)
2016 PyObject *list, *info;
2017 PyObject *result;
2019 DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
2020 err->message);
2022 if ((err == NULL) || (err->code == VIR_ERR_OK))
2023 return;
2025 LIBVIRT_ENSURE_THREAD_STATE;
2027 if ((libvirt_virPythonErrorFuncHandler == NULL) ||
2028 (libvirt_virPythonErrorFuncHandler == Py_None)) {
2029 virDefaultErrorFunc(err);
2030 } else {
2031 list = PyTuple_New(2);
2032 info = PyTuple_New(9);
2033 PyTuple_SetItem(list, 0, libvirt_virPythonErrorFuncCtxt);
2034 PyTuple_SetItem(list, 1, info);
2035 Py_XINCREF(libvirt_virPythonErrorFuncCtxt);
2036 PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code));
2037 PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain));
2038 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
2039 PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level));
2040 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
2041 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
2042 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
2043 PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1));
2044 PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2));
2045 /* TODO pass conn and dom if available */
2046 result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
2047 Py_XDECREF(list);
2048 Py_XDECREF(result);
2051 LIBVIRT_RELEASE_THREAD_STATE;
2054 static PyObject *
2055 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
2056 PyObject * args)
2058 PyObject *py_retval;
2059 PyObject *pyobj_f;
2060 PyObject *pyobj_ctx;
2062 if (!PyArg_ParseTuple
2063 (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f,
2064 &pyobj_ctx))
2065 return NULL;
2067 DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
2068 pyobj_f);
2070 virSetErrorFunc(NULL, libvirt_virErrorFuncHandler);
2071 if (libvirt_virPythonErrorFuncHandler != NULL) {
2072 Py_XDECREF(libvirt_virPythonErrorFuncHandler);
2074 if (libvirt_virPythonErrorFuncCtxt != NULL) {
2075 Py_XDECREF(libvirt_virPythonErrorFuncCtxt);
2078 if ((pyobj_f == Py_None) && (pyobj_ctx == Py_None)) {
2079 libvirt_virPythonErrorFuncHandler = NULL;
2080 libvirt_virPythonErrorFuncCtxt = NULL;
2081 } else {
2082 Py_XINCREF(pyobj_ctx);
2083 Py_XINCREF(pyobj_f);
2085 /* TODO: check f is a function ! */
2086 libvirt_virPythonErrorFuncHandler = pyobj_f;
2087 libvirt_virPythonErrorFuncCtxt = pyobj_ctx;
2090 py_retval = libvirt_intWrap(1);
2091 return py_retval;
2094 static int virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
2095 unsigned int ncred,
2096 void *cbdata) {
2097 PyObject *list;
2098 PyObject *pycred;
2099 PyObject *pyauth = (PyObject *)cbdata;
2100 PyObject *pycbdata;
2101 PyObject *pycb;
2102 PyObject *pyret;
2103 int ret = -1;
2104 size_t i;
2106 LIBVIRT_ENSURE_THREAD_STATE;
2108 pycb = PyList_GetItem(pyauth, 1);
2109 pycbdata = PyList_GetItem(pyauth, 2);
2111 list = PyTuple_New(2);
2112 pycred = PyTuple_New(ncred);
2113 for (i = 0; i < ncred; i++) {
2114 PyObject *pycreditem;
2115 pycreditem = PyList_New(5);
2116 Py_INCREF(Py_None);
2117 PyTuple_SetItem(pycred, i, pycreditem);
2118 PyList_SetItem(pycreditem, 0, PyInt_FromLong((long) cred[i].type));
2119 PyList_SetItem(pycreditem, 1, PyString_FromString(cred[i].prompt));
2120 if (cred[i].challenge) {
2121 PyList_SetItem(pycreditem, 2, PyString_FromString(cred[i].challenge));
2122 } else {
2123 Py_INCREF(Py_None);
2124 PyList_SetItem(pycreditem, 2, Py_None);
2126 if (cred[i].defresult) {
2127 PyList_SetItem(pycreditem, 3, PyString_FromString(cred[i].defresult));
2128 } else {
2129 Py_INCREF(Py_None);
2130 PyList_SetItem(pycreditem, 3, Py_None);
2132 PyList_SetItem(pycreditem, 4, Py_None);
2135 PyTuple_SetItem(list, 0, pycred);
2136 Py_XINCREF(pycbdata);
2137 PyTuple_SetItem(list, 1, pycbdata);
2139 PyErr_Clear();
2140 pyret = PyEval_CallObject(pycb, list);
2141 if (PyErr_Occurred()) {
2142 PyErr_Print();
2143 goto cleanup;
2146 ret = PyLong_AsLong(pyret);
2147 if (ret == 0) {
2148 for (i = 0; i < ncred; i++) {
2149 PyObject *pycreditem;
2150 PyObject *pyresult;
2151 char *result = NULL;
2152 pycreditem = PyTuple_GetItem(pycred, i);
2153 pyresult = PyList_GetItem(pycreditem, 4);
2154 if (pyresult != Py_None)
2155 result = PyString_AsString(pyresult);
2156 if (result != NULL) {
2157 cred[i].result = strdup(result);
2158 cred[i].resultlen = strlen(result);
2159 } else {
2160 cred[i].result = NULL;
2161 cred[i].resultlen = 0;
2166 cleanup:
2167 Py_XDECREF(list);
2168 Py_XDECREF(pyret);
2170 LIBVIRT_RELEASE_THREAD_STATE;
2172 return ret;
2176 static PyObject *
2177 libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2178 PyObject *py_retval;
2179 virConnectPtr c_retval;
2180 char * name;
2181 unsigned int flags;
2182 PyObject *pyauth;
2183 PyObject *pycredcb;
2184 PyObject *pycredtype;
2185 virConnectAuth auth;
2187 memset(&auth, 0, sizeof(auth));
2188 if (!PyArg_ParseTuple(args, (char *)"zOi:virConnectOpenAuth", &name, &pyauth, &flags))
2189 return NULL;
2191 pycredtype = PyList_GetItem(pyauth, 0);
2192 pycredcb = PyList_GetItem(pyauth, 1);
2194 auth.ncredtype = PyList_Size(pycredtype);
2195 if (auth.ncredtype) {
2196 size_t i;
2197 if (VIR_ALLOC_N_QUIET(auth.credtype, auth.ncredtype) < 0)
2198 return VIR_PY_NONE;
2199 for (i = 0; i < auth.ncredtype; i++) {
2200 PyObject *val;
2201 val = PyList_GetItem(pycredtype, i);
2202 auth.credtype[i] = (int)PyLong_AsLong(val);
2205 if (pycredcb && pycredcb != Py_None)
2206 auth.cb = virConnectCredCallbackWrapper;
2207 auth.cbdata = pyauth;
2209 LIBVIRT_BEGIN_ALLOW_THREADS;
2211 c_retval = virConnectOpenAuth(name, &auth, flags);
2212 LIBVIRT_END_ALLOW_THREADS;
2213 VIR_FREE(auth.credtype);
2214 py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval);
2215 return py_retval;
2219 /************************************************************************
2221 * Wrappers for functions where generator fails *
2223 ************************************************************************/
2225 static PyObject *
2226 libvirt_virGetVersion(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2228 char *type = NULL;
2229 unsigned long libVer, typeVer = 0;
2230 int c_retval;
2232 if (!PyArg_ParseTuple(args, (char *) "|s", &type))
2233 return NULL;
2235 LIBVIRT_BEGIN_ALLOW_THREADS;
2237 if (type == NULL)
2238 c_retval = virGetVersion(&libVer, NULL, NULL);
2239 else
2240 c_retval = virGetVersion(&libVer, type, &typeVer);
2242 LIBVIRT_END_ALLOW_THREADS;
2244 if (c_retval == -1)
2245 return VIR_PY_NONE;
2247 if (type == NULL)
2248 return PyInt_FromLong(libVer);
2249 else
2250 return Py_BuildValue((char *) "kk", libVer, typeVer);
2253 static PyObject *
2254 libvirt_virConnectGetVersion(PyObject *self ATTRIBUTE_UNUSED,
2255 PyObject *args)
2257 unsigned long hvVersion;
2258 int c_retval;
2259 virConnectPtr conn;
2260 PyObject *pyobj_conn;
2262 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetVersion",
2263 &pyobj_conn))
2264 return NULL;
2265 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2267 LIBVIRT_BEGIN_ALLOW_THREADS;
2269 c_retval = virConnectGetVersion(conn, &hvVersion);
2271 LIBVIRT_END_ALLOW_THREADS;
2273 if (c_retval == -1)
2274 return VIR_PY_INT_FAIL;
2276 return PyInt_FromLong(hvVersion);
2279 static PyObject *
2280 libvirt_virConnectGetLibVersion(PyObject *self ATTRIBUTE_UNUSED,
2281 PyObject *args)
2283 unsigned long libVer;
2284 int c_retval;
2285 virConnectPtr conn;
2286 PyObject *pyobj_conn;
2288 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetLibVersion",
2289 &pyobj_conn))
2290 return NULL;
2291 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2293 LIBVIRT_BEGIN_ALLOW_THREADS;
2295 c_retval = virConnectGetLibVersion(conn, &libVer);
2297 LIBVIRT_END_ALLOW_THREADS;
2299 if (c_retval == -1)
2300 return VIR_PY_INT_FAIL;
2302 return PyInt_FromLong(libVer);
2305 static PyObject *
2306 libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
2307 PyObject *args) {
2308 PyObject *py_retval;
2309 int *ids = NULL, c_retval;
2310 size_t i;
2311 virConnectPtr conn;
2312 PyObject *pyobj_conn;
2315 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDomains", &pyobj_conn))
2316 return NULL;
2317 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2319 LIBVIRT_BEGIN_ALLOW_THREADS;
2320 c_retval = virConnectNumOfDomains(conn);
2321 LIBVIRT_END_ALLOW_THREADS;
2322 if (c_retval < 0)
2323 return VIR_PY_NONE;
2325 if (c_retval) {
2326 if (VIR_ALLOC_N_QUIET(ids, c_retval) < 0)
2327 return VIR_PY_NONE;
2329 LIBVIRT_BEGIN_ALLOW_THREADS;
2330 c_retval = virConnectListDomains(conn, ids, c_retval);
2331 LIBVIRT_END_ALLOW_THREADS;
2332 if (c_retval < 0) {
2333 VIR_FREE(ids);
2334 return VIR_PY_NONE;
2337 py_retval = PyList_New(c_retval);
2339 if (ids) {
2340 for (i = 0; i < c_retval; i++) {
2341 PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
2343 VIR_FREE(ids);
2346 return py_retval;
2349 static PyObject *
2350 libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
2351 PyObject *args)
2353 PyObject *pyobj_conn;
2354 PyObject *py_retval = NULL;
2355 PyObject *tmp = NULL;
2356 virConnectPtr conn;
2357 virDomainPtr *doms = NULL;
2358 int c_retval = 0;
2359 size_t i;
2360 unsigned int flags;
2362 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllDomains",
2363 &pyobj_conn, &flags))
2364 return NULL;
2365 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2367 LIBVIRT_BEGIN_ALLOW_THREADS;
2368 c_retval = virConnectListAllDomains(conn, &doms, flags);
2369 LIBVIRT_END_ALLOW_THREADS;
2370 if (c_retval < 0)
2371 return VIR_PY_NONE;
2373 if (!(py_retval = PyList_New(c_retval)))
2374 goto cleanup;
2376 for (i = 0; i < c_retval; i++) {
2377 if (!(tmp = libvirt_virDomainPtrWrap(doms[i])) ||
2378 PyList_SetItem(py_retval, i, tmp) < 0) {
2379 Py_XDECREF(tmp);
2380 Py_DECREF(py_retval);
2381 py_retval = NULL;
2382 goto cleanup;
2384 /* python steals the pointer */
2385 doms[i] = NULL;
2388 cleanup:
2389 for (i = 0; i < c_retval; i++)
2390 if (doms[i])
2391 virDomainFree(doms[i]);
2392 VIR_FREE(doms);
2393 return py_retval;
2396 static PyObject *
2397 libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
2398 PyObject *args) {
2399 PyObject *py_retval;
2400 char **names = NULL;
2401 int c_retval;
2402 size_t i;
2403 virConnectPtr conn;
2404 PyObject *pyobj_conn;
2407 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedDomains", &pyobj_conn))
2408 return NULL;
2409 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2411 LIBVIRT_BEGIN_ALLOW_THREADS;
2412 c_retval = virConnectNumOfDefinedDomains(conn);
2413 LIBVIRT_END_ALLOW_THREADS;
2414 if (c_retval < 0)
2415 return VIR_PY_NONE;
2417 if (c_retval) {
2418 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
2419 return VIR_PY_NONE;
2420 LIBVIRT_BEGIN_ALLOW_THREADS;
2421 c_retval = virConnectListDefinedDomains(conn, names, c_retval);
2422 LIBVIRT_END_ALLOW_THREADS;
2423 if (c_retval < 0) {
2424 VIR_FREE(names);
2425 return VIR_PY_NONE;
2428 py_retval = PyList_New(c_retval);
2430 if (names) {
2431 for (i = 0; i < c_retval; i++) {
2432 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2433 VIR_FREE(names[i]);
2435 VIR_FREE(names);
2438 return py_retval;
2441 static PyObject *
2442 libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
2443 PyObject *args)
2445 PyObject *py_retval;
2446 char **names = NULL;
2447 int c_retval;
2448 size_t i;
2449 virDomainPtr dom;
2450 PyObject *pyobj_dom;
2451 PyObject *pyobj_snap;
2452 unsigned int flags;
2454 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames",
2455 &pyobj_dom, &flags))
2456 return NULL;
2457 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2459 LIBVIRT_BEGIN_ALLOW_THREADS;
2460 c_retval = virDomainSnapshotNum(dom, flags);
2461 LIBVIRT_END_ALLOW_THREADS;
2462 if (c_retval < 0)
2463 return VIR_PY_NONE;
2465 if (c_retval) {
2466 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
2467 return PyErr_NoMemory();
2468 LIBVIRT_BEGIN_ALLOW_THREADS;
2469 c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
2470 LIBVIRT_END_ALLOW_THREADS;
2471 if (c_retval < 0) {
2472 VIR_FREE(names);
2473 return VIR_PY_NONE;
2476 py_retval = PyList_New(c_retval);
2477 if (!py_retval)
2478 goto cleanup;
2480 for (i = 0; i < c_retval; i++) {
2481 if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
2482 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2483 Py_XDECREF(pyobj_snap);
2484 Py_DECREF(py_retval);
2485 py_retval = NULL;
2486 goto cleanup;
2488 VIR_FREE(names[i]);
2491 cleanup:
2492 for (i = 0; i < c_retval; i++)
2493 VIR_FREE(names[i]);
2494 VIR_FREE(names);
2495 return py_retval;
2498 static PyObject *
2499 libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
2500 PyObject *args)
2502 PyObject *py_retval = NULL;
2503 virDomainSnapshotPtr *snaps = NULL;
2504 int c_retval;
2505 size_t i;
2506 virDomainPtr dom;
2507 PyObject *pyobj_dom;
2508 unsigned int flags;
2509 PyObject *pyobj_snap;
2511 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainListAllSnapshots",
2512 &pyobj_dom, &flags))
2513 return NULL;
2514 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2516 LIBVIRT_BEGIN_ALLOW_THREADS;
2517 c_retval = virDomainListAllSnapshots(dom, &snaps, flags);
2518 LIBVIRT_END_ALLOW_THREADS;
2519 if (c_retval < 0)
2520 return VIR_PY_NONE;
2522 if (!(py_retval = PyList_New(c_retval)))
2523 goto cleanup;
2525 for (i = 0; i < c_retval; i++) {
2526 if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
2527 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2528 Py_XDECREF(pyobj_snap);
2529 Py_DECREF(py_retval);
2530 py_retval = NULL;
2531 goto cleanup;
2533 snaps[i] = NULL;
2536 cleanup:
2537 for (i = 0; i < c_retval; i++)
2538 if (snaps[i])
2539 virDomainSnapshotFree(snaps[i]);
2540 VIR_FREE(snaps);
2541 return py_retval;
2544 static PyObject *
2545 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
2546 PyObject *args)
2548 PyObject *py_retval;
2549 char **names = NULL;
2550 int c_retval;
2551 size_t i;
2552 virDomainSnapshotPtr snap;
2553 PyObject *pyobj_snap;
2554 unsigned int flags;
2556 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListChildrenNames",
2557 &pyobj_snap, &flags))
2558 return NULL;
2559 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2561 LIBVIRT_BEGIN_ALLOW_THREADS;
2562 c_retval = virDomainSnapshotNumChildren(snap, flags);
2563 LIBVIRT_END_ALLOW_THREADS;
2564 if (c_retval < 0)
2565 return VIR_PY_NONE;
2567 if (c_retval) {
2568 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
2569 return PyErr_NoMemory();
2570 LIBVIRT_BEGIN_ALLOW_THREADS;
2571 c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
2572 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);
2581 for (i = 0; i < c_retval; i++) {
2582 if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
2583 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2584 Py_XDECREF(pyobj_snap);
2585 Py_DECREF(py_retval);
2586 py_retval = NULL;
2587 goto cleanup;
2589 VIR_FREE(names[i]);
2592 cleanup:
2593 for (i = 0; i < c_retval; i++)
2594 VIR_FREE(names[i]);
2595 VIR_FREE(names);
2596 return py_retval;
2599 static PyObject *
2600 libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2601 PyObject *args)
2603 PyObject *py_retval = NULL;
2604 virDomainSnapshotPtr *snaps = NULL;
2605 int c_retval;
2606 size_t i;
2607 virDomainSnapshotPtr parent;
2608 PyObject *pyobj_parent;
2609 unsigned int flags;
2610 PyObject *pyobj_snap;
2612 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListAllChildren",
2613 &pyobj_parent, &flags))
2614 return NULL;
2615 parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
2617 LIBVIRT_BEGIN_ALLOW_THREADS;
2618 c_retval = virDomainSnapshotListAllChildren(parent, &snaps, flags);
2619 LIBVIRT_END_ALLOW_THREADS;
2620 if (c_retval < 0)
2621 return VIR_PY_NONE;
2623 if (!(py_retval = PyList_New(c_retval)))
2624 goto cleanup;
2626 for (i = 0; i < c_retval; i++) {
2627 if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
2628 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2629 Py_XDECREF(pyobj_snap);
2630 Py_DECREF(py_retval);
2631 py_retval = NULL;
2632 goto cleanup;
2634 snaps[i] = NULL;
2637 cleanup:
2638 for (i = 0; i < c_retval; i++)
2639 if (snaps[i])
2640 virDomainSnapshotFree(snaps[i]);
2641 VIR_FREE(snaps);
2642 return py_retval;
2645 static PyObject *
2646 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
2647 PyObject *args) {
2648 int c_retval;
2649 virDomainSnapshotPtr snap;
2650 PyObject *pyobj_snap;
2651 PyObject *pyobj_dom;
2652 unsigned int flags;
2654 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainRevertToSnapshot", &pyobj_dom, &pyobj_snap, &flags))
2655 return NULL;
2656 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2658 LIBVIRT_BEGIN_ALLOW_THREADS;
2659 c_retval = virDomainRevertToSnapshot(snap, flags);
2660 LIBVIRT_END_ALLOW_THREADS;
2661 if (c_retval < 0)
2662 return VIR_PY_INT_FAIL;
2664 return PyInt_FromLong(c_retval);
2667 static PyObject *
2668 libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2669 PyObject *py_retval;
2670 int c_retval;
2671 virDomainPtr domain;
2672 PyObject *pyobj_domain;
2673 virDomainInfo info;
2675 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_domain))
2676 return NULL;
2677 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2679 LIBVIRT_BEGIN_ALLOW_THREADS;
2680 c_retval = virDomainGetInfo(domain, &info);
2681 LIBVIRT_END_ALLOW_THREADS;
2682 if (c_retval < 0)
2683 return VIR_PY_NONE;
2684 py_retval = PyList_New(5);
2685 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
2686 PyList_SetItem(py_retval, 1, libvirt_ulongWrap(info.maxMem));
2687 PyList_SetItem(py_retval, 2, libvirt_ulongWrap(info.memory));
2688 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
2689 PyList_SetItem(py_retval, 4,
2690 libvirt_longlongWrap((unsigned long long) info.cpuTime));
2691 return py_retval;
2694 static PyObject *
2695 libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2697 PyObject *py_retval;
2698 int c_retval;
2699 virDomainPtr domain;
2700 PyObject *pyobj_domain;
2701 int state;
2702 int reason;
2703 unsigned int flags;
2705 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetState",
2706 &pyobj_domain, &flags))
2707 return NULL;
2709 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2711 LIBVIRT_BEGIN_ALLOW_THREADS;
2712 c_retval = virDomainGetState(domain, &state, &reason, flags);
2713 LIBVIRT_END_ALLOW_THREADS;
2714 if (c_retval < 0)
2715 return VIR_PY_NONE;
2717 py_retval = PyList_New(2);
2718 PyList_SetItem(py_retval, 0, libvirt_intWrap(state));
2719 PyList_SetItem(py_retval, 1, libvirt_intWrap(reason));
2720 return py_retval;
2723 static PyObject *
2724 libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2725 PyObject *py_retval;
2726 int c_retval;
2727 virDomainPtr domain;
2728 PyObject *pyobj_domain;
2729 virDomainControlInfo info;
2730 unsigned int flags;
2732 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetControlInfo",
2733 &pyobj_domain, &flags))
2734 return NULL;
2735 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2737 LIBVIRT_BEGIN_ALLOW_THREADS;
2738 c_retval = virDomainGetControlInfo(domain, &info, flags);
2739 LIBVIRT_END_ALLOW_THREADS;
2740 if (c_retval < 0)
2741 return VIR_PY_NONE;
2742 py_retval = PyList_New(3);
2743 PyList_SetItem(py_retval, 0, libvirt_intWrap(info.state));
2744 PyList_SetItem(py_retval, 1, libvirt_intWrap(info.details));
2745 PyList_SetItem(py_retval, 2, libvirt_longlongWrap(info.stateTime));
2746 return py_retval;
2749 static PyObject *
2750 libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2751 PyObject *py_retval;
2752 int c_retval;
2753 virDomainPtr domain;
2754 PyObject *pyobj_domain;
2755 virDomainBlockInfo info;
2756 const char *path;
2757 unsigned int flags;
2759 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInfo", &pyobj_domain, &path, &flags))
2760 return NULL;
2761 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2763 LIBVIRT_BEGIN_ALLOW_THREADS;
2764 c_retval = virDomainGetBlockInfo(domain, path, &info, flags);
2765 LIBVIRT_END_ALLOW_THREADS;
2766 if (c_retval < 0)
2767 return VIR_PY_NONE;
2768 py_retval = PyList_New(3);
2769 PyList_SetItem(py_retval, 0, libvirt_ulonglongWrap(info.capacity));
2770 PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.allocation));
2771 PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.physical));
2772 return py_retval;
2775 static PyObject *
2776 libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2777 PyObject *py_retval;
2778 int c_retval;
2779 virConnectPtr conn;
2780 PyObject *pyobj_conn;
2781 virNodeInfo info;
2783 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_conn))
2784 return NULL;
2785 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2787 LIBVIRT_BEGIN_ALLOW_THREADS;
2788 c_retval = virNodeGetInfo(conn, &info);
2789 LIBVIRT_END_ALLOW_THREADS;
2790 if (c_retval < 0)
2791 return VIR_PY_NONE;
2792 py_retval = PyList_New(8);
2793 PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&info.model[0]));
2794 PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.memory >> 10));
2795 PyList_SetItem(py_retval, 2, libvirt_intWrap((int) info.cpus));
2796 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.mhz));
2797 PyList_SetItem(py_retval, 4, libvirt_intWrap((int) info.nodes));
2798 PyList_SetItem(py_retval, 5, libvirt_intWrap((int) info.sockets));
2799 PyList_SetItem(py_retval, 6, libvirt_intWrap((int) info.cores));
2800 PyList_SetItem(py_retval, 7, libvirt_intWrap((int) info.threads));
2801 return py_retval;
2804 static PyObject *
2805 libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2806 PyObject *py_retval;
2807 unsigned char uuid[VIR_UUID_BUFLEN];
2808 virDomainPtr domain;
2809 PyObject *pyobj_domain;
2810 int c_retval;
2812 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
2813 return NULL;
2814 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2816 if (domain == NULL)
2817 return VIR_PY_NONE;
2818 LIBVIRT_BEGIN_ALLOW_THREADS;
2819 c_retval = virDomainGetUUID(domain, &uuid[0]);
2820 LIBVIRT_END_ALLOW_THREADS;
2822 if (c_retval < 0)
2823 return VIR_PY_NONE;
2824 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
2826 return py_retval;
2829 static PyObject *
2830 libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
2831 PyObject *args) {
2832 PyObject *py_retval;
2833 char uuidstr[VIR_UUID_STRING_BUFLEN];
2834 virDomainPtr dom;
2835 PyObject *pyobj_dom;
2836 int c_retval;
2838 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString",
2839 &pyobj_dom))
2840 return NULL;
2841 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2843 if (dom == NULL)
2844 return VIR_PY_NONE;
2845 LIBVIRT_BEGIN_ALLOW_THREADS;
2846 c_retval = virDomainGetUUIDString(dom, &uuidstr[0]);
2847 LIBVIRT_END_ALLOW_THREADS;
2849 if (c_retval < 0)
2850 return VIR_PY_NONE;
2852 py_retval = PyString_FromString((char *) &uuidstr[0]);
2853 return py_retval;
2856 static PyObject *
2857 libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2858 PyObject *py_retval;
2859 virDomainPtr c_retval;
2860 virConnectPtr conn;
2861 PyObject *pyobj_conn;
2862 unsigned char * uuid;
2863 int len;
2865 if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID", &pyobj_conn, &uuid, &len))
2866 return NULL;
2867 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2869 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
2870 return VIR_PY_NONE;
2872 LIBVIRT_BEGIN_ALLOW_THREADS;
2873 c_retval = virDomainLookupByUUID(conn, uuid);
2874 LIBVIRT_END_ALLOW_THREADS;
2875 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
2876 return py_retval;
2880 static PyObject *
2881 libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
2882 PyObject *args) {
2883 PyObject *py_retval;
2884 char **names = NULL;
2885 int c_retval;
2886 size_t i;
2887 virConnectPtr conn;
2888 PyObject *pyobj_conn;
2891 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks", &pyobj_conn))
2892 return NULL;
2893 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2895 LIBVIRT_BEGIN_ALLOW_THREADS;
2896 c_retval = virConnectNumOfNetworks(conn);
2897 LIBVIRT_END_ALLOW_THREADS;
2898 if (c_retval < 0)
2899 return VIR_PY_NONE;
2901 if (c_retval) {
2902 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
2903 return VIR_PY_NONE;
2904 LIBVIRT_BEGIN_ALLOW_THREADS;
2905 c_retval = virConnectListNetworks(conn, names, c_retval);
2906 LIBVIRT_END_ALLOW_THREADS;
2907 if (c_retval < 0) {
2908 VIR_FREE(names);
2909 return VIR_PY_NONE;
2912 py_retval = PyList_New(c_retval);
2914 if (names) {
2915 for (i = 0; i < c_retval; i++) {
2916 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2917 VIR_FREE(names[i]);
2919 VIR_FREE(names);
2922 return py_retval;
2926 static PyObject *
2927 libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
2928 PyObject *args) {
2929 PyObject *py_retval;
2930 char **names = NULL;
2931 int c_retval;
2932 size_t i;
2933 virConnectPtr conn;
2934 PyObject *pyobj_conn;
2937 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks", &pyobj_conn))
2938 return NULL;
2939 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2941 LIBVIRT_BEGIN_ALLOW_THREADS;
2942 c_retval = virConnectNumOfDefinedNetworks(conn);
2943 LIBVIRT_END_ALLOW_THREADS;
2944 if (c_retval < 0)
2945 return VIR_PY_NONE;
2947 if (c_retval) {
2948 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
2949 return VIR_PY_NONE;
2950 LIBVIRT_BEGIN_ALLOW_THREADS;
2951 c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
2952 LIBVIRT_END_ALLOW_THREADS;
2953 if (c_retval < 0) {
2954 VIR_FREE(names);
2955 return VIR_PY_NONE;
2958 py_retval = PyList_New(c_retval);
2960 if (names) {
2961 for (i = 0; i < c_retval; i++) {
2962 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2963 VIR_FREE(names[i]);
2965 VIR_FREE(names);
2968 return py_retval;
2971 static PyObject *
2972 libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
2973 PyObject *args)
2975 PyObject *pyobj_conn;
2976 PyObject *py_retval = NULL;
2977 PyObject *tmp = NULL;
2978 virConnectPtr conn;
2979 virNetworkPtr *nets = NULL;
2980 int c_retval = 0;
2981 size_t i;
2982 unsigned int flags;
2984 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNetworks",
2985 &pyobj_conn, &flags))
2986 return NULL;
2987 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2989 LIBVIRT_BEGIN_ALLOW_THREADS;
2990 c_retval = virConnectListAllNetworks(conn, &nets, flags);
2991 LIBVIRT_END_ALLOW_THREADS;
2992 if (c_retval < 0)
2993 return VIR_PY_NONE;
2995 if (!(py_retval = PyList_New(c_retval)))
2996 goto cleanup;
2998 for (i = 0; i < c_retval; i++) {
2999 if (!(tmp = libvirt_virNetworkPtrWrap(nets[i])) ||
3000 PyList_SetItem(py_retval, i, tmp) < 0) {
3001 Py_XDECREF(tmp);
3002 Py_DECREF(py_retval);
3003 py_retval = NULL;
3004 goto cleanup;
3006 /* python steals the pointer */
3007 nets[i] = NULL;
3010 cleanup:
3011 for (i = 0; i < c_retval; i++)
3012 if (nets[i])
3013 virNetworkFree(nets[i]);
3014 VIR_FREE(nets);
3015 return py_retval;
3019 static PyObject *
3020 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3021 PyObject *py_retval;
3022 unsigned char uuid[VIR_UUID_BUFLEN];
3023 virNetworkPtr domain;
3024 PyObject *pyobj_domain;
3025 int c_retval;
3027 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain))
3028 return NULL;
3029 domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
3031 if (domain == NULL)
3032 return VIR_PY_NONE;
3033 LIBVIRT_BEGIN_ALLOW_THREADS;
3034 c_retval = virNetworkGetUUID(domain, &uuid[0]);
3035 LIBVIRT_END_ALLOW_THREADS;
3037 if (c_retval < 0)
3038 return VIR_PY_NONE;
3039 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
3041 return py_retval;
3044 static PyObject *
3045 libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3046 PyObject *args) {
3047 PyObject *py_retval;
3048 char uuidstr[VIR_UUID_STRING_BUFLEN];
3049 virNetworkPtr net;
3050 PyObject *pyobj_net;
3051 int c_retval;
3053 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString",
3054 &pyobj_net))
3055 return NULL;
3056 net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net);
3058 if (net == NULL)
3059 return VIR_PY_NONE;
3060 LIBVIRT_BEGIN_ALLOW_THREADS;
3061 c_retval = virNetworkGetUUIDString(net, &uuidstr[0]);
3062 LIBVIRT_END_ALLOW_THREADS;
3064 if (c_retval < 0)
3065 return VIR_PY_NONE;
3067 py_retval = PyString_FromString((char *) &uuidstr[0]);
3068 return py_retval;
3071 static PyObject *
3072 libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3073 PyObject *py_retval;
3074 virNetworkPtr c_retval;
3075 virConnectPtr conn;
3076 PyObject *pyobj_conn;
3077 unsigned char * uuid;
3078 int len;
3080 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID", &pyobj_conn, &uuid, &len))
3081 return NULL;
3082 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3084 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3085 return VIR_PY_NONE;
3087 LIBVIRT_BEGIN_ALLOW_THREADS;
3088 c_retval = virNetworkLookupByUUID(conn, uuid);
3089 LIBVIRT_END_ALLOW_THREADS;
3090 py_retval = libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval);
3091 return py_retval;
3095 static PyObject *
3096 libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3097 PyObject *py_retval;
3098 int c_retval, autostart;
3099 virDomainPtr domain;
3100 PyObject *pyobj_domain;
3102 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetAutostart", &pyobj_domain))
3103 return NULL;
3105 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
3107 LIBVIRT_BEGIN_ALLOW_THREADS;
3108 c_retval = virDomainGetAutostart(domain, &autostart);
3109 LIBVIRT_END_ALLOW_THREADS;
3111 if (c_retval < 0)
3112 return VIR_PY_INT_FAIL;
3113 py_retval = libvirt_intWrap(autostart);
3114 return py_retval;
3118 static PyObject *
3119 libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3120 PyObject *py_retval;
3121 int c_retval, autostart;
3122 virNetworkPtr network;
3123 PyObject *pyobj_network;
3125 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetAutostart", &pyobj_network))
3126 return NULL;
3128 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
3130 LIBVIRT_BEGIN_ALLOW_THREADS;
3131 c_retval = virNetworkGetAutostart(network, &autostart);
3132 LIBVIRT_END_ALLOW_THREADS;
3134 if (c_retval < 0)
3135 return VIR_PY_INT_FAIL;
3136 py_retval = libvirt_intWrap(autostart);
3137 return py_retval;
3140 static PyObject *
3141 libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
3143 PyObject *py_retval;
3144 PyObject *pyobj_conn;
3145 int startCell, maxCells, c_retval;
3146 size_t i;
3147 virConnectPtr conn;
3148 unsigned long long *freeMems;
3150 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory", &pyobj_conn, &startCell, &maxCells))
3151 return NULL;
3153 if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
3154 return VIR_PY_NONE;
3156 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3157 if (VIR_ALLOC_N_QUIET(freeMems, maxCells) < 0)
3158 return VIR_PY_NONE;
3160 LIBVIRT_BEGIN_ALLOW_THREADS;
3161 c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
3162 LIBVIRT_END_ALLOW_THREADS;
3164 if (c_retval < 0) {
3165 VIR_FREE(freeMems);
3166 return VIR_PY_NONE;
3168 py_retval = PyList_New(c_retval);
3169 for (i = 0; i < c_retval; i++) {
3170 PyList_SetItem(py_retval, i,
3171 libvirt_longlongWrap((long long) freeMems[i]));
3173 VIR_FREE(freeMems);
3174 return py_retval;
3177 static PyObject *
3178 libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
3180 PyObject *ret = NULL;
3181 PyObject *key = NULL;
3182 PyObject *val = NULL;
3183 PyObject *pyobj_conn;
3184 virConnectPtr conn;
3185 unsigned int flags;
3186 int cpuNum, c_retval;
3187 size_t i;
3188 int nparams = 0;
3189 virNodeCPUStatsPtr stats = NULL;
3191 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn, &cpuNum, &flags))
3192 return ret;
3193 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3195 LIBVIRT_BEGIN_ALLOW_THREADS;
3196 c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
3197 LIBVIRT_END_ALLOW_THREADS;
3198 if (c_retval < 0)
3199 return VIR_PY_NONE;
3201 if (nparams) {
3202 if (VIR_ALLOC_N_QUIET(stats, nparams) < 0)
3203 return PyErr_NoMemory();
3205 LIBVIRT_BEGIN_ALLOW_THREADS;
3206 c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
3207 LIBVIRT_END_ALLOW_THREADS;
3208 if (c_retval < 0) {
3209 VIR_FREE(stats);
3210 return VIR_PY_NONE;
3214 if (!(ret = PyDict_New()))
3215 goto error;
3217 for (i = 0; i < nparams; i++) {
3218 key = libvirt_constcharPtrWrap(stats[i].field);
3219 val = libvirt_ulonglongWrap(stats[i].value);
3221 if (!key || !val || PyDict_SetItem(ret, key, val) < 0) {
3222 Py_DECREF(ret);
3223 ret = NULL;
3224 goto error;
3227 Py_DECREF(key);
3228 Py_DECREF(val);
3231 VIR_FREE(stats);
3232 return ret;
3234 error:
3235 VIR_FREE(stats);
3236 Py_XDECREF(key);
3237 Py_XDECREF(val);
3238 return ret;
3241 static PyObject *
3242 libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
3244 PyObject *ret = NULL;
3245 PyObject *key = NULL;
3246 PyObject *val = NULL;
3247 PyObject *pyobj_conn;
3248 virConnectPtr conn;
3249 unsigned int flags;
3250 int cellNum, c_retval;
3251 size_t i;
3252 int nparams = 0;
3253 virNodeMemoryStatsPtr stats = NULL;
3255 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetMemoryStats", &pyobj_conn, &cellNum, &flags))
3256 return ret;
3257 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
3259 LIBVIRT_BEGIN_ALLOW_THREADS;
3260 c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
3261 LIBVIRT_END_ALLOW_THREADS;
3262 if (c_retval < 0)
3263 return VIR_PY_NONE;
3265 if (nparams) {
3266 if (VIR_ALLOC_N_QUIET(stats, nparams) < 0)
3267 return PyErr_NoMemory();
3269 LIBVIRT_BEGIN_ALLOW_THREADS;
3270 c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
3271 LIBVIRT_END_ALLOW_THREADS;
3272 if (c_retval < 0) {
3273 VIR_FREE(stats);
3274 return VIR_PY_NONE;
3278 if (!(ret = PyDict_New()))
3279 goto error;
3281 for (i = 0; i < nparams; i++) {
3282 key = libvirt_constcharPtrWrap(stats[i].field);
3283 val = libvirt_ulonglongWrap(stats[i].value);
3285 if (!key || !val || PyDict_SetItem(ret, key, val) < 0) {
3286 Py_DECREF(ret);
3287 ret = NULL;
3288 goto error;
3291 Py_DECREF(key);
3292 Py_DECREF(val);
3295 VIR_FREE(stats);
3296 return ret;
3298 error:
3299 VIR_FREE(stats);
3300 Py_XDECREF(key);
3301 Py_XDECREF(val);
3302 return ret;
3305 static PyObject *
3306 libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3307 PyObject *args) {
3308 PyObject *py_retval;
3309 char **names = NULL;
3310 int c_retval;
3311 size_t i;
3312 virConnectPtr conn;
3313 PyObject *pyobj_conn;
3316 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListStoragePools", &pyobj_conn))
3317 return NULL;
3318 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3320 LIBVIRT_BEGIN_ALLOW_THREADS;
3321 c_retval = virConnectNumOfStoragePools(conn);
3322 LIBVIRT_END_ALLOW_THREADS;
3323 if (c_retval < 0)
3324 return VIR_PY_NONE;
3326 if (c_retval) {
3327 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
3328 return VIR_PY_NONE;
3329 LIBVIRT_BEGIN_ALLOW_THREADS;
3330 c_retval = virConnectListStoragePools(conn, names, c_retval);
3331 LIBVIRT_END_ALLOW_THREADS;
3332 if (c_retval < 0) {
3333 VIR_FREE(names);
3334 return VIR_PY_NONE;
3337 py_retval = PyList_New(c_retval);
3338 if (py_retval == NULL) {
3339 if (names) {
3340 for (i = 0; i < c_retval; i++)
3341 VIR_FREE(names[i]);
3342 VIR_FREE(names);
3344 return VIR_PY_NONE;
3347 if (names) {
3348 for (i = 0; i < c_retval; i++) {
3349 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3350 VIR_FREE(names[i]);
3352 VIR_FREE(names);
3355 return py_retval;
3359 static PyObject *
3360 libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3361 PyObject *args) {
3362 PyObject *py_retval;
3363 char **names = NULL;
3364 int c_retval;
3365 size_t i;
3366 virConnectPtr conn;
3367 PyObject *pyobj_conn;
3370 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedStoragePools", &pyobj_conn))
3371 return NULL;
3372 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3374 LIBVIRT_BEGIN_ALLOW_THREADS;
3375 c_retval = virConnectNumOfDefinedStoragePools(conn);
3376 LIBVIRT_END_ALLOW_THREADS;
3377 if (c_retval < 0)
3378 return VIR_PY_NONE;
3380 if (c_retval) {
3381 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
3382 return VIR_PY_NONE;
3383 LIBVIRT_BEGIN_ALLOW_THREADS;
3384 c_retval = virConnectListDefinedStoragePools(conn, names, c_retval);
3385 LIBVIRT_END_ALLOW_THREADS;
3386 if (c_retval < 0) {
3387 VIR_FREE(names);
3388 return VIR_PY_NONE;
3391 py_retval = PyList_New(c_retval);
3392 if (py_retval == NULL) {
3393 if (names) {
3394 for (i = 0; i < c_retval; i++)
3395 VIR_FREE(names[i]);
3396 VIR_FREE(names);
3398 return VIR_PY_NONE;
3401 if (names) {
3402 for (i = 0; i < c_retval; i++) {
3403 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3404 VIR_FREE(names[i]);
3406 VIR_FREE(names);
3409 return py_retval;
3412 static PyObject *
3413 libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3414 PyObject *args)
3416 PyObject *pyobj_conn;
3417 PyObject *py_retval = NULL;
3418 PyObject *tmp = NULL;
3419 virConnectPtr conn;
3420 virStoragePoolPtr *pools = NULL;
3421 int c_retval = 0;
3422 size_t i;
3423 unsigned int flags;
3425 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllStoragePools",
3426 &pyobj_conn, &flags))
3427 return NULL;
3428 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3430 LIBVIRT_BEGIN_ALLOW_THREADS;
3431 c_retval = virConnectListAllStoragePools(conn, &pools, flags);
3432 LIBVIRT_END_ALLOW_THREADS;
3433 if (c_retval < 0)
3434 return VIR_PY_NONE;
3436 if (!(py_retval = PyList_New(c_retval)))
3437 goto cleanup;
3439 for (i = 0; i < c_retval; i++) {
3440 if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i])) ||
3441 PyList_SetItem(py_retval, i, tmp) < 0) {
3442 Py_XDECREF(tmp);
3443 Py_DECREF(py_retval);
3444 py_retval = NULL;
3445 goto cleanup;
3447 /* python steals the pointer */
3448 pools[i] = NULL;
3451 cleanup:
3452 for (i = 0; i < c_retval; i++)
3453 if (pools[i])
3454 virStoragePoolFree(pools[i]);
3455 VIR_FREE(pools);
3456 return py_retval;
3459 static PyObject *
3460 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
3461 PyObject *args) {
3462 PyObject *py_retval;
3463 char **names = NULL;
3464 int c_retval;
3465 size_t i;
3466 virStoragePoolPtr pool;
3467 PyObject *pyobj_pool;
3470 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolListVolumes", &pyobj_pool))
3471 return NULL;
3472 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3474 LIBVIRT_BEGIN_ALLOW_THREADS;
3475 c_retval = virStoragePoolNumOfVolumes(pool);
3476 LIBVIRT_END_ALLOW_THREADS;
3477 if (c_retval < 0)
3478 return VIR_PY_NONE;
3480 if (c_retval) {
3481 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
3482 return VIR_PY_NONE;
3483 LIBVIRT_BEGIN_ALLOW_THREADS;
3484 c_retval = virStoragePoolListVolumes(pool, names, c_retval);
3485 LIBVIRT_END_ALLOW_THREADS;
3486 if (c_retval < 0) {
3487 VIR_FREE(names);
3488 return VIR_PY_NONE;
3491 py_retval = PyList_New(c_retval);
3492 if (py_retval == NULL) {
3493 if (names) {
3494 for (i = 0; i < c_retval; i++)
3495 VIR_FREE(names[i]);
3496 VIR_FREE(names);
3498 return VIR_PY_NONE;
3501 if (names) {
3502 for (i = 0; i < c_retval; i++) {
3503 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3504 VIR_FREE(names[i]);
3506 VIR_FREE(names);
3509 return py_retval;
3512 static PyObject *
3513 libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
3514 PyObject *args)
3516 PyObject *py_retval = NULL;
3517 PyObject *tmp = NULL;
3518 virStoragePoolPtr pool;
3519 virStorageVolPtr *vols = NULL;
3520 int c_retval = 0;
3521 size_t i;
3522 unsigned int flags;
3523 PyObject *pyobj_pool;
3525 if (!PyArg_ParseTuple(args, (char *)"Oi:virStoragePoolListAllVolumes",
3526 &pyobj_pool, &flags))
3527 return NULL;
3529 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3531 LIBVIRT_BEGIN_ALLOW_THREADS;
3532 c_retval = virStoragePoolListAllVolumes(pool, &vols, flags);
3533 LIBVIRT_END_ALLOW_THREADS;
3534 if (c_retval < 0)
3535 return VIR_PY_NONE;
3537 if (!(py_retval = PyList_New(c_retval)))
3538 goto cleanup;
3540 for (i = 0; i < c_retval; i++) {
3541 if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i])) ||
3542 PyList_SetItem(py_retval, i, tmp) < 0) {
3543 Py_XDECREF(tmp);
3544 Py_DECREF(py_retval);
3545 py_retval = NULL;
3546 goto cleanup;
3548 /* python steals the pointer */
3549 vols[i] = NULL;
3552 cleanup:
3553 for (i = 0; i < c_retval; i++)
3554 if (vols[i])
3555 virStorageVolFree(vols[i]);
3556 VIR_FREE(vols);
3557 return py_retval;
3561 static PyObject *
3562 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3563 PyObject *py_retval;
3564 int c_retval, autostart;
3565 virStoragePoolPtr pool;
3566 PyObject *pyobj_pool;
3568 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetAutostart", &pyobj_pool))
3569 return NULL;
3571 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3573 LIBVIRT_BEGIN_ALLOW_THREADS;
3574 c_retval = virStoragePoolGetAutostart(pool, &autostart);
3575 LIBVIRT_END_ALLOW_THREADS;
3577 if (c_retval < 0)
3578 return VIR_PY_NONE;
3580 py_retval = libvirt_intWrap(autostart);
3581 return py_retval;
3584 static PyObject *
3585 libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3586 PyObject *py_retval;
3587 int c_retval;
3588 virStoragePoolPtr pool;
3589 PyObject *pyobj_pool;
3590 virStoragePoolInfo info;
3592 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetInfo", &pyobj_pool))
3593 return NULL;
3594 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3596 LIBVIRT_BEGIN_ALLOW_THREADS;
3597 c_retval = virStoragePoolGetInfo(pool, &info);
3598 LIBVIRT_END_ALLOW_THREADS;
3599 if (c_retval < 0)
3600 return VIR_PY_NONE;
3602 if ((py_retval = PyList_New(4)) == NULL)
3603 return VIR_PY_NONE;
3605 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
3606 PyList_SetItem(py_retval, 1,
3607 libvirt_longlongWrap((unsigned long long) info.capacity));
3608 PyList_SetItem(py_retval, 2,
3609 libvirt_longlongWrap((unsigned long long) info.allocation));
3610 PyList_SetItem(py_retval, 3,
3611 libvirt_longlongWrap((unsigned long long) info.available));
3612 return py_retval;
3616 static PyObject *
3617 libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3618 PyObject *py_retval;
3619 int c_retval;
3620 virStorageVolPtr pool;
3621 PyObject *pyobj_pool;
3622 virStorageVolInfo info;
3624 if (!PyArg_ParseTuple(args, (char *)"O:virStorageVolGetInfo", &pyobj_pool))
3625 return NULL;
3626 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3628 LIBVIRT_BEGIN_ALLOW_THREADS;
3629 c_retval = virStorageVolGetInfo(pool, &info);
3630 LIBVIRT_END_ALLOW_THREADS;
3631 if (c_retval < 0)
3632 return VIR_PY_NONE;
3634 if ((py_retval = PyList_New(3)) == NULL)
3635 return VIR_PY_NONE;
3636 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
3637 PyList_SetItem(py_retval, 1,
3638 libvirt_longlongWrap((unsigned long long) info.capacity));
3639 PyList_SetItem(py_retval, 2,
3640 libvirt_longlongWrap((unsigned long long) info.allocation));
3641 return py_retval;
3644 static PyObject *
3645 libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3646 PyObject *py_retval;
3647 unsigned char uuid[VIR_UUID_BUFLEN];
3648 virStoragePoolPtr pool;
3649 PyObject *pyobj_pool;
3650 int c_retval;
3652 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUID", &pyobj_pool))
3653 return NULL;
3654 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3656 if (pool == NULL)
3657 return VIR_PY_NONE;
3658 LIBVIRT_BEGIN_ALLOW_THREADS;
3659 c_retval = virStoragePoolGetUUID(pool, &uuid[0]);
3660 LIBVIRT_END_ALLOW_THREADS;
3662 if (c_retval < 0)
3663 return VIR_PY_NONE;
3665 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
3667 return py_retval;
3670 static PyObject *
3671 libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3672 PyObject *args) {
3673 PyObject *py_retval;
3674 char uuidstr[VIR_UUID_STRING_BUFLEN];
3675 virStoragePoolPtr pool;
3676 PyObject *pyobj_pool;
3677 int c_retval;
3679 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString", &pyobj_pool))
3680 return NULL;
3681 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3683 if (pool == NULL)
3684 return VIR_PY_NONE;
3685 LIBVIRT_BEGIN_ALLOW_THREADS;
3686 c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]);
3687 LIBVIRT_END_ALLOW_THREADS;
3689 if (c_retval < 0)
3690 return VIR_PY_NONE;
3692 py_retval = PyString_FromString((char *) &uuidstr[0]);
3693 return py_retval;
3696 static PyObject *
3697 libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3698 PyObject *py_retval;
3699 virStoragePoolPtr c_retval;
3700 virConnectPtr conn;
3701 PyObject *pyobj_conn;
3702 unsigned char * uuid;
3703 int len;
3705 if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID", &pyobj_conn, &uuid, &len))
3706 return NULL;
3707 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3709 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3710 return VIR_PY_NONE;
3712 LIBVIRT_BEGIN_ALLOW_THREADS;
3713 c_retval = virStoragePoolLookupByUUID(conn, uuid);
3714 LIBVIRT_END_ALLOW_THREADS;
3715 py_retval = libvirt_virStoragePoolPtrWrap((virStoragePoolPtr) c_retval);
3716 return py_retval;
3719 static PyObject *
3720 libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
3721 PyObject *args) {
3722 PyObject *py_retval;
3723 char **names = NULL;
3724 int c_retval;
3725 size_t i;
3726 virConnectPtr conn;
3727 PyObject *pyobj_conn;
3728 char *cap;
3729 unsigned int flags;
3731 if (!PyArg_ParseTuple(args, (char *)"Ozi:virNodeListDevices",
3732 &pyobj_conn, &cap, &flags))
3733 return NULL;
3734 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3736 LIBVIRT_BEGIN_ALLOW_THREADS;
3737 c_retval = virNodeNumOfDevices(conn, cap, flags);
3738 LIBVIRT_END_ALLOW_THREADS;
3739 if (c_retval < 0)
3740 return VIR_PY_NONE;
3742 if (c_retval) {
3743 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
3744 return VIR_PY_NONE;
3745 LIBVIRT_BEGIN_ALLOW_THREADS;
3746 c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
3747 LIBVIRT_END_ALLOW_THREADS;
3748 if (c_retval < 0) {
3749 VIR_FREE(names);
3750 return VIR_PY_NONE;
3753 py_retval = PyList_New(c_retval);
3755 if (names) {
3756 for (i = 0; i < c_retval; i++) {
3757 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3758 VIR_FREE(names[i]);
3760 VIR_FREE(names);
3763 return py_retval;
3766 static PyObject *
3767 libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
3768 PyObject *args)
3770 PyObject *pyobj_conn;
3771 PyObject *py_retval = NULL;
3772 PyObject *tmp = NULL;
3773 virConnectPtr conn;
3774 virNodeDevicePtr *devices = NULL;
3775 int c_retval = 0;
3776 size_t i;
3777 unsigned int flags;
3779 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNodeDevices",
3780 &pyobj_conn, &flags))
3781 return NULL;
3782 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3784 LIBVIRT_BEGIN_ALLOW_THREADS;
3785 c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
3786 LIBVIRT_END_ALLOW_THREADS;
3787 if (c_retval < 0)
3788 return VIR_PY_NONE;
3790 if (!(py_retval = PyList_New(c_retval)))
3791 goto cleanup;
3793 for (i = 0; i < c_retval; i++) {
3794 if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i])) ||
3795 PyList_SetItem(py_retval, i, tmp) < 0) {
3796 Py_XDECREF(tmp);
3797 Py_DECREF(py_retval);
3798 py_retval = NULL;
3799 goto cleanup;
3801 /* python steals the pointer */
3802 devices[i] = NULL;
3805 cleanup:
3806 for (i = 0; i < c_retval; i++)
3807 if (devices[i])
3808 virNodeDeviceFree(devices[i]);
3809 VIR_FREE(devices);
3810 return py_retval;
3813 static PyObject *
3814 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
3815 PyObject *args) {
3816 PyObject *py_retval;
3817 char **names = NULL;
3818 int c_retval;
3819 size_t i;
3820 virNodeDevicePtr dev;
3821 PyObject *pyobj_dev;
3823 if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
3824 return NULL;
3825 dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
3827 LIBVIRT_BEGIN_ALLOW_THREADS;
3828 c_retval = virNodeDeviceNumOfCaps(dev);
3829 LIBVIRT_END_ALLOW_THREADS;
3830 if (c_retval < 0)
3831 return VIR_PY_NONE;
3833 if (c_retval) {
3834 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
3835 return VIR_PY_NONE;
3836 LIBVIRT_BEGIN_ALLOW_THREADS;
3837 c_retval = virNodeDeviceListCaps(dev, names, c_retval);
3838 LIBVIRT_END_ALLOW_THREADS;
3839 if (c_retval < 0) {
3840 VIR_FREE(names);
3841 return VIR_PY_NONE;
3844 py_retval = PyList_New(c_retval);
3846 if (names) {
3847 for (i = 0; i < c_retval; i++) {
3848 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3849 VIR_FREE(names[i]);
3851 VIR_FREE(names);
3854 return py_retval;
3857 static PyObject *
3858 libvirt_virSecretGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3859 PyObject *py_retval;
3860 unsigned char uuid[VIR_UUID_BUFLEN];
3861 virSecretPtr secret;
3862 PyObject *pyobj_secret;
3863 int c_retval;
3865 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUID", &pyobj_secret))
3866 return NULL;
3867 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
3869 if (secret == NULL)
3870 return VIR_PY_NONE;
3871 LIBVIRT_BEGIN_ALLOW_THREADS;
3872 c_retval = virSecretGetUUID(secret, &uuid[0]);
3873 LIBVIRT_END_ALLOW_THREADS;
3875 if (c_retval < 0)
3876 return VIR_PY_NONE;
3877 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
3879 return py_retval;
3882 static PyObject *
3883 libvirt_virSecretGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3884 PyObject *args) {
3885 PyObject *py_retval;
3886 char uuidstr[VIR_UUID_STRING_BUFLEN];
3887 virSecretPtr dom;
3888 PyObject *pyobj_dom;
3889 int c_retval;
3891 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUIDString",
3892 &pyobj_dom))
3893 return NULL;
3894 dom = (virSecretPtr) PyvirSecret_Get(pyobj_dom);
3896 if (dom == NULL)
3897 return VIR_PY_NONE;
3898 LIBVIRT_BEGIN_ALLOW_THREADS;
3899 c_retval = virSecretGetUUIDString(dom, &uuidstr[0]);
3900 LIBVIRT_END_ALLOW_THREADS;
3902 if (c_retval < 0)
3903 return VIR_PY_NONE;
3905 py_retval = PyString_FromString((char *) &uuidstr[0]);
3906 return py_retval;
3909 static PyObject *
3910 libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3911 PyObject *py_retval;
3912 virSecretPtr c_retval;
3913 virConnectPtr conn;
3914 PyObject *pyobj_conn;
3915 unsigned char * uuid;
3916 int len;
3918 if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID", &pyobj_conn, &uuid, &len))
3919 return NULL;
3920 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3922 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3923 return VIR_PY_NONE;
3925 LIBVIRT_BEGIN_ALLOW_THREADS;
3926 c_retval = virSecretLookupByUUID(conn, uuid);
3927 LIBVIRT_END_ALLOW_THREADS;
3928 py_retval = libvirt_virSecretPtrWrap((virSecretPtr) c_retval);
3929 return py_retval;
3933 static PyObject *
3934 libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
3935 PyObject *args) {
3936 PyObject *py_retval;
3937 char **uuids = NULL;
3938 virConnectPtr conn;
3939 int c_retval;
3940 size_t i;
3941 PyObject *pyobj_conn;
3943 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
3944 return NULL;
3945 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3947 LIBVIRT_BEGIN_ALLOW_THREADS;
3948 c_retval = virConnectNumOfSecrets(conn);
3949 LIBVIRT_END_ALLOW_THREADS;
3950 if (c_retval < 0)
3951 return VIR_PY_NONE;
3953 if (c_retval) {
3954 if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0)
3955 return VIR_PY_NONE;
3956 LIBVIRT_BEGIN_ALLOW_THREADS;
3957 c_retval = virConnectListSecrets(conn, uuids, c_retval);
3958 LIBVIRT_END_ALLOW_THREADS;
3959 if (c_retval < 0) {
3960 VIR_FREE(uuids);
3961 return VIR_PY_NONE;
3964 py_retval = PyList_New(c_retval);
3966 if (uuids) {
3967 for (i = 0; i < c_retval; i++) {
3968 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
3969 VIR_FREE(uuids[i]);
3971 VIR_FREE(uuids);
3974 return py_retval;
3977 static PyObject *
3978 libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
3979 PyObject *args)
3981 PyObject *pyobj_conn;
3982 PyObject *py_retval = NULL;
3983 PyObject *tmp = NULL;
3984 virConnectPtr conn;
3985 virSecretPtr *secrets = NULL;
3986 int c_retval = 0;
3987 size_t i;
3988 unsigned int flags;
3990 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllSecrets",
3991 &pyobj_conn, &flags))
3992 return NULL;
3993 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3995 LIBVIRT_BEGIN_ALLOW_THREADS;
3996 c_retval = virConnectListAllSecrets(conn, &secrets, flags);
3997 LIBVIRT_END_ALLOW_THREADS;
3998 if (c_retval < 0)
3999 return VIR_PY_NONE;
4001 if (!(py_retval = PyList_New(c_retval)))
4002 goto cleanup;
4004 for (i = 0; i < c_retval; i++) {
4005 if (!(tmp = libvirt_virSecretPtrWrap(secrets[i])) ||
4006 PyList_SetItem(py_retval, i, tmp) < 0) {
4007 Py_XDECREF(tmp);
4008 Py_DECREF(py_retval);
4009 py_retval = NULL;
4010 goto cleanup;
4012 /* python steals the pointer */
4013 secrets[i] = NULL;
4016 cleanup:
4017 for (i = 0; i < c_retval; i++)
4018 if (secrets[i])
4019 virSecretFree(secrets[i]);
4020 VIR_FREE(secrets);
4021 return py_retval;
4024 static PyObject *
4025 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
4026 PyObject *args) {
4027 PyObject *py_retval;
4028 unsigned char *c_retval;
4029 size_t size;
4030 virSecretPtr secret;
4031 PyObject *pyobj_secret;
4032 unsigned int flags;
4034 if (!PyArg_ParseTuple(args, (char *)"Oi:virSecretGetValue", &pyobj_secret,
4035 &flags))
4036 return NULL;
4037 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4039 LIBVIRT_BEGIN_ALLOW_THREADS;
4040 c_retval = virSecretGetValue(secret, &size, flags);
4041 LIBVIRT_END_ALLOW_THREADS;
4043 if (c_retval == NULL)
4044 return VIR_PY_NONE;
4046 py_retval = PyString_FromStringAndSize((const char *)c_retval, size);
4047 VIR_FREE(c_retval);
4049 return py_retval;
4052 static PyObject *
4053 libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
4054 PyObject *args) {
4055 PyObject *py_retval;
4056 int c_retval;
4057 virSecretPtr secret;
4058 PyObject *pyobj_secret;
4059 const char *value;
4060 int size;
4061 unsigned int flags;
4063 if (!PyArg_ParseTuple(args, (char *)"Oz#i:virSecretSetValue", &pyobj_secret,
4064 &value, &size, &flags))
4065 return NULL;
4066 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
4068 LIBVIRT_BEGIN_ALLOW_THREADS;
4069 c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
4070 flags);
4071 LIBVIRT_END_ALLOW_THREADS;
4073 py_retval = libvirt_intWrap(c_retval);
4074 return py_retval;
4077 static PyObject *
4078 libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4079 PyObject *py_retval;
4080 unsigned char uuid[VIR_UUID_BUFLEN];
4081 virNWFilterPtr nwfilter;
4082 PyObject *pyobj_nwfilter;
4083 int c_retval;
4085 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID", &pyobj_nwfilter))
4086 return NULL;
4087 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4089 if (nwfilter == NULL)
4090 return VIR_PY_NONE;
4091 LIBVIRT_BEGIN_ALLOW_THREADS;
4092 c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
4093 LIBVIRT_END_ALLOW_THREADS;
4095 if (c_retval < 0)
4096 return VIR_PY_NONE;
4097 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
4099 return py_retval;
4102 static PyObject *
4103 libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
4104 PyObject *args) {
4105 PyObject *py_retval;
4106 char uuidstr[VIR_UUID_STRING_BUFLEN];
4107 virNWFilterPtr nwfilter;
4108 PyObject *pyobj_nwfilter;
4109 int c_retval;
4111 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
4112 &pyobj_nwfilter))
4113 return NULL;
4114 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
4116 if (nwfilter == NULL)
4117 return VIR_PY_NONE;
4118 LIBVIRT_BEGIN_ALLOW_THREADS;
4119 c_retval = virNWFilterGetUUIDString(nwfilter, &uuidstr[0]);
4120 LIBVIRT_END_ALLOW_THREADS;
4122 if (c_retval < 0)
4123 return VIR_PY_NONE;
4125 py_retval = PyString_FromString((char *) &uuidstr[0]);
4126 return py_retval;
4129 static PyObject *
4130 libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4131 PyObject *py_retval;
4132 virNWFilterPtr c_retval;
4133 virConnectPtr conn;
4134 PyObject *pyobj_conn;
4135 unsigned char * uuid;
4136 int len;
4138 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID", &pyobj_conn, &uuid, &len))
4139 return NULL;
4140 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4142 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
4143 return VIR_PY_NONE;
4145 LIBVIRT_BEGIN_ALLOW_THREADS;
4146 c_retval = virNWFilterLookupByUUID(conn, uuid);
4147 LIBVIRT_END_ALLOW_THREADS;
4148 py_retval = libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
4149 return py_retval;
4153 static PyObject *
4154 libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4155 PyObject *args) {
4156 PyObject *py_retval;
4157 char **uuids = NULL;
4158 virConnectPtr conn;
4159 int c_retval;
4160 size_t i;
4161 PyObject *pyobj_conn;
4163 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters", &pyobj_conn))
4164 return NULL;
4165 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4167 LIBVIRT_BEGIN_ALLOW_THREADS;
4168 c_retval = virConnectNumOfNWFilters(conn);
4169 LIBVIRT_END_ALLOW_THREADS;
4170 if (c_retval < 0)
4171 return VIR_PY_NONE;
4173 if (c_retval) {
4174 if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0)
4175 return VIR_PY_NONE;
4176 LIBVIRT_BEGIN_ALLOW_THREADS;
4177 c_retval = virConnectListNWFilters(conn, uuids, c_retval);
4178 LIBVIRT_END_ALLOW_THREADS;
4179 if (c_retval < 0) {
4180 VIR_FREE(uuids);
4181 return VIR_PY_NONE;
4184 py_retval = PyList_New(c_retval);
4186 if (uuids) {
4187 for (i = 0; i < c_retval; i++) {
4188 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
4189 VIR_FREE(uuids[i]);
4191 VIR_FREE(uuids);
4194 return py_retval;
4197 static PyObject *
4198 libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
4199 PyObject *args)
4201 PyObject *pyobj_conn;
4202 PyObject *py_retval = NULL;
4203 PyObject *tmp = NULL;
4204 virConnectPtr conn;
4205 virNWFilterPtr *filters = NULL;
4206 int c_retval = 0;
4207 size_t i;
4208 unsigned int flags;
4210 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNWFilters",
4211 &pyobj_conn, &flags))
4212 return NULL;
4213 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4215 LIBVIRT_BEGIN_ALLOW_THREADS;
4216 c_retval = virConnectListAllNWFilters(conn, &filters, flags);
4217 LIBVIRT_END_ALLOW_THREADS;
4218 if (c_retval < 0)
4219 return VIR_PY_NONE;
4221 if (!(py_retval = PyList_New(c_retval)))
4222 goto cleanup;
4224 for (i = 0; i < c_retval; i++) {
4225 if (!(tmp = libvirt_virNWFilterPtrWrap(filters[i])) ||
4226 PyList_SetItem(py_retval, i, tmp) < 0) {
4227 Py_XDECREF(tmp);
4228 Py_DECREF(py_retval);
4229 py_retval = NULL;
4230 goto cleanup;
4232 /* python steals the pointer */
4233 filters[i] = NULL;
4236 cleanup:
4237 for (i = 0; i < c_retval; i++)
4238 if (filters[i])
4239 virNWFilterFree(filters[i]);
4240 VIR_FREE(filters);
4241 return py_retval;
4244 static PyObject *
4245 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4246 PyObject *args) {
4247 PyObject *py_retval;
4248 char **names = NULL;
4249 int c_retval;
4250 size_t i;
4251 virConnectPtr conn;
4252 PyObject *pyobj_conn;
4255 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListInterfaces", &pyobj_conn))
4256 return NULL;
4257 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4259 LIBVIRT_BEGIN_ALLOW_THREADS;
4260 c_retval = virConnectNumOfInterfaces(conn);
4261 LIBVIRT_END_ALLOW_THREADS;
4262 if (c_retval < 0)
4263 return VIR_PY_NONE;
4265 if (c_retval) {
4266 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
4267 return VIR_PY_NONE;
4268 LIBVIRT_BEGIN_ALLOW_THREADS;
4269 c_retval = virConnectListInterfaces(conn, names, c_retval);
4270 LIBVIRT_END_ALLOW_THREADS;
4271 if (c_retval < 0) {
4272 VIR_FREE(names);
4273 return VIR_PY_NONE;
4276 py_retval = PyList_New(c_retval);
4277 if (py_retval == NULL) {
4278 if (names) {
4279 for (i = 0; i < c_retval; i++)
4280 VIR_FREE(names[i]);
4281 VIR_FREE(names);
4283 return VIR_PY_NONE;
4286 if (names) {
4287 for (i = 0; i < c_retval; i++) {
4288 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
4289 VIR_FREE(names[i]);
4291 VIR_FREE(names);
4294 return py_retval;
4298 static PyObject *
4299 libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4300 PyObject *args) {
4301 PyObject *py_retval;
4302 char **names = NULL;
4303 int c_retval;
4304 size_t i;
4305 virConnectPtr conn;
4306 PyObject *pyobj_conn;
4309 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedInterfaces",
4310 &pyobj_conn))
4311 return NULL;
4312 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4314 LIBVIRT_BEGIN_ALLOW_THREADS;
4315 c_retval = virConnectNumOfDefinedInterfaces(conn);
4316 LIBVIRT_END_ALLOW_THREADS;
4317 if (c_retval < 0)
4318 return VIR_PY_NONE;
4320 if (c_retval) {
4321 if (VIR_ALLOC_N_QUIET(names, c_retval) < 0)
4322 return VIR_PY_NONE;
4323 LIBVIRT_BEGIN_ALLOW_THREADS;
4324 c_retval = virConnectListDefinedInterfaces(conn, names, c_retval);
4325 LIBVIRT_END_ALLOW_THREADS;
4326 if (c_retval < 0) {
4327 VIR_FREE(names);
4328 return VIR_PY_NONE;
4331 py_retval = PyList_New(c_retval);
4332 if (py_retval == NULL) {
4333 if (names) {
4334 for (i = 0; i < c_retval; i++)
4335 VIR_FREE(names[i]);
4336 VIR_FREE(names);
4338 return VIR_PY_NONE;
4341 if (names) {
4342 for (i = 0; i < c_retval; i++) {
4343 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
4344 VIR_FREE(names[i]);
4346 VIR_FREE(names);
4349 return py_retval;
4353 static PyObject *
4354 libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
4355 PyObject *args)
4357 PyObject *pyobj_conn;
4358 PyObject *py_retval = NULL;
4359 PyObject *tmp = NULL;
4360 virConnectPtr conn;
4361 virInterfacePtr *ifaces = NULL;
4362 int c_retval = 0;
4363 size_t i;
4364 unsigned int flags;
4366 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllInterfaces",
4367 &pyobj_conn, &flags))
4368 return NULL;
4369 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4371 LIBVIRT_BEGIN_ALLOW_THREADS;
4372 c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
4373 LIBVIRT_END_ALLOW_THREADS;
4374 if (c_retval < 0)
4375 return VIR_PY_NONE;
4377 if (!(py_retval = PyList_New(c_retval)))
4378 goto cleanup;
4380 for (i = 0; i < c_retval; i++) {
4381 if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) ||
4382 PyList_SetItem(py_retval, i, tmp) < 0) {
4383 Py_XDECREF(tmp);
4384 Py_DECREF(py_retval);
4385 py_retval = NULL;
4386 goto cleanup;
4388 /* python steals the pointer */
4389 ifaces[i] = NULL;
4392 cleanup:
4393 for (i = 0; i < c_retval; i++)
4394 if (ifaces[i])
4395 virInterfaceFree(ifaces[i]);
4396 VIR_FREE(ifaces);
4397 return py_retval;
4400 static PyObject *
4401 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
4402 PyObject *args) {
4403 PyObject *pyobj_conn;
4404 PyObject *list;
4405 virConnectPtr conn;
4406 unsigned int flags;
4407 const char **xmlcpus = NULL;
4408 int ncpus = 0;
4409 char *base_cpu;
4410 PyObject *pybase_cpu;
4412 if (!PyArg_ParseTuple(args, (char *)"OOi:virConnectBaselineCPU",
4413 &pyobj_conn, &list, &flags))
4414 return NULL;
4415 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4417 if (PyList_Check(list)) {
4418 size_t i;
4420 ncpus = PyList_Size(list);
4421 if (VIR_ALLOC_N_QUIET(xmlcpus, ncpus) < 0)
4422 return VIR_PY_INT_FAIL;
4424 for (i = 0; i < ncpus; i++) {
4425 xmlcpus[i] = PyString_AsString(PyList_GetItem(list, i));
4426 if (xmlcpus[i] == NULL) {
4427 VIR_FREE(xmlcpus);
4428 return VIR_PY_INT_FAIL;
4433 LIBVIRT_BEGIN_ALLOW_THREADS;
4434 base_cpu = virConnectBaselineCPU(conn, xmlcpus, ncpus, flags);
4435 LIBVIRT_END_ALLOW_THREADS;
4437 VIR_FREE(xmlcpus);
4439 if (base_cpu == NULL)
4440 return VIR_PY_INT_FAIL;
4442 pybase_cpu = PyString_FromString(base_cpu);
4443 VIR_FREE(base_cpu);
4445 if (pybase_cpu == NULL)
4446 return VIR_PY_INT_FAIL;
4448 return pybase_cpu;
4452 static PyObject *
4453 libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4454 PyObject *py_retval;
4455 int c_retval;
4456 virDomainPtr domain;
4457 PyObject *pyobj_domain;
4458 virDomainJobInfo info;
4460 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetJobInfo", &pyobj_domain))
4461 return NULL;
4462 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4464 LIBVIRT_BEGIN_ALLOW_THREADS;
4465 c_retval = virDomainGetJobInfo(domain, &info);
4466 LIBVIRT_END_ALLOW_THREADS;
4467 if (c_retval < 0)
4468 return VIR_PY_NONE;
4469 py_retval = PyList_New(12);
4470 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
4471 PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.timeElapsed));
4472 PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.timeRemaining));
4473 PyList_SetItem(py_retval, 3, libvirt_ulonglongWrap(info.dataTotal));
4474 PyList_SetItem(py_retval, 4, libvirt_ulonglongWrap(info.dataProcessed));
4475 PyList_SetItem(py_retval, 5, libvirt_ulonglongWrap(info.dataRemaining));
4476 PyList_SetItem(py_retval, 6, libvirt_ulonglongWrap(info.memTotal));
4477 PyList_SetItem(py_retval, 7, libvirt_ulonglongWrap(info.memProcessed));
4478 PyList_SetItem(py_retval, 8, libvirt_ulonglongWrap(info.memRemaining));
4479 PyList_SetItem(py_retval, 9, libvirt_ulonglongWrap(info.fileTotal));
4480 PyList_SetItem(py_retval, 10, libvirt_ulonglongWrap(info.fileProcessed));
4481 PyList_SetItem(py_retval, 11, libvirt_ulonglongWrap(info.fileRemaining));
4483 return py_retval;
4486 static PyObject *
4487 libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
4489 PyObject *pyobj_domain;
4490 virDomainPtr domain;
4491 unsigned int flags;
4492 virTypedParameterPtr params = NULL;
4493 int nparams = 0;
4494 int type;
4495 PyObject *dict = NULL;
4496 int rc;
4498 if (!PyArg_ParseTuple(args, (char *) "Oi:virDomainGetJobStats",
4499 &pyobj_domain, &flags))
4500 goto cleanup;
4501 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4503 LIBVIRT_BEGIN_ALLOW_THREADS;
4504 rc = virDomainGetJobStats(domain, &type, &params, &nparams, flags);
4505 LIBVIRT_END_ALLOW_THREADS;
4506 if (rc < 0)
4507 goto cleanup;
4509 if (!(dict = getPyVirTypedParameter(params, nparams)))
4510 goto cleanup;
4512 if (PyDict_SetItem(dict, libvirt_constcharPtrWrap("type"),
4513 libvirt_intWrap(type)) < 0) {
4514 Py_DECREF(dict);
4515 dict = NULL;
4516 goto cleanup;
4519 cleanup:
4520 virTypedParamsFree(params, nparams);
4521 if (dict)
4522 return dict;
4523 else
4524 return VIR_PY_NONE;
4527 static PyObject *
4528 libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4529 PyObject *args)
4531 virDomainPtr domain;
4532 PyObject *pyobj_domain;
4533 const char *path;
4534 unsigned int flags;
4535 virDomainBlockJobInfo info;
4536 int c_ret;
4537 PyObject *type = NULL, *bandwidth = NULL, *cur = NULL, *end = NULL;
4538 PyObject *dict;
4540 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetBlockJobInfo",
4541 &pyobj_domain, &path, &flags))
4542 return NULL;
4543 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4545 if ((dict = PyDict_New()) == NULL)
4546 return NULL;
4548 LIBVIRT_BEGIN_ALLOW_THREADS;
4549 c_ret = virDomainGetBlockJobInfo(domain, path, &info, flags);
4550 LIBVIRT_END_ALLOW_THREADS;
4552 if (c_ret == 0) {
4553 return dict;
4554 } else if (c_ret < 0) {
4555 Py_DECREF(dict);
4556 return VIR_PY_NONE;
4559 if ((type = libvirt_intWrap(info.type)) == NULL ||
4560 PyDict_SetItemString(dict, "type", type) < 0)
4561 goto error;
4562 Py_DECREF(type);
4564 if ((bandwidth = libvirt_ulongWrap(info.bandwidth)) == NULL ||
4565 PyDict_SetItemString(dict, "bandwidth", bandwidth) < 0)
4566 goto error;
4567 Py_DECREF(bandwidth);
4569 if ((cur = libvirt_ulonglongWrap(info.cur)) == NULL ||
4570 PyDict_SetItemString(dict, "cur", cur) < 0)
4571 goto error;
4572 Py_DECREF(cur);
4574 if ((end = libvirt_ulonglongWrap(info.end)) == NULL ||
4575 PyDict_SetItemString(dict, "end", end) < 0)
4576 goto error;
4577 Py_DECREF(end);
4579 return dict;
4581 error:
4582 Py_DECREF(dict);
4583 Py_XDECREF(type);
4584 Py_XDECREF(bandwidth);
4585 Py_XDECREF(cur);
4586 Py_XDECREF(end);
4587 return NULL;
4590 static PyObject *
4591 libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4592 PyObject *args)
4594 virDomainPtr domain;
4595 PyObject *pyobj_domain, *info;
4596 PyObject *ret = NULL;
4597 int i_retval;
4598 int nparams = 0;
4599 Py_ssize_t size = 0;
4600 const char *disk;
4601 unsigned int flags;
4602 virTypedParameterPtr params, new_params = NULL;
4604 if (!PyArg_ParseTuple(args, (char *)"OzOi:virDomainSetBlockIoTune",
4605 &pyobj_domain, &disk, &info, &flags))
4606 return NULL;
4607 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4609 if ((size = PyDict_Size(info)) < 0)
4610 return NULL;
4612 if (size == 0) {
4613 PyErr_Format(PyExc_LookupError,
4614 "Need non-empty dictionary to set attributes");
4615 return NULL;
4618 LIBVIRT_BEGIN_ALLOW_THREADS;
4619 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4620 LIBVIRT_END_ALLOW_THREADS;
4622 if (i_retval < 0)
4623 return VIR_PY_INT_FAIL;
4625 if (nparams == 0) {
4626 PyErr_Format(PyExc_LookupError,
4627 "Domain has no settable attributes");
4628 return NULL;
4631 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
4632 return PyErr_NoMemory();
4634 LIBVIRT_BEGIN_ALLOW_THREADS;
4635 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4636 LIBVIRT_END_ALLOW_THREADS;
4638 if (i_retval < 0) {
4639 ret = VIR_PY_INT_FAIL;
4640 goto cleanup;
4643 new_params = setPyVirTypedParameter(info, params, nparams);
4644 if (!new_params)
4645 goto cleanup;
4647 LIBVIRT_BEGIN_ALLOW_THREADS;
4648 i_retval = virDomainSetBlockIoTune(domain, disk, new_params, size, flags);
4649 LIBVIRT_END_ALLOW_THREADS;
4651 if (i_retval < 0) {
4652 ret = VIR_PY_INT_FAIL;
4653 goto cleanup;
4656 ret = VIR_PY_INT_SUCCESS;
4658 cleanup:
4659 virTypedParamsFree(params, nparams);
4660 VIR_FREE(new_params);
4661 return ret;
4664 static PyObject *
4665 libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4666 PyObject *args)
4668 virDomainPtr domain;
4669 PyObject *pyobj_domain;
4670 PyObject *ret = NULL;
4671 int i_retval;
4672 int nparams = 0;
4673 const char *disk;
4674 unsigned int flags;
4675 virTypedParameterPtr params;
4677 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetBlockIoTune",
4678 &pyobj_domain, &disk, &flags))
4679 return NULL;
4680 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4682 LIBVIRT_BEGIN_ALLOW_THREADS;
4683 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4684 LIBVIRT_END_ALLOW_THREADS;
4686 if (i_retval < 0)
4687 return VIR_PY_NONE;
4689 if (!nparams)
4690 return PyDict_New();
4692 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
4693 return PyErr_NoMemory();
4695 LIBVIRT_BEGIN_ALLOW_THREADS;
4696 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4697 LIBVIRT_END_ALLOW_THREADS;
4699 if (i_retval < 0) {
4700 ret = VIR_PY_NONE;
4701 goto cleanup;
4704 ret = getPyVirTypedParameter(params, nparams);
4706 cleanup:
4707 virTypedParamsFree(params, nparams);
4708 return ret;
4711 static PyObject *
4712 libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED,
4713 PyObject *args)
4715 PyObject *py_retval = VIR_PY_NONE;
4716 virDomainPtr domain;
4717 PyObject *pyobj_domain;
4718 unsigned int flags;
4719 virDomainDiskErrorPtr disks = NULL;
4720 unsigned int ndisks;
4721 int count;
4722 size_t i;
4724 if (!PyArg_ParseTuple(args, (char *) "Oi:virDomainGetDiskErrors",
4725 &pyobj_domain, &flags))
4726 return NULL;
4728 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4730 if ((count = virDomainGetDiskErrors(domain, NULL, 0, 0)) < 0)
4731 return VIR_PY_NONE;
4732 ndisks = count;
4734 if (ndisks) {
4735 if (VIR_ALLOC_N_QUIET(disks, ndisks) < 0)
4736 return VIR_PY_NONE;
4738 LIBVIRT_BEGIN_ALLOW_THREADS;
4739 count = virDomainGetDiskErrors(domain, disks, ndisks, 0);
4740 LIBVIRT_END_ALLOW_THREADS;
4742 if (count < 0)
4743 goto cleanup;
4746 if (!(py_retval = PyDict_New()))
4747 goto cleanup;
4749 for (i = 0; i < count; i++) {
4750 PyDict_SetItem(py_retval,
4751 libvirt_constcharPtrWrap(disks[i].disk),
4752 libvirt_intWrap(disks[i].error));
4755 cleanup:
4756 if (disks) {
4757 for (i = 0; i < count; i++)
4758 VIR_FREE(disks[i].disk);
4759 VIR_FREE(disks);
4761 return py_retval;
4764 /*******************************************
4765 * Helper functions to avoid importing modules
4766 * for every callback
4767 *******************************************/
4768 static PyObject *libvirt_module = NULL;
4769 static PyObject *libvirt_dict = NULL;
4770 static PyObject *libvirt_dom_class = NULL;
4772 static PyObject *
4773 getLibvirtModuleObject(void) {
4774 if (libvirt_module)
4775 return libvirt_module;
4777 // PyImport_ImportModule returns a new reference
4778 /* Bogus (char *) cast for RHEL-5 python API brokenness */
4779 libvirt_module = PyImport_ImportModule((char *)"libvirt");
4780 if (!libvirt_module) {
4781 DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
4782 PyErr_Print();
4783 return NULL;
4786 return libvirt_module;
4789 static PyObject *
4790 getLibvirtDictObject(void) {
4791 if (libvirt_dict)
4792 return libvirt_dict;
4794 // PyModule_GetDict returns a borrowed reference
4795 libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
4796 if (!libvirt_dict) {
4797 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
4798 PyErr_Print();
4799 return NULL;
4802 Py_INCREF(libvirt_dict);
4803 return libvirt_dict;
4806 static PyObject *
4807 getLibvirtDomainClassObject(void) {
4808 if (libvirt_dom_class)
4809 return libvirt_dom_class;
4811 // PyDict_GetItemString returns a borrowed reference
4812 libvirt_dom_class = PyDict_GetItemString(getLibvirtDictObject(),
4813 "virDomain");
4814 if (!libvirt_dom_class) {
4815 DEBUG("%s Error importing virDomain class\n", __FUNCTION__);
4816 PyErr_Print();
4817 return NULL;
4820 Py_INCREF(libvirt_dom_class);
4821 return libvirt_dom_class;
4824 static PyObject *
4825 libvirt_lookupPythonFunc(const char *funcname)
4827 PyObject *python_cb;
4829 /* Lookup the python callback */
4830 python_cb = PyDict_GetItemString(getLibvirtDictObject(), funcname);
4832 if (!python_cb) {
4833 DEBUG("%s: Error finding %s\n", __FUNCTION__, funcname);
4834 PyErr_Print();
4835 PyErr_Clear();
4836 return NULL;
4839 if (!PyCallable_Check(python_cb)) {
4840 DEBUG("%s: %s is not callable\n", __FUNCTION__, funcname);
4841 return NULL;
4844 return python_cb;
4847 /*******************************************
4848 * Domain Events
4849 *******************************************/
4851 static int
4852 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
4853 virDomainPtr dom,
4854 int event,
4855 int detail,
4856 void *opaque)
4858 PyObject *pyobj_ret;
4860 PyObject *pyobj_conn_inst = (PyObject*)opaque;
4861 PyObject *pyobj_dom;
4863 PyObject *pyobj_dom_args;
4864 PyObject *pyobj_dom_inst;
4866 PyObject *dom_class;
4867 int ret = -1;
4869 LIBVIRT_ENSURE_THREAD_STATE;
4871 /* Create a python instance of this virDomainPtr */
4872 virDomainRef(dom);
4873 pyobj_dom = libvirt_virDomainPtrWrap(dom);
4874 pyobj_dom_args = PyTuple_New(2);
4875 if (PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {
4876 DEBUG("%s error creating tuple",__FUNCTION__);
4877 goto cleanup;
4879 if (PyTuple_SetItem(pyobj_dom_args, 1, pyobj_dom)!=0) {
4880 DEBUG("%s error creating tuple",__FUNCTION__);
4881 goto cleanup;
4883 Py_INCREF(pyobj_conn_inst);
4885 dom_class = getLibvirtDomainClassObject();
4886 if (!PyClass_Check(dom_class)) {
4887 DEBUG("%s dom_class is not a class!\n", __FUNCTION__);
4888 goto cleanup;
4891 pyobj_dom_inst = PyInstance_New(dom_class,
4892 pyobj_dom_args,
4893 NULL);
4895 Py_DECREF(pyobj_dom_args);
4897 if (!pyobj_dom_inst) {
4898 DEBUG("%s Error creating a python instance of virDomain\n",
4899 __FUNCTION__);
4900 PyErr_Print();
4901 goto cleanup;
4904 /* Call the Callback Dispatcher */
4905 pyobj_ret = PyObject_CallMethod(pyobj_conn_inst,
4906 (char*)"_dispatchDomainEventCallbacks",
4907 (char*)"Oii",
4908 pyobj_dom_inst,
4909 event,
4910 detail);
4912 Py_DECREF(pyobj_dom_inst);
4914 if (!pyobj_ret) {
4915 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
4916 PyErr_Print();
4917 } else {
4918 Py_DECREF(pyobj_ret);
4919 ret = 0;
4923 cleanup:
4924 LIBVIRT_RELEASE_THREAD_STATE;
4925 return ret;
4928 static PyObject *
4929 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject * self,
4930 PyObject * args)
4932 PyObject *py_retval; /* return value */
4933 PyObject *pyobj_conn; /* virConnectPtr */
4934 PyObject *pyobj_conn_inst; /* virConnect Python object */
4936 virConnectPtr conn;
4937 int ret = 0;
4939 if (!PyArg_ParseTuple
4940 (args, (char *) "OO:virConnectDomainEventRegister",
4941 &pyobj_conn, &pyobj_conn_inst)) {
4942 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
4943 return VIR_PY_INT_FAIL;
4946 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
4947 pyobj_conn, pyobj_conn_inst);
4948 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4950 Py_INCREF(pyobj_conn_inst);
4952 LIBVIRT_BEGIN_ALLOW_THREADS;
4954 ret = virConnectDomainEventRegister(conn,
4955 libvirt_virConnectDomainEventCallback,
4956 (void *)pyobj_conn_inst, NULL);
4958 LIBVIRT_END_ALLOW_THREADS;
4960 py_retval = libvirt_intWrap(ret);
4961 return py_retval;
4964 static PyObject *
4965 libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject * self,
4966 PyObject * args)
4968 PyObject *py_retval;
4969 PyObject *pyobj_conn;
4970 PyObject *pyobj_conn_inst;
4972 virConnectPtr conn;
4973 int ret = 0;
4975 if (!PyArg_ParseTuple
4976 (args, (char *) "OO:virConnectDomainEventDeregister",
4977 &pyobj_conn, &pyobj_conn_inst))
4978 return NULL;
4980 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
4982 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4984 LIBVIRT_BEGIN_ALLOW_THREADS;
4986 ret = virConnectDomainEventDeregister(conn, libvirt_virConnectDomainEventCallback);
4988 LIBVIRT_END_ALLOW_THREADS;
4990 Py_DECREF(pyobj_conn_inst);
4991 py_retval = libvirt_intWrap(ret);
4992 return py_retval;
4995 /*******************************************
4996 * Event Impl
4997 *******************************************/
4998 static PyObject *addHandleObj = NULL;
4999 static char *addHandleName = NULL;
5000 static PyObject *updateHandleObj = NULL;
5001 static char *updateHandleName = NULL;
5002 static PyObject *removeHandleObj = NULL;
5003 static char *removeHandleName = NULL;
5004 static PyObject *addTimeoutObj = NULL;
5005 static char *addTimeoutName = NULL;
5006 static PyObject *updateTimeoutObj = NULL;
5007 static char *updateTimeoutName = NULL;
5008 static PyObject *removeTimeoutObj = NULL;
5009 static char *removeTimeoutName = NULL;
5011 #define NAME(fn) ( fn ## Name ? fn ## Name : # fn )
5013 static int
5014 libvirt_virEventAddHandleFunc (int fd,
5015 int event,
5016 virEventHandleCallback cb,
5017 void *opaque,
5018 virFreeCallback ff)
5020 PyObject *result;
5021 PyObject *python_cb;
5022 PyObject *cb_obj;
5023 PyObject *ff_obj;
5024 PyObject *opaque_obj;
5025 PyObject *cb_args;
5026 PyObject *pyobj_args;
5027 int retval = -1;
5029 LIBVIRT_ENSURE_THREAD_STATE;
5031 /* Lookup the python callback */
5032 python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
5033 if (!python_cb) {
5034 goto cleanup;
5036 Py_INCREF(python_cb);
5038 /* create tuple for cb */
5039 cb_obj = libvirt_virEventHandleCallbackWrap(cb);
5040 ff_obj = libvirt_virFreeCallbackWrap(ff);
5041 opaque_obj = libvirt_virVoidPtrWrap(opaque);
5043 cb_args = PyTuple_New(3);
5044 PyTuple_SetItem(cb_args, 0, cb_obj);
5045 PyTuple_SetItem(cb_args, 1, opaque_obj);
5046 PyTuple_SetItem(cb_args, 2, ff_obj);
5048 pyobj_args = PyTuple_New(4);
5049 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd));
5050 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event));
5051 PyTuple_SetItem(pyobj_args, 2, python_cb);
5052 PyTuple_SetItem(pyobj_args, 3, cb_args);
5054 result = PyEval_CallObject(addHandleObj, pyobj_args);
5055 if (!result) {
5056 PyErr_Print();
5057 PyErr_Clear();
5058 } else if (!PyInt_Check(result)) {
5059 DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addHandle));
5060 } else {
5061 retval = (int)PyInt_AsLong(result);
5064 Py_XDECREF(result);
5065 Py_DECREF(pyobj_args);
5067 cleanup:
5068 LIBVIRT_RELEASE_THREAD_STATE;
5070 return retval;
5073 static void
5074 libvirt_virEventUpdateHandleFunc(int watch, int event)
5076 PyObject *result;
5077 PyObject *pyobj_args;
5079 LIBVIRT_ENSURE_THREAD_STATE;
5081 pyobj_args = PyTuple_New(2);
5082 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch));
5083 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event));
5085 result = PyEval_CallObject(updateHandleObj, pyobj_args);
5086 if (!result) {
5087 PyErr_Print();
5088 PyErr_Clear();
5091 Py_XDECREF(result);
5092 Py_DECREF(pyobj_args);
5094 LIBVIRT_RELEASE_THREAD_STATE;
5098 static int
5099 libvirt_virEventRemoveHandleFunc(int watch)
5101 PyObject *result;
5102 PyObject *pyobj_args;
5103 PyObject *opaque;
5104 PyObject *ff;
5105 int retval = -1;
5106 virFreeCallback cff;
5108 LIBVIRT_ENSURE_THREAD_STATE;
5110 pyobj_args = PyTuple_New(1);
5111 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch));
5113 result = PyEval_CallObject(removeHandleObj, pyobj_args);
5114 if (!result) {
5115 PyErr_Print();
5116 PyErr_Clear();
5117 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
5118 DEBUG("%s: %s must return opaque obj registered with %s"
5119 "to avoid leaking libvirt memory\n",
5120 __FUNCTION__, NAME(removeHandle), NAME(addHandle));
5121 } else {
5122 opaque = PyTuple_GetItem(result, 1);
5123 ff = PyTuple_GetItem(result, 2);
5124 cff = PyvirFreeCallback_Get(ff);
5125 if (cff)
5126 (*cff)(PyvirVoidPtr_Get(opaque));
5127 retval = 0;
5130 Py_XDECREF(result);
5131 Py_DECREF(pyobj_args);
5133 LIBVIRT_RELEASE_THREAD_STATE;
5135 return retval;
5139 static int
5140 libvirt_virEventAddTimeoutFunc(int timeout,
5141 virEventTimeoutCallback cb,
5142 void *opaque,
5143 virFreeCallback ff)
5145 PyObject *result;
5147 PyObject *python_cb;
5149 PyObject *cb_obj;
5150 PyObject *ff_obj;
5151 PyObject *opaque_obj;
5152 PyObject *cb_args;
5153 PyObject *pyobj_args;
5154 int retval = -1;
5156 LIBVIRT_ENSURE_THREAD_STATE;
5158 /* Lookup the python callback */
5159 python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
5160 if (!python_cb) {
5161 goto cleanup;
5163 Py_INCREF(python_cb);
5165 /* create tuple for cb */
5166 cb_obj = libvirt_virEventTimeoutCallbackWrap(cb);
5167 ff_obj = libvirt_virFreeCallbackWrap(ff);
5168 opaque_obj = libvirt_virVoidPtrWrap(opaque);
5170 cb_args = PyTuple_New(3);
5171 PyTuple_SetItem(cb_args, 0, cb_obj);
5172 PyTuple_SetItem(cb_args, 1, opaque_obj);
5173 PyTuple_SetItem(cb_args, 2, ff_obj);
5175 pyobj_args = PyTuple_New(3);
5177 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timeout));
5178 PyTuple_SetItem(pyobj_args, 1, python_cb);
5179 PyTuple_SetItem(pyobj_args, 2, cb_args);
5181 result = PyEval_CallObject(addTimeoutObj, pyobj_args);
5182 if (!result) {
5183 PyErr_Print();
5184 PyErr_Clear();
5185 } else if (!PyInt_Check(result)) {
5186 DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addTimeout));
5187 } else {
5188 retval = (int)PyInt_AsLong(result);
5191 Py_XDECREF(result);
5192 Py_DECREF(pyobj_args);
5194 cleanup:
5195 LIBVIRT_RELEASE_THREAD_STATE;
5196 return retval;
5199 static void
5200 libvirt_virEventUpdateTimeoutFunc(int timer, int timeout)
5202 PyObject *result = NULL;
5203 PyObject *pyobj_args;
5205 LIBVIRT_ENSURE_THREAD_STATE;
5207 pyobj_args = PyTuple_New(2);
5208 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer));
5209 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(timeout));
5211 result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
5212 if (!result) {
5213 PyErr_Print();
5214 PyErr_Clear();
5217 Py_XDECREF(result);
5218 Py_DECREF(pyobj_args);
5220 LIBVIRT_RELEASE_THREAD_STATE;
5223 static int
5224 libvirt_virEventRemoveTimeoutFunc(int timer)
5226 PyObject *result = NULL;
5227 PyObject *pyobj_args;
5228 PyObject *opaque;
5229 PyObject *ff;
5230 int retval = -1;
5231 virFreeCallback cff;
5233 LIBVIRT_ENSURE_THREAD_STATE;
5235 pyobj_args = PyTuple_New(1);
5236 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer));
5238 result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
5239 if (!result) {
5240 PyErr_Print();
5241 PyErr_Clear();
5242 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
5243 DEBUG("%s: %s must return opaque obj registered with %s"
5244 "to avoid leaking libvirt memory\n",
5245 __FUNCTION__, NAME(removeTimeout), NAME(addTimeout));
5246 } else {
5247 opaque = PyTuple_GetItem(result, 1);
5248 ff = PyTuple_GetItem(result, 2);
5249 cff = PyvirFreeCallback_Get(ff);
5250 if (cff)
5251 (*cff)(PyvirVoidPtr_Get(opaque));
5252 retval = 0;
5255 Py_XDECREF(result);
5256 Py_DECREF(pyobj_args);
5258 LIBVIRT_RELEASE_THREAD_STATE;
5260 return retval;
5263 static PyObject *
5264 libvirt_virEventRegisterImpl(ATTRIBUTE_UNUSED PyObject * self,
5265 PyObject * args)
5267 /* Unref the previously-registered impl (if any) */
5268 Py_XDECREF(addHandleObj);
5269 Py_XDECREF(updateHandleObj);
5270 Py_XDECREF(removeHandleObj);
5271 Py_XDECREF(addTimeoutObj);
5272 Py_XDECREF(updateTimeoutObj);
5273 Py_XDECREF(removeTimeoutObj);
5275 /* Parse and check arguments */
5276 if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
5277 &addHandleObj, &updateHandleObj,
5278 &removeHandleObj, &addTimeoutObj,
5279 &updateTimeoutObj, &removeTimeoutObj) ||
5280 !PyCallable_Check(addHandleObj) ||
5281 !PyCallable_Check(updateHandleObj) ||
5282 !PyCallable_Check(removeHandleObj) ||
5283 !PyCallable_Check(addTimeoutObj) ||
5284 !PyCallable_Check(updateTimeoutObj) ||
5285 !PyCallable_Check(removeTimeoutObj))
5286 return VIR_PY_INT_FAIL;
5288 /* Get argument string representations (for error reporting) */
5289 addHandleName = py_str(addHandleObj);
5290 updateHandleName = py_str(updateHandleObj);
5291 removeHandleName = py_str(removeHandleObj);
5292 addTimeoutName = py_str(addTimeoutObj);
5293 updateTimeoutName = py_str(updateTimeoutObj);
5294 removeTimeoutName = py_str(removeTimeoutObj);
5296 /* Inc refs since we're holding on to these objects until
5297 * the next call (if any) to this function.
5299 Py_INCREF(addHandleObj);
5300 Py_INCREF(updateHandleObj);
5301 Py_INCREF(removeHandleObj);
5302 Py_INCREF(addTimeoutObj);
5303 Py_INCREF(updateTimeoutObj);
5304 Py_INCREF(removeTimeoutObj);
5306 LIBVIRT_BEGIN_ALLOW_THREADS;
5308 /* Now register our C EventImpl, which will dispatch
5309 * to the Python callbacks passed in as args.
5311 virEventRegisterImpl(libvirt_virEventAddHandleFunc,
5312 libvirt_virEventUpdateHandleFunc,
5313 libvirt_virEventRemoveHandleFunc,
5314 libvirt_virEventAddTimeoutFunc,
5315 libvirt_virEventUpdateTimeoutFunc,
5316 libvirt_virEventRemoveTimeoutFunc);
5318 LIBVIRT_END_ALLOW_THREADS;
5320 return VIR_PY_INT_SUCCESS;
5323 static PyObject *
5324 libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
5325 PyObject *args)
5327 int watch, fd, event;
5328 PyObject *py_f;
5329 PyObject *py_opaque;
5330 virEventHandleCallback cb;
5331 void *opaque;
5333 if (!PyArg_ParseTuple
5334 (args, (char *) "iiiOO:virEventInvokeHandleCallback",
5335 &watch, &fd, &event, &py_f, &py_opaque
5337 return VIR_PY_INT_FAIL;
5339 cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
5340 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5342 if (cb) {
5343 LIBVIRT_BEGIN_ALLOW_THREADS;
5344 cb(watch, fd, event, opaque);
5345 LIBVIRT_END_ALLOW_THREADS;
5348 return VIR_PY_INT_SUCCESS;
5351 static PyObject *
5352 libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
5353 PyObject *args)
5355 int timer;
5356 PyObject *py_f;
5357 PyObject *py_opaque;
5358 virEventTimeoutCallback cb;
5359 void *opaque;
5361 if (!PyArg_ParseTuple
5362 (args, (char *) "iOO:virEventInvokeTimeoutCallback",
5363 &timer, &py_f, &py_opaque
5365 return VIR_PY_INT_FAIL;
5367 cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
5368 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
5369 if (cb) {
5370 LIBVIRT_BEGIN_ALLOW_THREADS;
5371 cb(timer, opaque);
5372 LIBVIRT_END_ALLOW_THREADS;
5375 return VIR_PY_INT_SUCCESS;
5378 static void
5379 libvirt_virEventHandleCallback(int watch,
5380 int fd,
5381 int events,
5382 void *opaque)
5384 PyObject *pyobj_cbData = (PyObject *)opaque;
5385 PyObject *pyobj_ret;
5386 PyObject *python_cb;
5388 LIBVIRT_ENSURE_THREAD_STATE;
5390 /* Lookup the python callback */
5391 python_cb = libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
5392 if (!python_cb) {
5393 goto cleanup;
5396 Py_INCREF(pyobj_cbData);
5398 /* Call the pure python dispatcher */
5399 pyobj_ret = PyObject_CallFunction(python_cb,
5400 (char *)"iiiO",
5401 watch, fd, events, pyobj_cbData);
5403 Py_DECREF(pyobj_cbData);
5405 if (!pyobj_ret) {
5406 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5407 PyErr_Print();
5408 } else {
5409 Py_DECREF(pyobj_ret);
5412 cleanup:
5413 LIBVIRT_RELEASE_THREAD_STATE;
5416 static PyObject *
5417 libvirt_virEventAddHandle(PyObject *self ATTRIBUTE_UNUSED,
5418 PyObject *args)
5420 PyObject *py_retval;
5421 PyObject *pyobj_cbData;
5422 virEventHandleCallback cb = libvirt_virEventHandleCallback;
5423 int events;
5424 int fd;
5425 int ret;
5427 if (!PyArg_ParseTuple(args, (char *) "iiO:virEventAddHandle",
5428 &fd, &events, &pyobj_cbData)) {
5429 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
5430 return VIR_PY_INT_FAIL;
5433 Py_INCREF(pyobj_cbData);
5435 LIBVIRT_BEGIN_ALLOW_THREADS;
5436 ret = virEventAddHandle(fd, events, cb, pyobj_cbData, NULL);
5437 LIBVIRT_END_ALLOW_THREADS;
5439 if (ret < 0) {
5440 Py_DECREF(pyobj_cbData);
5443 py_retval = libvirt_intWrap(ret);
5444 return py_retval;
5447 static void
5448 libvirt_virEventTimeoutCallback(int timer,
5449 void *opaque)
5451 PyObject *pyobj_cbData = (PyObject *)opaque;
5452 PyObject *pyobj_ret;
5453 PyObject *python_cb;
5455 LIBVIRT_ENSURE_THREAD_STATE;
5457 /* Lookup the python callback */
5458 python_cb = libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
5459 if (!python_cb) {
5460 goto cleanup;
5463 Py_INCREF(pyobj_cbData);
5465 /* Call the pure python dispatcher */
5466 pyobj_ret = PyObject_CallFunction(python_cb,
5467 (char *)"iO",
5468 timer, pyobj_cbData);
5470 Py_DECREF(pyobj_cbData);
5472 if (!pyobj_ret) {
5473 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5474 PyErr_Print();
5475 } else {
5476 Py_DECREF(pyobj_ret);
5479 cleanup:
5480 LIBVIRT_RELEASE_THREAD_STATE;
5483 static PyObject *
5484 libvirt_virEventAddTimeout(PyObject *self ATTRIBUTE_UNUSED,
5485 PyObject *args)
5487 PyObject *py_retval;
5488 PyObject *pyobj_cbData;
5489 virEventTimeoutCallback cb = libvirt_virEventTimeoutCallback;
5490 int timeout;
5491 int ret;
5493 if (!PyArg_ParseTuple(args, (char *) "iO:virEventAddTimeout",
5494 &timeout, &pyobj_cbData)) {
5495 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
5496 return VIR_PY_INT_FAIL;
5499 Py_INCREF(pyobj_cbData);
5501 LIBVIRT_BEGIN_ALLOW_THREADS;
5502 ret = virEventAddTimeout(timeout, cb, pyobj_cbData, NULL);
5503 LIBVIRT_END_ALLOW_THREADS;
5505 if (ret < 0) {
5506 Py_DECREF(pyobj_cbData);
5509 py_retval = libvirt_intWrap(ret);
5510 return py_retval;
5513 static void
5514 libvirt_virConnectDomainEventFreeFunc(void *opaque)
5516 PyObject *pyobj_conn = (PyObject*)opaque;
5517 LIBVIRT_ENSURE_THREAD_STATE;
5518 Py_DECREF(pyobj_conn);
5519 LIBVIRT_RELEASE_THREAD_STATE;
5522 static int
5523 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5524 virDomainPtr dom,
5525 int event,
5526 int detail,
5527 void *opaque)
5529 PyObject *pyobj_cbData = (PyObject*)opaque;
5530 PyObject *pyobj_dom;
5531 PyObject *pyobj_ret;
5532 PyObject *pyobj_conn;
5533 PyObject *dictKey;
5534 int ret = -1;
5536 LIBVIRT_ENSURE_THREAD_STATE;
5538 /* Create a python instance of this virDomainPtr */
5539 virDomainRef(dom);
5540 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5541 Py_INCREF(pyobj_cbData);
5543 dictKey = libvirt_constcharPtrWrap("conn");
5544 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5545 Py_DECREF(dictKey);
5547 /* Call the Callback Dispatcher */
5548 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5549 (char*)"_dispatchDomainEventLifecycleCallback",
5550 (char*)"OiiO",
5551 pyobj_dom,
5552 event, detail,
5553 pyobj_cbData);
5555 Py_DECREF(pyobj_cbData);
5556 Py_DECREF(pyobj_dom);
5558 if (!pyobj_ret) {
5559 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5560 PyErr_Print();
5561 } else {
5562 Py_DECREF(pyobj_ret);
5563 ret = 0;
5566 LIBVIRT_RELEASE_THREAD_STATE;
5567 return ret;
5570 static int
5571 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5572 virDomainPtr dom,
5573 void *opaque)
5575 PyObject *pyobj_cbData = (PyObject*)opaque;
5576 PyObject *pyobj_dom;
5577 PyObject *pyobj_ret;
5578 PyObject *pyobj_conn;
5579 PyObject *dictKey;
5580 int ret = -1;
5582 LIBVIRT_ENSURE_THREAD_STATE;
5584 /* Create a python instance of this virDomainPtr */
5585 virDomainRef(dom);
5586 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5587 Py_INCREF(pyobj_cbData);
5589 dictKey = libvirt_constcharPtrWrap("conn");
5590 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5591 Py_DECREF(dictKey);
5593 /* Call the Callback Dispatcher */
5594 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5595 (char*)"_dispatchDomainEventGenericCallback",
5596 (char*)"OO",
5597 pyobj_dom, pyobj_cbData);
5599 Py_DECREF(pyobj_cbData);
5600 Py_DECREF(pyobj_dom);
5602 if (!pyobj_ret) {
5603 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5604 PyErr_Print();
5605 } else {
5606 Py_DECREF(pyobj_ret);
5607 ret = 0;
5610 LIBVIRT_RELEASE_THREAD_STATE;
5611 return ret;
5614 static int
5615 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5616 virDomainPtr dom,
5617 long long utcoffset,
5618 void *opaque)
5620 PyObject *pyobj_cbData = (PyObject*)opaque;
5621 PyObject *pyobj_dom;
5622 PyObject *pyobj_ret;
5623 PyObject *pyobj_conn;
5624 PyObject *dictKey;
5625 int ret = -1;
5627 LIBVIRT_ENSURE_THREAD_STATE;
5629 /* Create a python instance of this virDomainPtr */
5630 virDomainRef(dom);
5631 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5632 Py_INCREF(pyobj_cbData);
5634 dictKey = libvirt_constcharPtrWrap("conn");
5635 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5636 Py_DECREF(dictKey);
5638 /* Call the Callback Dispatcher */
5639 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5640 (char*)"_dispatchDomainEventRTCChangeCallback",
5641 (char*)"OLO",
5642 pyobj_dom,
5643 (PY_LONG_LONG)utcoffset,
5644 pyobj_cbData);
5646 Py_DECREF(pyobj_cbData);
5647 Py_DECREF(pyobj_dom);
5649 if (!pyobj_ret) {
5650 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5651 PyErr_Print();
5652 } else {
5653 Py_DECREF(pyobj_ret);
5654 ret = 0;
5657 LIBVIRT_RELEASE_THREAD_STATE;
5658 return ret;
5661 static int
5662 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5663 virDomainPtr dom,
5664 int action,
5665 void *opaque)
5667 PyObject *pyobj_cbData = (PyObject*)opaque;
5668 PyObject *pyobj_dom;
5669 PyObject *pyobj_ret;
5670 PyObject *pyobj_conn;
5671 PyObject *dictKey;
5672 int ret = -1;
5674 LIBVIRT_ENSURE_THREAD_STATE;
5676 /* Create a python instance of this virDomainPtr */
5677 virDomainRef(dom);
5678 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5679 Py_INCREF(pyobj_cbData);
5681 dictKey = libvirt_constcharPtrWrap("conn");
5682 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5683 Py_DECREF(dictKey);
5685 /* Call the Callback Dispatcher */
5686 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5687 (char*)"_dispatchDomainEventWatchdogCallback",
5688 (char*)"OiO",
5689 pyobj_dom,
5690 action,
5691 pyobj_cbData);
5693 Py_DECREF(pyobj_cbData);
5694 Py_DECREF(pyobj_dom);
5696 if (!pyobj_ret) {
5697 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5698 PyErr_Print();
5699 } else {
5700 Py_DECREF(pyobj_ret);
5701 ret = 0;
5704 LIBVIRT_RELEASE_THREAD_STATE;
5705 return ret;
5708 static int
5709 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5710 virDomainPtr dom,
5711 const char *srcPath,
5712 const char *devAlias,
5713 int action,
5714 void *opaque)
5716 PyObject *pyobj_cbData = (PyObject*)opaque;
5717 PyObject *pyobj_dom;
5718 PyObject *pyobj_ret;
5719 PyObject *pyobj_conn;
5720 PyObject *dictKey;
5721 int ret = -1;
5723 LIBVIRT_ENSURE_THREAD_STATE;
5725 /* Create a python instance of this virDomainPtr */
5726 virDomainRef(dom);
5727 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5728 Py_INCREF(pyobj_cbData);
5730 dictKey = libvirt_constcharPtrWrap("conn");
5731 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5732 Py_DECREF(dictKey);
5734 /* Call the Callback Dispatcher */
5735 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5736 (char*)"_dispatchDomainEventIOErrorCallback",
5737 (char*)"OssiO",
5738 pyobj_dom,
5739 srcPath, devAlias, action,
5740 pyobj_cbData);
5742 Py_DECREF(pyobj_cbData);
5743 Py_DECREF(pyobj_dom);
5745 if (!pyobj_ret) {
5746 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5747 PyErr_Print();
5748 } else {
5749 Py_DECREF(pyobj_ret);
5750 ret = 0;
5753 LIBVIRT_RELEASE_THREAD_STATE;
5754 return ret;
5757 static int
5758 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5759 virDomainPtr dom,
5760 const char *srcPath,
5761 const char *devAlias,
5762 int action,
5763 const char *reason,
5764 void *opaque)
5766 PyObject *pyobj_cbData = (PyObject*)opaque;
5767 PyObject *pyobj_dom;
5768 PyObject *pyobj_ret;
5769 PyObject *pyobj_conn;
5770 PyObject *dictKey;
5771 int ret = -1;
5773 LIBVIRT_ENSURE_THREAD_STATE;
5775 /* Create a python instance of this virDomainPtr */
5776 virDomainRef(dom);
5777 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5778 Py_INCREF(pyobj_cbData);
5780 dictKey = libvirt_constcharPtrWrap("conn");
5781 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5782 Py_DECREF(dictKey);
5784 /* Call the Callback Dispatcher */
5785 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5786 (char*)"_dispatchDomainEventIOErrorReasonCallback",
5787 (char*)"OssisO",
5788 pyobj_dom,
5789 srcPath, devAlias, action, reason,
5790 pyobj_cbData);
5792 Py_DECREF(pyobj_cbData);
5793 Py_DECREF(pyobj_dom);
5795 if (!pyobj_ret) {
5796 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5797 PyErr_Print();
5798 } else {
5799 Py_DECREF(pyobj_ret);
5800 ret = 0;
5803 LIBVIRT_RELEASE_THREAD_STATE;
5804 return ret;
5807 static int
5808 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5809 virDomainPtr dom,
5810 int phase,
5811 virDomainEventGraphicsAddressPtr local,
5812 virDomainEventGraphicsAddressPtr remote,
5813 const char *authScheme,
5814 virDomainEventGraphicsSubjectPtr subject,
5815 void *opaque)
5817 PyObject *pyobj_cbData = (PyObject*)opaque;
5818 PyObject *pyobj_dom;
5819 PyObject *pyobj_ret;
5820 PyObject *pyobj_conn;
5821 PyObject *dictKey;
5822 PyObject *pyobj_local;
5823 PyObject *pyobj_remote;
5824 PyObject *pyobj_subject;
5825 int ret = -1;
5826 size_t i;
5828 LIBVIRT_ENSURE_THREAD_STATE;
5830 /* Create a python instance of this virDomainPtr */
5831 virDomainRef(dom);
5832 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5833 Py_INCREF(pyobj_cbData);
5835 dictKey = libvirt_constcharPtrWrap("conn");
5836 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5837 Py_DECREF(dictKey);
5839 pyobj_local = PyDict_New();
5840 PyDict_SetItem(pyobj_local,
5841 libvirt_constcharPtrWrap("family"),
5842 libvirt_intWrap(local->family));
5843 PyDict_SetItem(pyobj_local,
5844 libvirt_constcharPtrWrap("node"),
5845 libvirt_constcharPtrWrap(local->node));
5846 PyDict_SetItem(pyobj_local,
5847 libvirt_constcharPtrWrap("service"),
5848 libvirt_constcharPtrWrap(local->service));
5850 pyobj_remote = PyDict_New();
5851 PyDict_SetItem(pyobj_remote,
5852 libvirt_constcharPtrWrap("family"),
5853 libvirt_intWrap(remote->family));
5854 PyDict_SetItem(pyobj_remote,
5855 libvirt_constcharPtrWrap("node"),
5856 libvirt_constcharPtrWrap(remote->node));
5857 PyDict_SetItem(pyobj_remote,
5858 libvirt_constcharPtrWrap("service"),
5859 libvirt_constcharPtrWrap(remote->service));
5861 pyobj_subject = PyList_New(subject->nidentity);
5862 for (i = 0; i < subject->nidentity; i++) {
5863 PyObject *pair = PyTuple_New(2);
5864 PyTuple_SetItem(pair, 0, libvirt_constcharPtrWrap(subject->identities[i].type));
5865 PyTuple_SetItem(pair, 1, libvirt_constcharPtrWrap(subject->identities[i].name));
5867 PyList_SetItem(pyobj_subject, i, pair);
5870 /* Call the Callback Dispatcher */
5871 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5872 (char*)"_dispatchDomainEventGraphicsCallback",
5873 (char*)"OiOOsOO",
5874 pyobj_dom,
5875 phase, pyobj_local, pyobj_remote,
5876 authScheme, pyobj_subject,
5877 pyobj_cbData);
5879 Py_DECREF(pyobj_cbData);
5880 Py_DECREF(pyobj_dom);
5882 if (!pyobj_ret) {
5883 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5884 PyErr_Print();
5885 } else {
5886 Py_DECREF(pyobj_ret);
5887 ret = 0;
5890 LIBVIRT_RELEASE_THREAD_STATE;
5891 return ret;
5894 static int
5895 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5896 virDomainPtr dom,
5897 const char *path,
5898 int type,
5899 int status,
5900 void *opaque)
5902 PyObject *pyobj_cbData = (PyObject*)opaque;
5903 PyObject *pyobj_dom;
5904 PyObject *pyobj_ret;
5905 PyObject *pyobj_conn;
5906 PyObject *dictKey;
5907 int ret = -1;
5909 LIBVIRT_ENSURE_THREAD_STATE;
5911 /* Create a python instance of this virDomainPtr */
5912 virDomainRef(dom);
5913 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5914 Py_INCREF(pyobj_cbData);
5916 dictKey = libvirt_constcharPtrWrap("conn");
5917 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5918 Py_DECREF(dictKey);
5920 /* Call the Callback Dispatcher */
5921 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5922 (char*)"dispatchDomainEventBlockPullCallback",
5923 (char*)"OsiiO",
5924 pyobj_dom, path, type, status, pyobj_cbData);
5926 Py_DECREF(pyobj_cbData);
5927 Py_DECREF(pyobj_dom);
5929 if (!pyobj_ret) {
5930 #if DEBUG_ERROR
5931 printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5932 #endif
5933 PyErr_Print();
5934 } else {
5935 Py_DECREF(pyobj_ret);
5936 ret = 0;
5939 LIBVIRT_RELEASE_THREAD_STATE;
5940 return ret;
5943 static int
5944 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5945 virDomainPtr dom,
5946 const char *oldSrcPath,
5947 const char *newSrcPath,
5948 const char *devAlias,
5949 int reason,
5950 void *opaque)
5952 PyObject *pyobj_cbData = (PyObject*)opaque;
5953 PyObject *pyobj_dom;
5954 PyObject *pyobj_ret;
5955 PyObject *pyobj_conn;
5956 PyObject *dictKey;
5957 int ret = -1;
5959 LIBVIRT_ENSURE_THREAD_STATE;
5960 /* Create a python instance of this virDomainPtr */
5961 virDomainRef(dom);
5963 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5964 Py_INCREF(pyobj_cbData);
5966 dictKey = libvirt_constcharPtrWrap("conn");
5967 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5968 Py_DECREF(dictKey);
5970 /* Call the Callback Dispatcher */
5971 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5972 (char*)"_dispatchDomainEventDiskChangeCallback",
5973 (char*)"OsssiO",
5974 pyobj_dom,
5975 oldSrcPath, newSrcPath,
5976 devAlias, reason, pyobj_cbData);
5978 Py_DECREF(pyobj_cbData);
5979 Py_DECREF(pyobj_dom);
5981 if (!pyobj_ret) {
5982 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5983 PyErr_Print();
5984 } else {
5985 Py_DECREF(pyobj_ret);
5986 ret = 0;
5989 LIBVIRT_RELEASE_THREAD_STATE;
5990 return ret;
5993 static int
5994 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5995 virDomainPtr dom,
5996 const char *devAlias,
5997 int reason,
5998 void *opaque)
6000 PyObject *pyobj_cbData = (PyObject*)opaque;
6001 PyObject *pyobj_dom;
6002 PyObject *pyobj_ret;
6003 PyObject *pyobj_conn;
6004 PyObject *dictKey;
6005 int ret = -1;
6007 LIBVIRT_ENSURE_THREAD_STATE;
6008 /* Create a python instance of this virDomainPtr */
6009 virDomainRef(dom);
6011 pyobj_dom = libvirt_virDomainPtrWrap(dom);
6012 Py_INCREF(pyobj_cbData);
6014 dictKey = libvirt_constcharPtrWrap("conn");
6015 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6016 Py_DECREF(dictKey);
6018 /* Call the Callback Dispatcher */
6019 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6020 (char*)"_dispatchDomainEventTrayChangeCallback",
6021 (char*)"OsiO",
6022 pyobj_dom,
6023 devAlias, reason, pyobj_cbData);
6025 Py_DECREF(pyobj_cbData);
6026 Py_DECREF(pyobj_dom);
6028 if (!pyobj_ret) {
6029 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6030 PyErr_Print();
6031 } else {
6032 Py_DECREF(pyobj_ret);
6033 ret = 0;
6036 LIBVIRT_RELEASE_THREAD_STATE;
6037 return ret;
6040 static int
6041 libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6042 virDomainPtr dom,
6043 int reason,
6044 void *opaque)
6046 PyObject *pyobj_cbData = (PyObject*)opaque;
6047 PyObject *pyobj_dom;
6048 PyObject *pyobj_ret;
6049 PyObject *pyobj_conn;
6050 PyObject *dictKey;
6051 int ret = -1;
6053 LIBVIRT_ENSURE_THREAD_STATE;
6054 /* Create a python instance of this virDomainPtr */
6055 virDomainRef(dom);
6057 pyobj_dom = libvirt_virDomainPtrWrap(dom);
6058 Py_INCREF(pyobj_cbData);
6060 dictKey = libvirt_constcharPtrWrap("conn");
6061 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6062 Py_DECREF(dictKey);
6064 /* Call the Callback Dispatcher */
6065 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6066 (char*)"_dispatchDomainEventPMWakeupCallback",
6067 (char*)"OiO",
6068 pyobj_dom,
6069 reason,
6070 pyobj_cbData);
6072 Py_DECREF(pyobj_cbData);
6073 Py_DECREF(pyobj_dom);
6075 if (!pyobj_ret) {
6076 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6077 PyErr_Print();
6078 } else {
6079 Py_DECREF(pyobj_ret);
6080 ret = 0;
6083 LIBVIRT_RELEASE_THREAD_STATE;
6084 return ret;
6087 static int
6088 libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6089 virDomainPtr dom,
6090 int reason,
6091 void *opaque)
6093 PyObject *pyobj_cbData = (PyObject*)opaque;
6094 PyObject *pyobj_dom;
6095 PyObject *pyobj_ret;
6096 PyObject *pyobj_conn;
6097 PyObject *dictKey;
6098 int ret = -1;
6100 LIBVIRT_ENSURE_THREAD_STATE;
6101 /* Create a python instance of this virDomainPtr */
6102 virDomainRef(dom);
6104 pyobj_dom = libvirt_virDomainPtrWrap(dom);
6105 Py_INCREF(pyobj_cbData);
6107 dictKey = libvirt_constcharPtrWrap("conn");
6108 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6109 Py_DECREF(dictKey);
6111 /* Call the Callback Dispatcher */
6112 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6113 (char*)"_dispatchDomainEventPMSuspendCallback",
6114 (char*)"OiO",
6115 pyobj_dom,
6116 reason,
6117 pyobj_cbData);
6119 Py_DECREF(pyobj_cbData);
6120 Py_DECREF(pyobj_dom);
6122 if (!pyobj_ret) {
6123 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6124 PyErr_Print();
6125 } else {
6126 Py_DECREF(pyobj_ret);
6127 ret = 0;
6130 LIBVIRT_RELEASE_THREAD_STATE;
6131 return ret;
6134 static int
6135 libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6136 virDomainPtr dom,
6137 unsigned long long actual,
6138 void *opaque)
6140 PyObject *pyobj_cbData = (PyObject*)opaque;
6141 PyObject *pyobj_dom;
6142 PyObject *pyobj_ret;
6143 PyObject *pyobj_conn;
6144 PyObject *dictKey;
6145 int ret = -1;
6147 LIBVIRT_ENSURE_THREAD_STATE;
6149 /* Create a python instance of this virDomainPtr */
6150 virDomainRef(dom);
6151 pyobj_dom = libvirt_virDomainPtrWrap(dom);
6152 Py_INCREF(pyobj_cbData);
6154 dictKey = libvirt_constcharPtrWrap("conn");
6155 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6156 Py_DECREF(dictKey);
6158 /* Call the Callback Dispatcher */
6159 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6160 (char*)"_dispatchDomainEventBalloonChangeCallback",
6161 (char*)"OLO",
6162 pyobj_dom,
6163 (PY_LONG_LONG)actual,
6164 pyobj_cbData);
6166 Py_DECREF(pyobj_cbData);
6167 Py_DECREF(pyobj_dom);
6169 if (!pyobj_ret) {
6170 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6171 PyErr_Print();
6172 } else {
6173 Py_DECREF(pyobj_ret);
6174 ret = 0;
6177 LIBVIRT_RELEASE_THREAD_STATE;
6178 return ret;
6181 static int
6182 libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
6183 virDomainPtr dom,
6184 int reason,
6185 void *opaque)
6187 PyObject *pyobj_cbData = (PyObject*)opaque;
6188 PyObject *pyobj_dom;
6189 PyObject *pyobj_ret;
6190 PyObject *pyobj_conn;
6191 PyObject *dictKey;
6192 int ret = -1;
6194 LIBVIRT_ENSURE_THREAD_STATE;
6195 /* Create a python instance of this virDomainPtr */
6196 virDomainRef(dom);
6198 pyobj_dom = libvirt_virDomainPtrWrap(dom);
6199 Py_INCREF(pyobj_cbData);
6201 dictKey = libvirt_constcharPtrWrap("conn");
6202 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6203 Py_DECREF(dictKey);
6205 /* Call the Callback Dispatcher */
6206 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6207 (char*)"_dispatchDomainEventPMSuspendDiskCallback",
6208 (char*)"OiO",
6209 pyobj_dom,
6210 reason,
6211 pyobj_cbData);
6213 Py_DECREF(pyobj_cbData);
6214 Py_DECREF(pyobj_dom);
6216 if (!pyobj_ret) {
6217 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6218 PyErr_Print();
6219 } else {
6220 Py_DECREF(pyobj_ret);
6221 ret = 0;
6224 LIBVIRT_RELEASE_THREAD_STATE;
6225 return ret;
6228 static PyObject *
6229 libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
6230 PyObject * args)
6232 PyObject *py_retval; /* return value */
6233 PyObject *pyobj_conn; /* virConnectPtr */
6234 PyObject *pyobj_dom;
6235 PyObject *pyobj_cbData; /* hash of callback data */
6236 int eventID;
6237 virConnectPtr conn;
6238 int ret = 0;
6239 virConnectDomainEventGenericCallback cb = NULL;
6240 virDomainPtr dom;
6242 if (!PyArg_ParseTuple
6243 (args, (char *) "OOiO:virConnectDomainEventRegisterAny",
6244 &pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData)) {
6245 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
6246 return VIR_PY_INT_FAIL;
6249 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
6250 pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
6251 conn = PyvirConnect_Get(pyobj_conn);
6252 if (pyobj_dom == Py_None)
6253 dom = NULL;
6254 else
6255 dom = PyvirDomain_Get(pyobj_dom);
6257 switch (eventID) {
6258 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
6259 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback);
6260 break;
6261 case VIR_DOMAIN_EVENT_ID_REBOOT:
6262 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
6263 break;
6264 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
6265 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback);
6266 break;
6267 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
6268 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback);
6269 break;
6270 case VIR_DOMAIN_EVENT_ID_IO_ERROR:
6271 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback);
6272 break;
6273 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
6274 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback);
6275 break;
6276 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
6277 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback);
6278 break;
6279 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
6280 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
6281 break;
6282 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
6283 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback);
6284 break;
6285 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
6286 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
6287 break;
6288 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
6289 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
6290 break;
6291 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
6292 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
6293 break;
6294 case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
6295 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
6296 break;
6297 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
6298 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback);
6299 break;
6300 case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
6301 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback);
6302 break;
6305 if (!cb) {
6306 return VIR_PY_INT_FAIL;
6309 Py_INCREF(pyobj_cbData);
6311 LIBVIRT_BEGIN_ALLOW_THREADS;
6312 ret = virConnectDomainEventRegisterAny(conn, dom, eventID,
6313 cb, pyobj_cbData,
6314 libvirt_virConnectDomainEventFreeFunc);
6315 LIBVIRT_END_ALLOW_THREADS;
6317 if (ret < 0) {
6318 Py_DECREF(pyobj_cbData);
6321 py_retval = libvirt_intWrap(ret);
6322 return py_retval;
6325 static PyObject *
6326 libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject * self,
6327 PyObject * args)
6329 PyObject *py_retval;
6330 PyObject *pyobj_conn;
6331 int callbackID;
6332 virConnectPtr conn;
6333 int ret = 0;
6335 if (!PyArg_ParseTuple
6336 (args, (char *) "Oi:virConnectDomainEventDeregister",
6337 &pyobj_conn, &callbackID))
6338 return NULL;
6340 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
6342 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6344 LIBVIRT_BEGIN_ALLOW_THREADS;
6346 ret = virConnectDomainEventDeregisterAny(conn, callbackID);
6348 LIBVIRT_END_ALLOW_THREADS;
6349 py_retval = libvirt_intWrap(ret);
6350 return py_retval;
6354 static void
6355 libvirt_virConnectCloseCallbackDispatch(virConnectPtr conn ATTRIBUTE_UNUSED,
6356 int reason,
6357 void *opaque)
6359 PyObject *pyobj_cbData = (PyObject*)opaque;
6360 PyObject *pyobj_ret;
6361 PyObject *pyobj_conn;
6362 PyObject *dictKey;
6364 LIBVIRT_ENSURE_THREAD_STATE;
6366 Py_INCREF(pyobj_cbData);
6368 dictKey = libvirt_constcharPtrWrap("conn");
6369 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
6370 Py_DECREF(dictKey);
6372 /* Call the Callback Dispatcher */
6373 pyobj_ret = PyObject_CallMethod(pyobj_conn,
6374 (char*)"_dispatchCloseCallback",
6375 (char*)"iO",
6376 reason,
6377 pyobj_cbData);
6379 Py_DECREF(pyobj_cbData);
6381 if (!pyobj_ret) {
6382 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6383 PyErr_Print();
6384 } else {
6385 Py_DECREF(pyobj_ret);
6388 LIBVIRT_RELEASE_THREAD_STATE;
6391 static PyObject *
6392 libvirt_virConnectRegisterCloseCallback(ATTRIBUTE_UNUSED PyObject * self,
6393 PyObject * args)
6395 PyObject *py_retval; /* return value */
6396 PyObject *pyobj_conn; /* virConnectPtr */
6397 PyObject *pyobj_cbData; /* hash of callback data */
6398 virConnectPtr conn;
6399 int ret = 0;
6401 if (!PyArg_ParseTuple
6402 (args, (char *) "OO:virConnectRegisterCloseCallback",
6403 &pyobj_conn, &pyobj_cbData)) {
6404 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
6405 return VIR_PY_INT_FAIL;
6408 DEBUG("libvirt_virConnectRegisterCloseCallback(%p %p) called\n",
6409 pyobj_conn, pyobj_cbData);
6410 conn = PyvirConnect_Get(pyobj_conn);
6412 Py_INCREF(pyobj_cbData);
6414 LIBVIRT_BEGIN_ALLOW_THREADS;
6415 ret = virConnectRegisterCloseCallback(conn,
6416 libvirt_virConnectCloseCallbackDispatch,
6417 pyobj_cbData,
6418 libvirt_virConnectDomainEventFreeFunc);
6419 LIBVIRT_END_ALLOW_THREADS;
6421 if (ret < 0) {
6422 Py_DECREF(pyobj_cbData);
6425 py_retval = libvirt_intWrap(ret);
6426 return py_retval;
6429 static PyObject *
6430 libvirt_virConnectUnregisterCloseCallback(ATTRIBUTE_UNUSED PyObject * self,
6431 PyObject * args)
6433 PyObject *py_retval;
6434 PyObject *pyobj_conn;
6435 virConnectPtr conn;
6436 int ret = 0;
6438 if (!PyArg_ParseTuple
6439 (args, (char *) "O:virConnectDomainEventUnregister",
6440 &pyobj_conn))
6441 return NULL;
6443 DEBUG("libvirt_virConnectDomainEventUnregister(%p) called\n",
6444 pyobj_conn);
6446 conn = PyvirConnect_Get(pyobj_conn);
6448 LIBVIRT_BEGIN_ALLOW_THREADS;
6450 ret = virConnectUnregisterCloseCallback(conn,
6451 libvirt_virConnectCloseCallbackDispatch);
6453 LIBVIRT_END_ALLOW_THREADS;
6454 py_retval = libvirt_intWrap(ret);
6455 return py_retval;
6458 static void
6459 libvirt_virStreamEventFreeFunc(void *opaque)
6461 PyObject *pyobj_stream = (PyObject*)opaque;
6462 LIBVIRT_ENSURE_THREAD_STATE;
6463 Py_DECREF(pyobj_stream);
6464 LIBVIRT_RELEASE_THREAD_STATE;
6467 static void
6468 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED,
6469 int events,
6470 void *opaque)
6472 PyObject *pyobj_cbData = (PyObject *)opaque;
6473 PyObject *pyobj_stream;
6474 PyObject *pyobj_ret;
6475 PyObject *dictKey;
6477 LIBVIRT_ENSURE_THREAD_STATE;
6479 Py_INCREF(pyobj_cbData);
6480 dictKey = libvirt_constcharPtrWrap("stream");
6481 pyobj_stream = PyDict_GetItem(pyobj_cbData, dictKey);
6482 Py_DECREF(dictKey);
6484 /* Call the pure python dispatcher */
6485 pyobj_ret = PyObject_CallMethod(pyobj_stream,
6486 (char *)"_dispatchStreamEventCallback",
6487 (char *)"iO",
6488 events, pyobj_cbData);
6490 Py_DECREF(pyobj_cbData);
6492 if (!pyobj_ret) {
6493 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
6494 PyErr_Print();
6495 } else {
6496 Py_DECREF(pyobj_ret);
6499 LIBVIRT_RELEASE_THREAD_STATE;
6502 static PyObject *
6503 libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
6504 PyObject *args)
6506 PyObject *py_retval;
6507 PyObject *pyobj_stream;
6508 PyObject *pyobj_cbData;
6509 virStreamPtr stream;
6510 virStreamEventCallback cb = libvirt_virStreamEventCallback;
6511 int ret;
6512 int events;
6514 if (!PyArg_ParseTuple(args, (char *) "OiO:virStreamEventAddCallback",
6515 &pyobj_stream, &events, &pyobj_cbData)) {
6516 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6517 return VIR_PY_INT_FAIL;
6520 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
6521 pyobj_stream, events, pyobj_cbData);
6522 stream = PyvirStream_Get(pyobj_stream);
6524 Py_INCREF(pyobj_cbData);
6526 LIBVIRT_BEGIN_ALLOW_THREADS;
6527 ret = virStreamEventAddCallback(stream, events, cb, pyobj_cbData,
6528 libvirt_virStreamEventFreeFunc);
6529 LIBVIRT_END_ALLOW_THREADS;
6531 if (ret < 0) {
6532 Py_DECREF(pyobj_cbData);
6535 py_retval = libvirt_intWrap(ret);
6536 return py_retval;
6539 static PyObject *
6540 libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
6541 PyObject *args)
6543 PyObject *pyobj_stream;
6544 virStreamPtr stream;
6545 char *buf = NULL;
6546 int ret;
6547 int nbytes;
6549 if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
6550 &pyobj_stream, &nbytes)) {
6551 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6552 return VIR_PY_NONE;
6554 stream = PyvirStream_Get(pyobj_stream);
6556 if (VIR_ALLOC_N_QUIET(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0)
6557 return VIR_PY_NONE;
6559 LIBVIRT_BEGIN_ALLOW_THREADS;
6560 ret = virStreamRecv(stream, buf, nbytes);
6561 LIBVIRT_END_ALLOW_THREADS;
6563 buf[ret > -1 ? ret : 0] = '\0';
6564 DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
6566 if (ret == -2)
6567 return libvirt_intWrap(ret);
6568 if (ret < 0)
6569 return VIR_PY_NONE;
6570 return libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
6573 static PyObject *
6574 libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
6575 PyObject *args)
6577 PyObject *py_retval;
6578 PyObject *pyobj_stream;
6579 virStreamPtr stream;
6580 char *data;
6581 int datalen;
6582 int ret;
6583 int nbytes;
6585 if (!PyArg_ParseTuple(args, (char *) "Oz#i:virStreamRecv",
6586 &pyobj_stream, &data, &datalen, &nbytes)) {
6587 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6588 return VIR_PY_INT_FAIL;
6590 stream = PyvirStream_Get(pyobj_stream);
6592 LIBVIRT_BEGIN_ALLOW_THREADS;
6593 ret = virStreamSend(stream, data, nbytes);
6594 LIBVIRT_END_ALLOW_THREADS;
6596 DEBUG("StreamSend ret=%d\n", ret);
6598 py_retval = libvirt_intWrap(ret);
6599 return py_retval;
6602 static PyObject *
6603 libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
6604 PyObject *args)
6606 PyObject *py_retval;
6607 virDomainPtr domain;
6608 PyObject *pyobj_domain;
6609 PyObject *pyobj_list;
6610 int codeset;
6611 int holdtime;
6612 unsigned int flags;
6613 int ret;
6614 size_t i;
6615 unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
6616 unsigned int nkeycodes;
6618 if (!PyArg_ParseTuple(args, (char *)"OiiOii:virDomainSendKey",
6619 &pyobj_domain, &codeset, &holdtime, &pyobj_list,
6620 &nkeycodes, &flags)) {
6621 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6622 return VIR_PY_INT_FAIL;
6624 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6626 if (!PyList_Check(pyobj_list)) {
6627 return VIR_PY_INT_FAIL;
6630 if (nkeycodes != PyList_Size(pyobj_list) ||
6631 nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
6632 return VIR_PY_INT_FAIL;
6635 for (i = 0; i < nkeycodes; i++) {
6636 keycodes[i] = (int)PyInt_AsLong(PyList_GetItem(pyobj_list, i));
6639 LIBVIRT_BEGIN_ALLOW_THREADS;
6640 ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
6641 LIBVIRT_END_ALLOW_THREADS;
6643 DEBUG("virDomainSendKey ret=%d\n", ret);
6645 py_retval = libvirt_intWrap(ret);
6646 return py_retval;
6649 static PyObject *
6650 libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED,
6651 PyObject *args)
6653 PyObject *pyobj_domain;
6654 virDomainPtr domain;
6655 unsigned int flags;
6656 unsigned long long cacheSize;
6657 int rc;
6659 if (!PyArg_ParseTuple(args,
6660 (char *) "Oi:virDomainMigrateGetCompressionCache",
6661 &pyobj_domain, &flags))
6662 return VIR_PY_NONE;
6664 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6666 LIBVIRT_BEGIN_ALLOW_THREADS;
6667 rc = virDomainMigrateGetCompressionCache(domain, &cacheSize, flags);
6668 LIBVIRT_END_ALLOW_THREADS;
6670 if (rc < 0)
6671 return VIR_PY_NONE;
6673 return libvirt_ulonglongWrap(cacheSize);
6676 static PyObject *
6677 libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
6678 PyObject *py_retval;
6679 int c_retval;
6680 unsigned long bandwidth;
6681 virDomainPtr domain;
6682 PyObject *pyobj_domain;
6683 unsigned int flags = 0;
6685 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainMigrateGetMaxSpeed",
6686 &pyobj_domain, &flags))
6687 return NULL;
6689 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6691 LIBVIRT_BEGIN_ALLOW_THREADS;
6692 c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, flags);
6693 LIBVIRT_END_ALLOW_THREADS;
6695 if (c_retval < 0)
6696 return VIR_PY_INT_FAIL;
6697 py_retval = libvirt_ulongWrap(bandwidth);
6698 return py_retval;
6701 static PyObject *
6702 libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
6703 PyObject *args)
6705 PyObject *pyobj_domain;
6706 virDomainPtr domain;
6707 PyObject *pyobj_dconn;
6708 virConnectPtr dconn;
6709 PyObject *dict;
6710 unsigned int flags;
6711 virTypedParameterPtr params;
6712 int nparams;
6713 virDomainPtr ddom = NULL;
6715 if (!PyArg_ParseTuple(args, (char *) "OOOi:virDomainMigrate3",
6716 &pyobj_domain, &pyobj_dconn, &dict, &flags))
6717 return NULL;
6719 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6720 dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);
6722 if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
6723 return NULL;
6725 LIBVIRT_BEGIN_ALLOW_THREADS;
6726 ddom = virDomainMigrate3(domain, dconn, params, nparams, flags);
6727 LIBVIRT_END_ALLOW_THREADS;
6729 virTypedParamsFree(params, nparams);
6730 return libvirt_virDomainPtrWrap(ddom);
6733 static PyObject *
6734 libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,
6735 PyObject *args)
6737 PyObject *pyobj_domain;
6738 virDomainPtr domain;
6739 char *dconnuri;
6740 PyObject *dict;
6741 unsigned int flags;
6742 virTypedParameterPtr params;
6743 int nparams;
6744 int ret = -1;
6746 if (!PyArg_ParseTuple(args, (char *) "OzOi:virDomainMigrate3",
6747 &pyobj_domain, &dconnuri, &dict, &flags))
6748 return NULL;
6750 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6752 if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
6753 return NULL;
6755 LIBVIRT_BEGIN_ALLOW_THREADS;
6756 ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
6757 LIBVIRT_END_ALLOW_THREADS;
6759 virTypedParamsFree(params, nparams);
6760 return libvirt_intWrap(ret);
6763 static PyObject *
6764 libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED,
6765 PyObject *args) {
6766 PyObject *py_retval = NULL;
6767 int c_retval;
6768 virDomainPtr domain;
6769 PyObject *pyobj_domain;
6770 const char *disk;
6771 unsigned long long offset;
6772 size_t size;
6773 char *buf;
6774 unsigned int flags;
6776 if (!PyArg_ParseTuple(args, (char *)"OzLni:virDomainBlockPeek", &pyobj_domain,
6777 &disk, &offset, &size, &flags))
6778 return NULL;
6780 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6782 if (VIR_ALLOC_N_QUIET(buf, size) < 0)
6783 return VIR_PY_NONE;
6785 LIBVIRT_BEGIN_ALLOW_THREADS;
6786 c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags);
6787 LIBVIRT_END_ALLOW_THREADS;
6789 if (c_retval < 0) {
6790 py_retval = VIR_PY_NONE;
6791 goto cleanup;
6794 py_retval = PyString_FromStringAndSize(buf, size);
6796 cleanup:
6797 VIR_FREE(buf);
6798 return py_retval;
6801 static PyObject *
6802 libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED,
6803 PyObject *args) {
6804 PyObject *py_retval = NULL;
6805 int c_retval;
6806 virDomainPtr domain;
6807 PyObject *pyobj_domain;
6808 unsigned long long start;
6809 size_t size;
6810 char *buf;
6811 unsigned int flags;
6813 if (!PyArg_ParseTuple(args, (char *)"OLni:virDomainMemoryPeek", &pyobj_domain,
6814 &start, &size, &flags))
6815 return NULL;
6817 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6819 if (VIR_ALLOC_N_QUIET(buf, size) < 0)
6820 return VIR_PY_NONE;
6822 LIBVIRT_BEGIN_ALLOW_THREADS;
6823 c_retval = virDomainMemoryPeek(domain, start, size, buf, flags);
6824 LIBVIRT_END_ALLOW_THREADS;
6826 if (c_retval < 0) {
6827 py_retval = VIR_PY_NONE;
6828 goto cleanup;
6831 py_retval = PyString_FromStringAndSize(buf, size);
6833 cleanup:
6834 VIR_FREE(buf);
6835 return py_retval;
6838 static PyObject *
6839 libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
6840 PyObject *args)
6842 virConnectPtr conn;
6843 PyObject *pyobj_conn, *info;
6844 PyObject *ret = NULL;
6845 int i_retval;
6846 int nparams = 0;
6847 Py_ssize_t size = 0;
6848 unsigned int flags;
6849 virTypedParameterPtr params, new_params = NULL;
6851 if (!PyArg_ParseTuple(args,
6852 (char *)"OOi:virNodeSetMemoryParameters",
6853 &pyobj_conn, &info, &flags))
6854 return NULL;
6855 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6857 if ((size = PyDict_Size(info)) < 0)
6858 return NULL;
6860 if (size == 0) {
6861 PyErr_Format(PyExc_LookupError,
6862 "Need non-empty dictionary to set attributes");
6863 return NULL;
6866 LIBVIRT_BEGIN_ALLOW_THREADS;
6867 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
6868 LIBVIRT_END_ALLOW_THREADS;
6870 if (i_retval < 0)
6871 return VIR_PY_INT_FAIL;
6873 if (nparams == 0) {
6874 PyErr_Format(PyExc_LookupError,
6875 "no settable attributes");
6876 return NULL;
6879 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
6880 return PyErr_NoMemory();
6882 LIBVIRT_BEGIN_ALLOW_THREADS;
6883 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
6884 LIBVIRT_END_ALLOW_THREADS;
6886 if (i_retval < 0) {
6887 ret = VIR_PY_INT_FAIL;
6888 goto cleanup;
6891 new_params = setPyVirTypedParameter(info, params, nparams);
6892 if (!new_params)
6893 goto cleanup;
6895 LIBVIRT_BEGIN_ALLOW_THREADS;
6896 i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
6897 LIBVIRT_END_ALLOW_THREADS;
6899 if (i_retval < 0) {
6900 ret = VIR_PY_INT_FAIL;
6901 goto cleanup;
6904 ret = VIR_PY_INT_SUCCESS;
6906 cleanup:
6907 virTypedParamsFree(params, nparams);
6908 VIR_FREE(new_params);
6909 return ret;
6912 static PyObject *
6913 libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
6914 PyObject *args)
6916 virConnectPtr conn;
6917 PyObject *pyobj_conn;
6918 PyObject *ret = NULL;
6919 int i_retval;
6920 int nparams = 0;
6921 unsigned int flags;
6922 virTypedParameterPtr params;
6924 if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetMemoryParameters",
6925 &pyobj_conn, &flags))
6926 return NULL;
6927 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6929 LIBVIRT_BEGIN_ALLOW_THREADS;
6930 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
6931 LIBVIRT_END_ALLOW_THREADS;
6933 if (i_retval < 0)
6934 return VIR_PY_NONE;
6936 if (!nparams)
6937 return PyDict_New();
6939 if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
6940 return PyErr_NoMemory();
6942 LIBVIRT_BEGIN_ALLOW_THREADS;
6943 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
6944 LIBVIRT_END_ALLOW_THREADS;
6946 if (i_retval < 0) {
6947 ret = VIR_PY_NONE;
6948 goto cleanup;
6951 ret = getPyVirTypedParameter(params, nparams);
6953 cleanup:
6954 virTypedParamsFree(params, nparams);
6955 return ret;
6958 static PyObject *
6959 libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
6960 PyObject *args)
6962 virConnectPtr conn;
6963 PyObject *pyobj_conn;
6964 PyObject *ret = NULL;
6965 PyObject *pycpumap = NULL;
6966 PyObject *pyused = NULL;
6967 PyObject *pycpunum = NULL;
6968 PyObject *pyonline = NULL;
6969 int i_retval;
6970 unsigned char *cpumap = NULL;
6971 unsigned int online = 0;
6972 unsigned int flags;
6973 size_t i;
6975 if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetCPUMap",
6976 &pyobj_conn, &flags))
6977 return NULL;
6978 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6980 LIBVIRT_BEGIN_ALLOW_THREADS;
6981 i_retval = virNodeGetCPUMap(conn, &cpumap, &online, flags);
6982 LIBVIRT_END_ALLOW_THREADS;
6984 if (i_retval < 0)
6985 return VIR_PY_NONE;
6987 if ((ret = PyTuple_New(3)) == NULL)
6988 goto error;
6990 /* 0: number of CPUs */
6991 if ((pycpunum = PyLong_FromLong(i_retval)) == NULL ||
6992 PyTuple_SetItem(ret, 0, pycpunum) < 0)
6993 goto error;
6995 /* 1: CPU map */
6996 if ((pycpumap = PyList_New(i_retval)) == NULL)
6997 goto error;
6999 for (i = 0; i < i_retval; i++) {
7000 if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL)
7001 goto error;
7002 if (PyList_SetItem(pycpumap, i, pyused) < 0)
7003 goto error;
7006 if (PyTuple_SetItem(ret, 1, pycpumap) < 0)
7007 goto error;
7009 /* 2: number of online CPUs */
7010 if ((pyonline = PyLong_FromLong(online)) == NULL ||
7011 PyTuple_SetItem(ret, 2, pyonline) < 0)
7012 goto error;
7014 cleanup:
7015 VIR_FREE(cpumap);
7016 return ret;
7017 error:
7018 Py_XDECREF(ret);
7019 Py_XDECREF(pycpumap);
7020 Py_XDECREF(pyused);
7021 Py_XDECREF(pycpunum);
7022 Py_XDECREF(pyonline);
7023 ret = NULL;
7024 goto cleanup;
7028 /************************************************************************
7030 * The registration stuff *
7032 ************************************************************************/
7033 static PyMethodDef libvirtMethods[] = {
7034 #include "libvirt-export.c"
7035 {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
7036 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL},
7037 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
7038 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
7039 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
7040 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
7041 {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
7042 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
7043 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
7044 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
7045 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
7046 {(char *) "virConnectRegisterCloseCallback", libvirt_virConnectRegisterCloseCallback, METH_VARARGS, NULL},
7047 {(char *) "virConnectUnregisterCloseCallback", libvirt_virConnectUnregisterCloseCallback, METH_VARARGS, NULL},
7048 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
7049 {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
7050 {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
7051 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
7052 {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
7053 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
7054 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
7055 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
7056 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
7057 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
7058 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
7059 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
7060 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
7061 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
7062 {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
7063 {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
7064 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
7065 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
7066 {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
7067 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
7068 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
7069 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},
7070 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL},
7071 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
7072 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
7073 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL},
7074 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats, METH_VARARGS, NULL},
7075 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
7076 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
7077 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
7078 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
7079 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
7080 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags, METH_VARARGS, NULL},
7081 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
7082 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags, METH_VARARGS, NULL},
7083 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters, METH_VARARGS, NULL},
7084 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters, METH_VARARGS, NULL},
7085 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters, METH_VARARGS, NULL},
7086 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
7087 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
7088 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
7089 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
7090 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
7091 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
7092 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
7093 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
7094 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
7095 {(char *) "virDomainGetEmulatorPinInfo", libvirt_virDomainGetEmulatorPinInfo, METH_VARARGS, NULL},
7096 {(char *) "virDomainPinEmulator", libvirt_virDomainPinEmulator, METH_VARARGS, NULL},
7097 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
7098 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
7099 {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
7100 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
7101 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
7102 {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
7103 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL},
7104 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL},
7105 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL},
7106 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL},
7107 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL},
7108 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
7109 {(char *) "virEventAddHandle", libvirt_virEventAddHandle, METH_VARARGS, NULL},
7110 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout, METH_VARARGS, NULL},
7111 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
7112 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
7113 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
7114 {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
7115 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
7116 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
7117 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},
7118 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL},
7119 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
7120 {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL},
7121 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
7122 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
7123 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL},
7124 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
7125 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
7126 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
7127 {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
7128 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
7129 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
7130 {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
7131 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
7132 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
7133 {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL},
7134 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
7135 {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
7136 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
7137 {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
7138 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
7139 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
7140 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
7141 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL},
7142 {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
7143 {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL},
7144 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
7145 {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL},
7146 {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL},
7147 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
7148 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
7149 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
7150 {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
7151 {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
7152 {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
7153 {NULL, NULL, 0, NULL}
7156 void
7157 #ifndef __CYGWIN__
7158 initlibvirtmod
7159 #else
7160 initcygvirtmod
7161 #endif
7162 (void)
7164 static int initialized = 0;
7166 if (initialized != 0)
7167 return;
7169 if (virInitialize() < 0)
7170 return;
7172 /* initialize the python extension module */
7173 Py_InitModule((char *)
7174 #ifndef __CYGWIN__
7175 "libvirtmod"
7176 #else
7177 "cygvirtmod"
7178 #endif
7179 , libvirtMethods);
7181 initialized = 1;