Add support for SUSPEND_DISK event
[libvirt-python/ericb.git] / libvirt-override.c
blob4d261e886198128a9decd33e5b3172fcd15f0bf8
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-2012 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 "memory.h"
28 #include "virtypedparam.h"
29 #include "ignore-value.h"
30 #include "util.h"
32 #ifndef __CYGWIN__
33 extern void initlibvirtmod(void);
34 #else
35 extern void initcygvirtmod(void);
36 #endif
38 #if 0
39 # define DEBUG_ERROR 1
40 #endif
42 #if DEBUG_ERROR
43 # define DEBUG(fmt, ...) \
44 printf(fmt, __VA_ARGS__)
45 #else
46 # define DEBUG(fmt, ...) \
47 do {} while (0)
48 #endif
50 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
51 is so common that we encapsulate it here. Now, each use is simply
52 return VIR_PY_NONE; */
53 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
54 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
55 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
57 /* We don't want to free() returned value. As written in doc:
58 * PyString_AsString returns pointer to 'internal buffer of string,
59 * not a copy' and 'It must not be deallocated'. */
60 static char *py_str(PyObject *obj)
62 PyObject *str = PyObject_Str(obj);
63 if (!str) {
64 PyErr_Print();
65 PyErr_Clear();
66 return NULL;
68 return PyString_AsString(str);
71 /* Helper function to convert a virTypedParameter output array into a
72 * Python dictionary for return to the user. Return NULL on failure,
73 * after raising a python exception. */
74 static PyObject *
75 getPyVirTypedParameter(const virTypedParameterPtr params, int nparams)
77 PyObject *key, *val, *info;
78 int i;
80 if ((info = PyDict_New()) == NULL)
81 return NULL;
83 for (i = 0 ; i < nparams ; i++) {
84 switch (params[i].type) {
85 case VIR_TYPED_PARAM_INT:
86 val = PyInt_FromLong(params[i].value.i);
87 break;
89 case VIR_TYPED_PARAM_UINT:
90 val = PyInt_FromLong(params[i].value.ui);
91 break;
93 case VIR_TYPED_PARAM_LLONG:
94 val = PyLong_FromLongLong(params[i].value.l);
95 break;
97 case VIR_TYPED_PARAM_ULLONG:
98 val = PyLong_FromUnsignedLongLong(params[i].value.ul);
99 break;
101 case VIR_TYPED_PARAM_DOUBLE:
102 val = PyFloat_FromDouble(params[i].value.d);
103 break;
105 case VIR_TYPED_PARAM_BOOLEAN:
106 val = PyBool_FromLong(params[i].value.b);
107 break;
109 case VIR_TYPED_PARAM_STRING:
110 val = libvirt_constcharPtrWrap(params[i].value.s);
111 break;
113 default:
114 /* Possible if a newer server has a bug and sent stuff we
115 * don't recognize. */
116 PyErr_Format(PyExc_LookupError,
117 "Type value \"%d\" not recognized",
118 params[i].type);
119 val = NULL;
120 break;
123 key = libvirt_constcharPtrWrap(params[i].field);
124 if (!key || !val)
125 goto cleanup;
127 if (PyDict_SetItem(info, key, val) < 0) {
128 Py_DECREF(info);
129 goto cleanup;
132 Py_DECREF(key);
133 Py_DECREF(val);
135 return info;
137 cleanup:
138 Py_XDECREF(key);
139 Py_XDECREF(val);
140 return NULL;
143 /* Allocate a new typed parameter array with the same contents and
144 * length as info, and using the array params of length nparams as
145 * hints on what types to use when creating the new array. The caller
146 * must NOT clear the array before freeing it, as it points into info
147 * rather than allocated strings. Return NULL on failure, after
148 * raising a python exception. */
149 static virTypedParameterPtr ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
150 setPyVirTypedParameter(PyObject *info,
151 const virTypedParameterPtr params, int nparams)
153 PyObject *key, *value;
154 Py_ssize_t pos = 0;
155 virTypedParameterPtr temp = NULL, ret = NULL;
156 Py_ssize_t size;
157 int i;
159 if ((size = PyDict_Size(info)) < 0)
160 return NULL;
162 /* Libvirt APIs use NULL array and 0 size as a special case;
163 * setting should have at least one parameter. */
164 if (size == 0) {
165 PyErr_Format(PyExc_LookupError, "Dictionary must not be empty");
166 return NULL;
169 if (VIR_ALLOC_N(ret, size) < 0) {
170 PyErr_NoMemory();
171 return NULL;
174 temp = &ret[0];
175 while (PyDict_Next(info, &pos, &key, &value)) {
176 char *keystr = NULL;
178 if ((keystr = PyString_AsString(key)) == NULL)
179 goto cleanup;
181 for (i = 0; i < nparams; i++) {
182 if (STREQ(params[i].field, keystr))
183 break;
185 if (i == nparams) {
186 PyErr_Format(PyExc_LookupError,
187 "Attribute name \"%s\" could not be recognized",
188 keystr);
189 goto cleanup;
192 ignore_value(virStrcpyStatic(temp->field, keystr));
193 temp->type = params[i].type;
195 switch(params[i].type) {
196 case VIR_TYPED_PARAM_INT:
197 if (libvirt_intUnwrap(value, &temp->value.i) < 0)
198 goto cleanup;
199 break;
201 case VIR_TYPED_PARAM_UINT:
202 if (libvirt_uintUnwrap(value, &temp->value.ui) < 0)
203 goto cleanup;
204 break;
206 case VIR_TYPED_PARAM_LLONG:
207 if (libvirt_longlongUnwrap(value, &temp->value.l) < 0)
208 goto cleanup;
209 break;
211 case VIR_TYPED_PARAM_ULLONG:
212 if (libvirt_ulonglongUnwrap(value, &temp->value.ul) < 0)
213 goto cleanup;
214 break;
216 case VIR_TYPED_PARAM_DOUBLE:
217 if (libvirt_doubleUnwrap(value, &temp->value.d) < 0)
218 goto cleanup;
219 break;
221 case VIR_TYPED_PARAM_BOOLEAN:
223 bool b;
224 if (libvirt_boolUnwrap(value, &b) < 0)
225 goto cleanup;
226 temp->value.b = b;
227 break;
229 case VIR_TYPED_PARAM_STRING:
231 char *string_val = PyString_AsString(value);
232 if (!string_val)
233 goto cleanup;
234 temp->value.s = string_val;
235 break;
238 default:
239 /* Possible if a newer server has a bug and sent stuff we
240 * don't recognize. */
241 PyErr_Format(PyExc_LookupError,
242 "Type value \"%d\" not recognized",
243 params[i].type);
244 goto cleanup;
247 temp++;
249 return ret;
251 cleanup:
252 VIR_FREE(ret);
253 return NULL;
256 /************************************************************************
258 * Statistics *
260 ************************************************************************/
262 static PyObject *
263 libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
264 virDomainPtr domain;
265 PyObject *pyobj_domain;
266 char * path;
267 int c_retval;
268 virDomainBlockStatsStruct stats;
269 PyObject *info;
271 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats",
272 &pyobj_domain,&path))
273 return NULL;
274 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
276 LIBVIRT_BEGIN_ALLOW_THREADS;
277 c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats));
278 LIBVIRT_END_ALLOW_THREADS;
280 if (c_retval < 0)
281 return VIR_PY_NONE;
283 /* convert to a Python tuple of long objects */
284 if ((info = PyTuple_New(5)) == NULL)
285 return VIR_PY_NONE;
286 PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rd_req));
287 PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rd_bytes));
288 PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.wr_req));
289 PyTuple_SetItem(info, 3, PyLong_FromLongLong(stats.wr_bytes));
290 PyTuple_SetItem(info, 4, PyLong_FromLongLong(stats.errs));
291 return info;
294 static PyObject *
295 libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED,
296 PyObject *args)
298 virDomainPtr domain;
299 PyObject *pyobj_domain;
300 PyObject *ret = NULL;
301 int i_retval;
302 int nparams = 0;
303 unsigned int flags;
304 virTypedParameterPtr params;
305 const char *path;
307 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainBlockStatsFlags",
308 &pyobj_domain, &path, &flags))
309 return NULL;
310 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
312 LIBVIRT_BEGIN_ALLOW_THREADS;
313 i_retval = virDomainBlockStatsFlags(domain, path, NULL, &nparams, flags);
314 LIBVIRT_END_ALLOW_THREADS;
316 if (i_retval < 0)
317 return VIR_PY_NONE;
319 if (!nparams)
320 return PyDict_New();
322 if (VIR_ALLOC_N(params, nparams) < 0)
323 return PyErr_NoMemory();
325 LIBVIRT_BEGIN_ALLOW_THREADS;
326 i_retval = virDomainBlockStatsFlags(domain, path, params, &nparams, flags);
327 LIBVIRT_END_ALLOW_THREADS;
329 if (i_retval < 0) {
330 ret = VIR_PY_NONE;
331 goto cleanup;
334 ret = getPyVirTypedParameter(params, nparams);
336 cleanup:
337 virTypedParameterArrayClear(params, nparams);
338 VIR_FREE(params);
339 return ret;
342 static PyObject *
343 libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
345 virDomainPtr domain;
346 PyObject *pyobj_domain, *totalbool;
347 PyObject *cpu, *total;
348 PyObject *ret = NULL;
349 PyObject *error = NULL;
350 int ncpus = -1, start_cpu = 0;
351 int sumparams = 0, nparams = -1;
352 int i, i_retval;
353 unsigned int flags;
354 bool totalflag;
355 virTypedParameterPtr params = NULL, cpuparams;
357 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainGetCPUStats",
358 &pyobj_domain, &totalbool, &flags))
359 return NULL;
360 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
362 if (libvirt_boolUnwrap(totalbool, &totalflag) < 0)
363 return NULL;
365 if ((ret = PyList_New(0)) == NULL)
366 return NULL;
368 if (!totalflag) {
369 LIBVIRT_BEGIN_ALLOW_THREADS;
370 ncpus = virDomainGetCPUStats(domain, NULL, 0, 0, 0, flags);
371 LIBVIRT_END_ALLOW_THREADS;
373 if (ncpus < 0) {
374 error = VIR_PY_NONE;
375 goto error;
378 LIBVIRT_BEGIN_ALLOW_THREADS;
379 nparams = virDomainGetCPUStats(domain, NULL, 0, 0, 1, flags);
380 LIBVIRT_END_ALLOW_THREADS;
382 if (nparams < 0) {
383 error = VIR_PY_NONE;
384 goto error;
387 sumparams = nparams * MIN(ncpus, 128);
389 if (VIR_ALLOC_N(params, sumparams) < 0) {
390 error = PyErr_NoMemory();
391 goto error;
394 while (ncpus) {
395 int queried_ncpus = MIN(ncpus, 128);
396 if (nparams) {
398 LIBVIRT_BEGIN_ALLOW_THREADS;
399 i_retval = virDomainGetCPUStats(domain, params,
400 nparams, start_cpu, queried_ncpus, flags);
401 LIBVIRT_END_ALLOW_THREADS;
403 if (i_retval < 0) {
404 error = VIR_PY_NONE;
405 goto error;
407 } else {
408 i_retval = 0;
411 for (i = 0; i < queried_ncpus; i++) {
412 cpuparams = &params[i * nparams];
413 if ((cpu = getPyVirTypedParameter(cpuparams, i_retval)) == NULL) {
414 goto error;
417 if (PyList_Append(ret, cpu) < 0) {
418 Py_DECREF(cpu);
419 goto error;
421 Py_DECREF(cpu);
424 start_cpu += queried_ncpus;
425 ncpus -= queried_ncpus;
426 virTypedParameterArrayClear(params, sumparams);
428 } else {
429 LIBVIRT_BEGIN_ALLOW_THREADS;
430 nparams = virDomainGetCPUStats(domain, NULL, 0, -1, 1, flags);
431 LIBVIRT_END_ALLOW_THREADS;
433 if (nparams < 0) {
434 error = VIR_PY_NONE;
435 goto error;
438 if (nparams) {
439 sumparams = nparams;
441 if (VIR_ALLOC_N(params, nparams) < 0) {
442 error = PyErr_NoMemory();
443 goto error;
446 LIBVIRT_BEGIN_ALLOW_THREADS;
447 i_retval = virDomainGetCPUStats(domain, params, nparams, -1, 1, flags);
448 LIBVIRT_END_ALLOW_THREADS;
450 if (i_retval < 0) {
451 error = VIR_PY_NONE;
452 goto error;
454 } else {
455 i_retval = 0;
458 if ((total = getPyVirTypedParameter(params, i_retval)) == NULL) {
459 goto error;
461 if (PyList_Append(ret, total) < 0) {
462 Py_DECREF(total);
463 goto error;
465 Py_DECREF(total);
468 virTypedParameterArrayClear(params, sumparams);
469 VIR_FREE(params);
470 return ret;
472 error:
473 virTypedParameterArrayClear(params, sumparams);
474 VIR_FREE(params);
475 Py_DECREF(ret);
476 return error;
479 static PyObject *
480 libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
481 virDomainPtr domain;
482 PyObject *pyobj_domain;
483 char * path;
484 int c_retval;
485 virDomainInterfaceStatsStruct stats;
486 PyObject *info;
488 if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainInterfaceStats",
489 &pyobj_domain,&path))
490 return NULL;
491 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
493 LIBVIRT_BEGIN_ALLOW_THREADS;
494 c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats));
495 LIBVIRT_END_ALLOW_THREADS;
497 if (c_retval < 0)
498 return VIR_PY_NONE;
500 /* convert to a Python tuple of long objects */
501 if ((info = PyTuple_New(8)) == NULL)
502 return VIR_PY_NONE;
503 PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rx_bytes));
504 PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rx_packets));
505 PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.rx_errs));
506 PyTuple_SetItem(info, 3, PyLong_FromLongLong(stats.rx_drop));
507 PyTuple_SetItem(info, 4, PyLong_FromLongLong(stats.tx_bytes));
508 PyTuple_SetItem(info, 5, PyLong_FromLongLong(stats.tx_packets));
509 PyTuple_SetItem(info, 6, PyLong_FromLongLong(stats.tx_errs));
510 PyTuple_SetItem(info, 7, PyLong_FromLongLong(stats.tx_drop));
511 return info;
514 static PyObject *
515 libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
516 virDomainPtr domain;
517 PyObject *pyobj_domain;
518 unsigned int nr_stats, i;
519 virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
520 PyObject *info;
522 if (!PyArg_ParseTuple(args, (char *)"O:virDomainMemoryStats", &pyobj_domain))
523 return NULL;
524 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
526 nr_stats = virDomainMemoryStats(domain, stats,
527 VIR_DOMAIN_MEMORY_STAT_NR, 0);
528 if (nr_stats == -1)
529 return VIR_PY_NONE;
531 /* convert to a Python dictionary */
532 if ((info = PyDict_New()) == NULL)
533 return VIR_PY_NONE;
535 for (i = 0; i < nr_stats; i++) {
536 if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_SWAP_IN)
537 PyDict_SetItem(info, libvirt_constcharPtrWrap("swap_in"),
538 PyLong_FromUnsignedLongLong(stats[i].val));
539 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_SWAP_OUT)
540 PyDict_SetItem(info, libvirt_constcharPtrWrap("swap_out"),
541 PyLong_FromUnsignedLongLong(stats[i].val));
542 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT)
543 PyDict_SetItem(info, libvirt_constcharPtrWrap("major_fault"),
544 PyLong_FromUnsignedLongLong(stats[i].val));
545 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT)
546 PyDict_SetItem(info, libvirt_constcharPtrWrap("minor_fault"),
547 PyLong_FromUnsignedLongLong(stats[i].val));
548 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_UNUSED)
549 PyDict_SetItem(info, libvirt_constcharPtrWrap("unused"),
550 PyLong_FromUnsignedLongLong(stats[i].val));
551 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_AVAILABLE)
552 PyDict_SetItem(info, libvirt_constcharPtrWrap("available"),
553 PyLong_FromUnsignedLongLong(stats[i].val));
554 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON)
555 PyDict_SetItem(info, libvirt_constcharPtrWrap("actual"),
556 PyLong_FromUnsignedLongLong(stats[i].val));
557 else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_RSS)
558 PyDict_SetItem(info, libvirt_constcharPtrWrap("rss"),
559 PyLong_FromUnsignedLongLong(stats[i].val));
561 return info;
564 static PyObject *
565 libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
566 PyObject *args) {
567 virDomainPtr domain;
568 PyObject *pyobj_domain, *info;
569 char *c_retval;
570 int nparams;
572 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerType",
573 &pyobj_domain))
574 return NULL;
575 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
577 LIBVIRT_BEGIN_ALLOW_THREADS;
578 c_retval = virDomainGetSchedulerType(domain, &nparams);
579 LIBVIRT_END_ALLOW_THREADS;
580 if (c_retval == NULL)
581 return VIR_PY_NONE;
583 /* convert to a Python tuple of long objects */
584 if ((info = PyTuple_New(2)) == NULL) {
585 VIR_FREE(c_retval);
586 return VIR_PY_NONE;
589 PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(c_retval));
590 PyTuple_SetItem(info, 1, PyInt_FromLong((long)nparams));
591 VIR_FREE(c_retval);
592 return info;
595 static PyObject *
596 libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
597 PyObject *args)
599 virDomainPtr domain;
600 PyObject *pyobj_domain;
601 PyObject *ret = NULL;
602 char *c_retval;
603 int i_retval;
604 int nparams = 0;
605 virTypedParameterPtr params;
607 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetScedulerParameters",
608 &pyobj_domain))
609 return NULL;
610 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
612 LIBVIRT_BEGIN_ALLOW_THREADS;
613 c_retval = virDomainGetSchedulerType(domain, &nparams);
614 LIBVIRT_END_ALLOW_THREADS;
616 if (c_retval == NULL)
617 return VIR_PY_NONE;
618 VIR_FREE(c_retval);
620 if (!nparams)
621 return PyDict_New();
623 if (VIR_ALLOC_N(params, nparams) < 0)
624 return PyErr_NoMemory();
626 LIBVIRT_BEGIN_ALLOW_THREADS;
627 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
628 LIBVIRT_END_ALLOW_THREADS;
630 if (i_retval < 0) {
631 ret = VIR_PY_NONE;
632 goto cleanup;
635 ret = getPyVirTypedParameter(params, nparams);
637 cleanup:
638 virTypedParameterArrayClear(params, nparams);
639 VIR_FREE(params);
640 return ret;
643 static PyObject *
644 libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
645 PyObject *args)
647 virDomainPtr domain;
648 PyObject *pyobj_domain;
649 PyObject *ret = NULL;
650 char *c_retval;
651 int i_retval;
652 int nparams = 0;
653 unsigned int flags;
654 virTypedParameterPtr params;
656 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetScedulerParametersFlags",
657 &pyobj_domain, &flags))
658 return NULL;
659 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
661 LIBVIRT_BEGIN_ALLOW_THREADS;
662 c_retval = virDomainGetSchedulerType(domain, &nparams);
663 LIBVIRT_END_ALLOW_THREADS;
665 if (c_retval == NULL)
666 return VIR_PY_NONE;
667 VIR_FREE(c_retval);
669 if (!nparams)
670 return PyDict_New();
672 if (VIR_ALLOC_N(params, nparams) < 0)
673 return PyErr_NoMemory();
675 LIBVIRT_BEGIN_ALLOW_THREADS;
676 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams, flags);
677 LIBVIRT_END_ALLOW_THREADS;
679 if (i_retval < 0) {
680 ret = VIR_PY_NONE;
681 goto cleanup;
684 ret = getPyVirTypedParameter(params, nparams);
686 cleanup:
687 virTypedParameterArrayClear(params, nparams);
688 VIR_FREE(params);
689 return ret;
692 static PyObject *
693 libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED,
694 PyObject *args)
696 virDomainPtr domain;
697 PyObject *pyobj_domain, *info;
698 PyObject *ret = NULL;
699 char *c_retval;
700 int i_retval;
701 int nparams = 0;
702 Py_ssize_t size = 0;
703 virTypedParameterPtr params, new_params = NULL;
705 if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetScedulerParameters",
706 &pyobj_domain, &info))
707 return NULL;
708 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
710 if ((size = PyDict_Size(info)) < 0)
711 return NULL;
713 if (size == 0) {
714 PyErr_Format(PyExc_LookupError,
715 "Need non-empty dictionary to set attributes");
716 return NULL;
719 LIBVIRT_BEGIN_ALLOW_THREADS;
720 c_retval = virDomainGetSchedulerType(domain, &nparams);
721 LIBVIRT_END_ALLOW_THREADS;
723 if (c_retval == NULL)
724 return VIR_PY_INT_FAIL;
725 VIR_FREE(c_retval);
727 if (nparams == 0) {
728 PyErr_Format(PyExc_LookupError,
729 "Domain has no settable attributes");
730 return NULL;
733 if (VIR_ALLOC_N(params, nparams) < 0)
734 return PyErr_NoMemory();
736 LIBVIRT_BEGIN_ALLOW_THREADS;
737 i_retval = virDomainGetSchedulerParameters(domain, params, &nparams);
738 LIBVIRT_END_ALLOW_THREADS;
740 if (i_retval < 0) {
741 ret = VIR_PY_INT_FAIL;
742 goto cleanup;
745 new_params = setPyVirTypedParameter(info, params, nparams);
746 if (!new_params)
747 goto cleanup;
749 LIBVIRT_BEGIN_ALLOW_THREADS;
750 i_retval = virDomainSetSchedulerParameters(domain, new_params, size);
751 LIBVIRT_END_ALLOW_THREADS;
753 if (i_retval < 0) {
754 ret = VIR_PY_INT_FAIL;
755 goto cleanup;
758 ret = VIR_PY_INT_SUCCESS;
760 cleanup:
761 virTypedParameterArrayClear(params, nparams);
762 VIR_FREE(params);
763 VIR_FREE(new_params);
764 return ret;
767 static PyObject *
768 libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED,
769 PyObject *args)
771 virDomainPtr domain;
772 PyObject *pyobj_domain, *info;
773 PyObject *ret = NULL;
774 char *c_retval;
775 int i_retval;
776 int nparams = 0;
777 Py_ssize_t size = 0;
778 unsigned int flags;
779 virTypedParameterPtr params, new_params;
781 if (!PyArg_ParseTuple(args,
782 (char *)"OOi:virDomainSetScedulerParametersFlags",
783 &pyobj_domain, &info, &flags))
784 return NULL;
785 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
787 if ((size = PyDict_Size(info)) < 0)
788 return NULL;
790 if (size == 0) {
791 PyErr_Format(PyExc_LookupError,
792 "Need non-empty dictionary to set attributes");
793 return NULL;
796 LIBVIRT_BEGIN_ALLOW_THREADS;
797 c_retval = virDomainGetSchedulerType(domain, &nparams);
798 LIBVIRT_END_ALLOW_THREADS;
800 if (c_retval == NULL)
801 return VIR_PY_INT_FAIL;
802 VIR_FREE(c_retval);
804 if (nparams == 0) {
805 PyErr_Format(PyExc_LookupError,
806 "Domain has no settable attributes");
807 return NULL;
810 if (VIR_ALLOC_N(params, nparams) < 0)
811 return PyErr_NoMemory();
813 LIBVIRT_BEGIN_ALLOW_THREADS;
814 i_retval = virDomainGetSchedulerParametersFlags(domain, params, &nparams, flags);
815 LIBVIRT_END_ALLOW_THREADS;
817 if (i_retval < 0) {
818 ret = VIR_PY_INT_FAIL;
819 goto cleanup;
822 new_params = setPyVirTypedParameter(info, params, nparams);
823 if (!new_params)
824 goto cleanup;
826 LIBVIRT_BEGIN_ALLOW_THREADS;
827 i_retval = virDomainSetSchedulerParametersFlags(domain, new_params, size, flags);
828 LIBVIRT_END_ALLOW_THREADS;
830 if (i_retval < 0) {
831 ret = VIR_PY_INT_FAIL;
832 goto cleanup;
835 ret = VIR_PY_INT_SUCCESS;
837 cleanup:
838 virTypedParameterArrayClear(params, nparams);
839 VIR_FREE(params);
840 VIR_FREE(new_params);
841 return ret;
844 static PyObject *
845 libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
846 PyObject *args)
848 virDomainPtr domain;
849 PyObject *pyobj_domain, *info;
850 PyObject *ret = NULL;
851 int i_retval;
852 int nparams = 0;
853 Py_ssize_t size = 0;
854 unsigned int flags;
855 virTypedParameterPtr params, new_params;
857 if (!PyArg_ParseTuple(args,
858 (char *)"OOi:virDomainSetBlkioParameters",
859 &pyobj_domain, &info, &flags))
860 return NULL;
861 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
863 if ((size = PyDict_Size(info)) < 0)
864 return NULL;
866 if (size == 0) {
867 PyErr_Format(PyExc_LookupError,
868 "Need non-empty dictionary to set attributes");
869 return NULL;
872 LIBVIRT_BEGIN_ALLOW_THREADS;
873 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
874 LIBVIRT_END_ALLOW_THREADS;
876 if (i_retval < 0)
877 return VIR_PY_INT_FAIL;
879 if (nparams == 0) {
880 PyErr_Format(PyExc_LookupError,
881 "Domain has no settable attributes");
882 return NULL;
885 if (VIR_ALLOC_N(params, nparams) < 0)
886 return PyErr_NoMemory();
888 LIBVIRT_BEGIN_ALLOW_THREADS;
889 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
890 LIBVIRT_END_ALLOW_THREADS;
892 if (i_retval < 0) {
893 ret = VIR_PY_INT_FAIL;
894 goto cleanup;
897 new_params = setPyVirTypedParameter(info, params, nparams);
898 if (!new_params)
899 goto cleanup;
901 LIBVIRT_BEGIN_ALLOW_THREADS;
902 i_retval = virDomainSetBlkioParameters(domain, new_params, size, flags);
903 LIBVIRT_END_ALLOW_THREADS;
905 if (i_retval < 0) {
906 ret = VIR_PY_INT_FAIL;
907 goto cleanup;
910 ret = VIR_PY_INT_SUCCESS;
912 cleanup:
913 virTypedParameterArrayClear(params, nparams);
914 VIR_FREE(params);
915 VIR_FREE(new_params);
916 return ret;
919 static PyObject *
920 libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED,
921 PyObject *args)
923 virDomainPtr domain;
924 PyObject *pyobj_domain;
925 PyObject *ret = NULL;
926 int i_retval;
927 int nparams = 0;
928 unsigned int flags;
929 virTypedParameterPtr params;
931 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetBlkioParameters",
932 &pyobj_domain, &flags))
933 return NULL;
934 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
936 LIBVIRT_BEGIN_ALLOW_THREADS;
937 i_retval = virDomainGetBlkioParameters(domain, NULL, &nparams, flags);
938 LIBVIRT_END_ALLOW_THREADS;
940 if (i_retval < 0)
941 return VIR_PY_NONE;
943 if (!nparams)
944 return PyDict_New();
946 if (VIR_ALLOC_N(params, nparams) < 0)
947 return PyErr_NoMemory();
949 LIBVIRT_BEGIN_ALLOW_THREADS;
950 i_retval = virDomainGetBlkioParameters(domain, params, &nparams, flags);
951 LIBVIRT_END_ALLOW_THREADS;
953 if (i_retval < 0) {
954 ret = VIR_PY_NONE;
955 goto cleanup;
958 ret = getPyVirTypedParameter(params, nparams);
960 cleanup:
961 virTypedParameterArrayClear(params, nparams);
962 VIR_FREE(params);
963 return ret;
966 static PyObject *
967 libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
968 PyObject *args)
970 virDomainPtr domain;
971 PyObject *pyobj_domain, *info;
972 PyObject *ret = NULL;
973 int i_retval;
974 int nparams = 0;
975 Py_ssize_t size = 0;
976 unsigned int flags;
977 virTypedParameterPtr params, new_params;
979 if (!PyArg_ParseTuple(args,
980 (char *)"OOi:virDomainSetMemoryParameters",
981 &pyobj_domain, &info, &flags))
982 return NULL;
983 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
985 if ((size = PyDict_Size(info)) < 0)
986 return NULL;
988 if (size == 0) {
989 PyErr_Format(PyExc_LookupError,
990 "Need non-empty dictionary to set attributes");
991 return NULL;
994 LIBVIRT_BEGIN_ALLOW_THREADS;
995 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
996 LIBVIRT_END_ALLOW_THREADS;
998 if (i_retval < 0)
999 return VIR_PY_INT_FAIL;
1001 if (nparams == 0) {
1002 PyErr_Format(PyExc_LookupError,
1003 "Domain has no settable attributes");
1004 return NULL;
1007 if (VIR_ALLOC_N(params, nparams) < 0)
1008 return PyErr_NoMemory();
1010 LIBVIRT_BEGIN_ALLOW_THREADS;
1011 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
1012 LIBVIRT_END_ALLOW_THREADS;
1014 if (i_retval < 0) {
1015 ret = VIR_PY_INT_FAIL;
1016 goto cleanup;
1019 new_params = setPyVirTypedParameter(info, params, nparams);
1020 if (!new_params)
1021 goto cleanup;
1023 LIBVIRT_BEGIN_ALLOW_THREADS;
1024 i_retval = virDomainSetMemoryParameters(domain, new_params, size, flags);
1025 LIBVIRT_END_ALLOW_THREADS;
1027 if (i_retval < 0) {
1028 ret = VIR_PY_INT_FAIL;
1029 goto cleanup;
1032 ret = VIR_PY_INT_SUCCESS;
1034 cleanup:
1035 virTypedParameterArrayClear(params, nparams);
1036 VIR_FREE(params);
1037 VIR_FREE(new_params);
1038 return ret;
1041 static PyObject *
1042 libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
1043 PyObject *args)
1045 virDomainPtr domain;
1046 PyObject *pyobj_domain;
1047 PyObject *ret = NULL;
1048 int i_retval;
1049 int nparams = 0;
1050 unsigned int flags;
1051 virTypedParameterPtr params;
1053 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetMemoryParameters",
1054 &pyobj_domain, &flags))
1055 return NULL;
1056 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1058 LIBVIRT_BEGIN_ALLOW_THREADS;
1059 i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
1060 LIBVIRT_END_ALLOW_THREADS;
1062 if (i_retval < 0)
1063 return VIR_PY_NONE;
1065 if (!nparams)
1066 return PyDict_New();
1068 if (VIR_ALLOC_N(params, nparams) < 0)
1069 return PyErr_NoMemory();
1071 LIBVIRT_BEGIN_ALLOW_THREADS;
1072 i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
1073 LIBVIRT_END_ALLOW_THREADS;
1075 if (i_retval < 0) {
1076 ret = VIR_PY_NONE;
1077 goto cleanup;
1080 ret = getPyVirTypedParameter(params, nparams);
1082 cleanup:
1083 virTypedParameterArrayClear(params, nparams);
1084 VIR_FREE(params);
1085 return ret;
1088 static PyObject *
1089 libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1090 PyObject *args)
1092 virDomainPtr domain;
1093 PyObject *pyobj_domain, *info;
1094 PyObject *ret = NULL;
1095 int i_retval;
1096 int nparams = 0;
1097 Py_ssize_t size = 0;
1098 unsigned int flags;
1099 virTypedParameterPtr params, new_params;
1101 if (!PyArg_ParseTuple(args,
1102 (char *)"OOi:virDomainSetNumaParameters",
1103 &pyobj_domain, &info, &flags))
1104 return NULL;
1105 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1107 if ((size = PyDict_Size(info)) < 0)
1108 return NULL;
1110 if (size == 0) {
1111 PyErr_Format(PyExc_LookupError,
1112 "Need non-empty dictionary to set attributes");
1113 return NULL;
1116 LIBVIRT_BEGIN_ALLOW_THREADS;
1117 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1118 LIBVIRT_END_ALLOW_THREADS;
1120 if (i_retval < 0)
1121 return VIR_PY_INT_FAIL;
1123 if (nparams == 0) {
1124 PyErr_Format(PyExc_LookupError,
1125 "Domain has no settable attributes");
1126 return NULL;
1129 if (VIR_ALLOC_N(params, nparams) < 0)
1130 return PyErr_NoMemory();
1132 LIBVIRT_BEGIN_ALLOW_THREADS;
1133 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1134 LIBVIRT_END_ALLOW_THREADS;
1136 if (i_retval < 0) {
1137 ret = VIR_PY_INT_FAIL;
1138 goto cleanup;
1141 new_params = setPyVirTypedParameter(info, params, nparams);
1142 if (!new_params)
1143 goto cleanup;
1145 LIBVIRT_BEGIN_ALLOW_THREADS;
1146 i_retval = virDomainSetNumaParameters(domain, new_params, size, flags);
1147 LIBVIRT_END_ALLOW_THREADS;
1149 if (i_retval < 0) {
1150 ret = VIR_PY_INT_FAIL;
1151 goto cleanup;
1154 ret = VIR_PY_INT_SUCCESS;
1156 cleanup:
1157 virTypedParameterArrayClear(params, nparams);
1158 VIR_FREE(params);
1159 VIR_FREE(new_params);
1160 return ret;
1163 static PyObject *
1164 libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
1165 PyObject *args)
1167 virDomainPtr domain;
1168 PyObject *pyobj_domain;
1169 PyObject *ret = NULL;
1170 int i_retval;
1171 int nparams = 0;
1172 unsigned int flags;
1173 virTypedParameterPtr params;
1175 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetNumaParameters",
1176 &pyobj_domain, &flags))
1177 return NULL;
1178 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1180 LIBVIRT_BEGIN_ALLOW_THREADS;
1181 i_retval = virDomainGetNumaParameters(domain, NULL, &nparams, flags);
1182 LIBVIRT_END_ALLOW_THREADS;
1184 if (i_retval < 0)
1185 return VIR_PY_NONE;
1187 if (!nparams)
1188 return PyDict_New();
1190 if (VIR_ALLOC_N(params, nparams) < 0)
1191 return PyErr_NoMemory();
1193 LIBVIRT_BEGIN_ALLOW_THREADS;
1194 i_retval = virDomainGetNumaParameters(domain, params, &nparams, flags);
1195 LIBVIRT_END_ALLOW_THREADS;
1197 if (i_retval < 0) {
1198 ret = VIR_PY_NONE;
1199 goto cleanup;
1202 ret = getPyVirTypedParameter(params, nparams);
1204 cleanup:
1205 virTypedParameterArrayClear(params, nparams);
1206 VIR_FREE(params);
1207 return ret;
1210 static PyObject *
1211 libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1212 PyObject *args)
1214 virDomainPtr domain;
1215 PyObject *pyobj_domain, *info;
1216 PyObject *ret = NULL;
1217 int i_retval;
1218 int nparams = 0;
1219 Py_ssize_t size = 0;
1220 unsigned int flags;
1221 const char *device = NULL;
1222 virTypedParameterPtr params, new_params;
1224 if (!PyArg_ParseTuple(args,
1225 (char *)"OzOi:virDomainSetInterfaceParameters",
1226 &pyobj_domain, &device, &info, &flags))
1227 return NULL;
1228 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1230 if ((size = PyDict_Size(info)) < 0)
1231 return NULL;
1233 if (size == 0) {
1234 PyErr_Format(PyExc_LookupError,
1235 "Need non-empty dictionary to set attributes");
1236 return NULL;
1239 LIBVIRT_BEGIN_ALLOW_THREADS;
1240 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
1241 LIBVIRT_END_ALLOW_THREADS;
1243 if (i_retval < 0)
1244 return VIR_PY_INT_FAIL;
1246 if (nparams == 0) {
1247 PyErr_Format(PyExc_LookupError,
1248 "Domain has no settable attributes");
1249 return NULL;
1252 if (VIR_ALLOC_N(params, nparams) < 0)
1253 return PyErr_NoMemory();
1255 LIBVIRT_BEGIN_ALLOW_THREADS;
1256 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
1257 LIBVIRT_END_ALLOW_THREADS;
1259 if (i_retval < 0) {
1260 ret = VIR_PY_INT_FAIL;
1261 goto cleanup;
1264 new_params = setPyVirTypedParameter(info, params, nparams);
1265 if (!new_params)
1266 goto cleanup;
1268 LIBVIRT_BEGIN_ALLOW_THREADS;
1269 i_retval = virDomainSetInterfaceParameters(domain, device, new_params, size, flags);
1270 LIBVIRT_END_ALLOW_THREADS;
1272 if (i_retval < 0) {
1273 ret = VIR_PY_INT_FAIL;
1274 goto cleanup;
1277 ret = VIR_PY_INT_SUCCESS;
1279 cleanup:
1280 virTypedParameterArrayClear(params, nparams);
1281 VIR_FREE(params);
1282 VIR_FREE(new_params);
1283 return ret;
1286 static PyObject *
1287 libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
1288 PyObject *args)
1290 virDomainPtr domain;
1291 PyObject *pyobj_domain;
1292 PyObject *ret = NULL;
1293 int i_retval;
1294 int nparams = 0;
1295 unsigned int flags;
1296 const char *device = NULL;
1297 virTypedParameterPtr params;
1299 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInterfaceParameters",
1300 &pyobj_domain, &device, &flags))
1301 return NULL;
1302 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1304 LIBVIRT_BEGIN_ALLOW_THREADS;
1305 i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
1306 LIBVIRT_END_ALLOW_THREADS;
1308 if (i_retval < 0)
1309 return VIR_PY_NONE;
1311 if (!nparams)
1312 return PyDict_New();
1314 if (VIR_ALLOC_N(params, nparams) < 0)
1315 return PyErr_NoMemory();
1317 LIBVIRT_BEGIN_ALLOW_THREADS;
1318 i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
1319 LIBVIRT_END_ALLOW_THREADS;
1321 if (i_retval < 0) {
1322 ret = VIR_PY_NONE;
1323 goto cleanup;
1326 ret = getPyVirTypedParameter(params, nparams);
1328 cleanup:
1329 virTypedParameterArrayClear(params, nparams);
1330 VIR_FREE(params);
1331 return ret;
1334 static PyObject *
1335 libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
1336 PyObject *args) {
1337 virDomainPtr domain;
1338 PyObject *pyobj_domain, *pyretval = NULL, *pycpuinfo = NULL, *pycpumap = NULL;
1339 virNodeInfo nodeinfo;
1340 virDomainInfo dominfo;
1341 virVcpuInfoPtr cpuinfo = NULL;
1342 unsigned char *cpumap = NULL;
1343 size_t cpumaplen, i;
1344 int i_retval;
1346 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
1347 &pyobj_domain))
1348 return NULL;
1349 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1351 LIBVIRT_BEGIN_ALLOW_THREADS;
1352 i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
1353 LIBVIRT_END_ALLOW_THREADS;
1354 if (i_retval < 0)
1355 return VIR_PY_NONE;
1357 LIBVIRT_BEGIN_ALLOW_THREADS;
1358 i_retval = virDomainGetInfo(domain, &dominfo);
1359 LIBVIRT_END_ALLOW_THREADS;
1360 if (i_retval < 0)
1361 return VIR_PY_NONE;
1363 if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0)
1364 return VIR_PY_NONE;
1366 cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
1367 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1368 VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0)
1369 goto cleanup;
1371 LIBVIRT_BEGIN_ALLOW_THREADS;
1372 i_retval = virDomainGetVcpus(domain,
1373 cpuinfo, dominfo.nrVirtCpu,
1374 cpumap, cpumaplen);
1375 LIBVIRT_END_ALLOW_THREADS;
1376 if (i_retval < 0)
1377 goto cleanup;
1379 /* convert to a Python tuple of long objects */
1380 if ((pyretval = PyTuple_New(2)) == NULL)
1381 goto cleanup;
1382 if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
1383 goto cleanup;
1384 if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
1385 goto cleanup;
1387 for (i = 0 ; i < dominfo.nrVirtCpu ; i++) {
1388 PyObject *info = PyTuple_New(4);
1389 if (info == NULL)
1390 goto cleanup;
1391 PyTuple_SetItem(info, 0, PyInt_FromLong((long)cpuinfo[i].number));
1392 PyTuple_SetItem(info, 1, PyInt_FromLong((long)cpuinfo[i].state));
1393 PyTuple_SetItem(info, 2, PyLong_FromLongLong((long long)cpuinfo[i].cpuTime));
1394 PyTuple_SetItem(info, 3, PyInt_FromLong((long)cpuinfo[i].cpu));
1395 PyList_SetItem(pycpuinfo, i, info);
1397 for (i = 0 ; i < dominfo.nrVirtCpu ; i++) {
1398 PyObject *info = PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo));
1399 int j;
1400 if (info == NULL)
1401 goto cleanup;
1402 for (j = 0 ; j < VIR_NODEINFO_MAXCPUS(nodeinfo) ; j++) {
1403 PyTuple_SetItem(info, j, PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, i, j)));
1405 PyList_SetItem(pycpumap, i, info);
1407 PyTuple_SetItem(pyretval, 0, pycpuinfo);
1408 PyTuple_SetItem(pyretval, 1, pycpumap);
1410 VIR_FREE(cpuinfo);
1411 VIR_FREE(cpumap);
1413 return pyretval;
1415 cleanup:
1416 VIR_FREE(cpuinfo);
1417 VIR_FREE(cpumap);
1418 Py_XDECREF(pyretval);
1419 Py_XDECREF(pycpuinfo);
1420 Py_XDECREF(pycpumap);
1421 return VIR_PY_NONE;
1425 static PyObject *
1426 libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
1427 PyObject *args) {
1428 virDomainPtr domain;
1429 PyObject *pyobj_domain, *pycpumap, *truth;
1430 virNodeInfo nodeinfo;
1431 unsigned char *cpumap;
1432 int cpumaplen, i, vcpu;
1433 int i_retval;
1435 if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu",
1436 &pyobj_domain, &vcpu, &pycpumap))
1437 return NULL;
1438 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1440 LIBVIRT_BEGIN_ALLOW_THREADS;
1441 i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
1442 LIBVIRT_END_ALLOW_THREADS;
1443 if (i_retval < 0)
1444 return VIR_PY_INT_FAIL;
1446 cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
1447 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1448 return VIR_PY_INT_FAIL;
1450 truth = PyBool_FromLong(1);
1451 for (i = 0 ; i < VIR_NODEINFO_MAXCPUS(nodeinfo) ; i++) {
1452 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1453 if (flag == truth)
1454 VIR_USE_CPU(cpumap, i);
1455 else
1456 VIR_UNUSE_CPU(cpumap, i);
1459 LIBVIRT_BEGIN_ALLOW_THREADS;
1460 i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen);
1461 LIBVIRT_END_ALLOW_THREADS;
1462 Py_DECREF(truth);
1463 VIR_FREE(cpumap);
1465 if (i_retval < 0)
1466 return VIR_PY_INT_FAIL;
1468 return VIR_PY_INT_SUCCESS;
1471 static PyObject *
1472 libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED,
1473 PyObject *args) {
1474 virDomainPtr domain;
1475 PyObject *pyobj_domain, *pycpumap, *truth;
1476 virNodeInfo nodeinfo;
1477 unsigned char *cpumap;
1478 int cpumaplen, i, vcpu;
1479 unsigned int flags;
1480 int i_retval;
1482 if (!PyArg_ParseTuple(args, (char *)"OiOi:virDomainPinVcpuFlags",
1483 &pyobj_domain, &vcpu, &pycpumap, &flags))
1484 return NULL;
1485 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1487 LIBVIRT_BEGIN_ALLOW_THREADS;
1488 i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
1489 LIBVIRT_END_ALLOW_THREADS;
1490 if (i_retval < 0)
1491 return VIR_PY_INT_FAIL;
1493 cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
1494 if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
1495 return VIR_PY_INT_FAIL;
1497 truth = PyBool_FromLong(1);
1498 for (i = 0 ; i < VIR_NODEINFO_MAXCPUS(nodeinfo) ; i++) {
1499 PyObject *flag = PyTuple_GetItem(pycpumap, i);
1500 if (flag == truth)
1501 VIR_USE_CPU(cpumap, i);
1502 else
1503 VIR_UNUSE_CPU(cpumap, i);
1506 LIBVIRT_BEGIN_ALLOW_THREADS;
1507 i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags);
1508 LIBVIRT_END_ALLOW_THREADS;
1509 Py_DECREF(truth);
1510 VIR_FREE(cpumap);
1512 if (i_retval < 0)
1513 return VIR_PY_INT_FAIL;
1515 return VIR_PY_INT_SUCCESS;
1518 static PyObject *
1519 libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
1520 PyObject *args) {
1521 virDomainPtr domain;
1522 PyObject *pyobj_domain, *pycpumaps = NULL;
1523 virNodeInfo nodeinfo;
1524 virDomainInfo dominfo;
1525 unsigned char *cpumaps;
1526 size_t cpumaplen, vcpu, pcpu;
1527 unsigned int flags;
1528 int i_retval;
1530 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetVcpuPinInfo",
1531 &pyobj_domain, &flags))
1532 return NULL;
1533 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
1535 LIBVIRT_BEGIN_ALLOW_THREADS;
1536 i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
1537 LIBVIRT_END_ALLOW_THREADS;
1538 if (i_retval < 0)
1539 return VIR_PY_NONE;
1541 LIBVIRT_BEGIN_ALLOW_THREADS;
1542 i_retval = virDomainGetInfo(domain, &dominfo);
1543 LIBVIRT_END_ALLOW_THREADS;
1544 if (i_retval < 0)
1545 return VIR_PY_NONE;
1547 cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
1548 if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) ||
1549 VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0)
1550 goto cleanup;
1552 LIBVIRT_BEGIN_ALLOW_THREADS;
1553 i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu,
1554 cpumaps, cpumaplen, flags);
1555 LIBVIRT_END_ALLOW_THREADS;
1556 if (i_retval < 0)
1557 goto cleanup;
1559 if ((pycpumaps = PyList_New(dominfo.nrVirtCpu)) == NULL)
1560 goto cleanup;
1562 for (vcpu = 0; vcpu < dominfo.nrVirtCpu; vcpu++) {
1563 PyObject *mapinfo = PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo));
1564 if (mapinfo == NULL)
1565 goto cleanup;
1567 for (pcpu = 0; pcpu < VIR_NODEINFO_MAXCPUS(nodeinfo); pcpu++) {
1568 PyTuple_SetItem(mapinfo, pcpu,
1569 PyBool_FromLong(VIR_CPU_USABLE(cpumaps, cpumaplen, vcpu, pcpu)));
1571 PyList_SetItem(pycpumaps, vcpu, mapinfo);
1574 VIR_FREE(cpumaps);
1576 return pycpumaps;
1578 cleanup:
1579 VIR_FREE(cpumaps);
1581 Py_XDECREF(pycpumaps);
1583 return VIR_PY_NONE;
1586 /************************************************************************
1588 * Global error handler at the Python level *
1590 ************************************************************************/
1592 static PyObject *libvirt_virPythonErrorFuncHandler = NULL;
1593 static PyObject *libvirt_virPythonErrorFuncCtxt = NULL;
1595 static PyObject *
1596 libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED)
1598 virError *err;
1599 PyObject *info;
1601 if ((err = virGetLastError()) == NULL)
1602 return VIR_PY_NONE;
1604 if ((info = PyTuple_New(9)) == NULL)
1605 return VIR_PY_NONE;
1606 PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code));
1607 PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain));
1608 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
1609 PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level));
1610 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
1611 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
1612 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
1613 PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1));
1614 PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2));
1616 return info;
1619 static PyObject *
1620 libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
1622 virError *err;
1623 PyObject *info;
1624 virConnectPtr conn;
1625 PyObject *pyobj_conn;
1627 if (!PyArg_ParseTuple(args, (char *)"O:virConGetLastError", &pyobj_conn))
1628 return NULL;
1629 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1631 LIBVIRT_BEGIN_ALLOW_THREADS;
1632 err = virConnGetLastError(conn);
1633 LIBVIRT_END_ALLOW_THREADS;
1634 if (err == NULL)
1635 return VIR_PY_NONE;
1637 if ((info = PyTuple_New(9)) == NULL)
1638 return VIR_PY_NONE;
1639 PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code));
1640 PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain));
1641 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
1642 PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level));
1643 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
1644 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
1645 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
1646 PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1));
1647 PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2));
1649 return info;
1652 static void
1653 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err)
1655 PyObject *list, *info;
1656 PyObject *result;
1658 DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
1659 err->message);
1661 if ((err == NULL) || (err->code == VIR_ERR_OK))
1662 return;
1664 LIBVIRT_ENSURE_THREAD_STATE;
1666 if ((libvirt_virPythonErrorFuncHandler == NULL) ||
1667 (libvirt_virPythonErrorFuncHandler == Py_None)) {
1668 virDefaultErrorFunc(err);
1669 } else {
1670 list = PyTuple_New(2);
1671 info = PyTuple_New(9);
1672 PyTuple_SetItem(list, 0, libvirt_virPythonErrorFuncCtxt);
1673 PyTuple_SetItem(list, 1, info);
1674 Py_XINCREF(libvirt_virPythonErrorFuncCtxt);
1675 PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code));
1676 PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain));
1677 PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
1678 PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level));
1679 PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
1680 PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
1681 PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
1682 PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1));
1683 PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2));
1684 /* TODO pass conn and dom if available */
1685 result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
1686 Py_XDECREF(list);
1687 Py_XDECREF(result);
1690 LIBVIRT_RELEASE_THREAD_STATE;
1693 static PyObject *
1694 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
1695 PyObject * args)
1697 PyObject *py_retval;
1698 PyObject *pyobj_f;
1699 PyObject *pyobj_ctx;
1701 if (!PyArg_ParseTuple
1702 (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f,
1703 &pyobj_ctx))
1704 return NULL;
1706 DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
1707 pyobj_f);
1709 virSetErrorFunc(NULL, libvirt_virErrorFuncHandler);
1710 if (libvirt_virPythonErrorFuncHandler != NULL) {
1711 Py_XDECREF(libvirt_virPythonErrorFuncHandler);
1713 if (libvirt_virPythonErrorFuncCtxt != NULL) {
1714 Py_XDECREF(libvirt_virPythonErrorFuncCtxt);
1717 if ((pyobj_f == Py_None) && (pyobj_ctx == Py_None)) {
1718 libvirt_virPythonErrorFuncHandler = NULL;
1719 libvirt_virPythonErrorFuncCtxt = NULL;
1720 } else {
1721 Py_XINCREF(pyobj_ctx);
1722 Py_XINCREF(pyobj_f);
1724 /* TODO: check f is a function ! */
1725 libvirt_virPythonErrorFuncHandler = pyobj_f;
1726 libvirt_virPythonErrorFuncCtxt = pyobj_ctx;
1729 py_retval = libvirt_intWrap(1);
1730 return py_retval;
1733 static int virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
1734 unsigned int ncred,
1735 void *cbdata) {
1736 PyObject *list;
1737 PyObject *pycred;
1738 PyObject *pyauth = (PyObject *)cbdata;
1739 PyObject *pycbdata;
1740 PyObject *pycb;
1741 PyObject *pyret;
1742 int ret = -1, i;
1744 LIBVIRT_ENSURE_THREAD_STATE;
1746 pycb = PyList_GetItem(pyauth, 1);
1747 pycbdata = PyList_GetItem(pyauth, 2);
1749 list = PyTuple_New(2);
1750 pycred = PyTuple_New(ncred);
1751 for (i = 0 ; i < ncred ; i++) {
1752 PyObject *pycreditem;
1753 pycreditem = PyList_New(5);
1754 Py_INCREF(Py_None);
1755 PyTuple_SetItem(pycred, i, pycreditem);
1756 PyList_SetItem(pycreditem, 0, PyInt_FromLong((long) cred[i].type));
1757 PyList_SetItem(pycreditem, 1, PyString_FromString(cred[i].prompt));
1758 if (cred[i].challenge) {
1759 PyList_SetItem(pycreditem, 2, PyString_FromString(cred[i].challenge));
1760 } else {
1761 Py_INCREF(Py_None);
1762 PyList_SetItem(pycreditem, 2, Py_None);
1764 if (cred[i].defresult) {
1765 PyList_SetItem(pycreditem, 3, PyString_FromString(cred[i].defresult));
1766 } else {
1767 Py_INCREF(Py_None);
1768 PyList_SetItem(pycreditem, 3, Py_None);
1770 PyList_SetItem(pycreditem, 4, Py_None);
1773 PyTuple_SetItem(list, 0, pycred);
1774 Py_XINCREF(pycbdata);
1775 PyTuple_SetItem(list, 1, pycbdata);
1777 PyErr_Clear();
1778 pyret = PyEval_CallObject(pycb, list);
1779 if (PyErr_Occurred()) {
1780 PyErr_Print();
1781 goto cleanup;
1784 ret = PyLong_AsLong(pyret);
1785 if (ret == 0) {
1786 for (i = 0 ; i < ncred ; i++) {
1787 PyObject *pycreditem;
1788 PyObject *pyresult;
1789 char *result = NULL;
1790 pycreditem = PyTuple_GetItem(pycred, i);
1791 pyresult = PyList_GetItem(pycreditem, 4);
1792 if (pyresult != Py_None)
1793 result = PyString_AsString(pyresult);
1794 if (result != NULL) {
1795 cred[i].result = strdup(result);
1796 cred[i].resultlen = strlen(result);
1797 } else {
1798 cred[i].result = NULL;
1799 cred[i].resultlen = 0;
1804 cleanup:
1805 Py_XDECREF(list);
1806 Py_XDECREF(pyret);
1808 LIBVIRT_RELEASE_THREAD_STATE;
1810 return ret;
1814 static PyObject *
1815 libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
1816 PyObject *py_retval;
1817 virConnectPtr c_retval;
1818 char * name;
1819 unsigned int flags;
1820 PyObject *pyauth;
1821 PyObject *pycredcb;
1822 PyObject *pycredtype;
1823 virConnectAuth auth;
1825 memset(&auth, 0, sizeof(auth));
1826 if (!PyArg_ParseTuple(args, (char *)"zOi:virConnectOpenAuth", &name, &pyauth, &flags))
1827 return NULL;
1829 pycredtype = PyList_GetItem(pyauth, 0);
1830 pycredcb = PyList_GetItem(pyauth, 1);
1832 auth.ncredtype = PyList_Size(pycredtype);
1833 if (auth.ncredtype) {
1834 int i;
1835 if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0)
1836 return VIR_PY_NONE;
1837 for (i = 0 ; i < auth.ncredtype ; i++) {
1838 PyObject *val;
1839 val = PyList_GetItem(pycredtype, i);
1840 auth.credtype[i] = (int)PyLong_AsLong(val);
1843 if (pycredcb && pycredcb != Py_None)
1844 auth.cb = virConnectCredCallbackWrapper;
1845 auth.cbdata = pyauth;
1847 LIBVIRT_BEGIN_ALLOW_THREADS;
1849 c_retval = virConnectOpenAuth(name, &auth, flags);
1850 LIBVIRT_END_ALLOW_THREADS;
1851 VIR_FREE(auth.credtype);
1852 py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval);
1853 return py_retval;
1857 /************************************************************************
1859 * Wrappers for functions where generator fails *
1861 ************************************************************************/
1863 static PyObject *
1864 libvirt_virGetVersion (PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
1866 char *type = NULL;
1867 unsigned long libVer, typeVer = 0;
1868 int c_retval;
1870 if (!PyArg_ParseTuple (args, (char *) "|s", &type))
1871 return NULL;
1873 LIBVIRT_BEGIN_ALLOW_THREADS;
1875 if (type == NULL)
1876 c_retval = virGetVersion (&libVer, NULL, NULL);
1877 else
1878 c_retval = virGetVersion (&libVer, type, &typeVer);
1880 LIBVIRT_END_ALLOW_THREADS;
1882 if (c_retval == -1)
1883 return VIR_PY_NONE;
1885 if (type == NULL)
1886 return PyInt_FromLong (libVer);
1887 else
1888 return Py_BuildValue ((char *) "kk", libVer, typeVer);
1891 static PyObject *
1892 libvirt_virConnectGetVersion (PyObject *self ATTRIBUTE_UNUSED,
1893 PyObject *args)
1895 unsigned long hvVersion;
1896 int c_retval;
1897 virConnectPtr conn;
1898 PyObject *pyobj_conn;
1900 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetVersion",
1901 &pyobj_conn))
1902 return NULL;
1903 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1905 LIBVIRT_BEGIN_ALLOW_THREADS;
1907 c_retval = virConnectGetVersion(conn, &hvVersion);
1909 LIBVIRT_END_ALLOW_THREADS;
1911 if (c_retval == -1)
1912 return VIR_PY_INT_FAIL;
1914 return PyInt_FromLong (hvVersion);
1917 static PyObject *
1918 libvirt_virConnectGetLibVersion (PyObject *self ATTRIBUTE_UNUSED,
1919 PyObject *args)
1921 unsigned long libVer;
1922 int c_retval;
1923 virConnectPtr conn;
1924 PyObject *pyobj_conn;
1926 if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetLibVersion",
1927 &pyobj_conn))
1928 return NULL;
1929 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1931 LIBVIRT_BEGIN_ALLOW_THREADS;
1933 c_retval = virConnectGetLibVersion(conn, &libVer);
1935 LIBVIRT_END_ALLOW_THREADS;
1937 if (c_retval == -1)
1938 return VIR_PY_INT_FAIL;
1940 return PyInt_FromLong (libVer);
1943 static PyObject *
1944 libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
1945 PyObject *args) {
1946 PyObject *py_retval;
1947 int *ids = NULL, c_retval, i;
1948 virConnectPtr conn;
1949 PyObject *pyobj_conn;
1952 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDomains", &pyobj_conn))
1953 return NULL;
1954 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
1956 LIBVIRT_BEGIN_ALLOW_THREADS;
1957 c_retval = virConnectNumOfDomains(conn);
1958 LIBVIRT_END_ALLOW_THREADS;
1959 if (c_retval < 0)
1960 return VIR_PY_NONE;
1962 if (c_retval) {
1963 if (VIR_ALLOC_N(ids, c_retval) < 0)
1964 return VIR_PY_NONE;
1966 LIBVIRT_BEGIN_ALLOW_THREADS;
1967 c_retval = virConnectListDomains(conn, ids, c_retval);
1968 LIBVIRT_END_ALLOW_THREADS;
1969 if (c_retval < 0) {
1970 VIR_FREE(ids);
1971 return VIR_PY_NONE;
1974 py_retval = PyList_New(c_retval);
1976 if (ids) {
1977 for (i = 0;i < c_retval;i++) {
1978 PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
1980 VIR_FREE(ids);
1983 return py_retval;
1986 static PyObject *
1987 libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
1988 PyObject *args)
1990 PyObject *pyobj_conn;
1991 PyObject *py_retval = NULL;
1992 PyObject *tmp = NULL;
1993 virConnectPtr conn;
1994 virDomainPtr *doms = NULL;
1995 int c_retval = 0;
1996 int i;
1997 unsigned int flags;
1999 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllDomains",
2000 &pyobj_conn, &flags))
2001 return NULL;
2002 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2004 LIBVIRT_BEGIN_ALLOW_THREADS;
2005 c_retval = virConnectListAllDomains(conn, &doms, flags);
2006 LIBVIRT_END_ALLOW_THREADS;
2007 if (c_retval < 0)
2008 return VIR_PY_NONE;
2010 if (!(py_retval = PyList_New(c_retval)))
2011 goto cleanup;
2013 for (i = 0; i < c_retval; i++) {
2014 if (!(tmp = libvirt_virDomainPtrWrap(doms[i])) ||
2015 PyList_SetItem(py_retval, i, tmp) < 0) {
2016 Py_XDECREF(tmp);
2017 Py_DECREF(py_retval);
2018 py_retval = NULL;
2019 goto cleanup;
2021 /* python steals the pointer */
2022 doms[i] = NULL;
2025 cleanup:
2026 for (i = 0; i < c_retval; i++)
2027 if (doms[i])
2028 virDomainFree(doms[i]);
2029 VIR_FREE(doms);
2030 return py_retval;
2033 static PyObject *
2034 libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
2035 PyObject *args) {
2036 PyObject *py_retval;
2037 char **names = NULL;
2038 int c_retval, i;
2039 virConnectPtr conn;
2040 PyObject *pyobj_conn;
2043 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedDomains", &pyobj_conn))
2044 return NULL;
2045 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2047 LIBVIRT_BEGIN_ALLOW_THREADS;
2048 c_retval = virConnectNumOfDefinedDomains(conn);
2049 LIBVIRT_END_ALLOW_THREADS;
2050 if (c_retval < 0)
2051 return VIR_PY_NONE;
2053 if (c_retval) {
2054 if (VIR_ALLOC_N(names, c_retval) < 0)
2055 return VIR_PY_NONE;
2056 LIBVIRT_BEGIN_ALLOW_THREADS;
2057 c_retval = virConnectListDefinedDomains(conn, names, c_retval);
2058 LIBVIRT_END_ALLOW_THREADS;
2059 if (c_retval < 0) {
2060 VIR_FREE(names);
2061 return VIR_PY_NONE;
2064 py_retval = PyList_New(c_retval);
2066 if (names) {
2067 for (i = 0;i < c_retval;i++) {
2068 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2069 VIR_FREE(names[i]);
2071 VIR_FREE(names);
2074 return py_retval;
2077 static PyObject *
2078 libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
2079 PyObject *args)
2081 PyObject *py_retval;
2082 char **names = NULL;
2083 int c_retval, i;
2084 virDomainPtr dom;
2085 PyObject *pyobj_dom;
2086 PyObject *pyobj_snap;
2087 unsigned int flags;
2089 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames",
2090 &pyobj_dom, &flags))
2091 return NULL;
2092 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2094 LIBVIRT_BEGIN_ALLOW_THREADS;
2095 c_retval = virDomainSnapshotNum(dom, flags);
2096 LIBVIRT_END_ALLOW_THREADS;
2097 if (c_retval < 0)
2098 return VIR_PY_NONE;
2100 if (c_retval) {
2101 if (VIR_ALLOC_N(names, c_retval) < 0)
2102 return PyErr_NoMemory();
2103 LIBVIRT_BEGIN_ALLOW_THREADS;
2104 c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
2105 LIBVIRT_END_ALLOW_THREADS;
2106 if (c_retval < 0) {
2107 VIR_FREE(names);
2108 return VIR_PY_NONE;
2111 py_retval = PyList_New(c_retval);
2112 if (!py_retval)
2113 goto cleanup;
2115 for (i = 0; i < c_retval; i++) {
2116 if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
2117 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2118 Py_XDECREF(pyobj_snap);
2119 Py_DECREF(py_retval);
2120 py_retval = NULL;
2121 goto cleanup;
2123 VIR_FREE(names[i]);
2126 cleanup:
2127 for (i = 0; i < c_retval; i++)
2128 VIR_FREE(names[i]);
2129 VIR_FREE(names);
2130 return py_retval;
2133 static PyObject *
2134 libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
2135 PyObject *args)
2137 PyObject *py_retval = NULL;
2138 virDomainSnapshotPtr *snaps = NULL;
2139 int c_retval, i;
2140 virDomainPtr dom;
2141 PyObject *pyobj_dom;
2142 unsigned int flags;
2143 PyObject *pyobj_snap;
2145 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainListAllSnapshots",
2146 &pyobj_dom, &flags))
2147 return NULL;
2148 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2150 LIBVIRT_BEGIN_ALLOW_THREADS;
2151 c_retval = virDomainListAllSnapshots(dom, &snaps, flags);
2152 LIBVIRT_END_ALLOW_THREADS;
2153 if (c_retval < 0)
2154 return VIR_PY_NONE;
2156 if (!(py_retval = PyList_New(c_retval)))
2157 goto cleanup;
2159 for (i = 0; i < c_retval; i++) {
2160 if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
2161 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2162 Py_XDECREF(pyobj_snap);
2163 Py_DECREF(py_retval);
2164 py_retval = NULL;
2165 goto cleanup;
2167 snaps[i] = NULL;
2170 cleanup:
2171 for (i = 0; i < c_retval; i++)
2172 if (snaps[i])
2173 virDomainSnapshotFree(snaps[i]);
2174 VIR_FREE(snaps);
2175 return py_retval;
2178 static PyObject *
2179 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
2180 PyObject *args)
2182 PyObject *py_retval;
2183 char **names = NULL;
2184 int c_retval, i;
2185 virDomainSnapshotPtr snap;
2186 PyObject *pyobj_snap;
2187 unsigned int flags;
2189 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListChildrenNames",
2190 &pyobj_snap, &flags))
2191 return NULL;
2192 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2194 LIBVIRT_BEGIN_ALLOW_THREADS;
2195 c_retval = virDomainSnapshotNumChildren(snap, flags);
2196 LIBVIRT_END_ALLOW_THREADS;
2197 if (c_retval < 0)
2198 return VIR_PY_NONE;
2200 if (c_retval) {
2201 if (VIR_ALLOC_N(names, c_retval) < 0)
2202 return PyErr_NoMemory();
2203 LIBVIRT_BEGIN_ALLOW_THREADS;
2204 c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
2205 flags);
2206 LIBVIRT_END_ALLOW_THREADS;
2207 if (c_retval < 0) {
2208 VIR_FREE(names);
2209 return VIR_PY_NONE;
2212 py_retval = PyList_New(c_retval);
2214 for (i = 0; i < c_retval; i++) {
2215 if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
2216 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2217 Py_XDECREF(pyobj_snap);
2218 Py_DECREF(py_retval);
2219 py_retval = NULL;
2220 goto cleanup;
2222 VIR_FREE(names[i]);
2225 cleanup:
2226 for (i = 0; i < c_retval; i++)
2227 VIR_FREE(names[i]);
2228 VIR_FREE(names);
2229 return py_retval;
2232 static PyObject *
2233 libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
2234 PyObject *args)
2236 PyObject *py_retval = NULL;
2237 virDomainSnapshotPtr *snaps = NULL;
2238 int c_retval, i;
2239 virDomainSnapshotPtr parent;
2240 PyObject *pyobj_parent;
2241 unsigned int flags;
2242 PyObject *pyobj_snap;
2244 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListAllChildren",
2245 &pyobj_parent, &flags))
2246 return NULL;
2247 parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
2249 LIBVIRT_BEGIN_ALLOW_THREADS;
2250 c_retval = virDomainSnapshotListAllChildren(parent, &snaps, flags);
2251 LIBVIRT_END_ALLOW_THREADS;
2252 if (c_retval < 0)
2253 return VIR_PY_NONE;
2255 if (!(py_retval = PyList_New(c_retval)))
2256 goto cleanup;
2258 for (i = 0; i < c_retval; i++) {
2259 if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
2260 PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
2261 Py_XDECREF(pyobj_snap);
2262 Py_DECREF(py_retval);
2263 py_retval = NULL;
2264 goto cleanup;
2266 snaps[i] = NULL;
2269 cleanup:
2270 for (i = 0; i < c_retval; i++)
2271 if (snaps[i])
2272 virDomainSnapshotFree(snaps[i]);
2273 VIR_FREE(snaps);
2274 return py_retval;
2277 static PyObject *
2278 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
2279 PyObject *args) {
2280 int c_retval;
2281 virDomainSnapshotPtr snap;
2282 PyObject *pyobj_snap;
2283 PyObject *pyobj_dom;
2284 unsigned int flags;
2286 if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainRevertToSnapshot", &pyobj_dom, &pyobj_snap, &flags))
2287 return NULL;
2288 snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
2290 LIBVIRT_BEGIN_ALLOW_THREADS;
2291 c_retval = virDomainRevertToSnapshot(snap, flags);
2292 LIBVIRT_END_ALLOW_THREADS;
2293 if (c_retval < 0)
2294 return VIR_PY_INT_FAIL;
2296 return PyInt_FromLong(c_retval);
2299 static PyObject *
2300 libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2301 PyObject *py_retval;
2302 int c_retval;
2303 virDomainPtr domain;
2304 PyObject *pyobj_domain;
2305 virDomainInfo info;
2307 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_domain))
2308 return NULL;
2309 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2311 LIBVIRT_BEGIN_ALLOW_THREADS;
2312 c_retval = virDomainGetInfo(domain, &info);
2313 LIBVIRT_END_ALLOW_THREADS;
2314 if (c_retval < 0)
2315 return VIR_PY_NONE;
2316 py_retval = PyList_New(5);
2317 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
2318 PyList_SetItem(py_retval, 1, libvirt_ulongWrap(info.maxMem));
2319 PyList_SetItem(py_retval, 2, libvirt_ulongWrap(info.memory));
2320 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
2321 PyList_SetItem(py_retval, 4,
2322 libvirt_longlongWrap((unsigned long long) info.cpuTime));
2323 return py_retval;
2326 static PyObject *
2327 libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2329 PyObject *py_retval;
2330 int c_retval;
2331 virDomainPtr domain;
2332 PyObject *pyobj_domain;
2333 int state;
2334 int reason;
2335 unsigned int flags;
2337 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetState",
2338 &pyobj_domain, &flags))
2339 return NULL;
2341 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2343 LIBVIRT_BEGIN_ALLOW_THREADS;
2344 c_retval = virDomainGetState(domain, &state, &reason, flags);
2345 LIBVIRT_END_ALLOW_THREADS;
2346 if (c_retval < 0)
2347 return VIR_PY_NONE;
2349 py_retval = PyList_New(2);
2350 PyList_SetItem(py_retval, 0, libvirt_intWrap(state));
2351 PyList_SetItem(py_retval, 1, libvirt_intWrap(reason));
2352 return py_retval;
2355 static PyObject *
2356 libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2357 PyObject *py_retval;
2358 int c_retval;
2359 virDomainPtr domain;
2360 PyObject *pyobj_domain;
2361 virDomainControlInfo info;
2362 unsigned int flags;
2364 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetControlInfo",
2365 &pyobj_domain, &flags))
2366 return NULL;
2367 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2369 LIBVIRT_BEGIN_ALLOW_THREADS;
2370 c_retval = virDomainGetControlInfo(domain, &info, flags);
2371 LIBVIRT_END_ALLOW_THREADS;
2372 if (c_retval < 0)
2373 return VIR_PY_NONE;
2374 py_retval = PyList_New(3);
2375 PyList_SetItem(py_retval, 0, libvirt_intWrap(info.state));
2376 PyList_SetItem(py_retval, 1, libvirt_intWrap(info.details));
2377 PyList_SetItem(py_retval, 2, libvirt_longlongWrap(info.stateTime));
2378 return py_retval;
2381 static PyObject *
2382 libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2383 PyObject *py_retval;
2384 int c_retval;
2385 virDomainPtr domain;
2386 PyObject *pyobj_domain;
2387 virDomainBlockInfo info;
2388 const char *path;
2389 unsigned int flags;
2391 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInfo", &pyobj_domain, &path, &flags))
2392 return NULL;
2393 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2395 LIBVIRT_BEGIN_ALLOW_THREADS;
2396 c_retval = virDomainGetBlockInfo(domain, path, &info, flags);
2397 LIBVIRT_END_ALLOW_THREADS;
2398 if (c_retval < 0)
2399 return VIR_PY_NONE;
2400 py_retval = PyList_New(3);
2401 PyList_SetItem(py_retval, 0, libvirt_ulonglongWrap(info.capacity));
2402 PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.allocation));
2403 PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.physical));
2404 return py_retval;
2407 static PyObject *
2408 libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2409 PyObject *py_retval;
2410 int c_retval;
2411 virConnectPtr conn;
2412 PyObject *pyobj_conn;
2413 virNodeInfo info;
2415 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetInfo", &pyobj_conn))
2416 return NULL;
2417 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2419 LIBVIRT_BEGIN_ALLOW_THREADS;
2420 c_retval = virNodeGetInfo(conn, &info);
2421 LIBVIRT_END_ALLOW_THREADS;
2422 if (c_retval < 0)
2423 return VIR_PY_NONE;
2424 py_retval = PyList_New(8);
2425 PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&info.model[0]));
2426 PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.memory >> 10));
2427 PyList_SetItem(py_retval, 2, libvirt_intWrap((int) info.cpus));
2428 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.mhz));
2429 PyList_SetItem(py_retval, 4, libvirt_intWrap((int) info.nodes));
2430 PyList_SetItem(py_retval, 5, libvirt_intWrap((int) info.sockets));
2431 PyList_SetItem(py_retval, 6, libvirt_intWrap((int) info.cores));
2432 PyList_SetItem(py_retval, 7, libvirt_intWrap((int) info.threads));
2433 return py_retval;
2436 static PyObject *
2437 libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2438 PyObject *py_retval;
2439 unsigned char uuid[VIR_UUID_BUFLEN];
2440 virDomainPtr domain;
2441 PyObject *pyobj_domain;
2442 int c_retval;
2444 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
2445 return NULL;
2446 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2448 if (domain == NULL)
2449 return VIR_PY_NONE;
2450 LIBVIRT_BEGIN_ALLOW_THREADS;
2451 c_retval = virDomainGetUUID(domain, &uuid[0]);
2452 LIBVIRT_END_ALLOW_THREADS;
2454 if (c_retval < 0)
2455 return VIR_PY_NONE;
2456 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
2458 return py_retval;
2461 static PyObject *
2462 libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
2463 PyObject *args) {
2464 PyObject *py_retval;
2465 char uuidstr[VIR_UUID_STRING_BUFLEN];
2466 virDomainPtr dom;
2467 PyObject *pyobj_dom;
2468 int c_retval;
2470 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString",
2471 &pyobj_dom))
2472 return NULL;
2473 dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
2475 if (dom == NULL)
2476 return VIR_PY_NONE;
2477 LIBVIRT_BEGIN_ALLOW_THREADS;
2478 c_retval = virDomainGetUUIDString(dom, &uuidstr[0]);
2479 LIBVIRT_END_ALLOW_THREADS;
2481 if (c_retval < 0)
2482 return VIR_PY_NONE;
2484 py_retval = PyString_FromString((char *) &uuidstr[0]);
2485 return py_retval;
2488 static PyObject *
2489 libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2490 PyObject *py_retval;
2491 virDomainPtr c_retval;
2492 virConnectPtr conn;
2493 PyObject *pyobj_conn;
2494 unsigned char * uuid;
2495 int len;
2497 if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID", &pyobj_conn, &uuid, &len))
2498 return NULL;
2499 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2501 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
2502 return VIR_PY_NONE;
2504 LIBVIRT_BEGIN_ALLOW_THREADS;
2505 c_retval = virDomainLookupByUUID(conn, uuid);
2506 LIBVIRT_END_ALLOW_THREADS;
2507 py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
2508 return py_retval;
2512 static PyObject *
2513 libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
2514 PyObject *args) {
2515 PyObject *py_retval;
2516 char **names = NULL;
2517 int c_retval, i;
2518 virConnectPtr conn;
2519 PyObject *pyobj_conn;
2522 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks", &pyobj_conn))
2523 return NULL;
2524 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2526 LIBVIRT_BEGIN_ALLOW_THREADS;
2527 c_retval = virConnectNumOfNetworks(conn);
2528 LIBVIRT_END_ALLOW_THREADS;
2529 if (c_retval < 0)
2530 return VIR_PY_NONE;
2532 if (c_retval) {
2533 if (VIR_ALLOC_N(names, c_retval) < 0)
2534 return VIR_PY_NONE;
2535 LIBVIRT_BEGIN_ALLOW_THREADS;
2536 c_retval = virConnectListNetworks(conn, names, c_retval);
2537 LIBVIRT_END_ALLOW_THREADS;
2538 if (c_retval < 0) {
2539 VIR_FREE(names);
2540 return VIR_PY_NONE;
2543 py_retval = PyList_New(c_retval);
2545 if (names) {
2546 for (i = 0;i < c_retval;i++) {
2547 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2548 VIR_FREE(names[i]);
2550 VIR_FREE(names);
2553 return py_retval;
2557 static PyObject *
2558 libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
2559 PyObject *args) {
2560 PyObject *py_retval;
2561 char **names = NULL;
2562 int c_retval, i;
2563 virConnectPtr conn;
2564 PyObject *pyobj_conn;
2567 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks", &pyobj_conn))
2568 return NULL;
2569 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2571 LIBVIRT_BEGIN_ALLOW_THREADS;
2572 c_retval = virConnectNumOfDefinedNetworks(conn);
2573 LIBVIRT_END_ALLOW_THREADS;
2574 if (c_retval < 0)
2575 return VIR_PY_NONE;
2577 if (c_retval) {
2578 if (VIR_ALLOC_N(names, c_retval) < 0)
2579 return VIR_PY_NONE;
2580 LIBVIRT_BEGIN_ALLOW_THREADS;
2581 c_retval = virConnectListDefinedNetworks(conn, names, c_retval);
2582 LIBVIRT_END_ALLOW_THREADS;
2583 if (c_retval < 0) {
2584 VIR_FREE(names);
2585 return VIR_PY_NONE;
2588 py_retval = PyList_New(c_retval);
2590 if (names) {
2591 for (i = 0;i < c_retval;i++) {
2592 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2593 VIR_FREE(names[i]);
2595 VIR_FREE(names);
2598 return py_retval;
2601 static PyObject *
2602 libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
2603 PyObject *args)
2605 PyObject *pyobj_conn;
2606 PyObject *py_retval = NULL;
2607 PyObject *tmp = NULL;
2608 virConnectPtr conn;
2609 virNetworkPtr *nets = NULL;
2610 int c_retval = 0;
2611 int i;
2612 unsigned int flags;
2614 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNetworks",
2615 &pyobj_conn, &flags))
2616 return NULL;
2617 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2619 LIBVIRT_BEGIN_ALLOW_THREADS;
2620 c_retval = virConnectListAllNetworks(conn, &nets, flags);
2621 LIBVIRT_END_ALLOW_THREADS;
2622 if (c_retval < 0)
2623 return VIR_PY_NONE;
2625 if (!(py_retval = PyList_New(c_retval)))
2626 goto cleanup;
2628 for (i = 0; i < c_retval; i++) {
2629 if (!(tmp = libvirt_virNetworkPtrWrap(nets[i])) ||
2630 PyList_SetItem(py_retval, i, tmp) < 0) {
2631 Py_XDECREF(tmp);
2632 Py_DECREF(py_retval);
2633 py_retval = NULL;
2634 goto cleanup;
2636 /* python steals the pointer */
2637 nets[i] = NULL;
2640 cleanup:
2641 for (i = 0; i < c_retval; i++)
2642 if (nets[i])
2643 virNetworkFree(nets[i]);
2644 VIR_FREE(nets);
2645 return py_retval;
2649 static PyObject *
2650 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2651 PyObject *py_retval;
2652 unsigned char uuid[VIR_UUID_BUFLEN];
2653 virNetworkPtr domain;
2654 PyObject *pyobj_domain;
2655 int c_retval;
2657 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain))
2658 return NULL;
2659 domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain);
2661 if (domain == NULL)
2662 return VIR_PY_NONE;
2663 LIBVIRT_BEGIN_ALLOW_THREADS;
2664 c_retval = virNetworkGetUUID(domain, &uuid[0]);
2665 LIBVIRT_END_ALLOW_THREADS;
2667 if (c_retval < 0)
2668 return VIR_PY_NONE;
2669 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
2671 return py_retval;
2674 static PyObject *
2675 libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
2676 PyObject *args) {
2677 PyObject *py_retval;
2678 char uuidstr[VIR_UUID_STRING_BUFLEN];
2679 virNetworkPtr net;
2680 PyObject *pyobj_net;
2681 int c_retval;
2683 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString",
2684 &pyobj_net))
2685 return NULL;
2686 net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net);
2688 if (net == NULL)
2689 return VIR_PY_NONE;
2690 LIBVIRT_BEGIN_ALLOW_THREADS;
2691 c_retval = virNetworkGetUUIDString(net, &uuidstr[0]);
2692 LIBVIRT_END_ALLOW_THREADS;
2694 if (c_retval < 0)
2695 return VIR_PY_NONE;
2697 py_retval = PyString_FromString((char *) &uuidstr[0]);
2698 return py_retval;
2701 static PyObject *
2702 libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2703 PyObject *py_retval;
2704 virNetworkPtr c_retval;
2705 virConnectPtr conn;
2706 PyObject *pyobj_conn;
2707 unsigned char * uuid;
2708 int len;
2710 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID", &pyobj_conn, &uuid, &len))
2711 return NULL;
2712 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2714 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
2715 return VIR_PY_NONE;
2717 LIBVIRT_BEGIN_ALLOW_THREADS;
2718 c_retval = virNetworkLookupByUUID(conn, uuid);
2719 LIBVIRT_END_ALLOW_THREADS;
2720 py_retval = libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval);
2721 return py_retval;
2725 static PyObject *
2726 libvirt_virDomainGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2727 PyObject *py_retval;
2728 int c_retval, autostart;
2729 virDomainPtr domain;
2730 PyObject *pyobj_domain;
2732 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetAutostart", &pyobj_domain))
2733 return NULL;
2735 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
2737 LIBVIRT_BEGIN_ALLOW_THREADS;
2738 c_retval = virDomainGetAutostart(domain, &autostart);
2739 LIBVIRT_END_ALLOW_THREADS;
2741 if (c_retval < 0)
2742 return VIR_PY_INT_FAIL;
2743 py_retval = libvirt_intWrap(autostart);
2744 return py_retval;
2748 static PyObject *
2749 libvirt_virNetworkGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
2750 PyObject *py_retval;
2751 int c_retval, autostart;
2752 virNetworkPtr network;
2753 PyObject *pyobj_network;
2755 if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetAutostart", &pyobj_network))
2756 return NULL;
2758 network = (virNetworkPtr) PyvirNetwork_Get(pyobj_network);
2760 LIBVIRT_BEGIN_ALLOW_THREADS;
2761 c_retval = virNetworkGetAutostart(network, &autostart);
2762 LIBVIRT_END_ALLOW_THREADS;
2764 if (c_retval < 0)
2765 return VIR_PY_INT_FAIL;
2766 py_retval = libvirt_intWrap(autostart);
2767 return py_retval;
2770 static PyObject *
2771 libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2773 PyObject *py_retval;
2774 PyObject *pyobj_conn;
2775 int startCell, maxCells, c_retval, i;
2776 virConnectPtr conn;
2777 unsigned long long *freeMems;
2779 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory", &pyobj_conn, &startCell, &maxCells))
2780 return NULL;
2782 if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
2783 return VIR_PY_NONE;
2785 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2786 if (VIR_ALLOC_N(freeMems, maxCells) < 0)
2787 return VIR_PY_NONE;
2789 LIBVIRT_BEGIN_ALLOW_THREADS;
2790 c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
2791 LIBVIRT_END_ALLOW_THREADS;
2793 if (c_retval < 0) {
2794 VIR_FREE(freeMems);
2795 return VIR_PY_NONE;
2797 py_retval = PyList_New(c_retval);
2798 for (i = 0;i < c_retval;i++) {
2799 PyList_SetItem(py_retval, i,
2800 libvirt_longlongWrap((long long) freeMems[i]));
2802 VIR_FREE(freeMems);
2803 return py_retval;
2806 static PyObject *
2807 libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2809 PyObject *ret = NULL;
2810 PyObject *key = NULL;
2811 PyObject *val = NULL;
2812 PyObject *pyobj_conn;
2813 virConnectPtr conn;
2814 unsigned int flags;
2815 int cpuNum, c_retval, i;
2816 int nparams = 0;
2817 virNodeCPUStatsPtr stats = NULL;
2819 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn, &cpuNum, &flags))
2820 return ret;
2821 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
2823 LIBVIRT_BEGIN_ALLOW_THREADS;
2824 c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
2825 LIBVIRT_END_ALLOW_THREADS;
2826 if (c_retval < 0)
2827 return VIR_PY_NONE;
2829 if (nparams) {
2830 if (VIR_ALLOC_N(stats, nparams) < 0)
2831 return PyErr_NoMemory();
2833 LIBVIRT_BEGIN_ALLOW_THREADS;
2834 c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
2835 LIBVIRT_END_ALLOW_THREADS;
2836 if (c_retval < 0) {
2837 VIR_FREE(stats);
2838 return VIR_PY_NONE;
2842 if (!(ret = PyDict_New()))
2843 goto error;
2845 for (i = 0; i < nparams; i++) {
2846 key = libvirt_constcharPtrWrap(stats[i].field);
2847 val = libvirt_ulonglongWrap(stats[i].value);
2849 if (!key || !val || PyDict_SetItem(ret, key, val) < 0) {
2850 Py_DECREF(ret);
2851 ret = NULL;
2852 goto error;
2855 Py_DECREF(key);
2856 Py_DECREF(val);
2859 VIR_FREE(stats);
2860 return ret;
2862 error:
2863 VIR_FREE(stats);
2864 Py_XDECREF(key);
2865 Py_XDECREF(val);
2866 return ret;
2869 static PyObject *
2870 libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
2872 PyObject *ret = NULL;
2873 PyObject *key = NULL;
2874 PyObject *val = NULL;
2875 PyObject *pyobj_conn;
2876 virConnectPtr conn;
2877 unsigned int flags;
2878 int cellNum, c_retval, i;
2879 int nparams = 0;
2880 virNodeMemoryStatsPtr stats = NULL;
2882 if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetMemoryStats", &pyobj_conn, &cellNum, &flags))
2883 return ret;
2884 conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
2886 LIBVIRT_BEGIN_ALLOW_THREADS;
2887 c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
2888 LIBVIRT_END_ALLOW_THREADS;
2889 if (c_retval < 0)
2890 return VIR_PY_NONE;
2892 if (nparams) {
2893 if (VIR_ALLOC_N(stats, nparams) < 0)
2894 return PyErr_NoMemory();
2896 LIBVIRT_BEGIN_ALLOW_THREADS;
2897 c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
2898 LIBVIRT_END_ALLOW_THREADS;
2899 if (c_retval < 0) {
2900 VIR_FREE(stats);
2901 return VIR_PY_NONE;
2905 if (!(ret = PyDict_New()))
2906 goto error;
2908 for (i = 0; i < nparams; i++) {
2909 key = libvirt_constcharPtrWrap(stats[i].field);
2910 val = libvirt_ulonglongWrap(stats[i].value);
2912 if (!key || !val || PyDict_SetItem(ret, key, val) < 0) {
2913 Py_DECREF(ret);
2914 ret = NULL;
2915 goto error;
2918 Py_DECREF(key);
2919 Py_DECREF(val);
2922 VIR_FREE(stats);
2923 return ret;
2925 error:
2926 VIR_FREE(stats);
2927 Py_XDECREF(key);
2928 Py_XDECREF(val);
2929 return ret;
2932 static PyObject *
2933 libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
2934 PyObject *args) {
2935 PyObject *py_retval;
2936 char **names = NULL;
2937 int c_retval, i;
2938 virConnectPtr conn;
2939 PyObject *pyobj_conn;
2942 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListStoragePools", &pyobj_conn))
2943 return NULL;
2944 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2946 LIBVIRT_BEGIN_ALLOW_THREADS;
2947 c_retval = virConnectNumOfStoragePools(conn);
2948 LIBVIRT_END_ALLOW_THREADS;
2949 if (c_retval < 0)
2950 return VIR_PY_NONE;
2952 if (c_retval) {
2953 if (VIR_ALLOC_N(names, c_retval) < 0)
2954 return VIR_PY_NONE;
2955 LIBVIRT_BEGIN_ALLOW_THREADS;
2956 c_retval = virConnectListStoragePools(conn, names, c_retval);
2957 LIBVIRT_END_ALLOW_THREADS;
2958 if (c_retval < 0) {
2959 VIR_FREE(names);
2960 return VIR_PY_NONE;
2963 py_retval = PyList_New(c_retval);
2964 if (py_retval == NULL) {
2965 if (names) {
2966 for (i = 0;i < c_retval;i++)
2967 VIR_FREE(names[i]);
2968 VIR_FREE(names);
2970 return VIR_PY_NONE;
2973 if (names) {
2974 for (i = 0;i < c_retval;i++) {
2975 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
2976 VIR_FREE(names[i]);
2978 VIR_FREE(names);
2981 return py_retval;
2985 static PyObject *
2986 libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
2987 PyObject *args) {
2988 PyObject *py_retval;
2989 char **names = NULL;
2990 int c_retval, i;
2991 virConnectPtr conn;
2992 PyObject *pyobj_conn;
2995 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedStoragePools", &pyobj_conn))
2996 return NULL;
2997 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
2999 LIBVIRT_BEGIN_ALLOW_THREADS;
3000 c_retval = virConnectNumOfDefinedStoragePools(conn);
3001 LIBVIRT_END_ALLOW_THREADS;
3002 if (c_retval < 0)
3003 return VIR_PY_NONE;
3005 if (c_retval) {
3006 if (VIR_ALLOC_N(names, c_retval) < 0)
3007 return VIR_PY_NONE;
3008 LIBVIRT_BEGIN_ALLOW_THREADS;
3009 c_retval = virConnectListDefinedStoragePools(conn, names, c_retval);
3010 LIBVIRT_END_ALLOW_THREADS;
3011 if (c_retval < 0) {
3012 VIR_FREE(names);
3013 return VIR_PY_NONE;
3016 py_retval = PyList_New(c_retval);
3017 if (py_retval == NULL) {
3018 if (names) {
3019 for (i = 0;i < c_retval;i++)
3020 VIR_FREE(names[i]);
3021 VIR_FREE(names);
3023 return VIR_PY_NONE;
3026 if (names) {
3027 for (i = 0;i < c_retval;i++) {
3028 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3029 VIR_FREE(names[i]);
3031 VIR_FREE(names);
3034 return py_retval;
3037 static PyObject *
3038 libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
3039 PyObject *args)
3041 PyObject *pyobj_conn;
3042 PyObject *py_retval = NULL;
3043 PyObject *tmp = NULL;
3044 virConnectPtr conn;
3045 virStoragePoolPtr *pools = NULL;
3046 int c_retval = 0;
3047 int i;
3048 unsigned int flags;
3050 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllStoragePools",
3051 &pyobj_conn, &flags))
3052 return NULL;
3053 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3055 LIBVIRT_BEGIN_ALLOW_THREADS;
3056 c_retval = virConnectListAllStoragePools(conn, &pools, flags);
3057 LIBVIRT_END_ALLOW_THREADS;
3058 if (c_retval < 0)
3059 return VIR_PY_NONE;
3061 if (!(py_retval = PyList_New(c_retval)))
3062 goto cleanup;
3064 for (i = 0; i < c_retval; i++) {
3065 if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i])) ||
3066 PyList_SetItem(py_retval, i, tmp) < 0) {
3067 Py_XDECREF(tmp);
3068 Py_DECREF(py_retval);
3069 py_retval = NULL;
3070 goto cleanup;
3072 /* python steals the pointer */
3073 pools[i] = NULL;
3076 cleanup:
3077 for (i = 0; i < c_retval; i++)
3078 if (pools[i])
3079 virStoragePoolFree(pools[i]);
3080 VIR_FREE(pools);
3081 return py_retval;
3084 static PyObject *
3085 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
3086 PyObject *args) {
3087 PyObject *py_retval;
3088 char **names = NULL;
3089 int c_retval, i;
3090 virStoragePoolPtr pool;
3091 PyObject *pyobj_pool;
3094 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolListVolumes", &pyobj_pool))
3095 return NULL;
3096 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3098 LIBVIRT_BEGIN_ALLOW_THREADS;
3099 c_retval = virStoragePoolNumOfVolumes(pool);
3100 LIBVIRT_END_ALLOW_THREADS;
3101 if (c_retval < 0)
3102 return VIR_PY_NONE;
3104 if (c_retval) {
3105 if (VIR_ALLOC_N(names, c_retval) < 0)
3106 return VIR_PY_NONE;
3107 LIBVIRT_BEGIN_ALLOW_THREADS;
3108 c_retval = virStoragePoolListVolumes(pool, names, c_retval);
3109 LIBVIRT_END_ALLOW_THREADS;
3110 if (c_retval < 0) {
3111 VIR_FREE(names);
3112 return VIR_PY_NONE;
3115 py_retval = PyList_New(c_retval);
3116 if (py_retval == NULL) {
3117 if (names) {
3118 for (i = 0;i < c_retval;i++)
3119 VIR_FREE(names[i]);
3120 VIR_FREE(names);
3122 return VIR_PY_NONE;
3125 if (names) {
3126 for (i = 0;i < c_retval;i++) {
3127 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3128 VIR_FREE(names[i]);
3130 VIR_FREE(names);
3133 return py_retval;
3136 static PyObject *
3137 libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
3138 PyObject *args)
3140 PyObject *py_retval = NULL;
3141 PyObject *tmp = NULL;
3142 virStoragePoolPtr pool;
3143 virStorageVolPtr *vols = NULL;
3144 int c_retval = 0;
3145 int i;
3146 unsigned int flags;
3147 PyObject *pyobj_pool;
3149 if (!PyArg_ParseTuple(args, (char *)"Oi:virStoragePoolListAllVolumes",
3150 &pyobj_pool, &flags))
3151 return NULL;
3153 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3155 LIBVIRT_BEGIN_ALLOW_THREADS;
3156 c_retval = virStoragePoolListAllVolumes(pool, &vols, flags);
3157 LIBVIRT_END_ALLOW_THREADS;
3158 if (c_retval < 0)
3159 return VIR_PY_NONE;
3161 if (!(py_retval = PyList_New(c_retval)))
3162 goto cleanup;
3164 for (i = 0; i < c_retval; i++) {
3165 if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i])) ||
3166 PyList_SetItem(py_retval, i, tmp) < 0) {
3167 Py_XDECREF(tmp);
3168 Py_DECREF(py_retval);
3169 py_retval = NULL;
3170 goto cleanup;
3172 /* python steals the pointer */
3173 vols[i] = NULL;
3176 cleanup:
3177 for (i = 0; i < c_retval; i++)
3178 if (vols[i])
3179 virStorageVolFree(vols[i]);
3180 VIR_FREE(vols);
3181 return py_retval;
3185 static PyObject *
3186 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3187 PyObject *py_retval;
3188 int c_retval, autostart;
3189 virStoragePoolPtr pool;
3190 PyObject *pyobj_pool;
3192 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetAutostart", &pyobj_pool))
3193 return NULL;
3195 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3197 LIBVIRT_BEGIN_ALLOW_THREADS;
3198 c_retval = virStoragePoolGetAutostart(pool, &autostart);
3199 LIBVIRT_END_ALLOW_THREADS;
3201 if (c_retval < 0)
3202 return VIR_PY_NONE;
3204 py_retval = libvirt_intWrap(autostart);
3205 return py_retval;
3208 static PyObject *
3209 libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3210 PyObject *py_retval;
3211 int c_retval;
3212 virStoragePoolPtr pool;
3213 PyObject *pyobj_pool;
3214 virStoragePoolInfo info;
3216 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetInfo", &pyobj_pool))
3217 return NULL;
3218 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3220 LIBVIRT_BEGIN_ALLOW_THREADS;
3221 c_retval = virStoragePoolGetInfo(pool, &info);
3222 LIBVIRT_END_ALLOW_THREADS;
3223 if (c_retval < 0)
3224 return VIR_PY_NONE;
3226 if ((py_retval = PyList_New(4)) == NULL)
3227 return VIR_PY_NONE;
3229 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
3230 PyList_SetItem(py_retval, 1,
3231 libvirt_longlongWrap((unsigned long long) info.capacity));
3232 PyList_SetItem(py_retval, 2,
3233 libvirt_longlongWrap((unsigned long long) info.allocation));
3234 PyList_SetItem(py_retval, 3,
3235 libvirt_longlongWrap((unsigned long long) info.available));
3236 return py_retval;
3240 static PyObject *
3241 libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3242 PyObject *py_retval;
3243 int c_retval;
3244 virStorageVolPtr pool;
3245 PyObject *pyobj_pool;
3246 virStorageVolInfo info;
3248 if (!PyArg_ParseTuple(args, (char *)"O:virStorageVolGetInfo", &pyobj_pool))
3249 return NULL;
3250 pool = (virStorageVolPtr) PyvirStorageVol_Get(pyobj_pool);
3252 LIBVIRT_BEGIN_ALLOW_THREADS;
3253 c_retval = virStorageVolGetInfo(pool, &info);
3254 LIBVIRT_END_ALLOW_THREADS;
3255 if (c_retval < 0)
3256 return VIR_PY_NONE;
3258 if ((py_retval = PyList_New(3)) == NULL)
3259 return VIR_PY_NONE;
3260 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
3261 PyList_SetItem(py_retval, 1,
3262 libvirt_longlongWrap((unsigned long long) info.capacity));
3263 PyList_SetItem(py_retval, 2,
3264 libvirt_longlongWrap((unsigned long long) info.allocation));
3265 return py_retval;
3268 static PyObject *
3269 libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3270 PyObject *py_retval;
3271 unsigned char uuid[VIR_UUID_BUFLEN];
3272 virStoragePoolPtr pool;
3273 PyObject *pyobj_pool;
3274 int c_retval;
3276 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUID", &pyobj_pool))
3277 return NULL;
3278 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3280 if (pool == NULL)
3281 return VIR_PY_NONE;
3282 LIBVIRT_BEGIN_ALLOW_THREADS;
3283 c_retval = virStoragePoolGetUUID(pool, &uuid[0]);
3284 LIBVIRT_END_ALLOW_THREADS;
3286 if (c_retval < 0)
3287 return VIR_PY_NONE;
3289 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
3291 return py_retval;
3294 static PyObject *
3295 libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3296 PyObject *args) {
3297 PyObject *py_retval;
3298 char uuidstr[VIR_UUID_STRING_BUFLEN];
3299 virStoragePoolPtr pool;
3300 PyObject *pyobj_pool;
3301 int c_retval;
3303 if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString", &pyobj_pool))
3304 return NULL;
3305 pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
3307 if (pool == NULL)
3308 return VIR_PY_NONE;
3309 LIBVIRT_BEGIN_ALLOW_THREADS;
3310 c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]);
3311 LIBVIRT_END_ALLOW_THREADS;
3313 if (c_retval < 0)
3314 return VIR_PY_NONE;
3316 py_retval = PyString_FromString((char *) &uuidstr[0]);
3317 return py_retval;
3320 static PyObject *
3321 libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3322 PyObject *py_retval;
3323 virStoragePoolPtr c_retval;
3324 virConnectPtr conn;
3325 PyObject *pyobj_conn;
3326 unsigned char * uuid;
3327 int len;
3329 if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID", &pyobj_conn, &uuid, &len))
3330 return NULL;
3331 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3333 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3334 return VIR_PY_NONE;
3336 LIBVIRT_BEGIN_ALLOW_THREADS;
3337 c_retval = virStoragePoolLookupByUUID(conn, uuid);
3338 LIBVIRT_END_ALLOW_THREADS;
3339 py_retval = libvirt_virStoragePoolPtrWrap((virStoragePoolPtr) c_retval);
3340 return py_retval;
3343 static PyObject *
3344 libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
3345 PyObject *args) {
3346 PyObject *py_retval;
3347 char **names = NULL;
3348 int c_retval, i;
3349 virConnectPtr conn;
3350 PyObject *pyobj_conn;
3351 char *cap;
3352 unsigned int flags;
3354 if (!PyArg_ParseTuple(args, (char *)"Ozi:virNodeListDevices",
3355 &pyobj_conn, &cap, &flags))
3356 return NULL;
3357 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3359 LIBVIRT_BEGIN_ALLOW_THREADS;
3360 c_retval = virNodeNumOfDevices(conn, cap, flags);
3361 LIBVIRT_END_ALLOW_THREADS;
3362 if (c_retval < 0)
3363 return VIR_PY_NONE;
3365 if (c_retval) {
3366 if (VIR_ALLOC_N(names, c_retval) < 0)
3367 return VIR_PY_NONE;
3368 LIBVIRT_BEGIN_ALLOW_THREADS;
3369 c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
3370 LIBVIRT_END_ALLOW_THREADS;
3371 if (c_retval < 0) {
3372 VIR_FREE(names);
3373 return VIR_PY_NONE;
3376 py_retval = PyList_New(c_retval);
3378 if (names) {
3379 for (i = 0;i < c_retval;i++) {
3380 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3381 VIR_FREE(names[i]);
3383 VIR_FREE(names);
3386 return py_retval;
3389 static PyObject *
3390 libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
3391 PyObject *args)
3393 PyObject *pyobj_conn;
3394 PyObject *py_retval = NULL;
3395 PyObject *tmp = NULL;
3396 virConnectPtr conn;
3397 virNodeDevicePtr *devices = NULL;
3398 int c_retval = 0;
3399 int i;
3400 unsigned int flags;
3402 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNodeDevices",
3403 &pyobj_conn, &flags))
3404 return NULL;
3405 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3407 LIBVIRT_BEGIN_ALLOW_THREADS;
3408 c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
3409 LIBVIRT_END_ALLOW_THREADS;
3410 if (c_retval < 0)
3411 return VIR_PY_NONE;
3413 if (!(py_retval = PyList_New(c_retval)))
3414 goto cleanup;
3416 for (i = 0; i < c_retval; i++) {
3417 if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i])) ||
3418 PyList_SetItem(py_retval, i, tmp) < 0) {
3419 Py_XDECREF(tmp);
3420 Py_DECREF(py_retval);
3421 py_retval = NULL;
3422 goto cleanup;
3424 /* python steals the pointer */
3425 devices[i] = NULL;
3428 cleanup:
3429 for (i = 0; i < c_retval; i++)
3430 if (devices[i])
3431 virNodeDeviceFree(devices[i]);
3432 VIR_FREE(devices);
3433 return py_retval;
3436 static PyObject *
3437 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
3438 PyObject *args) {
3439 PyObject *py_retval;
3440 char **names = NULL;
3441 int c_retval, i;
3442 virNodeDevicePtr dev;
3443 PyObject *pyobj_dev;
3445 if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
3446 return NULL;
3447 dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
3449 LIBVIRT_BEGIN_ALLOW_THREADS;
3450 c_retval = virNodeDeviceNumOfCaps(dev);
3451 LIBVIRT_END_ALLOW_THREADS;
3452 if (c_retval < 0)
3453 return VIR_PY_NONE;
3455 if (c_retval) {
3456 if (VIR_ALLOC_N(names, c_retval) < 0)
3457 return VIR_PY_NONE;
3458 LIBVIRT_BEGIN_ALLOW_THREADS;
3459 c_retval = virNodeDeviceListCaps(dev, names, c_retval);
3460 LIBVIRT_END_ALLOW_THREADS;
3461 if (c_retval < 0) {
3462 VIR_FREE(names);
3463 return VIR_PY_NONE;
3466 py_retval = PyList_New(c_retval);
3468 if (names) {
3469 for (i = 0;i < c_retval;i++) {
3470 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3471 VIR_FREE(names[i]);
3473 VIR_FREE(names);
3476 return py_retval;
3479 static PyObject *
3480 libvirt_virSecretGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3481 PyObject *py_retval;
3482 unsigned char uuid[VIR_UUID_BUFLEN];
3483 virSecretPtr secret;
3484 PyObject *pyobj_secret;
3485 int c_retval;
3487 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUID", &pyobj_secret))
3488 return NULL;
3489 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
3491 if (secret == NULL)
3492 return VIR_PY_NONE;
3493 LIBVIRT_BEGIN_ALLOW_THREADS;
3494 c_retval = virSecretGetUUID(secret, &uuid[0]);
3495 LIBVIRT_END_ALLOW_THREADS;
3497 if (c_retval < 0)
3498 return VIR_PY_NONE;
3499 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
3501 return py_retval;
3504 static PyObject *
3505 libvirt_virSecretGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3506 PyObject *args) {
3507 PyObject *py_retval;
3508 char uuidstr[VIR_UUID_STRING_BUFLEN];
3509 virSecretPtr dom;
3510 PyObject *pyobj_dom;
3511 int c_retval;
3513 if (!PyArg_ParseTuple(args, (char *)"O:virSecretGetUUIDString",
3514 &pyobj_dom))
3515 return NULL;
3516 dom = (virSecretPtr) PyvirSecret_Get(pyobj_dom);
3518 if (dom == NULL)
3519 return VIR_PY_NONE;
3520 LIBVIRT_BEGIN_ALLOW_THREADS;
3521 c_retval = virSecretGetUUIDString(dom, &uuidstr[0]);
3522 LIBVIRT_END_ALLOW_THREADS;
3524 if (c_retval < 0)
3525 return VIR_PY_NONE;
3527 py_retval = PyString_FromString((char *) &uuidstr[0]);
3528 return py_retval;
3531 static PyObject *
3532 libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3533 PyObject *py_retval;
3534 virSecretPtr c_retval;
3535 virConnectPtr conn;
3536 PyObject *pyobj_conn;
3537 unsigned char * uuid;
3538 int len;
3540 if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID", &pyobj_conn, &uuid, &len))
3541 return NULL;
3542 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3544 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3545 return VIR_PY_NONE;
3547 LIBVIRT_BEGIN_ALLOW_THREADS;
3548 c_retval = virSecretLookupByUUID(conn, uuid);
3549 LIBVIRT_END_ALLOW_THREADS;
3550 py_retval = libvirt_virSecretPtrWrap((virSecretPtr) c_retval);
3551 return py_retval;
3555 static PyObject *
3556 libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
3557 PyObject *args) {
3558 PyObject *py_retval;
3559 char **uuids = NULL;
3560 virConnectPtr conn;
3561 int c_retval, i;
3562 PyObject *pyobj_conn;
3564 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
3565 return NULL;
3566 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3568 LIBVIRT_BEGIN_ALLOW_THREADS;
3569 c_retval = virConnectNumOfSecrets(conn);
3570 LIBVIRT_END_ALLOW_THREADS;
3571 if (c_retval < 0)
3572 return VIR_PY_NONE;
3574 if (c_retval) {
3575 if (VIR_ALLOC_N(uuids, c_retval) < 0)
3576 return VIR_PY_NONE;
3577 LIBVIRT_BEGIN_ALLOW_THREADS;
3578 c_retval = virConnectListSecrets(conn, uuids, c_retval);
3579 LIBVIRT_END_ALLOW_THREADS;
3580 if (c_retval < 0) {
3581 VIR_FREE(uuids);
3582 return VIR_PY_NONE;
3585 py_retval = PyList_New(c_retval);
3587 if (uuids) {
3588 for (i = 0;i < c_retval;i++) {
3589 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
3590 VIR_FREE(uuids[i]);
3592 VIR_FREE(uuids);
3595 return py_retval;
3598 static PyObject *
3599 libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
3600 PyObject *args)
3602 PyObject *pyobj_conn;
3603 PyObject *py_retval = NULL;
3604 PyObject *tmp = NULL;
3605 virConnectPtr conn;
3606 virSecretPtr *secrets = NULL;
3607 int c_retval = 0;
3608 int i;
3609 unsigned int flags;
3611 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllSecrets",
3612 &pyobj_conn, &flags))
3613 return NULL;
3614 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3616 LIBVIRT_BEGIN_ALLOW_THREADS;
3617 c_retval = virConnectListAllSecrets(conn, &secrets, flags);
3618 LIBVIRT_END_ALLOW_THREADS;
3619 if (c_retval < 0)
3620 return VIR_PY_NONE;
3622 if (!(py_retval = PyList_New(c_retval)))
3623 goto cleanup;
3625 for (i = 0; i < c_retval; i++) {
3626 if (!(tmp = libvirt_virSecretPtrWrap(secrets[i])) ||
3627 PyList_SetItem(py_retval, i, tmp) < 0) {
3628 Py_XDECREF(tmp);
3629 Py_DECREF(py_retval);
3630 py_retval = NULL;
3631 goto cleanup;
3633 /* python steals the pointer */
3634 secrets[i] = NULL;
3637 cleanup:
3638 for (i = 0; i < c_retval; i++)
3639 if (secrets[i])
3640 virSecretFree(secrets[i]);
3641 VIR_FREE(secrets);
3642 return py_retval;
3645 static PyObject *
3646 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
3647 PyObject *args) {
3648 PyObject *py_retval;
3649 unsigned char *c_retval;
3650 size_t size;
3651 virSecretPtr secret;
3652 PyObject *pyobj_secret;
3653 unsigned int flags;
3655 if (!PyArg_ParseTuple(args, (char *)"Oi:virSecretGetValue", &pyobj_secret,
3656 &flags))
3657 return NULL;
3658 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
3660 LIBVIRT_BEGIN_ALLOW_THREADS;
3661 c_retval = virSecretGetValue(secret, &size, flags);
3662 LIBVIRT_END_ALLOW_THREADS;
3664 if (c_retval == NULL)
3665 return VIR_PY_NONE;
3667 py_retval = PyString_FromStringAndSize((const char *)c_retval, size);
3668 VIR_FREE(c_retval);
3670 return py_retval;
3673 static PyObject *
3674 libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
3675 PyObject *args) {
3676 PyObject *py_retval;
3677 int c_retval;
3678 virSecretPtr secret;
3679 PyObject *pyobj_secret;
3680 const char *value;
3681 int size;
3682 unsigned int flags;
3684 if (!PyArg_ParseTuple(args, (char *)"Oz#i:virSecretSetValue", &pyobj_secret,
3685 &value, &size, &flags))
3686 return NULL;
3687 secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
3689 LIBVIRT_BEGIN_ALLOW_THREADS;
3690 c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
3691 flags);
3692 LIBVIRT_END_ALLOW_THREADS;
3694 py_retval = libvirt_intWrap(c_retval);
3695 return py_retval;
3698 static PyObject *
3699 libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3700 PyObject *py_retval;
3701 unsigned char uuid[VIR_UUID_BUFLEN];
3702 virNWFilterPtr nwfilter;
3703 PyObject *pyobj_nwfilter;
3704 int c_retval;
3706 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID", &pyobj_nwfilter))
3707 return NULL;
3708 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
3710 if (nwfilter == NULL)
3711 return VIR_PY_NONE;
3712 LIBVIRT_BEGIN_ALLOW_THREADS;
3713 c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
3714 LIBVIRT_END_ALLOW_THREADS;
3716 if (c_retval < 0)
3717 return VIR_PY_NONE;
3718 py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
3720 return py_retval;
3723 static PyObject *
3724 libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
3725 PyObject *args) {
3726 PyObject *py_retval;
3727 char uuidstr[VIR_UUID_STRING_BUFLEN];
3728 virNWFilterPtr nwfilter;
3729 PyObject *pyobj_nwfilter;
3730 int c_retval;
3732 if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
3733 &pyobj_nwfilter))
3734 return NULL;
3735 nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
3737 if (nwfilter == NULL)
3738 return VIR_PY_NONE;
3739 LIBVIRT_BEGIN_ALLOW_THREADS;
3740 c_retval = virNWFilterGetUUIDString(nwfilter, &uuidstr[0]);
3741 LIBVIRT_END_ALLOW_THREADS;
3743 if (c_retval < 0)
3744 return VIR_PY_NONE;
3746 py_retval = PyString_FromString((char *) &uuidstr[0]);
3747 return py_retval;
3750 static PyObject *
3751 libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3752 PyObject *py_retval;
3753 virNWFilterPtr c_retval;
3754 virConnectPtr conn;
3755 PyObject *pyobj_conn;
3756 unsigned char * uuid;
3757 int len;
3759 if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID", &pyobj_conn, &uuid, &len))
3760 return NULL;
3761 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3763 if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
3764 return VIR_PY_NONE;
3766 LIBVIRT_BEGIN_ALLOW_THREADS;
3767 c_retval = virNWFilterLookupByUUID(conn, uuid);
3768 LIBVIRT_END_ALLOW_THREADS;
3769 py_retval = libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
3770 return py_retval;
3774 static PyObject *
3775 libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
3776 PyObject *args) {
3777 PyObject *py_retval;
3778 char **uuids = NULL;
3779 virConnectPtr conn;
3780 int c_retval, i;
3781 PyObject *pyobj_conn;
3783 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters", &pyobj_conn))
3784 return NULL;
3785 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3787 LIBVIRT_BEGIN_ALLOW_THREADS;
3788 c_retval = virConnectNumOfNWFilters(conn);
3789 LIBVIRT_END_ALLOW_THREADS;
3790 if (c_retval < 0)
3791 return VIR_PY_NONE;
3793 if (c_retval) {
3794 if (VIR_ALLOC_N(uuids, c_retval) < 0)
3795 return VIR_PY_NONE;
3796 LIBVIRT_BEGIN_ALLOW_THREADS;
3797 c_retval = virConnectListNWFilters(conn, uuids, c_retval);
3798 LIBVIRT_END_ALLOW_THREADS;
3799 if (c_retval < 0) {
3800 VIR_FREE(uuids);
3801 return VIR_PY_NONE;
3804 py_retval = PyList_New(c_retval);
3806 if (uuids) {
3807 for (i = 0;i < c_retval;i++) {
3808 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
3809 VIR_FREE(uuids[i]);
3811 VIR_FREE(uuids);
3814 return py_retval;
3817 static PyObject *
3818 libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
3819 PyObject *args)
3821 PyObject *pyobj_conn;
3822 PyObject *py_retval = NULL;
3823 PyObject *tmp = NULL;
3824 virConnectPtr conn;
3825 virNWFilterPtr *filters = NULL;
3826 int c_retval = 0;
3827 int i;
3828 unsigned int flags;
3830 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNWFilters",
3831 &pyobj_conn, &flags))
3832 return NULL;
3833 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3835 LIBVIRT_BEGIN_ALLOW_THREADS;
3836 c_retval = virConnectListAllNWFilters(conn, &filters, flags);
3837 LIBVIRT_END_ALLOW_THREADS;
3838 if (c_retval < 0)
3839 return VIR_PY_NONE;
3841 if (!(py_retval = PyList_New(c_retval)))
3842 goto cleanup;
3844 for (i = 0; i < c_retval; i++) {
3845 if (!(tmp = libvirt_virNWFilterPtrWrap(filters[i])) ||
3846 PyList_SetItem(py_retval, i, tmp) < 0) {
3847 Py_XDECREF(tmp);
3848 Py_DECREF(py_retval);
3849 py_retval = NULL;
3850 goto cleanup;
3852 /* python steals the pointer */
3853 filters[i] = NULL;
3856 cleanup:
3857 for (i = 0; i < c_retval; i++)
3858 if (filters[i])
3859 virNWFilterFree(filters[i]);
3860 VIR_FREE(filters);
3861 return py_retval;
3864 static PyObject *
3865 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
3866 PyObject *args) {
3867 PyObject *py_retval;
3868 char **names = NULL;
3869 int c_retval, i;
3870 virConnectPtr conn;
3871 PyObject *pyobj_conn;
3874 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListInterfaces", &pyobj_conn))
3875 return NULL;
3876 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3878 LIBVIRT_BEGIN_ALLOW_THREADS;
3879 c_retval = virConnectNumOfInterfaces(conn);
3880 LIBVIRT_END_ALLOW_THREADS;
3881 if (c_retval < 0)
3882 return VIR_PY_NONE;
3884 if (c_retval) {
3885 if (VIR_ALLOC_N(names, c_retval) < 0)
3886 return VIR_PY_NONE;
3887 LIBVIRT_BEGIN_ALLOW_THREADS;
3888 c_retval = virConnectListInterfaces(conn, names, c_retval);
3889 LIBVIRT_END_ALLOW_THREADS;
3890 if (c_retval < 0) {
3891 VIR_FREE(names);
3892 return VIR_PY_NONE;
3895 py_retval = PyList_New(c_retval);
3896 if (py_retval == NULL) {
3897 if (names) {
3898 for (i = 0;i < c_retval;i++)
3899 VIR_FREE(names[i]);
3900 VIR_FREE(names);
3902 return VIR_PY_NONE;
3905 if (names) {
3906 for (i = 0;i < c_retval;i++) {
3907 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3908 VIR_FREE(names[i]);
3910 VIR_FREE(names);
3913 return py_retval;
3917 static PyObject *
3918 libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
3919 PyObject *args) {
3920 PyObject *py_retval;
3921 char **names = NULL;
3922 int c_retval, i;
3923 virConnectPtr conn;
3924 PyObject *pyobj_conn;
3927 if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedInterfaces",
3928 &pyobj_conn))
3929 return NULL;
3930 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3932 LIBVIRT_BEGIN_ALLOW_THREADS;
3933 c_retval = virConnectNumOfDefinedInterfaces(conn);
3934 LIBVIRT_END_ALLOW_THREADS;
3935 if (c_retval < 0)
3936 return VIR_PY_NONE;
3938 if (c_retval) {
3939 if (VIR_ALLOC_N(names, c_retval) < 0)
3940 return VIR_PY_NONE;
3941 LIBVIRT_BEGIN_ALLOW_THREADS;
3942 c_retval = virConnectListDefinedInterfaces(conn, names, c_retval);
3943 LIBVIRT_END_ALLOW_THREADS;
3944 if (c_retval < 0) {
3945 VIR_FREE(names);
3946 return VIR_PY_NONE;
3949 py_retval = PyList_New(c_retval);
3950 if (py_retval == NULL) {
3951 if (names) {
3952 for (i = 0;i < c_retval;i++)
3953 VIR_FREE(names[i]);
3954 VIR_FREE(names);
3956 return VIR_PY_NONE;
3959 if (names) {
3960 for (i = 0;i < c_retval;i++) {
3961 PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
3962 VIR_FREE(names[i]);
3964 VIR_FREE(names);
3967 return py_retval;
3971 static PyObject *
3972 libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
3973 PyObject *args)
3975 PyObject *pyobj_conn;
3976 PyObject *py_retval = NULL;
3977 PyObject *tmp = NULL;
3978 virConnectPtr conn;
3979 virInterfacePtr *ifaces = NULL;
3980 int c_retval = 0;
3981 int i;
3982 unsigned int flags;
3984 if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllInterfaces",
3985 &pyobj_conn, &flags))
3986 return NULL;
3987 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
3989 LIBVIRT_BEGIN_ALLOW_THREADS;
3990 c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
3991 LIBVIRT_END_ALLOW_THREADS;
3992 if (c_retval < 0)
3993 return VIR_PY_NONE;
3995 if (!(py_retval = PyList_New(c_retval)))
3996 goto cleanup;
3998 for (i = 0; i < c_retval; i++) {
3999 if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) ||
4000 PyList_SetItem(py_retval, i, tmp) < 0) {
4001 Py_XDECREF(tmp);
4002 Py_DECREF(py_retval);
4003 py_retval = NULL;
4004 goto cleanup;
4006 /* python steals the pointer */
4007 ifaces[i] = NULL;
4010 cleanup:
4011 for (i = 0; i < c_retval; i++)
4012 if (ifaces[i])
4013 virInterfaceFree(ifaces[i]);
4014 VIR_FREE(ifaces);
4015 return py_retval;
4018 static PyObject *
4019 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
4020 PyObject *args) {
4021 PyObject *pyobj_conn;
4022 PyObject *list;
4023 virConnectPtr conn;
4024 unsigned int flags;
4025 const char **xmlcpus = NULL;
4026 int ncpus = 0;
4027 char *base_cpu;
4028 PyObject *pybase_cpu;
4030 if (!PyArg_ParseTuple(args, (char *)"OOi:virConnectBaselineCPU",
4031 &pyobj_conn, &list, &flags))
4032 return NULL;
4033 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4035 if (PyList_Check(list)) {
4036 int i;
4038 ncpus = PyList_Size(list);
4039 if (VIR_ALLOC_N(xmlcpus, ncpus) < 0)
4040 return VIR_PY_INT_FAIL;
4042 for (i = 0; i < ncpus; i++) {
4043 xmlcpus[i] = PyString_AsString(PyList_GetItem(list, i));
4044 if (xmlcpus[i] == NULL) {
4045 VIR_FREE(xmlcpus);
4046 return VIR_PY_INT_FAIL;
4051 LIBVIRT_BEGIN_ALLOW_THREADS;
4052 base_cpu = virConnectBaselineCPU(conn, xmlcpus, ncpus, flags);
4053 LIBVIRT_END_ALLOW_THREADS;
4055 VIR_FREE(xmlcpus);
4057 if (base_cpu == NULL)
4058 return VIR_PY_INT_FAIL;
4060 pybase_cpu = PyString_FromString(base_cpu);
4061 VIR_FREE(base_cpu);
4063 if (pybase_cpu == NULL)
4064 return VIR_PY_INT_FAIL;
4066 return pybase_cpu;
4070 static PyObject *
4071 libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
4072 PyObject *py_retval;
4073 int c_retval;
4074 virDomainPtr domain;
4075 PyObject *pyobj_domain;
4076 virDomainJobInfo info;
4078 if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetJobInfo", &pyobj_domain))
4079 return NULL;
4080 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4082 LIBVIRT_BEGIN_ALLOW_THREADS;
4083 c_retval = virDomainGetJobInfo(domain, &info);
4084 LIBVIRT_END_ALLOW_THREADS;
4085 if (c_retval < 0)
4086 return VIR_PY_NONE;
4087 py_retval = PyList_New(12);
4088 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
4089 PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.timeElapsed));
4090 PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.timeRemaining));
4091 PyList_SetItem(py_retval, 3, libvirt_ulonglongWrap(info.dataTotal));
4092 PyList_SetItem(py_retval, 4, libvirt_ulonglongWrap(info.dataProcessed));
4093 PyList_SetItem(py_retval, 5, libvirt_ulonglongWrap(info.dataRemaining));
4094 PyList_SetItem(py_retval, 6, libvirt_ulonglongWrap(info.memTotal));
4095 PyList_SetItem(py_retval, 7, libvirt_ulonglongWrap(info.memProcessed));
4096 PyList_SetItem(py_retval, 8, libvirt_ulonglongWrap(info.memRemaining));
4097 PyList_SetItem(py_retval, 9, libvirt_ulonglongWrap(info.fileTotal));
4098 PyList_SetItem(py_retval, 10, libvirt_ulonglongWrap(info.fileProcessed));
4099 PyList_SetItem(py_retval, 11, libvirt_ulonglongWrap(info.fileRemaining));
4101 return py_retval;
4104 static PyObject *
4105 libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED,
4106 PyObject *args)
4108 virDomainPtr domain;
4109 PyObject *pyobj_domain;
4110 const char *path;
4111 unsigned int flags;
4112 virDomainBlockJobInfo info;
4113 int c_ret;
4114 PyObject *ret;
4116 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetBlockJobInfo",
4117 &pyobj_domain, &path, &flags))
4118 return NULL;
4119 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4121 LIBVIRT_BEGIN_ALLOW_THREADS;
4122 c_ret = virDomainGetBlockJobInfo(domain, path, &info, flags);
4123 LIBVIRT_END_ALLOW_THREADS;
4125 if (c_ret != 1)
4126 return VIR_PY_NONE;
4128 if ((ret = PyDict_New()) == NULL)
4129 return VIR_PY_NONE;
4131 PyDict_SetItem(ret, libvirt_constcharPtrWrap("type"),
4132 libvirt_intWrap(info.type));
4133 PyDict_SetItem(ret, libvirt_constcharPtrWrap("bandwidth"),
4134 libvirt_ulongWrap(info.bandwidth));
4135 PyDict_SetItem(ret, libvirt_constcharPtrWrap("cur"),
4136 libvirt_ulonglongWrap(info.cur));
4137 PyDict_SetItem(ret, libvirt_constcharPtrWrap("end"),
4138 libvirt_ulonglongWrap(info.end));
4140 return ret;
4143 static PyObject *
4144 libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4145 PyObject *args)
4147 virDomainPtr domain;
4148 PyObject *pyobj_domain, *info;
4149 PyObject *ret = NULL;
4150 int i_retval;
4151 int nparams = 0;
4152 Py_ssize_t size = 0;
4153 const char *disk;
4154 unsigned int flags;
4155 virTypedParameterPtr params, new_params;
4157 if (!PyArg_ParseTuple(args, (char *)"OzOi:virDomainSetBlockIoTune",
4158 &pyobj_domain, &disk, &info, &flags))
4159 return NULL;
4160 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4162 if ((size = PyDict_Size(info)) < 0)
4163 return NULL;
4165 if (size == 0) {
4166 PyErr_Format(PyExc_LookupError,
4167 "Need non-empty dictionary to set attributes");
4168 return NULL;
4171 LIBVIRT_BEGIN_ALLOW_THREADS;
4172 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4173 LIBVIRT_END_ALLOW_THREADS;
4175 if (i_retval < 0)
4176 return VIR_PY_INT_FAIL;
4178 if (nparams == 0) {
4179 PyErr_Format(PyExc_LookupError,
4180 "Domain has no settable attributes");
4181 return NULL;
4184 if (VIR_ALLOC_N(params, nparams) < 0)
4185 return PyErr_NoMemory();
4187 LIBVIRT_BEGIN_ALLOW_THREADS;
4188 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4189 LIBVIRT_END_ALLOW_THREADS;
4191 if (i_retval < 0) {
4192 ret = VIR_PY_INT_FAIL;
4193 goto cleanup;
4196 new_params = setPyVirTypedParameter(info, params, nparams);
4197 if (!new_params)
4198 goto cleanup;
4200 LIBVIRT_BEGIN_ALLOW_THREADS;
4201 i_retval = virDomainSetBlockIoTune(domain, disk, new_params, size, flags);
4202 LIBVIRT_END_ALLOW_THREADS;
4204 if (i_retval < 0) {
4205 ret = VIR_PY_INT_FAIL;
4206 goto cleanup;
4209 ret = VIR_PY_INT_SUCCESS;
4211 cleanup:
4212 virTypedParameterArrayClear(params, nparams);
4213 VIR_FREE(params);
4214 VIR_FREE(new_params);
4215 return ret;
4218 static PyObject *
4219 libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
4220 PyObject *args)
4222 virDomainPtr domain;
4223 PyObject *pyobj_domain;
4224 PyObject *ret = NULL;
4225 int i_retval;
4226 int nparams = 0;
4227 const char *disk;
4228 unsigned int flags;
4229 virTypedParameterPtr params;
4231 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetBlockIoTune",
4232 &pyobj_domain, &disk, &flags))
4233 return NULL;
4234 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4236 LIBVIRT_BEGIN_ALLOW_THREADS;
4237 i_retval = virDomainGetBlockIoTune(domain, disk, NULL, &nparams, flags);
4238 LIBVIRT_END_ALLOW_THREADS;
4240 if (i_retval < 0)
4241 return VIR_PY_NONE;
4243 if (!nparams)
4244 return PyDict_New();
4246 if (VIR_ALLOC_N(params, nparams) < 0)
4247 return PyErr_NoMemory();
4249 LIBVIRT_BEGIN_ALLOW_THREADS;
4250 i_retval = virDomainGetBlockIoTune(domain, disk, params, &nparams, flags);
4251 LIBVIRT_END_ALLOW_THREADS;
4253 if (i_retval < 0) {
4254 ret = VIR_PY_NONE;
4255 goto cleanup;
4258 ret = getPyVirTypedParameter(params, nparams);
4260 cleanup:
4261 virTypedParameterArrayClear(params, nparams);
4262 VIR_FREE(params);
4263 return ret;
4266 static PyObject *
4267 libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED,
4268 PyObject *args)
4270 PyObject *py_retval = VIR_PY_NONE;
4271 virDomainPtr domain;
4272 PyObject *pyobj_domain;
4273 unsigned int flags;
4274 virDomainDiskErrorPtr disks = NULL;
4275 unsigned int ndisks;
4276 int count;
4277 int i;
4279 if (!PyArg_ParseTuple(args, (char *) "Oi:virDomainGetDiskErrors",
4280 &pyobj_domain, &flags))
4281 return NULL;
4283 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
4285 if ((count = virDomainGetDiskErrors(domain, NULL, 0, 0)) < 0)
4286 return VIR_PY_NONE;
4287 ndisks = count;
4289 if (ndisks) {
4290 if (VIR_ALLOC_N(disks, ndisks) < 0)
4291 return VIR_PY_NONE;
4293 LIBVIRT_BEGIN_ALLOW_THREADS;
4294 count = virDomainGetDiskErrors(domain, disks, ndisks, 0);
4295 LIBVIRT_END_ALLOW_THREADS;
4297 if (count < 0)
4298 goto cleanup;
4301 if (!(py_retval = PyDict_New()))
4302 goto cleanup;
4304 for (i = 0; i < count; i++) {
4305 PyDict_SetItem(py_retval,
4306 libvirt_constcharPtrWrap(disks[i].disk),
4307 libvirt_intWrap(disks[i].error));
4310 cleanup:
4311 if (disks) {
4312 for (i = 0; i < count; i++)
4313 VIR_FREE(disks[i].disk);
4314 VIR_FREE(disks);
4316 return py_retval;
4319 /*******************************************
4320 * Helper functions to avoid importing modules
4321 * for every callback
4322 *******************************************/
4323 static PyObject *libvirt_module = NULL;
4324 static PyObject *libvirt_dict = NULL;
4325 static PyObject *libvirt_dom_class = NULL;
4327 static PyObject *
4328 getLibvirtModuleObject (void) {
4329 if(libvirt_module)
4330 return libvirt_module;
4332 // PyImport_ImportModule returns a new reference
4333 /* Bogus (char *) cast for RHEL-5 python API brokenness */
4334 libvirt_module = PyImport_ImportModule((char *)"libvirt");
4335 if(!libvirt_module) {
4336 DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
4337 PyErr_Print();
4338 return NULL;
4341 return libvirt_module;
4344 static PyObject *
4345 getLibvirtDictObject (void) {
4346 if(libvirt_dict)
4347 return libvirt_dict;
4349 // PyModule_GetDict returns a borrowed reference
4350 libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
4351 if(!libvirt_dict) {
4352 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
4353 PyErr_Print();
4354 return NULL;
4357 Py_INCREF(libvirt_dict);
4358 return libvirt_dict;
4361 static PyObject *
4362 getLibvirtDomainClassObject (void) {
4363 if(libvirt_dom_class)
4364 return libvirt_dom_class;
4366 // PyDict_GetItemString returns a borrowed reference
4367 libvirt_dom_class = PyDict_GetItemString(getLibvirtDictObject(),
4368 "virDomain");
4369 if(!libvirt_dom_class) {
4370 DEBUG("%s Error importing virDomain class\n", __FUNCTION__);
4371 PyErr_Print();
4372 return NULL;
4375 Py_INCREF(libvirt_dom_class);
4376 return libvirt_dom_class;
4379 static PyObject *
4380 libvirt_lookupPythonFunc(const char *funcname)
4382 PyObject *python_cb;
4384 /* Lookup the python callback */
4385 python_cb = PyDict_GetItemString(getLibvirtDictObject(), funcname);
4387 if (!python_cb) {
4388 DEBUG("%s: Error finding %s\n", __FUNCTION__, funcname);
4389 PyErr_Print();
4390 PyErr_Clear();
4391 return NULL;
4394 if (!PyCallable_Check(python_cb)) {
4395 DEBUG("%s: %s is not callable\n", __FUNCTION__, funcname);
4396 return NULL;
4399 return python_cb;
4402 /*******************************************
4403 * Domain Events
4404 *******************************************/
4406 static int
4407 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
4408 virDomainPtr dom,
4409 int event,
4410 int detail,
4411 void *opaque)
4413 PyObject *pyobj_ret;
4415 PyObject *pyobj_conn_inst = (PyObject*)opaque;
4416 PyObject *pyobj_dom;
4418 PyObject *pyobj_dom_args;
4419 PyObject *pyobj_dom_inst;
4421 PyObject *dom_class;
4422 int ret = -1;
4424 LIBVIRT_ENSURE_THREAD_STATE;
4426 /* Create a python instance of this virDomainPtr */
4427 virDomainRef(dom);
4428 pyobj_dom = libvirt_virDomainPtrWrap(dom);
4429 pyobj_dom_args = PyTuple_New(2);
4430 if(PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {
4431 DEBUG("%s error creating tuple",__FUNCTION__);
4432 goto cleanup;
4434 if(PyTuple_SetItem(pyobj_dom_args, 1, pyobj_dom)!=0) {
4435 DEBUG("%s error creating tuple",__FUNCTION__);
4436 goto cleanup;
4438 Py_INCREF(pyobj_conn_inst);
4440 dom_class = getLibvirtDomainClassObject();
4441 if(!PyClass_Check(dom_class)) {
4442 DEBUG("%s dom_class is not a class!\n", __FUNCTION__);
4443 goto cleanup;
4446 pyobj_dom_inst = PyInstance_New(dom_class,
4447 pyobj_dom_args,
4448 NULL);
4450 Py_DECREF(pyobj_dom_args);
4452 if(!pyobj_dom_inst) {
4453 DEBUG("%s Error creating a python instance of virDomain\n",
4454 __FUNCTION__);
4455 PyErr_Print();
4456 goto cleanup;
4459 /* Call the Callback Dispatcher */
4460 pyobj_ret = PyObject_CallMethod(pyobj_conn_inst,
4461 (char*)"_dispatchDomainEventCallbacks",
4462 (char*)"Oii",
4463 pyobj_dom_inst,
4464 event,
4465 detail);
4467 Py_DECREF(pyobj_dom_inst);
4469 if(!pyobj_ret) {
4470 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
4471 PyErr_Print();
4472 } else {
4473 Py_DECREF(pyobj_ret);
4474 ret = 0;
4478 cleanup:
4479 LIBVIRT_RELEASE_THREAD_STATE;
4480 return ret;
4483 static PyObject *
4484 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject * self,
4485 PyObject * args)
4487 PyObject *py_retval; /* return value */
4488 PyObject *pyobj_conn; /* virConnectPtr */
4489 PyObject *pyobj_conn_inst; /* virConnect Python object */
4491 virConnectPtr conn;
4492 int ret = 0;
4494 if (!PyArg_ParseTuple
4495 (args, (char *) "OO:virConnectDomainEventRegister",
4496 &pyobj_conn, &pyobj_conn_inst)) {
4497 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
4498 return VIR_PY_INT_FAIL;
4501 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
4502 pyobj_conn, pyobj_conn_inst);
4503 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4505 Py_INCREF(pyobj_conn_inst);
4507 LIBVIRT_BEGIN_ALLOW_THREADS;
4509 ret = virConnectDomainEventRegister(conn,
4510 libvirt_virConnectDomainEventCallback,
4511 (void *)pyobj_conn_inst, NULL);
4513 LIBVIRT_END_ALLOW_THREADS;
4515 py_retval = libvirt_intWrap(ret);
4516 return py_retval;
4519 static PyObject *
4520 libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject * self,
4521 PyObject * args)
4523 PyObject *py_retval;
4524 PyObject *pyobj_conn;
4525 PyObject *pyobj_conn_inst;
4527 virConnectPtr conn;
4528 int ret = 0;
4530 if (!PyArg_ParseTuple
4531 (args, (char *) "OO:virConnectDomainEventDeregister",
4532 &pyobj_conn, &pyobj_conn_inst))
4533 return NULL;
4535 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
4537 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
4539 LIBVIRT_BEGIN_ALLOW_THREADS;
4541 ret = virConnectDomainEventDeregister(conn, libvirt_virConnectDomainEventCallback);
4543 LIBVIRT_END_ALLOW_THREADS;
4545 Py_DECREF(pyobj_conn_inst);
4546 py_retval = libvirt_intWrap(ret);
4547 return py_retval;
4550 /*******************************************
4551 * Event Impl
4552 *******************************************/
4553 static PyObject *addHandleObj = NULL;
4554 static char *addHandleName = NULL;
4555 static PyObject *updateHandleObj = NULL;
4556 static char *updateHandleName = NULL;
4557 static PyObject *removeHandleObj = NULL;
4558 static char *removeHandleName = NULL;
4559 static PyObject *addTimeoutObj = NULL;
4560 static char *addTimeoutName = NULL;
4561 static PyObject *updateTimeoutObj = NULL;
4562 static char *updateTimeoutName = NULL;
4563 static PyObject *removeTimeoutObj = NULL;
4564 static char *removeTimeoutName = NULL;
4566 #define NAME(fn) ( fn ## Name ? fn ## Name : # fn )
4568 static int
4569 libvirt_virEventAddHandleFunc (int fd,
4570 int event,
4571 virEventHandleCallback cb,
4572 void *opaque,
4573 virFreeCallback ff)
4575 PyObject *result;
4576 PyObject *python_cb;
4577 PyObject *cb_obj;
4578 PyObject *ff_obj;
4579 PyObject *opaque_obj;
4580 PyObject *cb_args;
4581 PyObject *pyobj_args;
4582 int retval = -1;
4584 LIBVIRT_ENSURE_THREAD_STATE;
4586 /* Lookup the python callback */
4587 python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
4588 if (!python_cb) {
4589 goto cleanup;
4591 Py_INCREF(python_cb);
4593 /* create tuple for cb */
4594 cb_obj = libvirt_virEventHandleCallbackWrap(cb);
4595 ff_obj = libvirt_virFreeCallbackWrap(ff);
4596 opaque_obj = libvirt_virVoidPtrWrap(opaque);
4598 cb_args = PyTuple_New(3);
4599 PyTuple_SetItem(cb_args, 0, cb_obj);
4600 PyTuple_SetItem(cb_args, 1, opaque_obj);
4601 PyTuple_SetItem(cb_args, 2, ff_obj);
4603 pyobj_args = PyTuple_New(4);
4604 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd));
4605 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event));
4606 PyTuple_SetItem(pyobj_args, 2, python_cb);
4607 PyTuple_SetItem(pyobj_args, 3, cb_args);
4609 result = PyEval_CallObject(addHandleObj, pyobj_args);
4610 if (!result) {
4611 PyErr_Print();
4612 PyErr_Clear();
4613 } else if (!PyInt_Check(result)) {
4614 DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addHandle));
4615 } else {
4616 retval = (int)PyInt_AsLong(result);
4619 Py_XDECREF(result);
4620 Py_DECREF(pyobj_args);
4622 cleanup:
4623 LIBVIRT_RELEASE_THREAD_STATE;
4625 return retval;
4628 static void
4629 libvirt_virEventUpdateHandleFunc(int watch, int event)
4631 PyObject *result;
4632 PyObject *pyobj_args;
4634 LIBVIRT_ENSURE_THREAD_STATE;
4636 pyobj_args = PyTuple_New(2);
4637 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch));
4638 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event));
4640 result = PyEval_CallObject(updateHandleObj, pyobj_args);
4641 if (!result) {
4642 PyErr_Print();
4643 PyErr_Clear();
4646 Py_XDECREF(result);
4647 Py_DECREF(pyobj_args);
4649 LIBVIRT_RELEASE_THREAD_STATE;
4653 static int
4654 libvirt_virEventRemoveHandleFunc(int watch)
4656 PyObject *result;
4657 PyObject *pyobj_args;
4658 PyObject *opaque;
4659 PyObject *ff;
4660 int retval = -1;
4661 virFreeCallback cff;
4663 LIBVIRT_ENSURE_THREAD_STATE;
4665 pyobj_args = PyTuple_New(1);
4666 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch));
4668 result = PyEval_CallObject(removeHandleObj, pyobj_args);
4669 if (!result) {
4670 PyErr_Print();
4671 PyErr_Clear();
4672 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
4673 DEBUG("%s: %s must return opaque obj registered with %s"
4674 "to avoid leaking libvirt memory\n",
4675 __FUNCTION__, NAME(removeHandle), NAME(addHandle));
4676 } else {
4677 opaque = PyTuple_GetItem(result, 1);
4678 ff = PyTuple_GetItem(result, 2);
4679 cff = PyvirFreeCallback_Get(ff);
4680 if (cff)
4681 (*cff)(PyvirVoidPtr_Get(opaque));
4682 retval = 0;
4685 Py_XDECREF(result);
4686 Py_DECREF(pyobj_args);
4688 LIBVIRT_RELEASE_THREAD_STATE;
4690 return retval;
4694 static int
4695 libvirt_virEventAddTimeoutFunc(int timeout,
4696 virEventTimeoutCallback cb,
4697 void *opaque,
4698 virFreeCallback ff)
4700 PyObject *result;
4702 PyObject *python_cb;
4704 PyObject *cb_obj;
4705 PyObject *ff_obj;
4706 PyObject *opaque_obj;
4707 PyObject *cb_args;
4708 PyObject *pyobj_args;
4709 int retval = -1;
4711 LIBVIRT_ENSURE_THREAD_STATE;
4713 /* Lookup the python callback */
4714 python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
4715 if (!python_cb) {
4716 goto cleanup;
4718 Py_INCREF(python_cb);
4720 /* create tuple for cb */
4721 cb_obj = libvirt_virEventTimeoutCallbackWrap(cb);
4722 ff_obj = libvirt_virFreeCallbackWrap(ff);
4723 opaque_obj = libvirt_virVoidPtrWrap(opaque);
4725 cb_args = PyTuple_New(3);
4726 PyTuple_SetItem(cb_args, 0, cb_obj);
4727 PyTuple_SetItem(cb_args, 1, opaque_obj);
4728 PyTuple_SetItem(cb_args, 2, ff_obj);
4730 pyobj_args = PyTuple_New(3);
4732 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timeout));
4733 PyTuple_SetItem(pyobj_args, 1, python_cb);
4734 PyTuple_SetItem(pyobj_args, 2, cb_args);
4736 result = PyEval_CallObject(addTimeoutObj, pyobj_args);
4737 if (!result) {
4738 PyErr_Print();
4739 PyErr_Clear();
4740 } else if (!PyInt_Check(result)) {
4741 DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addTimeout));
4742 } else {
4743 retval = (int)PyInt_AsLong(result);
4746 Py_XDECREF(result);
4747 Py_DECREF(pyobj_args);
4749 cleanup:
4750 LIBVIRT_RELEASE_THREAD_STATE;
4751 return retval;
4754 static void
4755 libvirt_virEventUpdateTimeoutFunc(int timer, int timeout)
4757 PyObject *result = NULL;
4758 PyObject *pyobj_args;
4760 LIBVIRT_ENSURE_THREAD_STATE;
4762 pyobj_args = PyTuple_New(2);
4763 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer));
4764 PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(timeout));
4766 result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
4767 if (!result) {
4768 PyErr_Print();
4769 PyErr_Clear();
4772 Py_XDECREF(result);
4773 Py_DECREF(pyobj_args);
4775 LIBVIRT_RELEASE_THREAD_STATE;
4778 static int
4779 libvirt_virEventRemoveTimeoutFunc(int timer)
4781 PyObject *result = NULL;
4782 PyObject *pyobj_args;
4783 PyObject *opaque;
4784 PyObject *ff;
4785 int retval = -1;
4786 virFreeCallback cff;
4788 LIBVIRT_ENSURE_THREAD_STATE;
4790 pyobj_args = PyTuple_New(1);
4791 PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer));
4793 result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
4794 if (!result) {
4795 PyErr_Print();
4796 PyErr_Clear();
4797 } else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
4798 DEBUG("%s: %s must return opaque obj registered with %s"
4799 "to avoid leaking libvirt memory\n",
4800 __FUNCTION__, NAME(removeTimeout), NAME(addTimeout));
4801 } else {
4802 opaque = PyTuple_GetItem(result, 1);
4803 ff = PyTuple_GetItem(result, 2);
4804 cff = PyvirFreeCallback_Get(ff);
4805 if (cff)
4806 (*cff)(PyvirVoidPtr_Get(opaque));
4807 retval = 0;
4810 Py_XDECREF(result);
4811 Py_DECREF(pyobj_args);
4813 LIBVIRT_RELEASE_THREAD_STATE;
4815 return retval;
4818 static PyObject *
4819 libvirt_virEventRegisterImpl(ATTRIBUTE_UNUSED PyObject * self,
4820 PyObject * args)
4822 /* Unref the previously-registered impl (if any) */
4823 Py_XDECREF(addHandleObj);
4824 Py_XDECREF(updateHandleObj);
4825 Py_XDECREF(removeHandleObj);
4826 Py_XDECREF(addTimeoutObj);
4827 Py_XDECREF(updateTimeoutObj);
4828 Py_XDECREF(removeTimeoutObj);
4830 /* Parse and check arguments */
4831 if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
4832 &addHandleObj, &updateHandleObj,
4833 &removeHandleObj, &addTimeoutObj,
4834 &updateTimeoutObj, &removeTimeoutObj) ||
4835 !PyCallable_Check(addHandleObj) ||
4836 !PyCallable_Check(updateHandleObj) ||
4837 !PyCallable_Check(removeHandleObj) ||
4838 !PyCallable_Check(addTimeoutObj) ||
4839 !PyCallable_Check(updateTimeoutObj) ||
4840 !PyCallable_Check(removeTimeoutObj))
4841 return VIR_PY_INT_FAIL;
4843 /* Get argument string representations (for error reporting) */
4844 addHandleName = py_str(addHandleObj);
4845 updateHandleName = py_str(updateHandleObj);
4846 removeHandleName = py_str(removeHandleObj);
4847 addTimeoutName = py_str(addTimeoutObj);
4848 updateTimeoutName = py_str(updateTimeoutObj);
4849 removeTimeoutName = py_str(removeTimeoutObj);
4851 /* Inc refs since we're holding onto these objects until
4852 * the next call (if any) to this function.
4854 Py_INCREF(addHandleObj);
4855 Py_INCREF(updateHandleObj);
4856 Py_INCREF(removeHandleObj);
4857 Py_INCREF(addTimeoutObj);
4858 Py_INCREF(updateTimeoutObj);
4859 Py_INCREF(removeTimeoutObj);
4861 LIBVIRT_BEGIN_ALLOW_THREADS;
4863 /* Now register our C EventImpl, which will dispatch
4864 * to the Python callbacks passed in as args.
4866 virEventRegisterImpl(libvirt_virEventAddHandleFunc,
4867 libvirt_virEventUpdateHandleFunc,
4868 libvirt_virEventRemoveHandleFunc,
4869 libvirt_virEventAddTimeoutFunc,
4870 libvirt_virEventUpdateTimeoutFunc,
4871 libvirt_virEventRemoveTimeoutFunc);
4873 LIBVIRT_END_ALLOW_THREADS;
4875 return VIR_PY_INT_SUCCESS;
4878 static PyObject *
4879 libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
4880 PyObject *args)
4882 int watch, fd, event;
4883 PyObject *py_f;
4884 PyObject *py_opaque;
4885 virEventHandleCallback cb;
4886 void *opaque;
4888 if (!PyArg_ParseTuple
4889 (args, (char *) "iiiOO:virEventInvokeHandleCallback",
4890 &watch, &fd, &event, &py_f, &py_opaque
4892 return VIR_PY_INT_FAIL;
4894 cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
4895 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
4897 if(cb) {
4898 LIBVIRT_BEGIN_ALLOW_THREADS;
4899 cb (watch, fd, event, opaque);
4900 LIBVIRT_END_ALLOW_THREADS;
4903 return VIR_PY_INT_SUCCESS;
4906 static PyObject *
4907 libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
4908 PyObject *args)
4910 int timer;
4911 PyObject *py_f;
4912 PyObject *py_opaque;
4913 virEventTimeoutCallback cb;
4914 void *opaque;
4916 if (!PyArg_ParseTuple
4917 (args, (char *) "iOO:virEventInvokeTimeoutCallback",
4918 &timer, &py_f, &py_opaque
4920 return VIR_PY_INT_FAIL;
4922 cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
4923 opaque = (void *) PyvirVoidPtr_Get(py_opaque);
4924 if(cb) {
4925 LIBVIRT_BEGIN_ALLOW_THREADS;
4926 cb (timer, opaque);
4927 LIBVIRT_END_ALLOW_THREADS;
4930 return VIR_PY_INT_SUCCESS;
4933 static void
4934 libvirt_virEventHandleCallback(int watch,
4935 int fd,
4936 int events,
4937 void *opaque)
4939 PyObject *pyobj_cbData = (PyObject *)opaque;
4940 PyObject *pyobj_ret;
4941 PyObject *python_cb;
4943 LIBVIRT_ENSURE_THREAD_STATE;
4945 /* Lookup the python callback */
4946 python_cb = libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
4947 if (!python_cb) {
4948 goto cleanup;
4951 Py_INCREF(pyobj_cbData);
4953 /* Call the pure python dispatcher */
4954 pyobj_ret = PyObject_CallFunction(python_cb,
4955 (char *)"iiiO",
4956 watch, fd, events, pyobj_cbData);
4958 Py_DECREF(pyobj_cbData);
4960 if (!pyobj_ret) {
4961 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
4962 PyErr_Print();
4963 } else {
4964 Py_DECREF(pyobj_ret);
4967 cleanup:
4968 LIBVIRT_RELEASE_THREAD_STATE;
4971 static PyObject *
4972 libvirt_virEventAddHandle(PyObject *self ATTRIBUTE_UNUSED,
4973 PyObject *args)
4975 PyObject *py_retval;
4976 PyObject *pyobj_cbData;
4977 virEventHandleCallback cb = libvirt_virEventHandleCallback;
4978 int events;
4979 int fd;
4980 int ret;
4982 if (!PyArg_ParseTuple(args, (char *) "iiO:virEventAddHandle",
4983 &fd, &events, &pyobj_cbData)) {
4984 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
4985 return VIR_PY_INT_FAIL;
4988 Py_INCREF(pyobj_cbData);
4990 LIBVIRT_BEGIN_ALLOW_THREADS;
4991 ret = virEventAddHandle(fd, events, cb, pyobj_cbData, NULL);
4992 LIBVIRT_END_ALLOW_THREADS;
4994 if (ret < 0) {
4995 Py_DECREF(pyobj_cbData);
4998 py_retval = libvirt_intWrap(ret);
4999 return py_retval;
5002 static void
5003 libvirt_virEventTimeoutCallback(int timer,
5004 void *opaque)
5006 PyObject *pyobj_cbData = (PyObject *)opaque;
5007 PyObject *pyobj_ret;
5008 PyObject *python_cb;
5010 LIBVIRT_ENSURE_THREAD_STATE;
5012 /* Lookup the python callback */
5013 python_cb = libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
5014 if (!python_cb) {
5015 goto cleanup;
5018 Py_INCREF(pyobj_cbData);
5020 /* Call the pure python dispatcher */
5021 pyobj_ret = PyObject_CallFunction(python_cb,
5022 (char *)"iO",
5023 timer, pyobj_cbData);
5025 Py_DECREF(pyobj_cbData);
5027 if (!pyobj_ret) {
5028 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5029 PyErr_Print();
5030 } else {
5031 Py_DECREF(pyobj_ret);
5034 cleanup:
5035 LIBVIRT_RELEASE_THREAD_STATE;
5038 static PyObject *
5039 libvirt_virEventAddTimeout(PyObject *self ATTRIBUTE_UNUSED,
5040 PyObject *args)
5042 PyObject *py_retval;
5043 PyObject *pyobj_cbData;
5044 virEventTimeoutCallback cb = libvirt_virEventTimeoutCallback;
5045 int timeout;
5046 int ret;
5048 if (!PyArg_ParseTuple(args, (char *) "iO:virEventAddTimeout",
5049 &timeout, &pyobj_cbData)) {
5050 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
5051 return VIR_PY_INT_FAIL;
5054 Py_INCREF(pyobj_cbData);
5056 LIBVIRT_BEGIN_ALLOW_THREADS;
5057 ret = virEventAddTimeout(timeout, cb, pyobj_cbData, NULL);
5058 LIBVIRT_END_ALLOW_THREADS;
5060 if (ret < 0) {
5061 Py_DECREF(pyobj_cbData);
5064 py_retval = libvirt_intWrap(ret);
5065 return py_retval;
5068 static void
5069 libvirt_virConnectDomainEventFreeFunc(void *opaque)
5071 PyObject *pyobj_conn = (PyObject*)opaque;
5072 LIBVIRT_ENSURE_THREAD_STATE;
5073 Py_DECREF(pyobj_conn);
5074 LIBVIRT_RELEASE_THREAD_STATE;
5077 static int
5078 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5079 virDomainPtr dom,
5080 int event,
5081 int detail,
5082 void *opaque)
5084 PyObject *pyobj_cbData = (PyObject*)opaque;
5085 PyObject *pyobj_dom;
5086 PyObject *pyobj_ret;
5087 PyObject *pyobj_conn;
5088 PyObject *dictKey;
5089 int ret = -1;
5091 LIBVIRT_ENSURE_THREAD_STATE;
5093 /* Create a python instance of this virDomainPtr */
5094 virDomainRef(dom);
5095 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5096 Py_INCREF(pyobj_cbData);
5098 dictKey = libvirt_constcharPtrWrap("conn");
5099 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5100 Py_DECREF(dictKey);
5102 /* Call the Callback Dispatcher */
5103 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5104 (char*)"_dispatchDomainEventLifecycleCallback",
5105 (char*)"OiiO",
5106 pyobj_dom,
5107 event, detail,
5108 pyobj_cbData);
5110 Py_DECREF(pyobj_cbData);
5111 Py_DECREF(pyobj_dom);
5113 if(!pyobj_ret) {
5114 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5115 PyErr_Print();
5116 } else {
5117 Py_DECREF(pyobj_ret);
5118 ret = 0;
5121 LIBVIRT_RELEASE_THREAD_STATE;
5122 return ret;
5125 static int
5126 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5127 virDomainPtr dom,
5128 void *opaque)
5130 PyObject *pyobj_cbData = (PyObject*)opaque;
5131 PyObject *pyobj_dom;
5132 PyObject *pyobj_ret;
5133 PyObject *pyobj_conn;
5134 PyObject *dictKey;
5135 int ret = -1;
5137 LIBVIRT_ENSURE_THREAD_STATE;
5139 /* Create a python instance of this virDomainPtr */
5140 virDomainRef(dom);
5141 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5142 Py_INCREF(pyobj_cbData);
5144 dictKey = libvirt_constcharPtrWrap("conn");
5145 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5146 Py_DECREF(dictKey);
5148 /* Call the Callback Dispatcher */
5149 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5150 (char*)"_dispatchDomainEventGenericCallback",
5151 (char*)"OO",
5152 pyobj_dom, pyobj_cbData);
5154 Py_DECREF(pyobj_cbData);
5155 Py_DECREF(pyobj_dom);
5157 if(!pyobj_ret) {
5158 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5159 PyErr_Print();
5160 } else {
5161 Py_DECREF(pyobj_ret);
5162 ret = 0;
5165 LIBVIRT_RELEASE_THREAD_STATE;
5166 return ret;
5169 static int
5170 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5171 virDomainPtr dom,
5172 long long utcoffset,
5173 void *opaque)
5175 PyObject *pyobj_cbData = (PyObject*)opaque;
5176 PyObject *pyobj_dom;
5177 PyObject *pyobj_ret;
5178 PyObject *pyobj_conn;
5179 PyObject *dictKey;
5180 int ret = -1;
5182 LIBVIRT_ENSURE_THREAD_STATE;
5184 /* Create a python instance of this virDomainPtr */
5185 virDomainRef(dom);
5186 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5187 Py_INCREF(pyobj_cbData);
5189 dictKey = libvirt_constcharPtrWrap("conn");
5190 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5191 Py_DECREF(dictKey);
5193 /* Call the Callback Dispatcher */
5194 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5195 (char*)"_dispatchDomainEventRTCChangeCallback",
5196 (char*)"OLO",
5197 pyobj_dom,
5198 (PY_LONG_LONG)utcoffset,
5199 pyobj_cbData);
5201 Py_DECREF(pyobj_cbData);
5202 Py_DECREF(pyobj_dom);
5204 if(!pyobj_ret) {
5205 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5206 PyErr_Print();
5207 } else {
5208 Py_DECREF(pyobj_ret);
5209 ret = 0;
5212 LIBVIRT_RELEASE_THREAD_STATE;
5213 return ret;
5216 static int
5217 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5218 virDomainPtr dom,
5219 int action,
5220 void *opaque)
5222 PyObject *pyobj_cbData = (PyObject*)opaque;
5223 PyObject *pyobj_dom;
5224 PyObject *pyobj_ret;
5225 PyObject *pyobj_conn;
5226 PyObject *dictKey;
5227 int ret = -1;
5229 LIBVIRT_ENSURE_THREAD_STATE;
5231 /* Create a python instance of this virDomainPtr */
5232 virDomainRef(dom);
5233 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5234 Py_INCREF(pyobj_cbData);
5236 dictKey = libvirt_constcharPtrWrap("conn");
5237 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5238 Py_DECREF(dictKey);
5240 /* Call the Callback Dispatcher */
5241 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5242 (char*)"_dispatchDomainEventWatchdogCallback",
5243 (char*)"OiO",
5244 pyobj_dom,
5245 action,
5246 pyobj_cbData);
5248 Py_DECREF(pyobj_cbData);
5249 Py_DECREF(pyobj_dom);
5251 if(!pyobj_ret) {
5252 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5253 PyErr_Print();
5254 } else {
5255 Py_DECREF(pyobj_ret);
5256 ret = 0;
5259 LIBVIRT_RELEASE_THREAD_STATE;
5260 return ret;
5263 static int
5264 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5265 virDomainPtr dom,
5266 const char *srcPath,
5267 const char *devAlias,
5268 int action,
5269 void *opaque)
5271 PyObject *pyobj_cbData = (PyObject*)opaque;
5272 PyObject *pyobj_dom;
5273 PyObject *pyobj_ret;
5274 PyObject *pyobj_conn;
5275 PyObject *dictKey;
5276 int ret = -1;
5278 LIBVIRT_ENSURE_THREAD_STATE;
5280 /* Create a python instance of this virDomainPtr */
5281 virDomainRef(dom);
5282 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5283 Py_INCREF(pyobj_cbData);
5285 dictKey = libvirt_constcharPtrWrap("conn");
5286 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5287 Py_DECREF(dictKey);
5289 /* Call the Callback Dispatcher */
5290 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5291 (char*)"_dispatchDomainEventIOErrorCallback",
5292 (char*)"OssiO",
5293 pyobj_dom,
5294 srcPath, devAlias, action,
5295 pyobj_cbData);
5297 Py_DECREF(pyobj_cbData);
5298 Py_DECREF(pyobj_dom);
5300 if(!pyobj_ret) {
5301 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5302 PyErr_Print();
5303 } else {
5304 Py_DECREF(pyobj_ret);
5305 ret = 0;
5308 LIBVIRT_RELEASE_THREAD_STATE;
5309 return ret;
5312 static int
5313 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5314 virDomainPtr dom,
5315 const char *srcPath,
5316 const char *devAlias,
5317 int action,
5318 const char *reason,
5319 void *opaque)
5321 PyObject *pyobj_cbData = (PyObject*)opaque;
5322 PyObject *pyobj_dom;
5323 PyObject *pyobj_ret;
5324 PyObject *pyobj_conn;
5325 PyObject *dictKey;
5326 int ret = -1;
5328 LIBVIRT_ENSURE_THREAD_STATE;
5330 /* Create a python instance of this virDomainPtr */
5331 virDomainRef(dom);
5332 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5333 Py_INCREF(pyobj_cbData);
5335 dictKey = libvirt_constcharPtrWrap("conn");
5336 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5337 Py_DECREF(dictKey);
5339 /* Call the Callback Dispatcher */
5340 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5341 (char*)"_dispatchDomainEventIOErrorReasonCallback",
5342 (char*)"OssisO",
5343 pyobj_dom,
5344 srcPath, devAlias, action, reason,
5345 pyobj_cbData);
5347 Py_DECREF(pyobj_cbData);
5348 Py_DECREF(pyobj_dom);
5350 if(!pyobj_ret) {
5351 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5352 PyErr_Print();
5353 } else {
5354 Py_DECREF(pyobj_ret);
5355 ret = 0;
5358 LIBVIRT_RELEASE_THREAD_STATE;
5359 return ret;
5362 static int
5363 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5364 virDomainPtr dom,
5365 int phase,
5366 virDomainEventGraphicsAddressPtr local,
5367 virDomainEventGraphicsAddressPtr remote,
5368 const char *authScheme,
5369 virDomainEventGraphicsSubjectPtr subject,
5370 void *opaque)
5372 PyObject *pyobj_cbData = (PyObject*)opaque;
5373 PyObject *pyobj_dom;
5374 PyObject *pyobj_ret;
5375 PyObject *pyobj_conn;
5376 PyObject *dictKey;
5377 PyObject *pyobj_local;
5378 PyObject *pyobj_remote;
5379 PyObject *pyobj_subject;
5380 int ret = -1;
5381 int i;
5383 LIBVIRT_ENSURE_THREAD_STATE;
5385 /* Create a python instance of this virDomainPtr */
5386 virDomainRef(dom);
5387 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5388 Py_INCREF(pyobj_cbData);
5390 dictKey = libvirt_constcharPtrWrap("conn");
5391 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5392 Py_DECREF(dictKey);
5394 pyobj_local = PyDict_New();
5395 PyDict_SetItem(pyobj_local,
5396 libvirt_constcharPtrWrap("family"),
5397 libvirt_intWrap(local->family));
5398 PyDict_SetItem(pyobj_local,
5399 libvirt_constcharPtrWrap("node"),
5400 libvirt_constcharPtrWrap(local->node));
5401 PyDict_SetItem(pyobj_local,
5402 libvirt_constcharPtrWrap("service"),
5403 libvirt_constcharPtrWrap(local->service));
5405 pyobj_remote = PyDict_New();
5406 PyDict_SetItem(pyobj_remote,
5407 libvirt_constcharPtrWrap("family"),
5408 libvirt_intWrap(remote->family));
5409 PyDict_SetItem(pyobj_remote,
5410 libvirt_constcharPtrWrap("node"),
5411 libvirt_constcharPtrWrap(remote->node));
5412 PyDict_SetItem(pyobj_remote,
5413 libvirt_constcharPtrWrap("service"),
5414 libvirt_constcharPtrWrap(remote->service));
5416 pyobj_subject = PyList_New(subject->nidentity);
5417 for (i = 0 ; i < subject->nidentity ; i++) {
5418 PyObject *pair = PyTuple_New(2);
5419 PyTuple_SetItem(pair, 0, libvirt_constcharPtrWrap(subject->identities[i].type));
5420 PyTuple_SetItem(pair, 1, libvirt_constcharPtrWrap(subject->identities[i].name));
5422 PyList_SetItem(pyobj_subject, i, pair);
5425 /* Call the Callback Dispatcher */
5426 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5427 (char*)"_dispatchDomainEventGraphicsCallback",
5428 (char*)"OiOOsOO",
5429 pyobj_dom,
5430 phase, pyobj_local, pyobj_remote,
5431 authScheme, pyobj_subject,
5432 pyobj_cbData);
5434 Py_DECREF(pyobj_cbData);
5435 Py_DECREF(pyobj_dom);
5437 if(!pyobj_ret) {
5438 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5439 PyErr_Print();
5440 } else {
5441 Py_DECREF(pyobj_ret);
5442 ret = 0;
5445 LIBVIRT_RELEASE_THREAD_STATE;
5446 return ret;
5449 static int
5450 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5451 virDomainPtr dom,
5452 const char *path,
5453 int type,
5454 int status,
5455 void *opaque)
5457 PyObject *pyobj_cbData = (PyObject*)opaque;
5458 PyObject *pyobj_dom;
5459 PyObject *pyobj_ret;
5460 PyObject *pyobj_conn;
5461 PyObject *dictKey;
5462 int ret = -1;
5464 LIBVIRT_ENSURE_THREAD_STATE;
5466 /* Create a python instance of this virDomainPtr */
5467 virDomainRef(dom);
5468 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5469 Py_INCREF(pyobj_cbData);
5471 dictKey = libvirt_constcharPtrWrap("conn");
5472 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5473 Py_DECREF(dictKey);
5475 /* Call the Callback Dispatcher */
5476 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5477 (char*)"dispatchDomainEventBlockPullCallback",
5478 (char*)"OsiiO",
5479 pyobj_dom, path, type, status, pyobj_cbData);
5481 Py_DECREF(pyobj_cbData);
5482 Py_DECREF(pyobj_dom);
5484 if(!pyobj_ret) {
5485 #if DEBUG_ERROR
5486 printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5487 #endif
5488 PyErr_Print();
5489 } else {
5490 Py_DECREF(pyobj_ret);
5491 ret = 0;
5494 LIBVIRT_RELEASE_THREAD_STATE;
5495 return ret;
5498 static int
5499 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5500 virDomainPtr dom,
5501 const char *oldSrcPath,
5502 const char *newSrcPath,
5503 const char *devAlias,
5504 int reason,
5505 void *opaque)
5507 PyObject *pyobj_cbData = (PyObject*)opaque;
5508 PyObject *pyobj_dom;
5509 PyObject *pyobj_ret;
5510 PyObject *pyobj_conn;
5511 PyObject *dictKey;
5512 int ret = -1;
5514 LIBVIRT_ENSURE_THREAD_STATE;
5515 /* Create a python instance of this virDomainPtr */
5516 virDomainRef(dom);
5518 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5519 Py_INCREF(pyobj_cbData);
5521 dictKey = libvirt_constcharPtrWrap("conn");
5522 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5523 Py_DECREF(dictKey);
5525 /* Call the Callback Dispatcher */
5526 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5527 (char*)"_dispatchDomainEventDiskChangeCallback",
5528 (char*)"OsssiO",
5529 pyobj_dom,
5530 oldSrcPath, newSrcPath,
5531 devAlias, reason, pyobj_cbData);
5533 Py_DECREF(pyobj_cbData);
5534 Py_DECREF(pyobj_dom);
5536 if(!pyobj_ret) {
5537 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5538 PyErr_Print();
5539 } else {
5540 Py_DECREF(pyobj_ret);
5541 ret = 0;
5544 LIBVIRT_RELEASE_THREAD_STATE;
5545 return ret;
5548 static int
5549 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5550 virDomainPtr dom,
5551 const char *devAlias,
5552 int reason,
5553 void *opaque)
5555 PyObject *pyobj_cbData = (PyObject*)opaque;
5556 PyObject *pyobj_dom;
5557 PyObject *pyobj_ret;
5558 PyObject *pyobj_conn;
5559 PyObject *dictKey;
5560 int ret = -1;
5562 LIBVIRT_ENSURE_THREAD_STATE;
5563 /* Create a python instance of this virDomainPtr */
5564 virDomainRef(dom);
5566 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5567 Py_INCREF(pyobj_cbData);
5569 dictKey = libvirt_constcharPtrWrap("conn");
5570 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5571 Py_DECREF(dictKey);
5573 /* Call the Callback Dispatcher */
5574 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5575 (char*)"_dispatchDomainEventTrayChangeCallback",
5576 (char*)"OsiO",
5577 pyobj_dom,
5578 devAlias, reason, pyobj_cbData);
5580 Py_DECREF(pyobj_cbData);
5581 Py_DECREF(pyobj_dom);
5583 if(!pyobj_ret) {
5584 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5585 PyErr_Print();
5586 } else {
5587 Py_DECREF(pyobj_ret);
5588 ret = 0;
5591 LIBVIRT_RELEASE_THREAD_STATE;
5592 return ret;
5595 static int
5596 libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5597 virDomainPtr dom,
5598 int reason,
5599 void *opaque)
5601 PyObject *pyobj_cbData = (PyObject*)opaque;
5602 PyObject *pyobj_dom;
5603 PyObject *pyobj_ret;
5604 PyObject *pyobj_conn;
5605 PyObject *dictKey;
5606 int ret = -1;
5608 LIBVIRT_ENSURE_THREAD_STATE;
5609 /* Create a python instance of this virDomainPtr */
5610 virDomainRef(dom);
5612 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5613 Py_INCREF(pyobj_cbData);
5615 dictKey = libvirt_constcharPtrWrap("conn");
5616 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5617 Py_DECREF(dictKey);
5619 /* Call the Callback Dispatcher */
5620 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5621 (char*)"_dispatchDomainEventPMWakeupCallback",
5622 (char*)"OiO",
5623 pyobj_dom,
5624 reason,
5625 pyobj_cbData);
5627 Py_DECREF(pyobj_cbData);
5628 Py_DECREF(pyobj_dom);
5630 if(!pyobj_ret) {
5631 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5632 PyErr_Print();
5633 } else {
5634 Py_DECREF(pyobj_ret);
5635 ret = 0;
5638 LIBVIRT_RELEASE_THREAD_STATE;
5639 return ret;
5642 static int
5643 libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5644 virDomainPtr dom,
5645 int reason,
5646 void *opaque)
5648 PyObject *pyobj_cbData = (PyObject*)opaque;
5649 PyObject *pyobj_dom;
5650 PyObject *pyobj_ret;
5651 PyObject *pyobj_conn;
5652 PyObject *dictKey;
5653 int ret = -1;
5655 LIBVIRT_ENSURE_THREAD_STATE;
5656 /* Create a python instance of this virDomainPtr */
5657 virDomainRef(dom);
5659 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5660 Py_INCREF(pyobj_cbData);
5662 dictKey = libvirt_constcharPtrWrap("conn");
5663 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5664 Py_DECREF(dictKey);
5666 /* Call the Callback Dispatcher */
5667 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5668 (char*)"_dispatchDomainEventPMSuspendCallback",
5669 (char*)"OiO",
5670 pyobj_dom,
5671 reason,
5672 pyobj_cbData);
5674 Py_DECREF(pyobj_cbData);
5675 Py_DECREF(pyobj_dom);
5677 if(!pyobj_ret) {
5678 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5679 PyErr_Print();
5680 } else {
5681 Py_DECREF(pyobj_ret);
5682 ret = 0;
5685 LIBVIRT_RELEASE_THREAD_STATE;
5686 return ret;
5689 static int
5690 libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5691 virDomainPtr dom,
5692 unsigned long long actual,
5693 void *opaque)
5695 PyObject *pyobj_cbData = (PyObject*)opaque;
5696 PyObject *pyobj_dom;
5697 PyObject *pyobj_ret;
5698 PyObject *pyobj_conn;
5699 PyObject *dictKey;
5700 int ret = -1;
5702 LIBVIRT_ENSURE_THREAD_STATE;
5704 /* Create a python instance of this virDomainPtr */
5705 virDomainRef(dom);
5706 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5707 Py_INCREF(pyobj_cbData);
5709 dictKey = libvirt_constcharPtrWrap("conn");
5710 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5711 Py_DECREF(dictKey);
5713 /* Call the Callback Dispatcher */
5714 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5715 (char*)"_dispatchDomainEventBalloonChangeCallback",
5716 (char*)"OLO",
5717 pyobj_dom,
5718 (PY_LONG_LONG)actual,
5719 pyobj_cbData);
5721 Py_DECREF(pyobj_cbData);
5722 Py_DECREF(pyobj_dom);
5724 if(!pyobj_ret) {
5725 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5726 PyErr_Print();
5727 } else {
5728 Py_DECREF(pyobj_ret);
5729 ret = 0;
5732 LIBVIRT_RELEASE_THREAD_STATE;
5733 return ret;
5736 static int
5737 libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
5738 virDomainPtr dom,
5739 int reason,
5740 void *opaque)
5742 PyObject *pyobj_cbData = (PyObject*)opaque;
5743 PyObject *pyobj_dom;
5744 PyObject *pyobj_ret;
5745 PyObject *pyobj_conn;
5746 PyObject *dictKey;
5747 int ret = -1;
5749 LIBVIRT_ENSURE_THREAD_STATE;
5750 /* Create a python instance of this virDomainPtr */
5751 virDomainRef(dom);
5753 pyobj_dom = libvirt_virDomainPtrWrap(dom);
5754 Py_INCREF(pyobj_cbData);
5756 dictKey = libvirt_constcharPtrWrap("conn");
5757 pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
5758 Py_DECREF(dictKey);
5760 /* Call the Callback Dispatcher */
5761 pyobj_ret = PyObject_CallMethod(pyobj_conn,
5762 (char*)"_dispatchDomainEventPMSuspendDiskCallback",
5763 (char*)"OiO",
5764 pyobj_dom,
5765 reason,
5766 pyobj_cbData);
5768 Py_DECREF(pyobj_cbData);
5769 Py_DECREF(pyobj_dom);
5771 if(!pyobj_ret) {
5772 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5773 PyErr_Print();
5774 } else {
5775 Py_DECREF(pyobj_ret);
5776 ret = 0;
5779 LIBVIRT_RELEASE_THREAD_STATE;
5780 return ret;
5783 static PyObject *
5784 libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
5785 PyObject * args)
5787 PyObject *py_retval; /* return value */
5788 PyObject *pyobj_conn; /* virConnectPtr */
5789 PyObject *pyobj_dom;
5790 PyObject *pyobj_cbData; /* hash of callback data */
5791 int eventID;
5792 virConnectPtr conn;
5793 int ret = 0;
5794 virConnectDomainEventGenericCallback cb = NULL;
5795 virDomainPtr dom;
5797 if (!PyArg_ParseTuple
5798 (args, (char *) "OOiO:virConnectDomainEventRegisterAny",
5799 &pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData)) {
5800 DEBUG("%s failed parsing tuple\n", __FUNCTION__);
5801 return VIR_PY_INT_FAIL;
5804 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
5805 pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
5806 conn = PyvirConnect_Get(pyobj_conn);
5807 if (pyobj_dom == Py_None)
5808 dom = NULL;
5809 else
5810 dom = PyvirDomain_Get(pyobj_dom);
5812 switch (eventID) {
5813 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
5814 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback);
5815 break;
5816 case VIR_DOMAIN_EVENT_ID_REBOOT:
5817 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
5818 break;
5819 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
5820 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback);
5821 break;
5822 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
5823 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback);
5824 break;
5825 case VIR_DOMAIN_EVENT_ID_IO_ERROR:
5826 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback);
5827 break;
5828 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
5829 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback);
5830 break;
5831 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
5832 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback);
5833 break;
5834 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
5835 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback);
5836 break;
5837 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
5838 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback);
5839 break;
5840 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
5841 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
5842 break;
5843 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
5844 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
5845 break;
5846 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
5847 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMWakeupCallback);
5848 break;
5849 case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
5850 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback);
5851 break;
5852 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
5853 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback);
5854 break;
5855 case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
5856 cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback);
5857 break;
5860 if (!cb) {
5861 return VIR_PY_INT_FAIL;
5864 Py_INCREF(pyobj_cbData);
5866 LIBVIRT_BEGIN_ALLOW_THREADS;
5867 ret = virConnectDomainEventRegisterAny(conn, dom, eventID,
5868 cb, pyobj_cbData,
5869 libvirt_virConnectDomainEventFreeFunc);
5870 LIBVIRT_END_ALLOW_THREADS;
5872 if (ret < 0) {
5873 Py_DECREF(pyobj_cbData);
5876 py_retval = libvirt_intWrap(ret);
5877 return py_retval;
5880 static PyObject *
5881 libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject * self,
5882 PyObject * args)
5884 PyObject *py_retval;
5885 PyObject *pyobj_conn;
5886 int callbackID;
5887 virConnectPtr conn;
5888 int ret = 0;
5890 if (!PyArg_ParseTuple
5891 (args, (char *) "Oi:virConnectDomainEventDeregister",
5892 &pyobj_conn, &callbackID))
5893 return NULL;
5895 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
5897 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
5899 LIBVIRT_BEGIN_ALLOW_THREADS;
5901 ret = virConnectDomainEventDeregisterAny(conn, callbackID);
5903 LIBVIRT_END_ALLOW_THREADS;
5904 py_retval = libvirt_intWrap(ret);
5905 return py_retval;
5908 static void
5909 libvirt_virStreamEventFreeFunc(void *opaque)
5911 PyObject *pyobj_stream = (PyObject*)opaque;
5912 LIBVIRT_ENSURE_THREAD_STATE;
5913 Py_DECREF(pyobj_stream);
5914 LIBVIRT_RELEASE_THREAD_STATE;
5917 static void
5918 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED,
5919 int events,
5920 void *opaque)
5922 PyObject *pyobj_cbData = (PyObject *)opaque;
5923 PyObject *pyobj_stream;
5924 PyObject *pyobj_ret;
5925 PyObject *dictKey;
5927 LIBVIRT_ENSURE_THREAD_STATE;
5929 Py_INCREF(pyobj_cbData);
5930 dictKey = libvirt_constcharPtrWrap("stream");
5931 pyobj_stream = PyDict_GetItem(pyobj_cbData, dictKey);
5932 Py_DECREF(dictKey);
5934 /* Call the pure python dispatcher */
5935 pyobj_ret = PyObject_CallMethod(pyobj_stream,
5936 (char *)"_dispatchStreamEventCallback",
5937 (char *)"iO",
5938 events, pyobj_cbData);
5940 Py_DECREF(pyobj_cbData);
5942 if (!pyobj_ret) {
5943 DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
5944 PyErr_Print();
5945 } else {
5946 Py_DECREF(pyobj_ret);
5949 LIBVIRT_RELEASE_THREAD_STATE;
5952 static PyObject *
5953 libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
5954 PyObject *args)
5956 PyObject *py_retval;
5957 PyObject *pyobj_stream;
5958 PyObject *pyobj_cbData;
5959 virStreamPtr stream;
5960 virStreamEventCallback cb = libvirt_virStreamEventCallback;
5961 int ret;
5962 int events;
5964 if (!PyArg_ParseTuple(args, (char *) "OiO:virStreamEventAddCallback",
5965 &pyobj_stream, &events, &pyobj_cbData)) {
5966 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
5967 return VIR_PY_INT_FAIL;
5970 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
5971 pyobj_stream, events, pyobj_cbData);
5972 stream = PyvirStream_Get(pyobj_stream);
5974 Py_INCREF(pyobj_cbData);
5976 LIBVIRT_BEGIN_ALLOW_THREADS;
5977 ret = virStreamEventAddCallback(stream, events, cb, pyobj_cbData,
5978 libvirt_virStreamEventFreeFunc);
5979 LIBVIRT_END_ALLOW_THREADS;
5981 if (ret < 0) {
5982 Py_DECREF(pyobj_cbData);
5985 py_retval = libvirt_intWrap(ret);
5986 return py_retval;
5989 static PyObject *
5990 libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
5991 PyObject *args)
5993 PyObject *pyobj_stream;
5994 virStreamPtr stream;
5995 char *buf = NULL;
5996 int ret;
5997 int nbytes;
5999 if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
6000 &pyobj_stream, &nbytes)) {
6001 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6002 return VIR_PY_NONE;
6004 stream = PyvirStream_Get(pyobj_stream);
6006 if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0)
6007 return VIR_PY_NONE;
6009 LIBVIRT_BEGIN_ALLOW_THREADS;
6010 ret = virStreamRecv(stream, buf, nbytes);
6011 LIBVIRT_END_ALLOW_THREADS;
6013 buf[ret > -1 ? ret : 0] = '\0';
6014 DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
6016 if (ret == -2)
6017 return libvirt_intWrap(ret);
6018 if (ret < 0)
6019 return VIR_PY_NONE;
6020 return libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
6023 static PyObject *
6024 libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
6025 PyObject *args)
6027 PyObject *py_retval;
6028 PyObject *pyobj_stream;
6029 virStreamPtr stream;
6030 char *data;
6031 int datalen;
6032 int ret;
6033 int nbytes;
6035 if (!PyArg_ParseTuple(args, (char *) "Oz#i:virStreamRecv",
6036 &pyobj_stream, &data, &datalen, &nbytes)) {
6037 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6038 return VIR_PY_INT_FAIL;
6040 stream = PyvirStream_Get(pyobj_stream);
6042 LIBVIRT_BEGIN_ALLOW_THREADS;
6043 ret = virStreamSend(stream, data, nbytes);
6044 LIBVIRT_END_ALLOW_THREADS;
6046 DEBUG("StreamSend ret=%d\n", ret);
6048 py_retval = libvirt_intWrap(ret);
6049 return py_retval;
6052 static PyObject *
6053 libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
6054 PyObject *args)
6056 PyObject *py_retval;
6057 virDomainPtr domain;
6058 PyObject *pyobj_domain;
6059 PyObject *pyobj_list;
6060 int codeset;
6061 int holdtime;
6062 unsigned int flags;
6063 int ret;
6064 int i;
6065 unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
6066 unsigned int nkeycodes;
6068 if (!PyArg_ParseTuple(args, (char *)"OiiOii:virDomainSendKey",
6069 &pyobj_domain, &codeset, &holdtime, &pyobj_list,
6070 &nkeycodes, &flags)) {
6071 DEBUG("%s failed to parse tuple\n", __FUNCTION__);
6072 return VIR_PY_INT_FAIL;
6074 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6076 if (!PyList_Check(pyobj_list)) {
6077 return VIR_PY_INT_FAIL;
6080 if (nkeycodes != PyList_Size(pyobj_list) ||
6081 nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
6082 return VIR_PY_INT_FAIL;
6085 for (i = 0; i < nkeycodes; i++) {
6086 keycodes[i] = (int)PyInt_AsLong(PyList_GetItem(pyobj_list, i));
6089 LIBVIRT_BEGIN_ALLOW_THREADS;
6090 ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
6091 LIBVIRT_END_ALLOW_THREADS;
6093 DEBUG("virDomainSendKey ret=%d\n", ret);
6095 py_retval = libvirt_intWrap(ret);
6096 return py_retval;
6099 static PyObject *
6100 libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
6101 PyObject *py_retval;
6102 int c_retval;
6103 unsigned long bandwidth;
6104 virDomainPtr domain;
6105 PyObject *pyobj_domain;
6106 unsigned int flags = 0;
6108 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainMigrateGetMaxSpeed",
6109 &pyobj_domain, &flags))
6110 return NULL;
6112 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6114 LIBVIRT_BEGIN_ALLOW_THREADS;
6115 c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, flags);
6116 LIBVIRT_END_ALLOW_THREADS;
6118 if (c_retval < 0)
6119 return VIR_PY_INT_FAIL;
6120 py_retval = libvirt_ulongWrap(bandwidth);
6121 return py_retval;
6124 static PyObject *
6125 libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED,
6126 PyObject *args) {
6127 PyObject *py_retval = NULL;
6128 int c_retval;
6129 virDomainPtr domain;
6130 PyObject *pyobj_domain;
6131 const char *disk;
6132 unsigned long long offset;
6133 size_t size;
6134 char *buf;
6135 unsigned int flags;
6137 if (!PyArg_ParseTuple(args, (char *)"OzLni:virDomainBlockPeek", &pyobj_domain,
6138 &disk, &offset, &size, &flags))
6139 return NULL;
6141 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6143 if (VIR_ALLOC_N(buf, size) < 0)
6144 return VIR_PY_NONE;
6146 LIBVIRT_BEGIN_ALLOW_THREADS;
6147 c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags);
6148 LIBVIRT_END_ALLOW_THREADS;
6150 if (c_retval < 0) {
6151 py_retval = VIR_PY_NONE;
6152 goto cleanup;
6155 py_retval = PyString_FromStringAndSize(buf, size);
6157 cleanup:
6158 VIR_FREE(buf);
6159 return py_retval;
6162 static PyObject *
6163 libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED,
6164 PyObject *args) {
6165 PyObject *py_retval = NULL;
6166 int c_retval;
6167 virDomainPtr domain;
6168 PyObject *pyobj_domain;
6169 unsigned long long start;
6170 size_t size;
6171 char *buf;
6172 unsigned int flags;
6174 if (!PyArg_ParseTuple(args, (char *)"OLni:virDomainMemoryPeek", &pyobj_domain,
6175 &start, &size, &flags))
6176 return NULL;
6178 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
6180 if (VIR_ALLOC_N(buf, size) < 0)
6181 return VIR_PY_NONE;
6183 LIBVIRT_BEGIN_ALLOW_THREADS;
6184 c_retval = virDomainMemoryPeek(domain, start, size, buf, flags);
6185 LIBVIRT_END_ALLOW_THREADS;
6187 if (c_retval < 0) {
6188 py_retval = VIR_PY_NONE;
6189 goto cleanup;
6192 py_retval = PyString_FromStringAndSize(buf, size);
6194 cleanup:
6195 VIR_FREE(buf);
6196 return py_retval;
6199 static PyObject *
6200 libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
6201 PyObject *args)
6203 virConnectPtr conn;
6204 PyObject *pyobj_conn, *info;
6205 PyObject *ret = NULL;
6206 int i_retval;
6207 int nparams = 0;
6208 Py_ssize_t size = 0;
6209 unsigned int flags;
6210 virTypedParameterPtr params, new_params;
6212 if (!PyArg_ParseTuple(args,
6213 (char *)"OOi:virNodeSetMemoryParameters",
6214 &pyobj_conn, &info, &flags))
6215 return NULL;
6216 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6218 if ((size = PyDict_Size(info)) < 0)
6219 return NULL;
6221 if (size == 0) {
6222 PyErr_Format(PyExc_LookupError,
6223 "Need non-empty dictionary to set attributes");
6224 return NULL;
6227 LIBVIRT_BEGIN_ALLOW_THREADS;
6228 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
6229 LIBVIRT_END_ALLOW_THREADS;
6231 if (i_retval < 0)
6232 return VIR_PY_INT_FAIL;
6234 if (nparams == 0) {
6235 PyErr_Format(PyExc_LookupError,
6236 "no settable attributes");
6237 return NULL;
6240 if (VIR_ALLOC_N(params, nparams) < 0)
6241 return PyErr_NoMemory();
6243 LIBVIRT_BEGIN_ALLOW_THREADS;
6244 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
6245 LIBVIRT_END_ALLOW_THREADS;
6247 if (i_retval < 0) {
6248 ret = VIR_PY_INT_FAIL;
6249 goto cleanup;
6252 new_params = setPyVirTypedParameter(info, params, nparams);
6253 if (!new_params)
6254 goto cleanup;
6256 LIBVIRT_BEGIN_ALLOW_THREADS;
6257 i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
6258 LIBVIRT_END_ALLOW_THREADS;
6260 if (i_retval < 0) {
6261 ret = VIR_PY_INT_FAIL;
6262 goto cleanup;
6265 ret = VIR_PY_INT_SUCCESS;
6267 cleanup:
6268 virTypedParameterArrayClear(params, nparams);
6269 VIR_FREE(params);
6270 VIR_FREE(new_params);
6271 return ret;
6274 static PyObject *
6275 libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
6276 PyObject *args)
6278 virConnectPtr conn;
6279 PyObject *pyobj_conn;
6280 PyObject *ret = NULL;
6281 int i_retval;
6282 int nparams = 0;
6283 unsigned int flags;
6284 virTypedParameterPtr params;
6286 if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetMemoryParameters",
6287 &pyobj_conn, &flags))
6288 return NULL;
6289 conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
6291 LIBVIRT_BEGIN_ALLOW_THREADS;
6292 i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
6293 LIBVIRT_END_ALLOW_THREADS;
6295 if (i_retval < 0)
6296 return VIR_PY_NONE;
6298 if (!nparams)
6299 return PyDict_New();
6301 if (VIR_ALLOC_N(params, nparams) < 0)
6302 return PyErr_NoMemory();
6304 LIBVIRT_BEGIN_ALLOW_THREADS;
6305 i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
6306 LIBVIRT_END_ALLOW_THREADS;
6308 if (i_retval < 0) {
6309 ret = VIR_PY_NONE;
6310 goto cleanup;
6313 ret = getPyVirTypedParameter(params, nparams);
6315 cleanup:
6316 virTypedParameterArrayClear(params, nparams);
6317 VIR_FREE(params);
6318 return ret;
6322 /************************************************************************
6324 * The registration stuff *
6326 ************************************************************************/
6327 static PyMethodDef libvirtMethods[] = {
6328 #include "libvirt-export.c"
6329 {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
6330 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL},
6331 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
6332 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
6333 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
6334 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
6335 {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
6336 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
6337 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
6338 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
6339 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
6340 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
6341 {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
6342 {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
6343 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
6344 {(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
6345 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
6346 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
6347 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
6348 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
6349 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
6350 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
6351 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
6352 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
6353 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL},
6354 {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL},
6355 {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
6356 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
6357 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
6358 {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
6359 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
6360 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
6361 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},
6362 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL},
6363 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
6364 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
6365 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL},
6366 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats, METH_VARARGS, NULL},
6367 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
6368 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
6369 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
6370 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
6371 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
6372 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags, METH_VARARGS, NULL},
6373 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters, METH_VARARGS, NULL},
6374 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags, METH_VARARGS, NULL},
6375 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters, METH_VARARGS, NULL},
6376 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters, METH_VARARGS, NULL},
6377 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters, METH_VARARGS, NULL},
6378 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
6379 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
6380 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
6381 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
6382 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
6383 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
6384 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
6385 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
6386 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
6387 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
6388 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
6389 {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
6390 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
6391 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
6392 {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
6393 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL},
6394 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL},
6395 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL},
6396 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL},
6397 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL},
6398 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
6399 {(char *) "virEventAddHandle", libvirt_virEventAddHandle, METH_VARARGS, NULL},
6400 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout, METH_VARARGS, NULL},
6401 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
6402 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
6403 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
6404 {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
6405 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
6406 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
6407 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},
6408 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL},
6409 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
6410 {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL},
6411 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
6412 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
6413 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL},
6414 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
6415 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
6416 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
6417 {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
6418 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
6419 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
6420 {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
6421 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
6422 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
6423 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
6424 {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
6425 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
6426 {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
6427 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
6428 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
6429 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
6430 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL},
6431 {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
6432 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
6433 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
6434 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
6435 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
6436 {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
6437 {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
6438 {NULL, NULL, 0, NULL}
6441 void
6442 #ifndef __CYGWIN__
6443 initlibvirtmod
6444 #else
6445 initcygvirtmod
6446 #endif
6447 (void)
6449 static int initialized = 0;
6451 if (initialized != 0)
6452 return;
6454 if (virInitialize() < 0)
6455 return;
6457 /* initialize the python extension module */
6458 Py_InitModule((char *)
6459 #ifndef __CYGWIN__
6460 "libvirtmod"
6461 #else
6462 "cygvirtmod"
6463 #endif
6464 , libvirtMethods);
6466 initialized = 1;