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
7 * Copyright (C) 2005, 2007-2012 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
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. */
19 /* We want to see *_LAST enums. */
20 #define VIR_ENUM_SENTINELS
23 #include "libvirt/libvirt.h"
24 #include "libvirt/virterror.h"
25 #include "typewrappers.h"
28 #include "virtypedparam.h"
29 #include "ignore-value.h"
33 extern void initlibvirtmod(void);
35 extern void initcygvirtmod(void);
39 # define DEBUG_ERROR 1
43 # define DEBUG(fmt, ...) \
44 printf(fmt, __VA_ARGS__)
46 # define DEBUG(fmt, ...) \
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
);
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
* ATTRIBUTE_NONNULL(1)
75 getPyVirTypedParameter(const virTypedParameterPtr params
, int nparams
)
77 PyObject
*key
, *val
, *info
;
80 if ((info
= PyDict_New()) == 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
);
89 case VIR_TYPED_PARAM_UINT
:
90 val
= PyInt_FromLong(params
[i
].value
.ui
);
93 case VIR_TYPED_PARAM_LLONG
:
94 val
= PyLong_FromLongLong(params
[i
].value
.l
);
97 case VIR_TYPED_PARAM_ULLONG
:
98 val
= PyLong_FromUnsignedLongLong(params
[i
].value
.ul
);
101 case VIR_TYPED_PARAM_DOUBLE
:
102 val
= PyFloat_FromDouble(params
[i
].value
.d
);
105 case VIR_TYPED_PARAM_BOOLEAN
:
106 val
= PyBool_FromLong(params
[i
].value
.b
);
109 case VIR_TYPED_PARAM_STRING
:
110 val
= libvirt_constcharPtrWrap(params
[i
].value
.s
);
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",
123 key
= libvirt_constcharPtrWrap(params
[i
].field
);
127 if (PyDict_SetItem(info
, key
, val
) < 0) {
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
;
155 virTypedParameterPtr temp
= NULL
, ret
= NULL
;
159 if ((size
= PyDict_Size(info
)) < 0)
162 /* Libvirt APIs use NULL array and 0 size as a special case;
163 * setting should have at least one parameter. */
165 PyErr_Format(PyExc_LookupError
, "Dictionary must not be empty");
169 if (VIR_ALLOC_N(ret
, size
) < 0) {
175 while (PyDict_Next(info
, &pos
, &key
, &value
)) {
178 if ((keystr
= PyString_AsString(key
)) == NULL
)
181 for (i
= 0; i
< nparams
; i
++) {
182 if (STREQ(params
[i
].field
, keystr
))
186 PyErr_Format(PyExc_LookupError
,
187 "Attribute name \"%s\" could not be recognized",
192 ignore_value(virStrcpyStatic(temp
->field
, keystr
));
193 temp
->type
= params
[i
].type
;
195 switch(params
[i
].type
) {
196 case VIR_TYPED_PARAM_INT
:
198 long long_val
= PyInt_AsLong(value
);
199 if ((long_val
== -1) && PyErr_Occurred())
201 if ((int)long_val
== long_val
) {
202 temp
->value
.i
= long_val
;
204 PyErr_Format(PyExc_ValueError
,
206 "attribute \"%s\" is out of int range", keystr
);
211 case VIR_TYPED_PARAM_UINT
:
213 long long_val
= PyInt_AsLong(value
);
214 if ((long_val
== -1) && PyErr_Occurred())
216 if ((unsigned int)long_val
== long_val
) {
217 temp
->value
.ui
= long_val
;
219 PyErr_Format(PyExc_ValueError
,
221 "attribute \"%s\" is out of int range", keystr
);
226 case VIR_TYPED_PARAM_LLONG
:
228 long long llong_val
= PyLong_AsLongLong(value
);
229 if ((llong_val
== -1) && PyErr_Occurred())
231 temp
->value
.l
= llong_val
;
234 case VIR_TYPED_PARAM_ULLONG
:
236 unsigned long long ullong_val
= PyLong_AsUnsignedLongLong(value
);
237 if ((ullong_val
== -1) && PyErr_Occurred())
239 temp
->value
.ul
= ullong_val
;
242 case VIR_TYPED_PARAM_DOUBLE
:
244 double double_val
= PyFloat_AsDouble(value
);
245 if ((double_val
== -1) && PyErr_Occurred())
247 temp
->value
.d
= double_val
;
250 case VIR_TYPED_PARAM_BOOLEAN
:
252 /* Hack - Python's definition of Py_True breaks strict
253 * aliasing rules, so can't directly compare
255 if (PyBool_Check(value
)) {
256 PyObject
*hacktrue
= PyBool_FromLong(1);
257 temp
->value
.b
= hacktrue
== value
? 1 : 0;
260 PyErr_Format(PyExc_TypeError
,
262 "attribute \"%s\" must be bool", keystr
);
267 case VIR_TYPED_PARAM_STRING
:
269 char *string_val
= PyString_AsString(value
);
272 temp
->value
.s
= string_val
;
277 /* Possible if a newer server has a bug and sent stuff we
278 * don't recognize. */
279 PyErr_Format(PyExc_LookupError
,
280 "Type value \"%d\" not recognized",
294 /************************************************************************
298 ************************************************************************/
301 libvirt_virDomainBlockStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
303 PyObject
*pyobj_domain
;
306 virDomainBlockStatsStruct stats
;
309 if (!PyArg_ParseTuple(args
, (char *)"Oz:virDomainBlockStats",
310 &pyobj_domain
,&path
))
312 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
314 LIBVIRT_BEGIN_ALLOW_THREADS
;
315 c_retval
= virDomainBlockStats(domain
, path
, &stats
, sizeof(stats
));
316 LIBVIRT_END_ALLOW_THREADS
;
321 /* convert to a Python tuple of long objects */
322 if ((info
= PyTuple_New(5)) == NULL
)
324 PyTuple_SetItem(info
, 0, PyLong_FromLongLong(stats
.rd_req
));
325 PyTuple_SetItem(info
, 1, PyLong_FromLongLong(stats
.rd_bytes
));
326 PyTuple_SetItem(info
, 2, PyLong_FromLongLong(stats
.wr_req
));
327 PyTuple_SetItem(info
, 3, PyLong_FromLongLong(stats
.wr_bytes
));
328 PyTuple_SetItem(info
, 4, PyLong_FromLongLong(stats
.errs
));
333 libvirt_virDomainBlockStatsFlags(PyObject
*self ATTRIBUTE_UNUSED
,
337 PyObject
*pyobj_domain
;
338 PyObject
*ret
= NULL
;
342 virTypedParameterPtr params
;
345 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainBlockStatsFlags",
346 &pyobj_domain
, &path
, &flags
))
348 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
350 LIBVIRT_BEGIN_ALLOW_THREADS
;
351 i_retval
= virDomainBlockStatsFlags(domain
, path
, NULL
, &nparams
, flags
);
352 LIBVIRT_END_ALLOW_THREADS
;
360 if (VIR_ALLOC_N(params
, nparams
) < 0)
361 return PyErr_NoMemory();
363 LIBVIRT_BEGIN_ALLOW_THREADS
;
364 i_retval
= virDomainBlockStatsFlags(domain
, path
, params
, &nparams
, flags
);
365 LIBVIRT_END_ALLOW_THREADS
;
372 ret
= getPyVirTypedParameter(params
, nparams
);
375 virTypedParameterArrayClear(params
, nparams
);
381 libvirt_virDomainGetCPUStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
384 PyObject
*pyobj_domain
, *totalbool
;
385 PyObject
*cpu
, *total
;
386 PyObject
*ret
= NULL
;
387 PyObject
*error
= NULL
;
388 int ncpus
= -1, start_cpu
= 0;
389 int sumparams
= 0, nparams
= -1;
391 unsigned int flags
, totalflag
;
392 virTypedParameterPtr params
= NULL
, cpuparams
;
394 if (!PyArg_ParseTuple(args
, (char *)"OOi:virDomainGetCPUStats",
395 &pyobj_domain
, &totalbool
, &flags
))
397 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
399 if (!PyBool_Check(totalbool
)) {
400 PyErr_Format(PyExc_TypeError
,
401 "The \"total\" attribute must be bool");
404 /* Hack - Python's definition of Py_True breaks strict
405 * aliasing rules, so can't directly compare
407 PyObject
*hacktrue
= PyBool_FromLong(1);
408 totalflag
= hacktrue
== totalbool
? 1 : 0;
412 if ((ret
= PyList_New(0)) == NULL
)
416 LIBVIRT_BEGIN_ALLOW_THREADS
;
417 ncpus
= virDomainGetCPUStats(domain
, NULL
, 0, 0, 0, flags
);
418 LIBVIRT_END_ALLOW_THREADS
;
425 LIBVIRT_BEGIN_ALLOW_THREADS
;
426 nparams
= virDomainGetCPUStats(domain
, NULL
, 0, 0, 1, flags
);
427 LIBVIRT_END_ALLOW_THREADS
;
434 sumparams
= nparams
* MIN(ncpus
, 128);
436 if (VIR_ALLOC_N(params
, sumparams
) < 0) {
437 error
= PyErr_NoMemory();
442 int queried_ncpus
= MIN(ncpus
, 128);
445 LIBVIRT_BEGIN_ALLOW_THREADS
;
446 i_retval
= virDomainGetCPUStats(domain
, params
,
447 nparams
, start_cpu
, queried_ncpus
, flags
);
448 LIBVIRT_END_ALLOW_THREADS
;
458 for (i
= 0; i
< queried_ncpus
; i
++) {
459 cpuparams
= ¶ms
[i
* nparams
];
460 if ((cpu
= getPyVirTypedParameter(cpuparams
, i_retval
)) == NULL
) {
464 if (PyList_Append(ret
, cpu
) < 0) {
471 start_cpu
+= queried_ncpus
;
472 ncpus
-= queried_ncpus
;
473 virTypedParameterArrayClear(params
, sumparams
);
476 LIBVIRT_BEGIN_ALLOW_THREADS
;
477 nparams
= virDomainGetCPUStats(domain
, NULL
, 0, -1, 1, flags
);
478 LIBVIRT_END_ALLOW_THREADS
;
488 if (VIR_ALLOC_N(params
, nparams
) < 0) {
489 error
= PyErr_NoMemory();
493 LIBVIRT_BEGIN_ALLOW_THREADS
;
494 i_retval
= virDomainGetCPUStats(domain
, params
, nparams
, -1, 1, flags
);
495 LIBVIRT_END_ALLOW_THREADS
;
505 if ((total
= getPyVirTypedParameter(params
, i_retval
)) == NULL
) {
508 if (PyList_Append(ret
, total
) < 0) {
515 virTypedParameterArrayClear(params
, sumparams
);
520 virTypedParameterArrayClear(params
, sumparams
);
527 libvirt_virDomainInterfaceStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
529 PyObject
*pyobj_domain
;
532 virDomainInterfaceStatsStruct stats
;
535 if (!PyArg_ParseTuple(args
, (char *)"Oz:virDomainInterfaceStats",
536 &pyobj_domain
,&path
))
538 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
540 LIBVIRT_BEGIN_ALLOW_THREADS
;
541 c_retval
= virDomainInterfaceStats(domain
, path
, &stats
, sizeof(stats
));
542 LIBVIRT_END_ALLOW_THREADS
;
547 /* convert to a Python tuple of long objects */
548 if ((info
= PyTuple_New(8)) == NULL
)
550 PyTuple_SetItem(info
, 0, PyLong_FromLongLong(stats
.rx_bytes
));
551 PyTuple_SetItem(info
, 1, PyLong_FromLongLong(stats
.rx_packets
));
552 PyTuple_SetItem(info
, 2, PyLong_FromLongLong(stats
.rx_errs
));
553 PyTuple_SetItem(info
, 3, PyLong_FromLongLong(stats
.rx_drop
));
554 PyTuple_SetItem(info
, 4, PyLong_FromLongLong(stats
.tx_bytes
));
555 PyTuple_SetItem(info
, 5, PyLong_FromLongLong(stats
.tx_packets
));
556 PyTuple_SetItem(info
, 6, PyLong_FromLongLong(stats
.tx_errs
));
557 PyTuple_SetItem(info
, 7, PyLong_FromLongLong(stats
.tx_drop
));
562 libvirt_virDomainMemoryStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
564 PyObject
*pyobj_domain
;
565 unsigned int nr_stats
, i
;
566 virDomainMemoryStatStruct stats
[VIR_DOMAIN_MEMORY_STAT_NR
];
569 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainMemoryStats", &pyobj_domain
))
571 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
573 nr_stats
= virDomainMemoryStats(domain
, stats
,
574 VIR_DOMAIN_MEMORY_STAT_NR
, 0);
578 /* convert to a Python dictionary */
579 if ((info
= PyDict_New()) == NULL
)
582 for (i
= 0; i
< nr_stats
; i
++) {
583 if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_SWAP_IN
)
584 PyDict_SetItem(info
, libvirt_constcharPtrWrap("swap_in"),
585 PyLong_FromUnsignedLongLong(stats
[i
].val
));
586 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_SWAP_OUT
)
587 PyDict_SetItem(info
, libvirt_constcharPtrWrap("swap_out"),
588 PyLong_FromUnsignedLongLong(stats
[i
].val
));
589 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT
)
590 PyDict_SetItem(info
, libvirt_constcharPtrWrap("major_fault"),
591 PyLong_FromUnsignedLongLong(stats
[i
].val
));
592 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT
)
593 PyDict_SetItem(info
, libvirt_constcharPtrWrap("minor_fault"),
594 PyLong_FromUnsignedLongLong(stats
[i
].val
));
595 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_UNUSED
)
596 PyDict_SetItem(info
, libvirt_constcharPtrWrap("unused"),
597 PyLong_FromUnsignedLongLong(stats
[i
].val
));
598 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_AVAILABLE
)
599 PyDict_SetItem(info
, libvirt_constcharPtrWrap("available"),
600 PyLong_FromUnsignedLongLong(stats
[i
].val
));
601 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON
)
602 PyDict_SetItem(info
, libvirt_constcharPtrWrap("actual"),
603 PyLong_FromUnsignedLongLong(stats
[i
].val
));
604 else if (stats
[i
].tag
== VIR_DOMAIN_MEMORY_STAT_RSS
)
605 PyDict_SetItem(info
, libvirt_constcharPtrWrap("rss"),
606 PyLong_FromUnsignedLongLong(stats
[i
].val
));
612 libvirt_virDomainGetSchedulerType(PyObject
*self ATTRIBUTE_UNUSED
,
615 PyObject
*pyobj_domain
, *info
;
619 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetScedulerType",
622 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
624 LIBVIRT_BEGIN_ALLOW_THREADS
;
625 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
626 LIBVIRT_END_ALLOW_THREADS
;
627 if (c_retval
== NULL
)
630 /* convert to a Python tuple of long objects */
631 if ((info
= PyTuple_New(2)) == NULL
) {
636 PyTuple_SetItem(info
, 0, libvirt_constcharPtrWrap(c_retval
));
637 PyTuple_SetItem(info
, 1, PyInt_FromLong((long)nparams
));
643 libvirt_virDomainGetSchedulerParameters(PyObject
*self ATTRIBUTE_UNUSED
,
647 PyObject
*pyobj_domain
;
648 PyObject
*ret
= NULL
;
652 virTypedParameterPtr params
;
654 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetScedulerParameters",
657 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
659 LIBVIRT_BEGIN_ALLOW_THREADS
;
660 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
661 LIBVIRT_END_ALLOW_THREADS
;
663 if (c_retval
== NULL
)
670 if (VIR_ALLOC_N(params
, nparams
) < 0)
671 return PyErr_NoMemory();
673 LIBVIRT_BEGIN_ALLOW_THREADS
;
674 i_retval
= virDomainGetSchedulerParameters(domain
, params
, &nparams
);
675 LIBVIRT_END_ALLOW_THREADS
;
682 ret
= getPyVirTypedParameter(params
, nparams
);
685 virTypedParameterArrayClear(params
, nparams
);
691 libvirt_virDomainGetSchedulerParametersFlags(PyObject
*self ATTRIBUTE_UNUSED
,
695 PyObject
*pyobj_domain
;
696 PyObject
*ret
= NULL
;
701 virTypedParameterPtr params
;
703 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetScedulerParametersFlags",
704 &pyobj_domain
, &flags
))
706 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
708 LIBVIRT_BEGIN_ALLOW_THREADS
;
709 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
710 LIBVIRT_END_ALLOW_THREADS
;
712 if (c_retval
== NULL
)
719 if (VIR_ALLOC_N(params
, nparams
) < 0)
720 return PyErr_NoMemory();
722 LIBVIRT_BEGIN_ALLOW_THREADS
;
723 i_retval
= virDomainGetSchedulerParametersFlags(domain
, params
, &nparams
, flags
);
724 LIBVIRT_END_ALLOW_THREADS
;
731 ret
= getPyVirTypedParameter(params
, nparams
);
734 virTypedParameterArrayClear(params
, nparams
);
740 libvirt_virDomainSetSchedulerParameters(PyObject
*self ATTRIBUTE_UNUSED
,
744 PyObject
*pyobj_domain
, *info
;
745 PyObject
*ret
= NULL
;
750 virTypedParameterPtr params
, new_params
;
752 if (!PyArg_ParseTuple(args
, (char *)"OO:virDomainSetScedulerParameters",
753 &pyobj_domain
, &info
))
755 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
757 if ((size
= PyDict_Size(info
)) < 0)
761 PyErr_Format(PyExc_LookupError
,
762 "Need non-empty dictionary to set attributes");
766 LIBVIRT_BEGIN_ALLOW_THREADS
;
767 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
768 LIBVIRT_END_ALLOW_THREADS
;
770 if (c_retval
== NULL
)
771 return VIR_PY_INT_FAIL
;
775 PyErr_Format(PyExc_LookupError
,
776 "Domain has no settable attributes");
780 if (VIR_ALLOC_N(params
, nparams
) < 0)
781 return PyErr_NoMemory();
783 LIBVIRT_BEGIN_ALLOW_THREADS
;
784 i_retval
= virDomainGetSchedulerParameters(domain
, params
, &nparams
);
785 LIBVIRT_END_ALLOW_THREADS
;
788 ret
= VIR_PY_INT_FAIL
;
792 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
796 LIBVIRT_BEGIN_ALLOW_THREADS
;
797 i_retval
= virDomainSetSchedulerParameters(domain
, new_params
, size
);
798 LIBVIRT_END_ALLOW_THREADS
;
801 ret
= VIR_PY_INT_FAIL
;
805 ret
= VIR_PY_INT_SUCCESS
;
808 virTypedParameterArrayClear(params
, nparams
);
810 VIR_FREE(new_params
);
815 libvirt_virDomainSetSchedulerParametersFlags(PyObject
*self ATTRIBUTE_UNUSED
,
819 PyObject
*pyobj_domain
, *info
;
820 PyObject
*ret
= NULL
;
826 virTypedParameterPtr params
, new_params
;
828 if (!PyArg_ParseTuple(args
,
829 (char *)"OOi:virDomainSetScedulerParametersFlags",
830 &pyobj_domain
, &info
, &flags
))
832 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
834 if ((size
= PyDict_Size(info
)) < 0)
838 PyErr_Format(PyExc_LookupError
,
839 "Need non-empty dictionary to set attributes");
843 LIBVIRT_BEGIN_ALLOW_THREADS
;
844 c_retval
= virDomainGetSchedulerType(domain
, &nparams
);
845 LIBVIRT_END_ALLOW_THREADS
;
847 if (c_retval
== NULL
)
848 return VIR_PY_INT_FAIL
;
852 PyErr_Format(PyExc_LookupError
,
853 "Domain has no settable attributes");
857 if (VIR_ALLOC_N(params
, nparams
) < 0)
858 return PyErr_NoMemory();
860 LIBVIRT_BEGIN_ALLOW_THREADS
;
861 i_retval
= virDomainGetSchedulerParametersFlags(domain
, params
, &nparams
, flags
);
862 LIBVIRT_END_ALLOW_THREADS
;
865 ret
= VIR_PY_INT_FAIL
;
869 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
873 LIBVIRT_BEGIN_ALLOW_THREADS
;
874 i_retval
= virDomainSetSchedulerParametersFlags(domain
, new_params
, size
, flags
);
875 LIBVIRT_END_ALLOW_THREADS
;
878 ret
= VIR_PY_INT_FAIL
;
882 ret
= VIR_PY_INT_SUCCESS
;
885 virTypedParameterArrayClear(params
, nparams
);
887 VIR_FREE(new_params
);
892 libvirt_virDomainSetBlkioParameters(PyObject
*self ATTRIBUTE_UNUSED
,
896 PyObject
*pyobj_domain
, *info
;
897 PyObject
*ret
= NULL
;
902 virTypedParameterPtr params
, new_params
;
904 if (!PyArg_ParseTuple(args
,
905 (char *)"OOi:virDomainSetBlkioParameters",
906 &pyobj_domain
, &info
, &flags
))
908 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
910 if ((size
= PyDict_Size(info
)) < 0)
914 PyErr_Format(PyExc_LookupError
,
915 "Need non-empty dictionary to set attributes");
919 LIBVIRT_BEGIN_ALLOW_THREADS
;
920 i_retval
= virDomainGetBlkioParameters(domain
, NULL
, &nparams
, flags
);
921 LIBVIRT_END_ALLOW_THREADS
;
924 return VIR_PY_INT_FAIL
;
927 PyErr_Format(PyExc_LookupError
,
928 "Domain has no settable attributes");
932 if (VIR_ALLOC_N(params
, nparams
) < 0)
933 return PyErr_NoMemory();
935 LIBVIRT_BEGIN_ALLOW_THREADS
;
936 i_retval
= virDomainGetBlkioParameters(domain
, params
, &nparams
, flags
);
937 LIBVIRT_END_ALLOW_THREADS
;
940 ret
= VIR_PY_INT_FAIL
;
944 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
948 LIBVIRT_BEGIN_ALLOW_THREADS
;
949 i_retval
= virDomainSetBlkioParameters(domain
, new_params
, size
, flags
);
950 LIBVIRT_END_ALLOW_THREADS
;
953 ret
= VIR_PY_INT_FAIL
;
957 ret
= VIR_PY_INT_SUCCESS
;
960 virTypedParameterArrayClear(params
, nparams
);
962 VIR_FREE(new_params
);
967 libvirt_virDomainGetBlkioParameters(PyObject
*self ATTRIBUTE_UNUSED
,
971 PyObject
*pyobj_domain
;
972 PyObject
*ret
= NULL
;
976 virTypedParameterPtr params
;
978 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetBlkioParameters",
979 &pyobj_domain
, &flags
))
981 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
983 LIBVIRT_BEGIN_ALLOW_THREADS
;
984 i_retval
= virDomainGetBlkioParameters(domain
, NULL
, &nparams
, flags
);
985 LIBVIRT_END_ALLOW_THREADS
;
993 if (VIR_ALLOC_N(params
, nparams
) < 0)
994 return PyErr_NoMemory();
996 LIBVIRT_BEGIN_ALLOW_THREADS
;
997 i_retval
= virDomainGetBlkioParameters(domain
, params
, &nparams
, flags
);
998 LIBVIRT_END_ALLOW_THREADS
;
1005 ret
= getPyVirTypedParameter(params
, nparams
);
1008 virTypedParameterArrayClear(params
, nparams
);
1014 libvirt_virDomainSetMemoryParameters(PyObject
*self ATTRIBUTE_UNUSED
,
1017 virDomainPtr domain
;
1018 PyObject
*pyobj_domain
, *info
;
1019 PyObject
*ret
= NULL
;
1022 Py_ssize_t size
= 0;
1024 virTypedParameterPtr params
, new_params
;
1026 if (!PyArg_ParseTuple(args
,
1027 (char *)"OOi:virDomainSetMemoryParameters",
1028 &pyobj_domain
, &info
, &flags
))
1030 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1032 if ((size
= PyDict_Size(info
)) < 0)
1036 PyErr_Format(PyExc_LookupError
,
1037 "Need non-empty dictionary to set attributes");
1041 LIBVIRT_BEGIN_ALLOW_THREADS
;
1042 i_retval
= virDomainGetMemoryParameters(domain
, NULL
, &nparams
, flags
);
1043 LIBVIRT_END_ALLOW_THREADS
;
1046 return VIR_PY_INT_FAIL
;
1049 PyErr_Format(PyExc_LookupError
,
1050 "Domain has no settable attributes");
1054 if (VIR_ALLOC_N(params
, nparams
) < 0)
1055 return PyErr_NoMemory();
1057 LIBVIRT_BEGIN_ALLOW_THREADS
;
1058 i_retval
= virDomainGetMemoryParameters(domain
, params
, &nparams
, flags
);
1059 LIBVIRT_END_ALLOW_THREADS
;
1062 ret
= VIR_PY_INT_FAIL
;
1066 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
1070 LIBVIRT_BEGIN_ALLOW_THREADS
;
1071 i_retval
= virDomainSetMemoryParameters(domain
, new_params
, size
, flags
);
1072 LIBVIRT_END_ALLOW_THREADS
;
1075 ret
= VIR_PY_INT_FAIL
;
1079 ret
= VIR_PY_INT_SUCCESS
;
1082 virTypedParameterArrayClear(params
, nparams
);
1084 VIR_FREE(new_params
);
1089 libvirt_virDomainGetMemoryParameters(PyObject
*self ATTRIBUTE_UNUSED
,
1092 virDomainPtr domain
;
1093 PyObject
*pyobj_domain
;
1094 PyObject
*ret
= NULL
;
1098 virTypedParameterPtr params
;
1100 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetMemoryParameters",
1101 &pyobj_domain
, &flags
))
1103 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1105 LIBVIRT_BEGIN_ALLOW_THREADS
;
1106 i_retval
= virDomainGetMemoryParameters(domain
, NULL
, &nparams
, flags
);
1107 LIBVIRT_END_ALLOW_THREADS
;
1113 return PyDict_New();
1115 if (VIR_ALLOC_N(params
, nparams
) < 0)
1116 return PyErr_NoMemory();
1118 LIBVIRT_BEGIN_ALLOW_THREADS
;
1119 i_retval
= virDomainGetMemoryParameters(domain
, params
, &nparams
, flags
);
1120 LIBVIRT_END_ALLOW_THREADS
;
1127 ret
= getPyVirTypedParameter(params
, nparams
);
1130 virTypedParameterArrayClear(params
, nparams
);
1136 libvirt_virDomainSetNumaParameters(PyObject
*self ATTRIBUTE_UNUSED
,
1139 virDomainPtr domain
;
1140 PyObject
*pyobj_domain
, *info
;
1141 PyObject
*ret
= NULL
;
1144 Py_ssize_t size
= 0;
1146 virTypedParameterPtr params
, new_params
;
1148 if (!PyArg_ParseTuple(args
,
1149 (char *)"OOi:virDomainSetNumaParameters",
1150 &pyobj_domain
, &info
, &flags
))
1152 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1154 if ((size
= PyDict_Size(info
)) < 0)
1158 PyErr_Format(PyExc_LookupError
,
1159 "Need non-empty dictionary to set attributes");
1163 LIBVIRT_BEGIN_ALLOW_THREADS
;
1164 i_retval
= virDomainGetNumaParameters(domain
, NULL
, &nparams
, flags
);
1165 LIBVIRT_END_ALLOW_THREADS
;
1168 return VIR_PY_INT_FAIL
;
1171 PyErr_Format(PyExc_LookupError
,
1172 "Domain has no settable attributes");
1176 if (VIR_ALLOC_N(params
, nparams
) < 0)
1177 return PyErr_NoMemory();
1179 LIBVIRT_BEGIN_ALLOW_THREADS
;
1180 i_retval
= virDomainGetNumaParameters(domain
, params
, &nparams
, flags
);
1181 LIBVIRT_END_ALLOW_THREADS
;
1184 ret
= VIR_PY_INT_FAIL
;
1188 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
1192 LIBVIRT_BEGIN_ALLOW_THREADS
;
1193 i_retval
= virDomainSetNumaParameters(domain
, new_params
, size
, flags
);
1194 LIBVIRT_END_ALLOW_THREADS
;
1197 ret
= VIR_PY_INT_FAIL
;
1201 ret
= VIR_PY_INT_SUCCESS
;
1204 virTypedParameterArrayClear(params
, nparams
);
1206 VIR_FREE(new_params
);
1211 libvirt_virDomainGetNumaParameters(PyObject
*self ATTRIBUTE_UNUSED
,
1214 virDomainPtr domain
;
1215 PyObject
*pyobj_domain
;
1216 PyObject
*ret
= NULL
;
1220 virTypedParameterPtr params
;
1222 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetNumaParameters",
1223 &pyobj_domain
, &flags
))
1225 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1227 LIBVIRT_BEGIN_ALLOW_THREADS
;
1228 i_retval
= virDomainGetNumaParameters(domain
, NULL
, &nparams
, flags
);
1229 LIBVIRT_END_ALLOW_THREADS
;
1235 return PyDict_New();
1237 if (VIR_ALLOC_N(params
, nparams
) < 0)
1238 return PyErr_NoMemory();
1240 LIBVIRT_BEGIN_ALLOW_THREADS
;
1241 i_retval
= virDomainGetNumaParameters(domain
, params
, &nparams
, flags
);
1242 LIBVIRT_END_ALLOW_THREADS
;
1249 ret
= getPyVirTypedParameter(params
, nparams
);
1252 virTypedParameterArrayClear(params
, nparams
);
1258 libvirt_virDomainSetInterfaceParameters(PyObject
*self ATTRIBUTE_UNUSED
,
1261 virDomainPtr domain
;
1262 PyObject
*pyobj_domain
, *info
;
1263 PyObject
*ret
= NULL
;
1266 Py_ssize_t size
= 0;
1268 const char *device
= NULL
;
1269 virTypedParameterPtr params
, new_params
;
1271 if (!PyArg_ParseTuple(args
,
1272 (char *)"OzOi:virDomainSetInterfaceParameters",
1273 &pyobj_domain
, &device
, &info
, &flags
))
1275 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1277 if ((size
= PyDict_Size(info
)) < 0)
1281 PyErr_Format(PyExc_LookupError
,
1282 "Need non-empty dictionary to set attributes");
1286 LIBVIRT_BEGIN_ALLOW_THREADS
;
1287 i_retval
= virDomainGetInterfaceParameters(domain
, device
, NULL
, &nparams
, flags
);
1288 LIBVIRT_END_ALLOW_THREADS
;
1291 return VIR_PY_INT_FAIL
;
1294 PyErr_Format(PyExc_LookupError
,
1295 "Domain has no settable attributes");
1299 if (VIR_ALLOC_N(params
, nparams
) < 0)
1300 return PyErr_NoMemory();
1302 LIBVIRT_BEGIN_ALLOW_THREADS
;
1303 i_retval
= virDomainGetInterfaceParameters(domain
, device
, params
, &nparams
, flags
);
1304 LIBVIRT_END_ALLOW_THREADS
;
1307 ret
= VIR_PY_INT_FAIL
;
1311 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
1315 LIBVIRT_BEGIN_ALLOW_THREADS
;
1316 i_retval
= virDomainSetInterfaceParameters(domain
, device
, new_params
, size
, flags
);
1317 LIBVIRT_END_ALLOW_THREADS
;
1320 ret
= VIR_PY_INT_FAIL
;
1324 ret
= VIR_PY_INT_SUCCESS
;
1327 virTypedParameterArrayClear(params
, nparams
);
1329 VIR_FREE(new_params
);
1334 libvirt_virDomainGetInterfaceParameters(PyObject
*self ATTRIBUTE_UNUSED
,
1337 virDomainPtr domain
;
1338 PyObject
*pyobj_domain
;
1339 PyObject
*ret
= NULL
;
1343 const char *device
= NULL
;
1344 virTypedParameterPtr params
;
1346 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainGetInterfaceParameters",
1347 &pyobj_domain
, &device
, &flags
))
1349 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1351 LIBVIRT_BEGIN_ALLOW_THREADS
;
1352 i_retval
= virDomainGetInterfaceParameters(domain
, device
, NULL
, &nparams
, flags
);
1353 LIBVIRT_END_ALLOW_THREADS
;
1359 return PyDict_New();
1361 if (VIR_ALLOC_N(params
, nparams
) < 0)
1362 return PyErr_NoMemory();
1364 LIBVIRT_BEGIN_ALLOW_THREADS
;
1365 i_retval
= virDomainGetInterfaceParameters(domain
, device
, params
, &nparams
, flags
);
1366 LIBVIRT_END_ALLOW_THREADS
;
1373 ret
= getPyVirTypedParameter(params
, nparams
);
1376 virTypedParameterArrayClear(params
, nparams
);
1382 libvirt_virDomainGetVcpus(PyObject
*self ATTRIBUTE_UNUSED
,
1384 virDomainPtr domain
;
1385 PyObject
*pyobj_domain
, *pyretval
= NULL
, *pycpuinfo
= NULL
, *pycpumap
= NULL
;
1386 virNodeInfo nodeinfo
;
1387 virDomainInfo dominfo
;
1388 virVcpuInfoPtr cpuinfo
= NULL
;
1389 unsigned char *cpumap
= NULL
;
1390 size_t cpumaplen
, i
;
1393 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetVcpus",
1396 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1398 LIBVIRT_BEGIN_ALLOW_THREADS
;
1399 i_retval
= virNodeGetInfo(virDomainGetConnect(domain
), &nodeinfo
);
1400 LIBVIRT_END_ALLOW_THREADS
;
1404 LIBVIRT_BEGIN_ALLOW_THREADS
;
1405 i_retval
= virDomainGetInfo(domain
, &dominfo
);
1406 LIBVIRT_END_ALLOW_THREADS
;
1410 if (VIR_ALLOC_N(cpuinfo
, dominfo
.nrVirtCpu
) < 0)
1413 cpumaplen
= VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo
));
1414 if (xalloc_oversized(dominfo
.nrVirtCpu
, cpumaplen
) ||
1415 VIR_ALLOC_N(cpumap
, dominfo
.nrVirtCpu
* cpumaplen
) < 0)
1418 LIBVIRT_BEGIN_ALLOW_THREADS
;
1419 i_retval
= virDomainGetVcpus(domain
,
1420 cpuinfo
, dominfo
.nrVirtCpu
,
1422 LIBVIRT_END_ALLOW_THREADS
;
1426 /* convert to a Python tuple of long objects */
1427 if ((pyretval
= PyTuple_New(2)) == NULL
)
1429 if ((pycpuinfo
= PyList_New(dominfo
.nrVirtCpu
)) == NULL
)
1431 if ((pycpumap
= PyList_New(dominfo
.nrVirtCpu
)) == NULL
)
1434 for (i
= 0 ; i
< dominfo
.nrVirtCpu
; i
++) {
1435 PyObject
*info
= PyTuple_New(4);
1438 PyTuple_SetItem(info
, 0, PyInt_FromLong((long)cpuinfo
[i
].number
));
1439 PyTuple_SetItem(info
, 1, PyInt_FromLong((long)cpuinfo
[i
].state
));
1440 PyTuple_SetItem(info
, 2, PyLong_FromLongLong((long long)cpuinfo
[i
].cpuTime
));
1441 PyTuple_SetItem(info
, 3, PyInt_FromLong((long)cpuinfo
[i
].cpu
));
1442 PyList_SetItem(pycpuinfo
, i
, info
);
1444 for (i
= 0 ; i
< dominfo
.nrVirtCpu
; i
++) {
1445 PyObject
*info
= PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo
));
1449 for (j
= 0 ; j
< VIR_NODEINFO_MAXCPUS(nodeinfo
) ; j
++) {
1450 PyTuple_SetItem(info
, j
, PyBool_FromLong(VIR_CPU_USABLE(cpumap
, cpumaplen
, i
, j
)));
1452 PyList_SetItem(pycpumap
, i
, info
);
1454 PyTuple_SetItem(pyretval
, 0, pycpuinfo
);
1455 PyTuple_SetItem(pyretval
, 1, pycpumap
);
1465 /* NB, Py_DECREF is a badly defined macro, so we require
1466 * braces here to avoid 'ambiguous else' warnings from
1468 * NB. this comment is true at of time of writing wrt to
1469 * at least python2.5.
1471 if (pyretval
) { Py_DECREF(pyretval
); }
1472 if (pycpuinfo
) { Py_DECREF(pycpuinfo
); }
1473 if (pycpumap
) { Py_DECREF(pycpumap
); }
1479 libvirt_virDomainPinVcpu(PyObject
*self ATTRIBUTE_UNUSED
,
1481 virDomainPtr domain
;
1482 PyObject
*pyobj_domain
, *pycpumap
, *truth
;
1483 virNodeInfo nodeinfo
;
1484 unsigned char *cpumap
;
1485 int cpumaplen
, i
, vcpu
;
1488 if (!PyArg_ParseTuple(args
, (char *)"OiO:virDomainPinVcpu",
1489 &pyobj_domain
, &vcpu
, &pycpumap
))
1491 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1493 LIBVIRT_BEGIN_ALLOW_THREADS
;
1494 i_retval
= virNodeGetInfo(virDomainGetConnect(domain
), &nodeinfo
);
1495 LIBVIRT_END_ALLOW_THREADS
;
1497 return VIR_PY_INT_FAIL
;
1499 cpumaplen
= VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo
));
1500 if (VIR_ALLOC_N(cpumap
, cpumaplen
) < 0)
1501 return VIR_PY_INT_FAIL
;
1503 truth
= PyBool_FromLong(1);
1504 for (i
= 0 ; i
< VIR_NODEINFO_MAXCPUS(nodeinfo
) ; i
++) {
1505 PyObject
*flag
= PyTuple_GetItem(pycpumap
, i
);
1507 VIR_USE_CPU(cpumap
, i
);
1509 VIR_UNUSE_CPU(cpumap
, i
);
1512 LIBVIRT_BEGIN_ALLOW_THREADS
;
1513 i_retval
= virDomainPinVcpu(domain
, vcpu
, cpumap
, cpumaplen
);
1514 LIBVIRT_END_ALLOW_THREADS
;
1519 return VIR_PY_INT_FAIL
;
1521 return VIR_PY_INT_SUCCESS
;
1525 libvirt_virDomainPinVcpuFlags(PyObject
*self ATTRIBUTE_UNUSED
,
1527 virDomainPtr domain
;
1528 PyObject
*pyobj_domain
, *pycpumap
, *truth
;
1529 virNodeInfo nodeinfo
;
1530 unsigned char *cpumap
;
1531 int cpumaplen
, i
, vcpu
;
1535 if (!PyArg_ParseTuple(args
, (char *)"OiOi:virDomainPinVcpuFlags",
1536 &pyobj_domain
, &vcpu
, &pycpumap
, &flags
))
1538 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1540 LIBVIRT_BEGIN_ALLOW_THREADS
;
1541 i_retval
= virNodeGetInfo(virDomainGetConnect(domain
), &nodeinfo
);
1542 LIBVIRT_END_ALLOW_THREADS
;
1544 return VIR_PY_INT_FAIL
;
1546 cpumaplen
= VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo
));
1547 if (VIR_ALLOC_N(cpumap
, cpumaplen
) < 0)
1548 return VIR_PY_INT_FAIL
;
1550 truth
= PyBool_FromLong(1);
1551 for (i
= 0 ; i
< VIR_NODEINFO_MAXCPUS(nodeinfo
) ; i
++) {
1552 PyObject
*flag
= PyTuple_GetItem(pycpumap
, i
);
1554 VIR_USE_CPU(cpumap
, i
);
1556 VIR_UNUSE_CPU(cpumap
, i
);
1559 LIBVIRT_BEGIN_ALLOW_THREADS
;
1560 i_retval
= virDomainPinVcpuFlags(domain
, vcpu
, cpumap
, cpumaplen
, flags
);
1561 LIBVIRT_END_ALLOW_THREADS
;
1566 return VIR_PY_INT_FAIL
;
1568 return VIR_PY_INT_SUCCESS
;
1572 libvirt_virDomainGetVcpuPinInfo(PyObject
*self ATTRIBUTE_UNUSED
,
1574 virDomainPtr domain
;
1575 PyObject
*pyobj_domain
, *pycpumaps
= NULL
;
1576 virNodeInfo nodeinfo
;
1577 virDomainInfo dominfo
;
1578 unsigned char *cpumaps
;
1579 size_t cpumaplen
, vcpu
, pcpu
;
1583 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetVcpuPinInfo",
1584 &pyobj_domain
, &flags
))
1586 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
1588 LIBVIRT_BEGIN_ALLOW_THREADS
;
1589 i_retval
= virNodeGetInfo(virDomainGetConnect(domain
), &nodeinfo
);
1590 LIBVIRT_END_ALLOW_THREADS
;
1594 LIBVIRT_BEGIN_ALLOW_THREADS
;
1595 i_retval
= virDomainGetInfo(domain
, &dominfo
);
1596 LIBVIRT_END_ALLOW_THREADS
;
1600 cpumaplen
= VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo
));
1601 if (xalloc_oversized(dominfo
.nrVirtCpu
, cpumaplen
) ||
1602 VIR_ALLOC_N(cpumaps
, dominfo
.nrVirtCpu
* cpumaplen
) < 0)
1605 LIBVIRT_BEGIN_ALLOW_THREADS
;
1606 i_retval
= virDomainGetVcpuPinInfo(domain
, dominfo
.nrVirtCpu
,
1607 cpumaps
, cpumaplen
, flags
);
1608 LIBVIRT_END_ALLOW_THREADS
;
1612 if ((pycpumaps
= PyList_New(dominfo
.nrVirtCpu
)) == NULL
)
1615 for (vcpu
= 0; vcpu
< dominfo
.nrVirtCpu
; vcpu
++) {
1616 PyObject
*mapinfo
= PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo
));
1617 if (mapinfo
== NULL
)
1620 for (pcpu
= 0; pcpu
< VIR_NODEINFO_MAXCPUS(nodeinfo
); pcpu
++) {
1621 PyTuple_SetItem(mapinfo
, pcpu
,
1622 PyBool_FromLong(VIR_CPU_USABLE(cpumaps
, cpumaplen
, vcpu
, pcpu
)));
1624 PyList_SetItem(pycpumaps
, vcpu
, mapinfo
);
1634 if (pycpumaps
) { Py_DECREF(pycpumaps
);}
1639 /************************************************************************
1641 * Global error handler at the Python level *
1643 ************************************************************************/
1645 static PyObject
*libvirt_virPythonErrorFuncHandler
= NULL
;
1646 static PyObject
*libvirt_virPythonErrorFuncCtxt
= NULL
;
1649 libvirt_virGetLastError(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args ATTRIBUTE_UNUSED
)
1654 if ((err
= virGetLastError()) == NULL
)
1657 if ((info
= PyTuple_New(9)) == NULL
)
1659 PyTuple_SetItem(info
, 0, PyInt_FromLong((long) err
->code
));
1660 PyTuple_SetItem(info
, 1, PyInt_FromLong((long) err
->domain
));
1661 PyTuple_SetItem(info
, 2, libvirt_constcharPtrWrap(err
->message
));
1662 PyTuple_SetItem(info
, 3, PyInt_FromLong((long) err
->level
));
1663 PyTuple_SetItem(info
, 4, libvirt_constcharPtrWrap(err
->str1
));
1664 PyTuple_SetItem(info
, 5, libvirt_constcharPtrWrap(err
->str2
));
1665 PyTuple_SetItem(info
, 6, libvirt_constcharPtrWrap(err
->str3
));
1666 PyTuple_SetItem(info
, 7, PyInt_FromLong((long) err
->int1
));
1667 PyTuple_SetItem(info
, 8, PyInt_FromLong((long) err
->int2
));
1673 libvirt_virConnGetLastError(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
1678 PyObject
*pyobj_conn
;
1680 if (!PyArg_ParseTuple(args
, (char *)"O:virConGetLastError", &pyobj_conn
))
1682 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1684 LIBVIRT_BEGIN_ALLOW_THREADS
;
1685 err
= virConnGetLastError(conn
);
1686 LIBVIRT_END_ALLOW_THREADS
;
1690 if ((info
= PyTuple_New(9)) == NULL
)
1692 PyTuple_SetItem(info
, 0, PyInt_FromLong((long) err
->code
));
1693 PyTuple_SetItem(info
, 1, PyInt_FromLong((long) err
->domain
));
1694 PyTuple_SetItem(info
, 2, libvirt_constcharPtrWrap(err
->message
));
1695 PyTuple_SetItem(info
, 3, PyInt_FromLong((long) err
->level
));
1696 PyTuple_SetItem(info
, 4, libvirt_constcharPtrWrap(err
->str1
));
1697 PyTuple_SetItem(info
, 5, libvirt_constcharPtrWrap(err
->str2
));
1698 PyTuple_SetItem(info
, 6, libvirt_constcharPtrWrap(err
->str3
));
1699 PyTuple_SetItem(info
, 7, PyInt_FromLong((long) err
->int1
));
1700 PyTuple_SetItem(info
, 8, PyInt_FromLong((long) err
->int2
));
1706 libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED
void *ctx
, virErrorPtr err
)
1708 PyObject
*list
, *info
;
1711 DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx
,
1714 if ((err
== NULL
) || (err
->code
== VIR_ERR_OK
))
1717 LIBVIRT_ENSURE_THREAD_STATE
;
1719 if ((libvirt_virPythonErrorFuncHandler
== NULL
) ||
1720 (libvirt_virPythonErrorFuncHandler
== Py_None
)) {
1721 virDefaultErrorFunc(err
);
1723 list
= PyTuple_New(2);
1724 info
= PyTuple_New(9);
1725 PyTuple_SetItem(list
, 0, libvirt_virPythonErrorFuncCtxt
);
1726 PyTuple_SetItem(list
, 1, info
);
1727 Py_XINCREF(libvirt_virPythonErrorFuncCtxt
);
1728 PyTuple_SetItem(info
, 0, PyInt_FromLong((long) err
->code
));
1729 PyTuple_SetItem(info
, 1, PyInt_FromLong((long) err
->domain
));
1730 PyTuple_SetItem(info
, 2, libvirt_constcharPtrWrap(err
->message
));
1731 PyTuple_SetItem(info
, 3, PyInt_FromLong((long) err
->level
));
1732 PyTuple_SetItem(info
, 4, libvirt_constcharPtrWrap(err
->str1
));
1733 PyTuple_SetItem(info
, 5, libvirt_constcharPtrWrap(err
->str2
));
1734 PyTuple_SetItem(info
, 6, libvirt_constcharPtrWrap(err
->str3
));
1735 PyTuple_SetItem(info
, 7, PyInt_FromLong((long) err
->int1
));
1736 PyTuple_SetItem(info
, 8, PyInt_FromLong((long) err
->int2
));
1737 /* TODO pass conn and dom if available */
1738 result
= PyEval_CallObject(libvirt_virPythonErrorFuncHandler
, list
);
1743 LIBVIRT_RELEASE_THREAD_STATE
;
1747 libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject
* self
,
1750 PyObject
*py_retval
;
1752 PyObject
*pyobj_ctx
;
1754 if (!PyArg_ParseTuple
1755 (args
, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f
,
1759 DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx
,
1762 virSetErrorFunc(NULL
, libvirt_virErrorFuncHandler
);
1763 if (libvirt_virPythonErrorFuncHandler
!= NULL
) {
1764 Py_XDECREF(libvirt_virPythonErrorFuncHandler
);
1766 if (libvirt_virPythonErrorFuncCtxt
!= NULL
) {
1767 Py_XDECREF(libvirt_virPythonErrorFuncCtxt
);
1770 if ((pyobj_f
== Py_None
) && (pyobj_ctx
== Py_None
)) {
1771 libvirt_virPythonErrorFuncHandler
= NULL
;
1772 libvirt_virPythonErrorFuncCtxt
= NULL
;
1774 Py_XINCREF(pyobj_ctx
);
1775 Py_XINCREF(pyobj_f
);
1777 /* TODO: check f is a function ! */
1778 libvirt_virPythonErrorFuncHandler
= pyobj_f
;
1779 libvirt_virPythonErrorFuncCtxt
= pyobj_ctx
;
1782 py_retval
= libvirt_intWrap(1);
1786 static int virConnectCredCallbackWrapper(virConnectCredentialPtr cred
,
1791 PyObject
*pyauth
= (PyObject
*)cbdata
;
1797 LIBVIRT_ENSURE_THREAD_STATE
;
1799 pycb
= PyList_GetItem(pyauth
, 1);
1800 pycbdata
= PyList_GetItem(pyauth
, 2);
1802 list
= PyTuple_New(2);
1803 pycred
= PyTuple_New(ncred
);
1804 for (i
= 0 ; i
< ncred
; i
++) {
1805 PyObject
*pycreditem
;
1806 pycreditem
= PyList_New(5);
1808 PyTuple_SetItem(pycred
, i
, pycreditem
);
1809 PyList_SetItem(pycreditem
, 0, PyInt_FromLong((long) cred
[i
].type
));
1810 PyList_SetItem(pycreditem
, 1, PyString_FromString(cred
[i
].prompt
));
1811 if (cred
[i
].challenge
) {
1812 PyList_SetItem(pycreditem
, 2, PyString_FromString(cred
[i
].challenge
));
1815 PyList_SetItem(pycreditem
, 2, Py_None
);
1817 if (cred
[i
].defresult
) {
1818 PyList_SetItem(pycreditem
, 3, PyString_FromString(cred
[i
].defresult
));
1821 PyList_SetItem(pycreditem
, 3, Py_None
);
1823 PyList_SetItem(pycreditem
, 4, Py_None
);
1826 PyTuple_SetItem(list
, 0, pycred
);
1827 Py_XINCREF(pycbdata
);
1828 PyTuple_SetItem(list
, 1, pycbdata
);
1831 pyret
= PyEval_CallObject(pycb
, list
);
1832 if (PyErr_Occurred())
1835 ret
= PyLong_AsLong(pyret
);
1837 for (i
= 0 ; i
< ncred
; i
++) {
1838 PyObject
*pycreditem
;
1840 char *result
= NULL
;
1841 pycreditem
= PyTuple_GetItem(pycred
, i
);
1842 pyresult
= PyList_GetItem(pycreditem
, 4);
1843 if (pyresult
!= Py_None
)
1844 result
= PyString_AsString(pyresult
);
1845 if (result
!= NULL
) {
1846 cred
[i
].result
= strdup(result
);
1847 cred
[i
].resultlen
= strlen(result
);
1849 cred
[i
].result
= NULL
;
1850 cred
[i
].resultlen
= 0;
1859 LIBVIRT_RELEASE_THREAD_STATE
;
1866 libvirt_virConnectOpenAuth(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
1867 PyObject
*py_retval
;
1868 virConnectPtr c_retval
;
1873 PyObject
*pycredtype
;
1874 virConnectAuth auth
;
1876 if (!PyArg_ParseTuple(args
, (char *)"zOi:virConnectOpenAuth", &name
, &pyauth
, &flags
))
1879 pycredtype
= PyList_GetItem(pyauth
, 0);
1880 pycredcb
= PyList_GetItem(pyauth
, 1);
1882 auth
.ncredtype
= PyList_Size(pycredtype
);
1883 if (auth
.ncredtype
) {
1885 if (VIR_ALLOC_N(auth
.credtype
, auth
.ncredtype
) < 0)
1887 for (i
= 0 ; i
< auth
.ncredtype
; i
++) {
1889 val
= PyList_GetItem(pycredtype
, i
);
1890 auth
.credtype
[i
] = (int)PyLong_AsLong(val
);
1893 auth
.cb
= pycredcb
? virConnectCredCallbackWrapper
: NULL
;
1894 auth
.cbdata
= pyauth
;
1896 LIBVIRT_BEGIN_ALLOW_THREADS
;
1898 c_retval
= virConnectOpenAuth(name
, &auth
, flags
);
1899 LIBVIRT_END_ALLOW_THREADS
;
1900 VIR_FREE(auth
.credtype
);
1901 py_retval
= libvirt_virConnectPtrWrap((virConnectPtr
) c_retval
);
1906 /************************************************************************
1908 * Wrappers for functions where generator fails *
1910 ************************************************************************/
1913 libvirt_virGetVersion (PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
1916 unsigned long libVer
, typeVer
= 0;
1919 if (!PyArg_ParseTuple (args
, (char *) "|s", &type
))
1922 LIBVIRT_BEGIN_ALLOW_THREADS
;
1925 c_retval
= virGetVersion (&libVer
, NULL
, NULL
);
1927 c_retval
= virGetVersion (&libVer
, type
, &typeVer
);
1929 LIBVIRT_END_ALLOW_THREADS
;
1935 return PyInt_FromLong (libVer
);
1937 return Py_BuildValue ((char *) "kk", libVer
, typeVer
);
1941 libvirt_virConnectGetVersion (PyObject
*self ATTRIBUTE_UNUSED
,
1944 unsigned long hvVersion
;
1947 PyObject
*pyobj_conn
;
1949 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectGetVersion",
1952 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1954 LIBVIRT_BEGIN_ALLOW_THREADS
;
1956 c_retval
= virConnectGetVersion(conn
, &hvVersion
);
1958 LIBVIRT_END_ALLOW_THREADS
;
1961 return VIR_PY_INT_FAIL
;
1963 return PyInt_FromLong (hvVersion
);
1967 libvirt_virConnectGetLibVersion (PyObject
*self ATTRIBUTE_UNUSED
,
1970 unsigned long libVer
;
1973 PyObject
*pyobj_conn
;
1975 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectGetLibVersion",
1978 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
1980 LIBVIRT_BEGIN_ALLOW_THREADS
;
1982 c_retval
= virConnectGetLibVersion(conn
, &libVer
);
1984 LIBVIRT_END_ALLOW_THREADS
;
1987 return VIR_PY_INT_FAIL
;
1989 return PyInt_FromLong (libVer
);
1993 libvirt_virConnectListDomainsID(PyObject
*self ATTRIBUTE_UNUSED
,
1995 PyObject
*py_retval
;
1996 int *ids
= NULL
, c_retval
, i
;
1998 PyObject
*pyobj_conn
;
2001 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDomains", &pyobj_conn
))
2003 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2005 LIBVIRT_BEGIN_ALLOW_THREADS
;
2006 c_retval
= virConnectNumOfDomains(conn
);
2007 LIBVIRT_END_ALLOW_THREADS
;
2012 if (VIR_ALLOC_N(ids
, c_retval
) < 0)
2015 LIBVIRT_BEGIN_ALLOW_THREADS
;
2016 c_retval
= virConnectListDomains(conn
, ids
, c_retval
);
2017 LIBVIRT_END_ALLOW_THREADS
;
2023 py_retval
= PyList_New(c_retval
);
2026 for (i
= 0;i
< c_retval
;i
++) {
2027 PyList_SetItem(py_retval
, i
, libvirt_intWrap(ids
[i
]));
2036 libvirt_virConnectListDefinedDomains(PyObject
*self ATTRIBUTE_UNUSED
,
2038 PyObject
*py_retval
;
2039 char **names
= NULL
;
2042 PyObject
*pyobj_conn
;
2045 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedDomains", &pyobj_conn
))
2047 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2049 LIBVIRT_BEGIN_ALLOW_THREADS
;
2050 c_retval
= virConnectNumOfDefinedDomains(conn
);
2051 LIBVIRT_END_ALLOW_THREADS
;
2056 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2058 LIBVIRT_BEGIN_ALLOW_THREADS
;
2059 c_retval
= virConnectListDefinedDomains(conn
, names
, c_retval
);
2060 LIBVIRT_END_ALLOW_THREADS
;
2066 py_retval
= PyList_New(c_retval
);
2069 for (i
= 0;i
< c_retval
;i
++) {
2070 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2080 libvirt_virDomainSnapshotListNames(PyObject
*self ATTRIBUTE_UNUSED
,
2082 PyObject
*py_retval
;
2083 char **names
= NULL
;
2086 PyObject
*pyobj_dom
;
2089 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainSnapshotListNames", &pyobj_dom
, &flags
))
2091 dom
= (virDomainPtr
) PyvirDomain_Get(pyobj_dom
);
2093 LIBVIRT_BEGIN_ALLOW_THREADS
;
2094 c_retval
= virDomainSnapshotNum(dom
, flags
);
2095 LIBVIRT_END_ALLOW_THREADS
;
2100 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2102 LIBVIRT_BEGIN_ALLOW_THREADS
;
2103 c_retval
= virDomainSnapshotListNames(dom
, names
, c_retval
, flags
);
2104 LIBVIRT_END_ALLOW_THREADS
;
2110 py_retval
= PyList_New(c_retval
);
2113 for (i
= 0;i
< c_retval
;i
++) {
2114 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2124 libvirt_virDomainSnapshotListChildrenNames(PyObject
*self ATTRIBUTE_UNUSED
,
2126 PyObject
*py_retval
;
2127 char **names
= NULL
;
2129 virDomainSnapshotPtr snap
;
2130 PyObject
*pyobj_snap
;
2133 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainSnapshotListChildrenNames", &pyobj_snap
, &flags
))
2135 snap
= (virDomainSnapshotPtr
) PyvirDomainSnapshot_Get(pyobj_snap
);
2137 LIBVIRT_BEGIN_ALLOW_THREADS
;
2138 c_retval
= virDomainSnapshotNumChildren(snap
, flags
);
2139 LIBVIRT_END_ALLOW_THREADS
;
2144 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2146 LIBVIRT_BEGIN_ALLOW_THREADS
;
2147 c_retval
= virDomainSnapshotListChildrenNames(snap
, names
, c_retval
, flags
);
2148 LIBVIRT_END_ALLOW_THREADS
;
2154 py_retval
= PyList_New(c_retval
);
2157 for (i
= 0;i
< c_retval
;i
++) {
2158 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2168 libvirt_virDomainRevertToSnapshot(PyObject
*self ATTRIBUTE_UNUSED
,
2171 virDomainSnapshotPtr snap
;
2172 PyObject
*pyobj_snap
;
2173 PyObject
*pyobj_dom
;
2176 if (!PyArg_ParseTuple(args
, (char *)"OOi:virDomainRevertToSnapshot", &pyobj_dom
, &pyobj_snap
, &flags
))
2178 snap
= (virDomainSnapshotPtr
) PyvirDomainSnapshot_Get(pyobj_snap
);
2180 LIBVIRT_BEGIN_ALLOW_THREADS
;
2181 c_retval
= virDomainRevertToSnapshot(snap
, flags
);
2182 LIBVIRT_END_ALLOW_THREADS
;
2184 return VIR_PY_INT_FAIL
;
2186 return PyInt_FromLong(c_retval
);
2190 libvirt_virDomainGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2191 PyObject
*py_retval
;
2193 virDomainPtr domain
;
2194 PyObject
*pyobj_domain
;
2197 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetInfo", &pyobj_domain
))
2199 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
2201 LIBVIRT_BEGIN_ALLOW_THREADS
;
2202 c_retval
= virDomainGetInfo(domain
, &info
);
2203 LIBVIRT_END_ALLOW_THREADS
;
2206 py_retval
= PyList_New(5);
2207 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.state
));
2208 PyList_SetItem(py_retval
, 1, libvirt_ulongWrap(info
.maxMem
));
2209 PyList_SetItem(py_retval
, 2, libvirt_ulongWrap(info
.memory
));
2210 PyList_SetItem(py_retval
, 3, libvirt_intWrap((int) info
.nrVirtCpu
));
2211 PyList_SetItem(py_retval
, 4,
2212 libvirt_longlongWrap((unsigned long long) info
.cpuTime
));
2217 libvirt_virDomainGetState(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
2219 PyObject
*py_retval
;
2221 virDomainPtr domain
;
2222 PyObject
*pyobj_domain
;
2227 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetState",
2228 &pyobj_domain
, &flags
))
2231 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
2233 LIBVIRT_BEGIN_ALLOW_THREADS
;
2234 c_retval
= virDomainGetState(domain
, &state
, &reason
, flags
);
2235 LIBVIRT_END_ALLOW_THREADS
;
2239 py_retval
= PyList_New(2);
2240 PyList_SetItem(py_retval
, 0, libvirt_intWrap(state
));
2241 PyList_SetItem(py_retval
, 1, libvirt_intWrap(reason
));
2246 libvirt_virDomainGetControlInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2247 PyObject
*py_retval
;
2249 virDomainPtr domain
;
2250 PyObject
*pyobj_domain
;
2251 virDomainControlInfo info
;
2254 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainGetControlInfo",
2255 &pyobj_domain
, &flags
))
2257 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
2259 LIBVIRT_BEGIN_ALLOW_THREADS
;
2260 c_retval
= virDomainGetControlInfo(domain
, &info
, flags
);
2261 LIBVIRT_END_ALLOW_THREADS
;
2264 py_retval
= PyList_New(3);
2265 PyList_SetItem(py_retval
, 0, libvirt_intWrap(info
.state
));
2266 PyList_SetItem(py_retval
, 1, libvirt_intWrap(info
.details
));
2267 PyList_SetItem(py_retval
, 2, libvirt_longlongWrap(info
.stateTime
));
2272 libvirt_virDomainGetBlockInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2273 PyObject
*py_retval
;
2275 virDomainPtr domain
;
2276 PyObject
*pyobj_domain
;
2277 virDomainBlockInfo info
;
2281 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainGetInfo", &pyobj_domain
, &path
, &flags
))
2283 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
2285 LIBVIRT_BEGIN_ALLOW_THREADS
;
2286 c_retval
= virDomainGetBlockInfo(domain
, path
, &info
, flags
);
2287 LIBVIRT_END_ALLOW_THREADS
;
2290 py_retval
= PyList_New(3);
2291 PyList_SetItem(py_retval
, 0, libvirt_ulonglongWrap(info
.capacity
));
2292 PyList_SetItem(py_retval
, 1, libvirt_ulonglongWrap(info
.allocation
));
2293 PyList_SetItem(py_retval
, 2, libvirt_ulonglongWrap(info
.physical
));
2298 libvirt_virNodeGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2299 PyObject
*py_retval
;
2302 PyObject
*pyobj_conn
;
2305 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetInfo", &pyobj_conn
))
2307 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2309 LIBVIRT_BEGIN_ALLOW_THREADS
;
2310 c_retval
= virNodeGetInfo(conn
, &info
);
2311 LIBVIRT_END_ALLOW_THREADS
;
2314 py_retval
= PyList_New(8);
2315 PyList_SetItem(py_retval
, 0, libvirt_constcharPtrWrap(&info
.model
[0]));
2316 PyList_SetItem(py_retval
, 1, libvirt_longWrap((long) info
.memory
>> 10));
2317 PyList_SetItem(py_retval
, 2, libvirt_intWrap((int) info
.cpus
));
2318 PyList_SetItem(py_retval
, 3, libvirt_intWrap((int) info
.mhz
));
2319 PyList_SetItem(py_retval
, 4, libvirt_intWrap((int) info
.nodes
));
2320 PyList_SetItem(py_retval
, 5, libvirt_intWrap((int) info
.sockets
));
2321 PyList_SetItem(py_retval
, 6, libvirt_intWrap((int) info
.cores
));
2322 PyList_SetItem(py_retval
, 7, libvirt_intWrap((int) info
.threads
));
2327 libvirt_virDomainGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2328 PyObject
*py_retval
;
2329 unsigned char uuid
[VIR_UUID_BUFLEN
];
2330 virDomainPtr domain
;
2331 PyObject
*pyobj_domain
;
2334 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetUUID", &pyobj_domain
))
2336 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
2340 LIBVIRT_BEGIN_ALLOW_THREADS
;
2341 c_retval
= virDomainGetUUID(domain
, &uuid
[0]);
2342 LIBVIRT_END_ALLOW_THREADS
;
2346 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
2352 libvirt_virDomainGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
2354 PyObject
*py_retval
;
2355 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
2357 PyObject
*pyobj_dom
;
2360 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetUUIDString",
2363 dom
= (virDomainPtr
) PyvirDomain_Get(pyobj_dom
);
2367 LIBVIRT_BEGIN_ALLOW_THREADS
;
2368 c_retval
= virDomainGetUUIDString(dom
, &uuidstr
[0]);
2369 LIBVIRT_END_ALLOW_THREADS
;
2374 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
2379 libvirt_virDomainLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2380 PyObject
*py_retval
;
2381 virDomainPtr c_retval
;
2383 PyObject
*pyobj_conn
;
2384 unsigned char * uuid
;
2387 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virDomainLookupByUUID", &pyobj_conn
, &uuid
, &len
))
2389 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2391 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
2394 LIBVIRT_BEGIN_ALLOW_THREADS
;
2395 c_retval
= virDomainLookupByUUID(conn
, uuid
);
2396 LIBVIRT_END_ALLOW_THREADS
;
2397 py_retval
= libvirt_virDomainPtrWrap((virDomainPtr
) c_retval
);
2403 libvirt_virConnectListNetworks(PyObject
*self ATTRIBUTE_UNUSED
,
2405 PyObject
*py_retval
;
2406 char **names
= NULL
;
2409 PyObject
*pyobj_conn
;
2412 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListNetworks", &pyobj_conn
))
2414 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2416 LIBVIRT_BEGIN_ALLOW_THREADS
;
2417 c_retval
= virConnectNumOfNetworks(conn
);
2418 LIBVIRT_END_ALLOW_THREADS
;
2423 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2425 LIBVIRT_BEGIN_ALLOW_THREADS
;
2426 c_retval
= virConnectListNetworks(conn
, names
, c_retval
);
2427 LIBVIRT_END_ALLOW_THREADS
;
2433 py_retval
= PyList_New(c_retval
);
2436 for (i
= 0;i
< c_retval
;i
++) {
2437 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2448 libvirt_virConnectListDefinedNetworks(PyObject
*self ATTRIBUTE_UNUSED
,
2450 PyObject
*py_retval
;
2451 char **names
= NULL
;
2454 PyObject
*pyobj_conn
;
2457 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedNetworks", &pyobj_conn
))
2459 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2461 LIBVIRT_BEGIN_ALLOW_THREADS
;
2462 c_retval
= virConnectNumOfDefinedNetworks(conn
);
2463 LIBVIRT_END_ALLOW_THREADS
;
2468 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2470 LIBVIRT_BEGIN_ALLOW_THREADS
;
2471 c_retval
= virConnectListDefinedNetworks(conn
, names
, c_retval
);
2472 LIBVIRT_END_ALLOW_THREADS
;
2478 py_retval
= PyList_New(c_retval
);
2481 for (i
= 0;i
< c_retval
;i
++) {
2482 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2493 libvirt_virNetworkGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2494 PyObject
*py_retval
;
2495 unsigned char uuid
[VIR_UUID_BUFLEN
];
2496 virNetworkPtr domain
;
2497 PyObject
*pyobj_domain
;
2500 if (!PyArg_ParseTuple(args
, (char *)"O:virNetworkGetUUID", &pyobj_domain
))
2502 domain
= (virNetworkPtr
) PyvirNetwork_Get(pyobj_domain
);
2506 LIBVIRT_BEGIN_ALLOW_THREADS
;
2507 c_retval
= virNetworkGetUUID(domain
, &uuid
[0]);
2508 LIBVIRT_END_ALLOW_THREADS
;
2512 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
2518 libvirt_virNetworkGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
2520 PyObject
*py_retval
;
2521 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
2523 PyObject
*pyobj_net
;
2526 if (!PyArg_ParseTuple(args
, (char *)"O:virNetworkGetUUIDString",
2529 net
= (virNetworkPtr
) PyvirNetwork_Get(pyobj_net
);
2533 LIBVIRT_BEGIN_ALLOW_THREADS
;
2534 c_retval
= virNetworkGetUUIDString(net
, &uuidstr
[0]);
2535 LIBVIRT_END_ALLOW_THREADS
;
2540 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
2545 libvirt_virNetworkLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2546 PyObject
*py_retval
;
2547 virNetworkPtr c_retval
;
2549 PyObject
*pyobj_conn
;
2550 unsigned char * uuid
;
2553 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virNetworkLookupByUUID", &pyobj_conn
, &uuid
, &len
))
2555 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2557 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
2560 LIBVIRT_BEGIN_ALLOW_THREADS
;
2561 c_retval
= virNetworkLookupByUUID(conn
, uuid
);
2562 LIBVIRT_END_ALLOW_THREADS
;
2563 py_retval
= libvirt_virNetworkPtrWrap((virNetworkPtr
) c_retval
);
2569 libvirt_virDomainGetAutostart(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2570 PyObject
*py_retval
;
2571 int c_retval
, autostart
;
2572 virDomainPtr domain
;
2573 PyObject
*pyobj_domain
;
2575 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetAutostart", &pyobj_domain
))
2578 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
2580 LIBVIRT_BEGIN_ALLOW_THREADS
;
2581 c_retval
= virDomainGetAutostart(domain
, &autostart
);
2582 LIBVIRT_END_ALLOW_THREADS
;
2585 return VIR_PY_INT_FAIL
;
2586 py_retval
= libvirt_intWrap(autostart
);
2592 libvirt_virNetworkGetAutostart(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2593 PyObject
*py_retval
;
2594 int c_retval
, autostart
;
2595 virNetworkPtr network
;
2596 PyObject
*pyobj_network
;
2598 if (!PyArg_ParseTuple(args
, (char *)"O:virNetworkGetAutostart", &pyobj_network
))
2601 network
= (virNetworkPtr
) PyvirNetwork_Get(pyobj_network
);
2603 LIBVIRT_BEGIN_ALLOW_THREADS
;
2604 c_retval
= virNetworkGetAutostart(network
, &autostart
);
2605 LIBVIRT_END_ALLOW_THREADS
;
2608 return VIR_PY_INT_FAIL
;
2609 py_retval
= libvirt_intWrap(autostart
);
2614 libvirt_virNodeGetCellsFreeMemory(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
2616 PyObject
*py_retval
;
2617 PyObject
*pyobj_conn
;
2618 int startCell
, maxCells
, c_retval
, i
;
2620 unsigned long long *freeMems
;
2622 if (!PyArg_ParseTuple(args
, (char *)"Oii:virNodeGetCellsFreeMemory", &pyobj_conn
, &startCell
, &maxCells
))
2625 if ((startCell
< 0) || (maxCells
<= 0) || (startCell
+ maxCells
> 10000))
2628 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2629 if (VIR_ALLOC_N(freeMems
, maxCells
) < 0)
2632 LIBVIRT_BEGIN_ALLOW_THREADS
;
2633 c_retval
= virNodeGetCellsFreeMemory(conn
, freeMems
, startCell
, maxCells
);
2634 LIBVIRT_END_ALLOW_THREADS
;
2640 py_retval
= PyList_New(c_retval
);
2641 for (i
= 0;i
< c_retval
;i
++) {
2642 PyList_SetItem(py_retval
, i
,
2643 libvirt_longlongWrap((long long) freeMems
[i
]));
2650 libvirt_virNodeGetCPUStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
2652 PyObject
*ret
= NULL
;
2653 PyObject
*key
= NULL
;
2654 PyObject
*val
= NULL
;
2655 PyObject
*pyobj_conn
;
2658 int cpuNum
, c_retval
, i
;
2660 virNodeCPUStatsPtr stats
= NULL
;
2662 if (!PyArg_ParseTuple(args
, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn
, &cpuNum
, &flags
))
2664 conn
= (virConnectPtr
)(PyvirConnect_Get(pyobj_conn
));
2666 LIBVIRT_BEGIN_ALLOW_THREADS
;
2667 c_retval
= virNodeGetCPUStats(conn
, cpuNum
, NULL
, &nparams
, flags
);
2668 LIBVIRT_END_ALLOW_THREADS
;
2673 if (VIR_ALLOC_N(stats
, nparams
) < 0)
2674 return PyErr_NoMemory();
2676 LIBVIRT_BEGIN_ALLOW_THREADS
;
2677 c_retval
= virNodeGetCPUStats(conn
, cpuNum
, stats
, &nparams
, flags
);
2678 LIBVIRT_END_ALLOW_THREADS
;
2685 if (!(ret
= PyDict_New()))
2688 for (i
= 0; i
< nparams
; i
++) {
2689 key
= libvirt_constcharPtrWrap(stats
[i
].field
);
2690 val
= libvirt_ulonglongWrap(stats
[i
].value
);
2692 if (!key
|| !val
|| PyDict_SetItem(ret
, key
, val
) < 0) {
2713 libvirt_virNodeGetMemoryStats(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
2715 PyObject
*ret
= NULL
;
2716 PyObject
*key
= NULL
;
2717 PyObject
*val
= NULL
;
2718 PyObject
*pyobj_conn
;
2721 int cellNum
, c_retval
, i
;
2723 virNodeMemoryStatsPtr stats
= NULL
;
2725 if (!PyArg_ParseTuple(args
, (char *)"Oii:virNodeGetMemoryStats", &pyobj_conn
, &cellNum
, &flags
))
2727 conn
= (virConnectPtr
)(PyvirConnect_Get(pyobj_conn
));
2729 LIBVIRT_BEGIN_ALLOW_THREADS
;
2730 c_retval
= virNodeGetMemoryStats(conn
, cellNum
, NULL
, &nparams
, flags
);
2731 LIBVIRT_END_ALLOW_THREADS
;
2736 if (VIR_ALLOC_N(stats
, nparams
) < 0)
2737 return PyErr_NoMemory();
2739 LIBVIRT_BEGIN_ALLOW_THREADS
;
2740 c_retval
= virNodeGetMemoryStats(conn
, cellNum
, stats
, &nparams
, flags
);
2741 LIBVIRT_END_ALLOW_THREADS
;
2748 if (!(ret
= PyDict_New()))
2751 for (i
= 0; i
< nparams
; i
++) {
2752 key
= libvirt_constcharPtrWrap(stats
[i
].field
);
2753 val
= libvirt_ulonglongWrap(stats
[i
].value
);
2755 if (!key
|| !val
|| PyDict_SetItem(ret
, key
, val
) < 0) {
2776 libvirt_virConnectListStoragePools(PyObject
*self ATTRIBUTE_UNUSED
,
2778 PyObject
*py_retval
;
2779 char **names
= NULL
;
2782 PyObject
*pyobj_conn
;
2785 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListStoragePools", &pyobj_conn
))
2787 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2789 LIBVIRT_BEGIN_ALLOW_THREADS
;
2790 c_retval
= virConnectNumOfStoragePools(conn
);
2791 LIBVIRT_END_ALLOW_THREADS
;
2796 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2798 LIBVIRT_BEGIN_ALLOW_THREADS
;
2799 c_retval
= virConnectListStoragePools(conn
, names
, c_retval
);
2800 LIBVIRT_END_ALLOW_THREADS
;
2806 py_retval
= PyList_New(c_retval
);
2807 if (py_retval
== NULL
) {
2809 for (i
= 0;i
< c_retval
;i
++)
2817 for (i
= 0;i
< c_retval
;i
++) {
2818 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2829 libvirt_virConnectListDefinedStoragePools(PyObject
*self ATTRIBUTE_UNUSED
,
2831 PyObject
*py_retval
;
2832 char **names
= NULL
;
2835 PyObject
*pyobj_conn
;
2838 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedStoragePools", &pyobj_conn
))
2840 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
2842 LIBVIRT_BEGIN_ALLOW_THREADS
;
2843 c_retval
= virConnectNumOfDefinedStoragePools(conn
);
2844 LIBVIRT_END_ALLOW_THREADS
;
2849 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2851 LIBVIRT_BEGIN_ALLOW_THREADS
;
2852 c_retval
= virConnectListDefinedStoragePools(conn
, names
, c_retval
);
2853 LIBVIRT_END_ALLOW_THREADS
;
2859 py_retval
= PyList_New(c_retval
);
2860 if (py_retval
== NULL
) {
2862 for (i
= 0;i
< c_retval
;i
++)
2870 for (i
= 0;i
< c_retval
;i
++) {
2871 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2882 libvirt_virStoragePoolListVolumes(PyObject
*self ATTRIBUTE_UNUSED
,
2884 PyObject
*py_retval
;
2885 char **names
= NULL
;
2887 virStoragePoolPtr pool
;
2888 PyObject
*pyobj_pool
;
2891 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolListVolumes", &pyobj_pool
))
2893 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
2895 LIBVIRT_BEGIN_ALLOW_THREADS
;
2896 c_retval
= virStoragePoolNumOfVolumes(pool
);
2897 LIBVIRT_END_ALLOW_THREADS
;
2902 if (VIR_ALLOC_N(names
, c_retval
) < 0)
2904 LIBVIRT_BEGIN_ALLOW_THREADS
;
2905 c_retval
= virStoragePoolListVolumes(pool
, names
, c_retval
);
2906 LIBVIRT_END_ALLOW_THREADS
;
2912 py_retval
= PyList_New(c_retval
);
2913 if (py_retval
== NULL
) {
2915 for (i
= 0;i
< c_retval
;i
++)
2923 for (i
= 0;i
< c_retval
;i
++) {
2924 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
2934 libvirt_virStoragePoolGetAutostart(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2935 PyObject
*py_retval
;
2936 int c_retval
, autostart
;
2937 virStoragePoolPtr pool
;
2938 PyObject
*pyobj_pool
;
2940 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetAutostart", &pyobj_pool
))
2943 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
2945 LIBVIRT_BEGIN_ALLOW_THREADS
;
2946 c_retval
= virStoragePoolGetAutostart(pool
, &autostart
);
2947 LIBVIRT_END_ALLOW_THREADS
;
2952 py_retval
= libvirt_intWrap(autostart
);
2957 libvirt_virStoragePoolGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2958 PyObject
*py_retval
;
2960 virStoragePoolPtr pool
;
2961 PyObject
*pyobj_pool
;
2962 virStoragePoolInfo info
;
2964 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetInfo", &pyobj_pool
))
2966 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
2968 LIBVIRT_BEGIN_ALLOW_THREADS
;
2969 c_retval
= virStoragePoolGetInfo(pool
, &info
);
2970 LIBVIRT_END_ALLOW_THREADS
;
2974 if ((py_retval
= PyList_New(4)) == NULL
)
2977 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.state
));
2978 PyList_SetItem(py_retval
, 1,
2979 libvirt_longlongWrap((unsigned long long) info
.capacity
));
2980 PyList_SetItem(py_retval
, 2,
2981 libvirt_longlongWrap((unsigned long long) info
.allocation
));
2982 PyList_SetItem(py_retval
, 3,
2983 libvirt_longlongWrap((unsigned long long) info
.available
));
2989 libvirt_virStorageVolGetInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
2990 PyObject
*py_retval
;
2992 virStorageVolPtr pool
;
2993 PyObject
*pyobj_pool
;
2994 virStorageVolInfo info
;
2996 if (!PyArg_ParseTuple(args
, (char *)"O:virStorageVolGetInfo", &pyobj_pool
))
2998 pool
= (virStorageVolPtr
) PyvirStorageVol_Get(pyobj_pool
);
3000 LIBVIRT_BEGIN_ALLOW_THREADS
;
3001 c_retval
= virStorageVolGetInfo(pool
, &info
);
3002 LIBVIRT_END_ALLOW_THREADS
;
3006 if ((py_retval
= PyList_New(3)) == NULL
)
3008 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.type
));
3009 PyList_SetItem(py_retval
, 1,
3010 libvirt_longlongWrap((unsigned long long) info
.capacity
));
3011 PyList_SetItem(py_retval
, 2,
3012 libvirt_longlongWrap((unsigned long long) info
.allocation
));
3017 libvirt_virStoragePoolGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3018 PyObject
*py_retval
;
3019 unsigned char uuid
[VIR_UUID_BUFLEN
];
3020 virStoragePoolPtr pool
;
3021 PyObject
*pyobj_pool
;
3024 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetUUID", &pyobj_pool
))
3026 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
3030 LIBVIRT_BEGIN_ALLOW_THREADS
;
3031 c_retval
= virStoragePoolGetUUID(pool
, &uuid
[0]);
3032 LIBVIRT_END_ALLOW_THREADS
;
3037 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
3043 libvirt_virStoragePoolGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
3045 PyObject
*py_retval
;
3046 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
3047 virStoragePoolPtr pool
;
3048 PyObject
*pyobj_pool
;
3051 if (!PyArg_ParseTuple(args
, (char *)"O:virStoragePoolGetUUIDString", &pyobj_pool
))
3053 pool
= (virStoragePoolPtr
) PyvirStoragePool_Get(pyobj_pool
);
3057 LIBVIRT_BEGIN_ALLOW_THREADS
;
3058 c_retval
= virStoragePoolGetUUIDString(pool
, &uuidstr
[0]);
3059 LIBVIRT_END_ALLOW_THREADS
;
3064 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
3069 libvirt_virStoragePoolLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3070 PyObject
*py_retval
;
3071 virStoragePoolPtr c_retval
;
3073 PyObject
*pyobj_conn
;
3074 unsigned char * uuid
;
3077 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virStoragePoolLookupByUUID", &pyobj_conn
, &uuid
, &len
))
3079 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3081 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
3084 LIBVIRT_BEGIN_ALLOW_THREADS
;
3085 c_retval
= virStoragePoolLookupByUUID(conn
, uuid
);
3086 LIBVIRT_END_ALLOW_THREADS
;
3087 py_retval
= libvirt_virStoragePoolPtrWrap((virStoragePoolPtr
) c_retval
);
3092 libvirt_virNodeListDevices(PyObject
*self ATTRIBUTE_UNUSED
,
3094 PyObject
*py_retval
;
3095 char **names
= NULL
;
3098 PyObject
*pyobj_conn
;
3102 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virNodeListDevices",
3103 &pyobj_conn
, &cap
, &flags
))
3105 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3107 LIBVIRT_BEGIN_ALLOW_THREADS
;
3108 c_retval
= virNodeNumOfDevices(conn
, cap
, flags
);
3109 LIBVIRT_END_ALLOW_THREADS
;
3114 if (VIR_ALLOC_N(names
, c_retval
) < 0)
3116 LIBVIRT_BEGIN_ALLOW_THREADS
;
3117 c_retval
= virNodeListDevices(conn
, cap
, names
, c_retval
, flags
);
3118 LIBVIRT_END_ALLOW_THREADS
;
3124 py_retval
= PyList_New(c_retval
);
3127 for (i
= 0;i
< c_retval
;i
++) {
3128 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
3138 libvirt_virNodeDeviceListCaps(PyObject
*self ATTRIBUTE_UNUSED
,
3140 PyObject
*py_retval
;
3141 char **names
= NULL
;
3143 virNodeDevicePtr dev
;
3144 PyObject
*pyobj_dev
;
3146 if (!PyArg_ParseTuple(args
, (char *)"O:virNodeDeviceListCaps", &pyobj_dev
))
3148 dev
= (virNodeDevicePtr
) PyvirNodeDevice_Get(pyobj_dev
);
3150 LIBVIRT_BEGIN_ALLOW_THREADS
;
3151 c_retval
= virNodeDeviceNumOfCaps(dev
);
3152 LIBVIRT_END_ALLOW_THREADS
;
3157 if (VIR_ALLOC_N(names
, c_retval
) < 0)
3159 LIBVIRT_BEGIN_ALLOW_THREADS
;
3160 c_retval
= virNodeDeviceListCaps(dev
, names
, c_retval
);
3161 LIBVIRT_END_ALLOW_THREADS
;
3167 py_retval
= PyList_New(c_retval
);
3170 for (i
= 0;i
< c_retval
;i
++) {
3171 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
3181 libvirt_virSecretGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3182 PyObject
*py_retval
;
3183 unsigned char uuid
[VIR_UUID_BUFLEN
];
3184 virSecretPtr secret
;
3185 PyObject
*pyobj_secret
;
3188 if (!PyArg_ParseTuple(args
, (char *)"O:virSecretGetUUID", &pyobj_secret
))
3190 secret
= (virSecretPtr
) PyvirSecret_Get(pyobj_secret
);
3194 LIBVIRT_BEGIN_ALLOW_THREADS
;
3195 c_retval
= virSecretGetUUID(secret
, &uuid
[0]);
3196 LIBVIRT_END_ALLOW_THREADS
;
3200 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
3206 libvirt_virSecretGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
3208 PyObject
*py_retval
;
3209 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
3211 PyObject
*pyobj_dom
;
3214 if (!PyArg_ParseTuple(args
, (char *)"O:virSecretGetUUIDString",
3217 dom
= (virSecretPtr
) PyvirSecret_Get(pyobj_dom
);
3221 LIBVIRT_BEGIN_ALLOW_THREADS
;
3222 c_retval
= virSecretGetUUIDString(dom
, &uuidstr
[0]);
3223 LIBVIRT_END_ALLOW_THREADS
;
3228 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
3233 libvirt_virSecretLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3234 PyObject
*py_retval
;
3235 virSecretPtr c_retval
;
3237 PyObject
*pyobj_conn
;
3238 unsigned char * uuid
;
3241 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virSecretLookupByUUID", &pyobj_conn
, &uuid
, &len
))
3243 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3245 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
3248 LIBVIRT_BEGIN_ALLOW_THREADS
;
3249 c_retval
= virSecretLookupByUUID(conn
, uuid
);
3250 LIBVIRT_END_ALLOW_THREADS
;
3251 py_retval
= libvirt_virSecretPtrWrap((virSecretPtr
) c_retval
);
3257 libvirt_virConnectListSecrets(PyObject
*self ATTRIBUTE_UNUSED
,
3259 PyObject
*py_retval
;
3260 char **uuids
= NULL
;
3263 PyObject
*pyobj_conn
;
3265 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListSecrets", &pyobj_conn
))
3267 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3269 LIBVIRT_BEGIN_ALLOW_THREADS
;
3270 c_retval
= virConnectNumOfSecrets(conn
);
3271 LIBVIRT_END_ALLOW_THREADS
;
3276 if (VIR_ALLOC_N(uuids
, c_retval
) < 0)
3278 LIBVIRT_BEGIN_ALLOW_THREADS
;
3279 c_retval
= virConnectListSecrets(conn
, uuids
, c_retval
);
3280 LIBVIRT_END_ALLOW_THREADS
;
3286 py_retval
= PyList_New(c_retval
);
3289 for (i
= 0;i
< c_retval
;i
++) {
3290 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(uuids
[i
]));
3300 libvirt_virSecretGetValue(PyObject
*self ATTRIBUTE_UNUSED
,
3302 PyObject
*py_retval
;
3303 unsigned char *c_retval
;
3305 virSecretPtr secret
;
3306 PyObject
*pyobj_secret
;
3309 if (!PyArg_ParseTuple(args
, (char *)"Oi:virSecretGetValue", &pyobj_secret
,
3312 secret
= (virSecretPtr
) PyvirSecret_Get(pyobj_secret
);
3314 LIBVIRT_BEGIN_ALLOW_THREADS
;
3315 c_retval
= virSecretGetValue(secret
, &size
, flags
);
3316 LIBVIRT_END_ALLOW_THREADS
;
3318 if (c_retval
== NULL
)
3321 py_retval
= PyString_FromStringAndSize((const char *)c_retval
, size
);
3328 libvirt_virSecretSetValue(PyObject
*self ATTRIBUTE_UNUSED
,
3330 PyObject
*py_retval
;
3332 virSecretPtr secret
;
3333 PyObject
*pyobj_secret
;
3338 if (!PyArg_ParseTuple(args
, (char *)"Oz#i:virSecretSetValue", &pyobj_secret
,
3339 &value
, &size
, &flags
))
3341 secret
= (virSecretPtr
) PyvirSecret_Get(pyobj_secret
);
3343 LIBVIRT_BEGIN_ALLOW_THREADS
;
3344 c_retval
= virSecretSetValue(secret
, (const unsigned char *)value
, size
,
3346 LIBVIRT_END_ALLOW_THREADS
;
3348 py_retval
= libvirt_intWrap(c_retval
);
3353 libvirt_virNWFilterGetUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3354 PyObject
*py_retval
;
3355 unsigned char uuid
[VIR_UUID_BUFLEN
];
3356 virNWFilterPtr nwfilter
;
3357 PyObject
*pyobj_nwfilter
;
3360 if (!PyArg_ParseTuple(args
, (char *)"O:virNWFilterGetUUID", &pyobj_nwfilter
))
3362 nwfilter
= (virNWFilterPtr
) PyvirNWFilter_Get(pyobj_nwfilter
);
3364 if (nwfilter
== NULL
)
3366 LIBVIRT_BEGIN_ALLOW_THREADS
;
3367 c_retval
= virNWFilterGetUUID(nwfilter
, &uuid
[0]);
3368 LIBVIRT_END_ALLOW_THREADS
;
3372 py_retval
= PyString_FromStringAndSize((char *) &uuid
[0], VIR_UUID_BUFLEN
);
3378 libvirt_virNWFilterGetUUIDString(PyObject
*self ATTRIBUTE_UNUSED
,
3380 PyObject
*py_retval
;
3381 char uuidstr
[VIR_UUID_STRING_BUFLEN
];
3382 virNWFilterPtr nwfilter
;
3383 PyObject
*pyobj_nwfilter
;
3386 if (!PyArg_ParseTuple(args
, (char *)"O:virNWFilterGetUUIDString",
3389 nwfilter
= (virNWFilterPtr
) PyvirNWFilter_Get(pyobj_nwfilter
);
3391 if (nwfilter
== NULL
)
3393 LIBVIRT_BEGIN_ALLOW_THREADS
;
3394 c_retval
= virNWFilterGetUUIDString(nwfilter
, &uuidstr
[0]);
3395 LIBVIRT_END_ALLOW_THREADS
;
3400 py_retval
= PyString_FromString((char *) &uuidstr
[0]);
3405 libvirt_virNWFilterLookupByUUID(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3406 PyObject
*py_retval
;
3407 virNWFilterPtr c_retval
;
3409 PyObject
*pyobj_conn
;
3410 unsigned char * uuid
;
3413 if (!PyArg_ParseTuple(args
, (char *)"Oz#:virNWFilterLookupByUUID", &pyobj_conn
, &uuid
, &len
))
3415 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3417 if ((uuid
== NULL
) || (len
!= VIR_UUID_BUFLEN
))
3420 LIBVIRT_BEGIN_ALLOW_THREADS
;
3421 c_retval
= virNWFilterLookupByUUID(conn
, uuid
);
3422 LIBVIRT_END_ALLOW_THREADS
;
3423 py_retval
= libvirt_virNWFilterPtrWrap((virNWFilterPtr
) c_retval
);
3429 libvirt_virConnectListNWFilters(PyObject
*self ATTRIBUTE_UNUSED
,
3431 PyObject
*py_retval
;
3432 char **uuids
= NULL
;
3435 PyObject
*pyobj_conn
;
3437 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListNWFilters", &pyobj_conn
))
3439 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3441 LIBVIRT_BEGIN_ALLOW_THREADS
;
3442 c_retval
= virConnectNumOfNWFilters(conn
);
3443 LIBVIRT_END_ALLOW_THREADS
;
3448 if (VIR_ALLOC_N(uuids
, c_retval
) < 0)
3450 LIBVIRT_BEGIN_ALLOW_THREADS
;
3451 c_retval
= virConnectListNWFilters(conn
, uuids
, c_retval
);
3452 LIBVIRT_END_ALLOW_THREADS
;
3458 py_retval
= PyList_New(c_retval
);
3461 for (i
= 0;i
< c_retval
;i
++) {
3462 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(uuids
[i
]));
3472 libvirt_virConnectListInterfaces(PyObject
*self ATTRIBUTE_UNUSED
,
3474 PyObject
*py_retval
;
3475 char **names
= NULL
;
3478 PyObject
*pyobj_conn
;
3481 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListInterfaces", &pyobj_conn
))
3483 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3485 LIBVIRT_BEGIN_ALLOW_THREADS
;
3486 c_retval
= virConnectNumOfInterfaces(conn
);
3487 LIBVIRT_END_ALLOW_THREADS
;
3492 if (VIR_ALLOC_N(names
, c_retval
) < 0)
3494 LIBVIRT_BEGIN_ALLOW_THREADS
;
3495 c_retval
= virConnectListInterfaces(conn
, names
, c_retval
);
3496 LIBVIRT_END_ALLOW_THREADS
;
3502 py_retval
= PyList_New(c_retval
);
3503 if (py_retval
== NULL
) {
3505 for (i
= 0;i
< c_retval
;i
++)
3513 for (i
= 0;i
< c_retval
;i
++) {
3514 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
3525 libvirt_virConnectListDefinedInterfaces(PyObject
*self ATTRIBUTE_UNUSED
,
3527 PyObject
*py_retval
;
3528 char **names
= NULL
;
3531 PyObject
*pyobj_conn
;
3534 if (!PyArg_ParseTuple(args
, (char *)"O:virConnectListDefinedInterfaces",
3537 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3539 LIBVIRT_BEGIN_ALLOW_THREADS
;
3540 c_retval
= virConnectNumOfDefinedInterfaces(conn
);
3541 LIBVIRT_END_ALLOW_THREADS
;
3546 if (VIR_ALLOC_N(names
, c_retval
) < 0)
3548 LIBVIRT_BEGIN_ALLOW_THREADS
;
3549 c_retval
= virConnectListDefinedInterfaces(conn
, names
, c_retval
);
3550 LIBVIRT_END_ALLOW_THREADS
;
3556 py_retval
= PyList_New(c_retval
);
3557 if (py_retval
== NULL
) {
3559 for (i
= 0;i
< c_retval
;i
++)
3567 for (i
= 0;i
< c_retval
;i
++) {
3568 PyList_SetItem(py_retval
, i
, libvirt_constcharPtrWrap(names
[i
]));
3579 libvirt_virConnectBaselineCPU(PyObject
*self ATTRIBUTE_UNUSED
,
3581 PyObject
*pyobj_conn
;
3585 const char **xmlcpus
= NULL
;
3588 PyObject
*pybase_cpu
;
3590 if (!PyArg_ParseTuple(args
, (char *)"OOi:virConnectBaselineCPU",
3591 &pyobj_conn
, &list
, &flags
))
3593 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
3595 if (PyList_Check(list
)) {
3598 ncpus
= PyList_Size(list
);
3599 if (VIR_ALLOC_N(xmlcpus
, ncpus
) < 0)
3600 return VIR_PY_INT_FAIL
;
3602 for (i
= 0; i
< ncpus
; i
++) {
3603 xmlcpus
[i
] = PyString_AsString(PyList_GetItem(list
, i
));
3604 if (xmlcpus
[i
] == NULL
) {
3606 return VIR_PY_INT_FAIL
;
3611 LIBVIRT_BEGIN_ALLOW_THREADS
;
3612 base_cpu
= virConnectBaselineCPU(conn
, xmlcpus
, ncpus
, flags
);
3613 LIBVIRT_END_ALLOW_THREADS
;
3617 if (base_cpu
== NULL
)
3618 return VIR_PY_INT_FAIL
;
3620 pybase_cpu
= PyString_FromString(base_cpu
);
3623 if (pybase_cpu
== NULL
)
3624 return VIR_PY_INT_FAIL
;
3631 libvirt_virDomainGetJobInfo(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
3632 PyObject
*py_retval
;
3634 virDomainPtr domain
;
3635 PyObject
*pyobj_domain
;
3636 virDomainJobInfo info
;
3638 if (!PyArg_ParseTuple(args
, (char *)"O:virDomainGetJobInfo", &pyobj_domain
))
3640 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
3642 LIBVIRT_BEGIN_ALLOW_THREADS
;
3643 c_retval
= virDomainGetJobInfo(domain
, &info
);
3644 LIBVIRT_END_ALLOW_THREADS
;
3647 py_retval
= PyList_New(12);
3648 PyList_SetItem(py_retval
, 0, libvirt_intWrap((int) info
.type
));
3649 PyList_SetItem(py_retval
, 1, libvirt_ulonglongWrap(info
.timeElapsed
));
3650 PyList_SetItem(py_retval
, 2, libvirt_ulonglongWrap(info
.timeRemaining
));
3651 PyList_SetItem(py_retval
, 3, libvirt_ulonglongWrap(info
.dataTotal
));
3652 PyList_SetItem(py_retval
, 4, libvirt_ulonglongWrap(info
.dataProcessed
));
3653 PyList_SetItem(py_retval
, 5, libvirt_ulonglongWrap(info
.dataRemaining
));
3654 PyList_SetItem(py_retval
, 6, libvirt_ulonglongWrap(info
.memTotal
));
3655 PyList_SetItem(py_retval
, 7, libvirt_ulonglongWrap(info
.memProcessed
));
3656 PyList_SetItem(py_retval
, 8, libvirt_ulonglongWrap(info
.memRemaining
));
3657 PyList_SetItem(py_retval
, 9, libvirt_ulonglongWrap(info
.fileTotal
));
3658 PyList_SetItem(py_retval
, 10, libvirt_ulonglongWrap(info
.fileProcessed
));
3659 PyList_SetItem(py_retval
, 11, libvirt_ulonglongWrap(info
.fileRemaining
));
3665 libvirt_virDomainGetBlockJobInfo(PyObject
*self ATTRIBUTE_UNUSED
,
3668 virDomainPtr domain
;
3669 PyObject
*pyobj_domain
;
3672 virDomainBlockJobInfo info
;
3676 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainGetBlockJobInfo",
3677 &pyobj_domain
, &path
, &flags
))
3679 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
3681 LIBVIRT_BEGIN_ALLOW_THREADS
;
3682 c_ret
= virDomainGetBlockJobInfo(domain
, path
, &info
, flags
);
3683 LIBVIRT_END_ALLOW_THREADS
;
3688 if ((ret
= PyDict_New()) == NULL
)
3691 PyDict_SetItem(ret
, libvirt_constcharPtrWrap("type"),
3692 libvirt_intWrap(info
.type
));
3693 PyDict_SetItem(ret
, libvirt_constcharPtrWrap("bandwidth"),
3694 libvirt_ulongWrap(info
.bandwidth
));
3695 PyDict_SetItem(ret
, libvirt_constcharPtrWrap("cur"),
3696 libvirt_ulonglongWrap(info
.cur
));
3697 PyDict_SetItem(ret
, libvirt_constcharPtrWrap("end"),
3698 libvirt_ulonglongWrap(info
.end
));
3704 libvirt_virDomainSetBlockIoTune(PyObject
*self ATTRIBUTE_UNUSED
,
3707 virDomainPtr domain
;
3708 PyObject
*pyobj_domain
, *info
;
3709 PyObject
*ret
= NULL
;
3712 Py_ssize_t size
= 0;
3715 virTypedParameterPtr params
, new_params
;
3717 if (!PyArg_ParseTuple(args
, (char *)"OzOi:virDomainSetBlockIoTune",
3718 &pyobj_domain
, &disk
, &info
, &flags
))
3720 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
3722 if ((size
= PyDict_Size(info
)) < 0)
3726 PyErr_Format(PyExc_LookupError
,
3727 "Need non-empty dictionary to set attributes");
3731 LIBVIRT_BEGIN_ALLOW_THREADS
;
3732 i_retval
= virDomainGetBlockIoTune(domain
, disk
, NULL
, &nparams
, flags
);
3733 LIBVIRT_END_ALLOW_THREADS
;
3736 return VIR_PY_INT_FAIL
;
3739 PyErr_Format(PyExc_LookupError
,
3740 "Domain has no settable attributes");
3744 if (VIR_ALLOC_N(params
, nparams
) < 0)
3745 return PyErr_NoMemory();
3747 LIBVIRT_BEGIN_ALLOW_THREADS
;
3748 i_retval
= virDomainGetBlockIoTune(domain
, disk
, params
, &nparams
, flags
);
3749 LIBVIRT_END_ALLOW_THREADS
;
3752 ret
= VIR_PY_INT_FAIL
;
3756 new_params
= setPyVirTypedParameter(info
, params
, nparams
);
3760 LIBVIRT_BEGIN_ALLOW_THREADS
;
3761 i_retval
= virDomainSetBlockIoTune(domain
, disk
, new_params
, size
, flags
);
3762 LIBVIRT_END_ALLOW_THREADS
;
3765 ret
= VIR_PY_INT_FAIL
;
3769 ret
= VIR_PY_INT_SUCCESS
;
3772 virTypedParameterArrayClear(params
, nparams
);
3774 VIR_FREE(new_params
);
3779 libvirt_virDomainGetBlockIoTune(PyObject
*self ATTRIBUTE_UNUSED
,
3782 virDomainPtr domain
;
3783 PyObject
*pyobj_domain
;
3784 PyObject
*ret
= NULL
;
3789 virTypedParameterPtr params
;
3791 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainGetBlockIoTune",
3792 &pyobj_domain
, &disk
, &flags
))
3794 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
3796 LIBVIRT_BEGIN_ALLOW_THREADS
;
3797 i_retval
= virDomainGetBlockIoTune(domain
, disk
, NULL
, &nparams
, flags
);
3798 LIBVIRT_END_ALLOW_THREADS
;
3804 return PyDict_New();
3806 if (VIR_ALLOC_N(params
, nparams
) < 0)
3807 return PyErr_NoMemory();
3809 LIBVIRT_BEGIN_ALLOW_THREADS
;
3810 i_retval
= virDomainGetBlockIoTune(domain
, disk
, params
, &nparams
, flags
);
3811 LIBVIRT_END_ALLOW_THREADS
;
3818 ret
= getPyVirTypedParameter(params
, nparams
);
3821 virTypedParameterArrayClear(params
, nparams
);
3827 libvirt_virDomainGetDiskErrors(PyObject
*self ATTRIBUTE_UNUSED
,
3830 PyObject
*py_retval
= VIR_PY_NONE
;
3831 virDomainPtr domain
;
3832 PyObject
*pyobj_domain
;
3834 virDomainDiskErrorPtr disks
= NULL
;
3835 unsigned int ndisks
;
3839 if (!PyArg_ParseTuple(args
, (char *) "Oi:virDomainGetDiskErrors",
3840 &pyobj_domain
, &flags
))
3843 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
3845 if ((count
= virDomainGetDiskErrors(domain
, NULL
, 0, 0)) < 0)
3850 if (VIR_ALLOC_N(disks
, ndisks
) < 0)
3853 LIBVIRT_BEGIN_ALLOW_THREADS
;
3854 count
= virDomainGetDiskErrors(domain
, disks
, ndisks
, 0);
3855 LIBVIRT_END_ALLOW_THREADS
;
3861 if (!(py_retval
= PyDict_New()))
3864 for (i
= 0; i
< count
; i
++) {
3865 PyDict_SetItem(py_retval
,
3866 libvirt_constcharPtrWrap(disks
[i
].disk
),
3867 libvirt_intWrap(disks
[i
].error
));
3872 for (i
= 0; i
< count
; i
++)
3873 VIR_FREE(disks
[i
].disk
);
3879 /*******************************************
3880 * Helper functions to avoid importing modules
3881 * for every callback
3882 *******************************************/
3883 static PyObject
*libvirt_module
= NULL
;
3884 static PyObject
*libvirt_dict
= NULL
;
3885 static PyObject
*libvirt_dom_class
= NULL
;
3888 getLibvirtModuleObject (void) {
3890 return libvirt_module
;
3892 // PyImport_ImportModule returns a new reference
3893 /* Bogus (char *) cast for RHEL-5 python API brokenness */
3894 libvirt_module
= PyImport_ImportModule((char *)"libvirt");
3895 if(!libvirt_module
) {
3896 DEBUG("%s Error importing libvirt module\n", __FUNCTION__
);
3901 return libvirt_module
;
3905 getLibvirtDictObject (void) {
3907 return libvirt_dict
;
3909 // PyModule_GetDict returns a borrowed reference
3910 libvirt_dict
= PyModule_GetDict(getLibvirtModuleObject());
3912 DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__
);
3917 Py_INCREF(libvirt_dict
);
3918 return libvirt_dict
;
3922 getLibvirtDomainClassObject (void) {
3923 if(libvirt_dom_class
)
3924 return libvirt_dom_class
;
3926 // PyDict_GetItemString returns a borrowed reference
3927 libvirt_dom_class
= PyDict_GetItemString(getLibvirtDictObject(),
3929 if(!libvirt_dom_class
) {
3930 DEBUG("%s Error importing virDomain class\n", __FUNCTION__
);
3935 Py_INCREF(libvirt_dom_class
);
3936 return libvirt_dom_class
;
3940 libvirt_lookupPythonFunc(const char *funcname
)
3942 PyObject
*python_cb
;
3944 /* Lookup the python callback */
3945 python_cb
= PyDict_GetItemString(getLibvirtDictObject(), funcname
);
3948 DEBUG("%s: Error finding %s\n", __FUNCTION__
, funcname
);
3954 if (!PyCallable_Check(python_cb
)) {
3955 DEBUG("%s: %s is not callable\n", __FUNCTION__
, funcname
);
3962 /*******************************************
3964 *******************************************/
3967 libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
3973 PyObject
*pyobj_ret
;
3975 PyObject
*pyobj_conn_inst
= (PyObject
*)opaque
;
3976 PyObject
*pyobj_dom
;
3978 PyObject
*pyobj_dom_args
;
3979 PyObject
*pyobj_dom_inst
;
3981 PyObject
*dom_class
;
3984 LIBVIRT_ENSURE_THREAD_STATE
;
3986 /* Create a python instance of this virDomainPtr */
3988 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
3989 pyobj_dom_args
= PyTuple_New(2);
3990 if(PyTuple_SetItem(pyobj_dom_args
, 0, pyobj_conn_inst
)!=0) {
3991 DEBUG("%s error creating tuple",__FUNCTION__
);
3994 if(PyTuple_SetItem(pyobj_dom_args
, 1, pyobj_dom
)!=0) {
3995 DEBUG("%s error creating tuple",__FUNCTION__
);
3998 Py_INCREF(pyobj_conn_inst
);
4000 dom_class
= getLibvirtDomainClassObject();
4001 if(!PyClass_Check(dom_class
)) {
4002 DEBUG("%s dom_class is not a class!\n", __FUNCTION__
);
4006 pyobj_dom_inst
= PyInstance_New(dom_class
,
4010 Py_DECREF(pyobj_dom_args
);
4012 if(!pyobj_dom_inst
) {
4013 DEBUG("%s Error creating a python instance of virDomain\n",
4019 /* Call the Callback Dispatcher */
4020 pyobj_ret
= PyObject_CallMethod(pyobj_conn_inst
,
4021 (char*)"_dispatchDomainEventCallbacks",
4027 Py_DECREF(pyobj_dom_inst
);
4030 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4033 Py_DECREF(pyobj_ret
);
4039 LIBVIRT_RELEASE_THREAD_STATE
;
4044 libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject
* self
,
4047 PyObject
*py_retval
; /* return value */
4048 PyObject
*pyobj_conn
; /* virConnectPtr */
4049 PyObject
*pyobj_conn_inst
; /* virConnect Python object */
4054 if (!PyArg_ParseTuple
4055 (args
, (char *) "OO:virConnectDomainEventRegister",
4056 &pyobj_conn
, &pyobj_conn_inst
)) {
4057 DEBUG("%s failed parsing tuple\n", __FUNCTION__
);
4058 return VIR_PY_INT_FAIL
;
4061 DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
4062 pyobj_conn
, pyobj_conn_inst
);
4063 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
4065 Py_INCREF(pyobj_conn_inst
);
4067 LIBVIRT_BEGIN_ALLOW_THREADS
;
4069 ret
= virConnectDomainEventRegister(conn
,
4070 libvirt_virConnectDomainEventCallback
,
4071 (void *)pyobj_conn_inst
, NULL
);
4073 LIBVIRT_END_ALLOW_THREADS
;
4075 py_retval
= libvirt_intWrap(ret
);
4080 libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject
* self
,
4083 PyObject
*py_retval
;
4084 PyObject
*pyobj_conn
;
4085 PyObject
*pyobj_conn_inst
;
4090 if (!PyArg_ParseTuple
4091 (args
, (char *) "OO:virConnectDomainEventDeregister",
4092 &pyobj_conn
, &pyobj_conn_inst
))
4095 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn
);
4097 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
4099 LIBVIRT_BEGIN_ALLOW_THREADS
;
4101 ret
= virConnectDomainEventDeregister(conn
, libvirt_virConnectDomainEventCallback
);
4103 LIBVIRT_END_ALLOW_THREADS
;
4105 Py_DECREF(pyobj_conn_inst
);
4106 py_retval
= libvirt_intWrap(ret
);
4110 /*******************************************
4112 *******************************************/
4113 static PyObject
*addHandleObj
= NULL
;
4114 static char *addHandleName
= NULL
;
4115 static PyObject
*updateHandleObj
= NULL
;
4116 static char *updateHandleName
= NULL
;
4117 static PyObject
*removeHandleObj
= NULL
;
4118 static char *removeHandleName
= NULL
;
4119 static PyObject
*addTimeoutObj
= NULL
;
4120 static char *addTimeoutName
= NULL
;
4121 static PyObject
*updateTimeoutObj
= NULL
;
4122 static char *updateTimeoutName
= NULL
;
4123 static PyObject
*removeTimeoutObj
= NULL
;
4124 static char *removeTimeoutName
= NULL
;
4126 #define NAME(fn) ( fn ## Name ? fn ## Name : # fn )
4129 libvirt_virEventAddHandleFunc (int fd
,
4131 virEventHandleCallback cb
,
4136 PyObject
*python_cb
;
4139 PyObject
*opaque_obj
;
4141 PyObject
*pyobj_args
;
4144 LIBVIRT_ENSURE_THREAD_STATE
;
4146 /* Lookup the python callback */
4147 python_cb
= libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
4151 Py_INCREF(python_cb
);
4153 /* create tuple for cb */
4154 cb_obj
= libvirt_virEventHandleCallbackWrap(cb
);
4155 ff_obj
= libvirt_virFreeCallbackWrap(ff
);
4156 opaque_obj
= libvirt_virVoidPtrWrap(opaque
);
4158 cb_args
= PyTuple_New(3);
4159 PyTuple_SetItem(cb_args
, 0, cb_obj
);
4160 PyTuple_SetItem(cb_args
, 1, opaque_obj
);
4161 PyTuple_SetItem(cb_args
, 2, ff_obj
);
4163 pyobj_args
= PyTuple_New(4);
4164 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(fd
));
4165 PyTuple_SetItem(pyobj_args
, 1, libvirt_intWrap(event
));
4166 PyTuple_SetItem(pyobj_args
, 2, python_cb
);
4167 PyTuple_SetItem(pyobj_args
, 3, cb_args
);
4169 result
= PyEval_CallObject(addHandleObj
, pyobj_args
);
4173 } else if (!PyInt_Check(result
)) {
4174 DEBUG("%s: %s should return an int\n", __FUNCTION__
, NAME(addHandle
));
4176 retval
= (int)PyInt_AsLong(result
);
4180 Py_DECREF(pyobj_args
);
4183 LIBVIRT_RELEASE_THREAD_STATE
;
4189 libvirt_virEventUpdateHandleFunc(int watch
, int event
)
4192 PyObject
*pyobj_args
;
4194 LIBVIRT_ENSURE_THREAD_STATE
;
4196 pyobj_args
= PyTuple_New(2);
4197 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(watch
));
4198 PyTuple_SetItem(pyobj_args
, 1, libvirt_intWrap(event
));
4200 result
= PyEval_CallObject(updateHandleObj
, pyobj_args
);
4207 Py_DECREF(pyobj_args
);
4209 LIBVIRT_RELEASE_THREAD_STATE
;
4214 libvirt_virEventRemoveHandleFunc(int watch
)
4217 PyObject
*pyobj_args
;
4221 virFreeCallback cff
;
4223 LIBVIRT_ENSURE_THREAD_STATE
;
4225 pyobj_args
= PyTuple_New(1);
4226 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(watch
));
4228 result
= PyEval_CallObject(removeHandleObj
, pyobj_args
);
4232 } else if (!PyTuple_Check(result
) || PyTuple_Size(result
) != 3) {
4233 DEBUG("%s: %s must return opaque obj registered with %s"
4234 "to avoid leaking libvirt memory\n",
4235 __FUNCTION__
, NAME(removeHandle
), NAME(addHandle
));
4237 opaque
= PyTuple_GetItem(result
, 1);
4238 ff
= PyTuple_GetItem(result
, 2);
4239 cff
= PyvirFreeCallback_Get(ff
);
4241 (*cff
)(PyvirVoidPtr_Get(opaque
));
4246 Py_DECREF(pyobj_args
);
4248 LIBVIRT_RELEASE_THREAD_STATE
;
4255 libvirt_virEventAddTimeoutFunc(int timeout
,
4256 virEventTimeoutCallback cb
,
4262 PyObject
*python_cb
;
4266 PyObject
*opaque_obj
;
4268 PyObject
*pyobj_args
;
4271 LIBVIRT_ENSURE_THREAD_STATE
;
4273 /* Lookup the python callback */
4274 python_cb
= libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
4278 Py_INCREF(python_cb
);
4280 /* create tuple for cb */
4281 cb_obj
= libvirt_virEventTimeoutCallbackWrap(cb
);
4282 ff_obj
= libvirt_virFreeCallbackWrap(ff
);
4283 opaque_obj
= libvirt_virVoidPtrWrap(opaque
);
4285 cb_args
= PyTuple_New(3);
4286 PyTuple_SetItem(cb_args
, 0, cb_obj
);
4287 PyTuple_SetItem(cb_args
, 1, opaque_obj
);
4288 PyTuple_SetItem(cb_args
, 2, ff_obj
);
4290 pyobj_args
= PyTuple_New(3);
4292 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(timeout
));
4293 PyTuple_SetItem(pyobj_args
, 1, python_cb
);
4294 PyTuple_SetItem(pyobj_args
, 2, cb_args
);
4296 result
= PyEval_CallObject(addTimeoutObj
, pyobj_args
);
4300 } else if (!PyInt_Check(result
)) {
4301 DEBUG("%s: %s should return an int\n", __FUNCTION__
, NAME(addTimeout
));
4303 retval
= (int)PyInt_AsLong(result
);
4307 Py_DECREF(pyobj_args
);
4310 LIBVIRT_RELEASE_THREAD_STATE
;
4315 libvirt_virEventUpdateTimeoutFunc(int timer
, int timeout
)
4317 PyObject
*result
= NULL
;
4318 PyObject
*pyobj_args
;
4320 LIBVIRT_ENSURE_THREAD_STATE
;
4322 pyobj_args
= PyTuple_New(2);
4323 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(timer
));
4324 PyTuple_SetItem(pyobj_args
, 1, libvirt_intWrap(timeout
));
4326 result
= PyEval_CallObject(updateTimeoutObj
, pyobj_args
);
4333 Py_DECREF(pyobj_args
);
4335 LIBVIRT_RELEASE_THREAD_STATE
;
4339 libvirt_virEventRemoveTimeoutFunc(int timer
)
4341 PyObject
*result
= NULL
;
4342 PyObject
*pyobj_args
;
4346 virFreeCallback cff
;
4348 LIBVIRT_ENSURE_THREAD_STATE
;
4350 pyobj_args
= PyTuple_New(1);
4351 PyTuple_SetItem(pyobj_args
, 0, libvirt_intWrap(timer
));
4353 result
= PyEval_CallObject(removeTimeoutObj
, pyobj_args
);
4357 } else if (!PyTuple_Check(result
) || PyTuple_Size(result
) != 3) {
4358 DEBUG("%s: %s must return opaque obj registered with %s"
4359 "to avoid leaking libvirt memory\n",
4360 __FUNCTION__
, NAME(removeTimeout
), NAME(addTimeout
));
4362 opaque
= PyTuple_GetItem(result
, 1);
4363 ff
= PyTuple_GetItem(result
, 2);
4364 cff
= PyvirFreeCallback_Get(ff
);
4366 (*cff
)(PyvirVoidPtr_Get(opaque
));
4371 Py_DECREF(pyobj_args
);
4373 LIBVIRT_RELEASE_THREAD_STATE
;
4379 libvirt_virEventRegisterImpl(ATTRIBUTE_UNUSED PyObject
* self
,
4382 /* Unref the previously-registered impl (if any) */
4383 Py_XDECREF(addHandleObj
);
4384 Py_XDECREF(updateHandleObj
);
4385 Py_XDECREF(removeHandleObj
);
4386 Py_XDECREF(addTimeoutObj
);
4387 Py_XDECREF(updateTimeoutObj
);
4388 Py_XDECREF(removeTimeoutObj
);
4390 /* Parse and check arguments */
4391 if (!PyArg_ParseTuple(args
, (char *) "OOOOOO:virEventRegisterImpl",
4392 &addHandleObj
, &updateHandleObj
,
4393 &removeHandleObj
, &addTimeoutObj
,
4394 &updateTimeoutObj
, &removeTimeoutObj
) ||
4395 !PyCallable_Check(addHandleObj
) ||
4396 !PyCallable_Check(updateHandleObj
) ||
4397 !PyCallable_Check(removeHandleObj
) ||
4398 !PyCallable_Check(addTimeoutObj
) ||
4399 !PyCallable_Check(updateTimeoutObj
) ||
4400 !PyCallable_Check(removeTimeoutObj
))
4401 return VIR_PY_INT_FAIL
;
4403 /* Get argument string representations (for error reporting) */
4404 addHandleName
= py_str(addHandleObj
);
4405 updateHandleName
= py_str(updateHandleObj
);
4406 removeHandleName
= py_str(removeHandleObj
);
4407 addTimeoutName
= py_str(addTimeoutObj
);
4408 updateTimeoutName
= py_str(updateTimeoutObj
);
4409 removeTimeoutName
= py_str(removeTimeoutObj
);
4411 /* Inc refs since we're holding onto these objects until
4412 * the next call (if any) to this function.
4414 Py_INCREF(addHandleObj
);
4415 Py_INCREF(updateHandleObj
);
4416 Py_INCREF(removeHandleObj
);
4417 Py_INCREF(addTimeoutObj
);
4418 Py_INCREF(updateTimeoutObj
);
4419 Py_INCREF(removeTimeoutObj
);
4421 LIBVIRT_BEGIN_ALLOW_THREADS
;
4423 /* Now register our C EventImpl, which will dispatch
4424 * to the Python callbacks passed in as args.
4426 virEventRegisterImpl(libvirt_virEventAddHandleFunc
,
4427 libvirt_virEventUpdateHandleFunc
,
4428 libvirt_virEventRemoveHandleFunc
,
4429 libvirt_virEventAddTimeoutFunc
,
4430 libvirt_virEventUpdateTimeoutFunc
,
4431 libvirt_virEventRemoveTimeoutFunc
);
4433 LIBVIRT_END_ALLOW_THREADS
;
4435 return VIR_PY_INT_SUCCESS
;
4439 libvirt_virEventInvokeHandleCallback(PyObject
*self ATTRIBUTE_UNUSED
,
4442 int watch
, fd
, event
;
4444 PyObject
*py_opaque
;
4445 virEventHandleCallback cb
;
4448 if (!PyArg_ParseTuple
4449 (args
, (char *) "iiiOO:virEventInvokeHandleCallback",
4450 &watch
, &fd
, &event
, &py_f
, &py_opaque
4452 return VIR_PY_INT_FAIL
;
4454 cb
= (virEventHandleCallback
) PyvirEventHandleCallback_Get(py_f
);
4455 opaque
= (void *) PyvirVoidPtr_Get(py_opaque
);
4458 LIBVIRT_BEGIN_ALLOW_THREADS
;
4459 cb (watch
, fd
, event
, opaque
);
4460 LIBVIRT_END_ALLOW_THREADS
;
4463 return VIR_PY_INT_SUCCESS
;
4467 libvirt_virEventInvokeTimeoutCallback(PyObject
*self ATTRIBUTE_UNUSED
,
4472 PyObject
*py_opaque
;
4473 virEventTimeoutCallback cb
;
4476 if (!PyArg_ParseTuple
4477 (args
, (char *) "iOO:virEventInvokeTimeoutCallback",
4478 &timer
, &py_f
, &py_opaque
4480 return VIR_PY_INT_FAIL
;
4482 cb
= (virEventTimeoutCallback
) PyvirEventTimeoutCallback_Get(py_f
);
4483 opaque
= (void *) PyvirVoidPtr_Get(py_opaque
);
4485 LIBVIRT_BEGIN_ALLOW_THREADS
;
4487 LIBVIRT_END_ALLOW_THREADS
;
4490 return VIR_PY_INT_SUCCESS
;
4494 libvirt_virEventHandleCallback(int watch
,
4499 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4500 PyObject
*pyobj_ret
;
4501 PyObject
*python_cb
;
4503 LIBVIRT_ENSURE_THREAD_STATE
;
4505 /* Lookup the python callback */
4506 python_cb
= libvirt_lookupPythonFunc("_dispatchEventHandleCallback");
4511 Py_INCREF(pyobj_cbData
);
4513 /* Call the pure python dispatcher */
4514 pyobj_ret
= PyObject_CallFunction(python_cb
,
4516 watch
, fd
, events
, pyobj_cbData
);
4518 Py_DECREF(pyobj_cbData
);
4521 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4524 Py_DECREF(pyobj_ret
);
4528 LIBVIRT_RELEASE_THREAD_STATE
;
4532 libvirt_virEventAddHandle(PyObject
*self ATTRIBUTE_UNUSED
,
4535 PyObject
*py_retval
;
4536 PyObject
*pyobj_cbData
;
4537 virEventHandleCallback cb
= libvirt_virEventHandleCallback
;
4542 if (!PyArg_ParseTuple(args
, (char *) "iiO:virEventAddHandle",
4543 &fd
, &events
, &pyobj_cbData
)) {
4544 DEBUG("%s failed to parse tuple\n", __FUNCTION__
);
4545 return VIR_PY_INT_FAIL
;
4548 Py_INCREF(pyobj_cbData
);
4550 LIBVIRT_BEGIN_ALLOW_THREADS
;
4551 ret
= virEventAddHandle(fd
, events
, cb
, pyobj_cbData
, NULL
);
4552 LIBVIRT_END_ALLOW_THREADS
;
4555 Py_DECREF(pyobj_cbData
);
4558 py_retval
= libvirt_intWrap(ret
);
4563 libvirt_virEventTimeoutCallback(int timer
,
4566 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4567 PyObject
*pyobj_ret
;
4568 PyObject
*python_cb
;
4570 LIBVIRT_ENSURE_THREAD_STATE
;
4572 /* Lookup the python callback */
4573 python_cb
= libvirt_lookupPythonFunc("_dispatchEventTimeoutCallback");
4578 Py_INCREF(pyobj_cbData
);
4580 /* Call the pure python dispatcher */
4581 pyobj_ret
= PyObject_CallFunction(python_cb
,
4583 timer
, pyobj_cbData
);
4585 Py_DECREF(pyobj_cbData
);
4588 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4591 Py_DECREF(pyobj_ret
);
4595 LIBVIRT_RELEASE_THREAD_STATE
;
4599 libvirt_virEventAddTimeout(PyObject
*self ATTRIBUTE_UNUSED
,
4602 PyObject
*py_retval
;
4603 PyObject
*pyobj_cbData
;
4604 virEventTimeoutCallback cb
= libvirt_virEventTimeoutCallback
;
4608 if (!PyArg_ParseTuple(args
, (char *) "iO:virEventAddTimeout",
4609 &timeout
, &pyobj_cbData
)) {
4610 DEBUG("%s failed to parse tuple\n", __FUNCTION__
);
4611 return VIR_PY_INT_FAIL
;
4614 Py_INCREF(pyobj_cbData
);
4616 LIBVIRT_BEGIN_ALLOW_THREADS
;
4617 ret
= virEventAddTimeout(timeout
, cb
, pyobj_cbData
, NULL
);
4618 LIBVIRT_END_ALLOW_THREADS
;
4621 Py_DECREF(pyobj_cbData
);
4624 py_retval
= libvirt_intWrap(ret
);
4629 libvirt_virConnectDomainEventFreeFunc(void *opaque
)
4631 PyObject
*pyobj_conn
= (PyObject
*)opaque
;
4632 LIBVIRT_ENSURE_THREAD_STATE
;
4633 Py_DECREF(pyobj_conn
);
4634 LIBVIRT_RELEASE_THREAD_STATE
;
4638 libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4644 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4645 PyObject
*pyobj_dom
;
4646 PyObject
*pyobj_ret
;
4647 PyObject
*pyobj_conn
;
4651 LIBVIRT_ENSURE_THREAD_STATE
;
4653 /* Create a python instance of this virDomainPtr */
4655 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4656 Py_INCREF(pyobj_cbData
);
4658 dictKey
= libvirt_constcharPtrWrap("conn");
4659 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4662 /* Call the Callback Dispatcher */
4663 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4664 (char*)"_dispatchDomainEventLifecycleCallback",
4670 Py_DECREF(pyobj_cbData
);
4671 Py_DECREF(pyobj_dom
);
4674 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4677 Py_DECREF(pyobj_ret
);
4681 LIBVIRT_RELEASE_THREAD_STATE
;
4686 libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4690 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4691 PyObject
*pyobj_dom
;
4692 PyObject
*pyobj_ret
;
4693 PyObject
*pyobj_conn
;
4697 LIBVIRT_ENSURE_THREAD_STATE
;
4699 /* Create a python instance of this virDomainPtr */
4701 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4702 Py_INCREF(pyobj_cbData
);
4704 dictKey
= libvirt_constcharPtrWrap("conn");
4705 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4708 /* Call the Callback Dispatcher */
4709 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4710 (char*)"_dispatchDomainEventGenericCallback",
4712 pyobj_dom
, pyobj_cbData
);
4714 Py_DECREF(pyobj_cbData
);
4715 Py_DECREF(pyobj_dom
);
4718 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4721 Py_DECREF(pyobj_ret
);
4725 LIBVIRT_RELEASE_THREAD_STATE
;
4730 libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4732 long long utcoffset
,
4735 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4736 PyObject
*pyobj_dom
;
4737 PyObject
*pyobj_ret
;
4738 PyObject
*pyobj_conn
;
4742 LIBVIRT_ENSURE_THREAD_STATE
;
4744 /* Create a python instance of this virDomainPtr */
4746 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4747 Py_INCREF(pyobj_cbData
);
4749 dictKey
= libvirt_constcharPtrWrap("conn");
4750 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4753 /* Call the Callback Dispatcher */
4754 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4755 (char*)"_dispatchDomainEventRTCChangeCallback",
4758 (PY_LONG_LONG
)utcoffset
,
4761 Py_DECREF(pyobj_cbData
);
4762 Py_DECREF(pyobj_dom
);
4765 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4768 Py_DECREF(pyobj_ret
);
4772 LIBVIRT_RELEASE_THREAD_STATE
;
4777 libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4782 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4783 PyObject
*pyobj_dom
;
4784 PyObject
*pyobj_ret
;
4785 PyObject
*pyobj_conn
;
4789 LIBVIRT_ENSURE_THREAD_STATE
;
4791 /* Create a python instance of this virDomainPtr */
4793 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4794 Py_INCREF(pyobj_cbData
);
4796 dictKey
= libvirt_constcharPtrWrap("conn");
4797 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4800 /* Call the Callback Dispatcher */
4801 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4802 (char*)"_dispatchDomainEventWatchdogCallback",
4808 Py_DECREF(pyobj_cbData
);
4809 Py_DECREF(pyobj_dom
);
4812 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4815 Py_DECREF(pyobj_ret
);
4819 LIBVIRT_RELEASE_THREAD_STATE
;
4824 libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4826 const char *srcPath
,
4827 const char *devAlias
,
4831 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4832 PyObject
*pyobj_dom
;
4833 PyObject
*pyobj_ret
;
4834 PyObject
*pyobj_conn
;
4838 LIBVIRT_ENSURE_THREAD_STATE
;
4840 /* Create a python instance of this virDomainPtr */
4842 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4843 Py_INCREF(pyobj_cbData
);
4845 dictKey
= libvirt_constcharPtrWrap("conn");
4846 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4849 /* Call the Callback Dispatcher */
4850 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4851 (char*)"_dispatchDomainEventIOErrorCallback",
4854 srcPath
, devAlias
, action
,
4857 Py_DECREF(pyobj_cbData
);
4858 Py_DECREF(pyobj_dom
);
4861 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4864 Py_DECREF(pyobj_ret
);
4868 LIBVIRT_RELEASE_THREAD_STATE
;
4873 libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4875 const char *srcPath
,
4876 const char *devAlias
,
4881 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4882 PyObject
*pyobj_dom
;
4883 PyObject
*pyobj_ret
;
4884 PyObject
*pyobj_conn
;
4888 LIBVIRT_ENSURE_THREAD_STATE
;
4890 /* Create a python instance of this virDomainPtr */
4892 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4893 Py_INCREF(pyobj_cbData
);
4895 dictKey
= libvirt_constcharPtrWrap("conn");
4896 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4899 /* Call the Callback Dispatcher */
4900 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4901 (char*)"_dispatchDomainEventIOErrorReasonCallback",
4904 srcPath
, devAlias
, action
, reason
,
4907 Py_DECREF(pyobj_cbData
);
4908 Py_DECREF(pyobj_dom
);
4911 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
4914 Py_DECREF(pyobj_ret
);
4918 LIBVIRT_RELEASE_THREAD_STATE
;
4923 libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
4926 virDomainEventGraphicsAddressPtr local
,
4927 virDomainEventGraphicsAddressPtr remote
,
4928 const char *authScheme
,
4929 virDomainEventGraphicsSubjectPtr subject
,
4932 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
4933 PyObject
*pyobj_dom
;
4934 PyObject
*pyobj_ret
;
4935 PyObject
*pyobj_conn
;
4937 PyObject
*pyobj_local
;
4938 PyObject
*pyobj_remote
;
4939 PyObject
*pyobj_subject
;
4943 LIBVIRT_ENSURE_THREAD_STATE
;
4945 /* Create a python instance of this virDomainPtr */
4947 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
4948 Py_INCREF(pyobj_cbData
);
4950 dictKey
= libvirt_constcharPtrWrap("conn");
4951 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
4954 pyobj_local
= PyDict_New();
4955 PyDict_SetItem(pyobj_local
,
4956 libvirt_constcharPtrWrap("family"),
4957 libvirt_intWrap(local
->family
));
4958 PyDict_SetItem(pyobj_local
,
4959 libvirt_constcharPtrWrap("node"),
4960 libvirt_constcharPtrWrap(local
->node
));
4961 PyDict_SetItem(pyobj_local
,
4962 libvirt_constcharPtrWrap("service"),
4963 libvirt_constcharPtrWrap(local
->service
));
4965 pyobj_remote
= PyDict_New();
4966 PyDict_SetItem(pyobj_remote
,
4967 libvirt_constcharPtrWrap("family"),
4968 libvirt_intWrap(remote
->family
));
4969 PyDict_SetItem(pyobj_remote
,
4970 libvirt_constcharPtrWrap("node"),
4971 libvirt_constcharPtrWrap(remote
->node
));
4972 PyDict_SetItem(pyobj_remote
,
4973 libvirt_constcharPtrWrap("service"),
4974 libvirt_constcharPtrWrap(remote
->service
));
4976 pyobj_subject
= PyList_New(subject
->nidentity
);
4977 for (i
= 0 ; i
< subject
->nidentity
; i
++) {
4978 PyObject
*pair
= PyTuple_New(2);
4979 PyTuple_SetItem(pair
, 0, libvirt_constcharPtrWrap(subject
->identities
[i
].type
));
4980 PyTuple_SetItem(pair
, 1, libvirt_constcharPtrWrap(subject
->identities
[i
].name
));
4982 PyList_SetItem(pyobj_subject
, i
, pair
);
4985 /* Call the Callback Dispatcher */
4986 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
4987 (char*)"_dispatchDomainEventGraphicsCallback",
4990 phase
, pyobj_local
, pyobj_remote
,
4991 authScheme
, pyobj_subject
,
4994 Py_DECREF(pyobj_cbData
);
4995 Py_DECREF(pyobj_dom
);
4998 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
5001 Py_DECREF(pyobj_ret
);
5005 LIBVIRT_RELEASE_THREAD_STATE
;
5010 libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
5017 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
5018 PyObject
*pyobj_dom
;
5019 PyObject
*pyobj_ret
;
5020 PyObject
*pyobj_conn
;
5024 LIBVIRT_ENSURE_THREAD_STATE
;
5026 /* Create a python instance of this virDomainPtr */
5028 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
5029 Py_INCREF(pyobj_cbData
);
5031 dictKey
= libvirt_constcharPtrWrap("conn");
5032 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
5035 /* Call the Callback Dispatcher */
5036 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
5037 (char*)"dispatchDomainEventBlockPullCallback",
5039 pyobj_dom
, path
, type
, status
, pyobj_cbData
);
5041 Py_DECREF(pyobj_cbData
);
5042 Py_DECREF(pyobj_dom
);
5046 printf("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
5050 Py_DECREF(pyobj_ret
);
5054 LIBVIRT_RELEASE_THREAD_STATE
;
5059 libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
5061 const char *oldSrcPath
,
5062 const char *newSrcPath
,
5063 const char *devAlias
,
5067 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
5068 PyObject
*pyobj_dom
;
5069 PyObject
*pyobj_ret
;
5070 PyObject
*pyobj_conn
;
5074 LIBVIRT_ENSURE_THREAD_STATE
;
5075 /* Create a python instance of this virDomainPtr */
5078 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
5079 Py_INCREF(pyobj_cbData
);
5081 dictKey
= libvirt_constcharPtrWrap("conn");
5082 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
5085 /* Call the Callback Dispatcher */
5086 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
5087 (char*)"_dispatchDomainEventDiskChangeCallback",
5090 oldSrcPath
, newSrcPath
,
5091 devAlias
, reason
, pyobj_cbData
);
5093 Py_DECREF(pyobj_cbData
);
5094 Py_DECREF(pyobj_dom
);
5097 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
5100 Py_DECREF(pyobj_ret
);
5104 LIBVIRT_RELEASE_THREAD_STATE
;
5109 libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED
,
5111 const char *devAlias
,
5115 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
5116 PyObject
*pyobj_dom
;
5117 PyObject
*pyobj_ret
;
5118 PyObject
*pyobj_conn
;
5122 LIBVIRT_ENSURE_THREAD_STATE
;
5123 /* Create a python instance of this virDomainPtr */
5126 pyobj_dom
= libvirt_virDomainPtrWrap(dom
);
5127 Py_INCREF(pyobj_cbData
);
5129 dictKey
= libvirt_constcharPtrWrap("conn");
5130 pyobj_conn
= PyDict_GetItem(pyobj_cbData
, dictKey
);
5133 /* Call the Callback Dispatcher */
5134 pyobj_ret
= PyObject_CallMethod(pyobj_conn
,
5135 (char*)"_dispatchDomainEventTrayChangeCallback",
5138 devAlias
, reason
, pyobj_cbData
);
5140 Py_DECREF(pyobj_cbData
);
5141 Py_DECREF(pyobj_dom
);
5144 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
5147 Py_DECREF(pyobj_ret
);
5151 LIBVIRT_RELEASE_THREAD_STATE
;
5156 libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject
* self
,
5159 PyObject
*py_retval
; /* return value */
5160 PyObject
*pyobj_conn
; /* virConnectPtr */
5161 PyObject
*pyobj_dom
;
5162 PyObject
*pyobj_cbData
; /* hash of callback data */
5166 virConnectDomainEventGenericCallback cb
= NULL
;
5169 if (!PyArg_ParseTuple
5170 (args
, (char *) "OOiO:virConnectDomainEventRegisterAny",
5171 &pyobj_conn
, &pyobj_dom
, &eventID
, &pyobj_cbData
)) {
5172 DEBUG("%s failed parsing tuple\n", __FUNCTION__
);
5173 return VIR_PY_INT_FAIL
;
5176 DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
5177 pyobj_conn
, pyobj_dom
, eventID
, pyobj_cbData
);
5178 conn
= PyvirConnect_Get(pyobj_conn
);
5179 if (pyobj_dom
== Py_None
)
5182 dom
= PyvirDomain_Get(pyobj_dom
);
5185 case VIR_DOMAIN_EVENT_ID_LIFECYCLE
:
5186 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventLifecycleCallback
);
5188 case VIR_DOMAIN_EVENT_ID_REBOOT
:
5189 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback
);
5191 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE
:
5192 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventRTCChangeCallback
);
5194 case VIR_DOMAIN_EVENT_ID_WATCHDOG
:
5195 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventWatchdogCallback
);
5197 case VIR_DOMAIN_EVENT_ID_IO_ERROR
:
5198 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorCallback
);
5200 case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
:
5201 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventIOErrorReasonCallback
);
5203 case VIR_DOMAIN_EVENT_ID_GRAPHICS
:
5204 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGraphicsCallback
);
5206 case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR
:
5207 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventGenericCallback
);
5209 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB
:
5210 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockJobCallback
);
5212 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE
:
5213 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback
);
5215 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE
:
5216 cb
= VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback
);
5221 return VIR_PY_INT_FAIL
;
5224 Py_INCREF(pyobj_cbData
);
5226 LIBVIRT_BEGIN_ALLOW_THREADS
;
5227 ret
= virConnectDomainEventRegisterAny(conn
, dom
, eventID
,
5229 libvirt_virConnectDomainEventFreeFunc
);
5230 LIBVIRT_END_ALLOW_THREADS
;
5233 Py_DECREF(pyobj_cbData
);
5236 py_retval
= libvirt_intWrap(ret
);
5241 libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject
* self
,
5244 PyObject
*py_retval
;
5245 PyObject
*pyobj_conn
;
5250 if (!PyArg_ParseTuple
5251 (args
, (char *) "Oi:virConnectDomainEventDeregister",
5252 &pyobj_conn
, &callbackID
))
5255 DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn
);
5257 conn
= (virConnectPtr
) PyvirConnect_Get(pyobj_conn
);
5259 LIBVIRT_BEGIN_ALLOW_THREADS
;
5261 ret
= virConnectDomainEventDeregisterAny(conn
, callbackID
);
5263 LIBVIRT_END_ALLOW_THREADS
;
5264 py_retval
= libvirt_intWrap(ret
);
5269 libvirt_virStreamEventFreeFunc(void *opaque
)
5271 PyObject
*pyobj_stream
= (PyObject
*)opaque
;
5272 LIBVIRT_ENSURE_THREAD_STATE
;
5273 Py_DECREF(pyobj_stream
);
5274 LIBVIRT_RELEASE_THREAD_STATE
;
5278 libvirt_virStreamEventCallback(virStreamPtr st ATTRIBUTE_UNUSED
,
5282 PyObject
*pyobj_cbData
= (PyObject
*)opaque
;
5283 PyObject
*pyobj_stream
;
5284 PyObject
*pyobj_ret
;
5287 LIBVIRT_ENSURE_THREAD_STATE
;
5289 Py_INCREF(pyobj_cbData
);
5290 dictKey
= libvirt_constcharPtrWrap("stream");
5291 pyobj_stream
= PyDict_GetItem(pyobj_cbData
, dictKey
);
5294 /* Call the pure python dispatcher */
5295 pyobj_ret
= PyObject_CallMethod(pyobj_stream
,
5296 (char *)"_dispatchStreamEventCallback",
5298 events
, pyobj_cbData
);
5300 Py_DECREF(pyobj_cbData
);
5303 DEBUG("%s - ret:%p\n", __FUNCTION__
, pyobj_ret
);
5306 Py_DECREF(pyobj_ret
);
5309 LIBVIRT_RELEASE_THREAD_STATE
;
5313 libvirt_virStreamEventAddCallback(PyObject
*self ATTRIBUTE_UNUSED
,
5316 PyObject
*py_retval
;
5317 PyObject
*pyobj_stream
;
5318 PyObject
*pyobj_cbData
;
5319 virStreamPtr stream
;
5320 virStreamEventCallback cb
= libvirt_virStreamEventCallback
;
5324 if (!PyArg_ParseTuple(args
, (char *) "OiO:virStreamEventAddCallback",
5325 &pyobj_stream
, &events
, &pyobj_cbData
)) {
5326 DEBUG("%s failed to parse tuple\n", __FUNCTION__
);
5327 return VIR_PY_INT_FAIL
;
5330 DEBUG("libvirt_virStreamEventAddCallback(%p, %d, %p) called\n",
5331 pyobj_stream
, events
, pyobj_cbData
);
5332 stream
= PyvirStream_Get(pyobj_stream
);
5334 Py_INCREF(pyobj_cbData
);
5336 LIBVIRT_BEGIN_ALLOW_THREADS
;
5337 ret
= virStreamEventAddCallback(stream
, events
, cb
, pyobj_cbData
,
5338 libvirt_virStreamEventFreeFunc
);
5339 LIBVIRT_END_ALLOW_THREADS
;
5342 Py_DECREF(pyobj_cbData
);
5345 py_retval
= libvirt_intWrap(ret
);
5350 libvirt_virStreamRecv(PyObject
*self ATTRIBUTE_UNUSED
,
5353 PyObject
*pyobj_stream
;
5354 virStreamPtr stream
;
5359 if (!PyArg_ParseTuple(args
, (char *) "Oi:virStreamRecv",
5360 &pyobj_stream
, &nbytes
)) {
5361 DEBUG("%s failed to parse tuple\n", __FUNCTION__
);
5364 stream
= PyvirStream_Get(pyobj_stream
);
5366 if (VIR_ALLOC_N(buf
, nbytes
+1 > 0 ? nbytes
+1 : 1) < 0)
5369 LIBVIRT_BEGIN_ALLOW_THREADS
;
5370 ret
= virStreamRecv(stream
, buf
, nbytes
);
5371 LIBVIRT_END_ALLOW_THREADS
;
5373 buf
[ret
> -1 ? ret
: 0] = '\0';
5374 DEBUG("StreamRecv ret=%d strlen=%d\n", ret
, (int) strlen(buf
));
5377 return libvirt_intWrap(ret
);
5380 return libvirt_charPtrSizeWrap((char *) buf
, (Py_ssize_t
) ret
);
5384 libvirt_virStreamSend(PyObject
*self ATTRIBUTE_UNUSED
,
5387 PyObject
*py_retval
;
5388 PyObject
*pyobj_stream
;
5389 virStreamPtr stream
;
5395 if (!PyArg_ParseTuple(args
, (char *) "Oz#i:virStreamRecv",
5396 &pyobj_stream
, &data
, &datalen
, &nbytes
)) {
5397 DEBUG("%s failed to parse tuple\n", __FUNCTION__
);
5398 return VIR_PY_INT_FAIL
;
5400 stream
= PyvirStream_Get(pyobj_stream
);
5402 LIBVIRT_BEGIN_ALLOW_THREADS
;
5403 ret
= virStreamSend(stream
, data
, nbytes
);
5404 LIBVIRT_END_ALLOW_THREADS
;
5406 DEBUG("StreamSend ret=%d\n", ret
);
5408 py_retval
= libvirt_intWrap(ret
);
5413 libvirt_virDomainSendKey(PyObject
*self ATTRIBUTE_UNUSED
,
5416 PyObject
*py_retval
;
5417 virDomainPtr domain
;
5418 PyObject
*pyobj_domain
;
5419 PyObject
*pyobj_list
;
5425 unsigned int keycodes
[VIR_DOMAIN_SEND_KEY_MAX_KEYS
];
5426 unsigned int nkeycodes
;
5428 if (!PyArg_ParseTuple(args
, (char *)"OiiOii:virDomainSendKey",
5429 &pyobj_domain
, &codeset
, &holdtime
, &pyobj_list
,
5430 &nkeycodes
, &flags
)) {
5431 DEBUG("%s failed to parse tuple\n", __FUNCTION__
);
5432 return VIR_PY_INT_FAIL
;
5434 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
5436 if (!PyList_Check(pyobj_list
)) {
5437 return VIR_PY_INT_FAIL
;
5440 if (nkeycodes
!= PyList_Size(pyobj_list
) ||
5441 nkeycodes
> VIR_DOMAIN_SEND_KEY_MAX_KEYS
) {
5442 return VIR_PY_INT_FAIL
;
5445 for (i
= 0; i
< nkeycodes
; i
++) {
5446 keycodes
[i
] = (int)PyInt_AsLong(PyList_GetItem(pyobj_list
, i
));
5449 LIBVIRT_BEGIN_ALLOW_THREADS
;
5450 ret
= virDomainSendKey(domain
, codeset
, holdtime
, keycodes
, nkeycodes
, flags
);
5451 LIBVIRT_END_ALLOW_THREADS
;
5453 DEBUG("virDomainSendKey ret=%d\n", ret
);
5455 py_retval
= libvirt_intWrap(ret
);
5460 libvirt_virDomainMigrateGetMaxSpeed(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
) {
5461 PyObject
*py_retval
;
5463 unsigned long bandwidth
;
5464 virDomainPtr domain
;
5465 PyObject
*pyobj_domain
;
5466 unsigned int flags
= 0;
5468 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainMigrateGetMaxSpeed",
5469 &pyobj_domain
, &flags
))
5472 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
5474 LIBVIRT_BEGIN_ALLOW_THREADS
;
5475 c_retval
= virDomainMigrateGetMaxSpeed(domain
, &bandwidth
, flags
);
5476 LIBVIRT_END_ALLOW_THREADS
;
5479 return VIR_PY_INT_FAIL
;
5480 py_retval
= libvirt_ulongWrap(bandwidth
);
5485 libvirt_virDomainBlockPeek(PyObject
*self ATTRIBUTE_UNUSED
,
5487 PyObject
*py_retval
= NULL
;
5489 virDomainPtr domain
;
5490 PyObject
*pyobj_domain
;
5492 unsigned long long offset
;
5497 if (!PyArg_ParseTuple(args
, (char *)"OzLni:virDomainBlockPeek", &pyobj_domain
,
5498 &disk
, &offset
, &size
, &flags
))
5501 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
5503 if (VIR_ALLOC_N(buf
, size
) < 0)
5506 LIBVIRT_BEGIN_ALLOW_THREADS
;
5507 c_retval
= virDomainBlockPeek(domain
, disk
, offset
, size
, buf
, flags
);
5508 LIBVIRT_END_ALLOW_THREADS
;
5513 py_retval
= PyString_FromStringAndSize(buf
, size
);
5521 libvirt_virDomainMemoryPeek(PyObject
*self ATTRIBUTE_UNUSED
,
5523 PyObject
*py_retval
= NULL
;
5525 virDomainPtr domain
;
5526 PyObject
*pyobj_domain
;
5527 unsigned long long start
;
5532 if (!PyArg_ParseTuple(args
, (char *)"OLni:virDomainMemoryPeek", &pyobj_domain
,
5533 &start
, &size
, &flags
))
5536 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
5538 if (VIR_ALLOC_N(buf
, size
) < 0)
5541 LIBVIRT_BEGIN_ALLOW_THREADS
;
5542 c_retval
= virDomainMemoryPeek(domain
, start
, size
, buf
, flags
);
5543 LIBVIRT_END_ALLOW_THREADS
;
5548 py_retval
= PyString_FromStringAndSize(buf
, size
);
5555 /************************************************************************
5557 * The registration stuff *
5559 ************************************************************************/
5560 static PyMethodDef libvirtMethods
[] = {
5561 #include "libvirt-export.c"
5562 {(char *) "virGetVersion", libvirt_virGetVersion
, METH_VARARGS
, NULL
},
5563 {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion
, METH_VARARGS
, NULL
},
5564 {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion
, METH_VARARGS
, NULL
},
5565 {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth
, METH_VARARGS
, NULL
},
5566 {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID
, METH_VARARGS
, NULL
},
5567 {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains
, METH_VARARGS
, NULL
},
5568 {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister
, METH_VARARGS
, NULL
},
5569 {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister
, METH_VARARGS
, NULL
},
5570 {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny
, METH_VARARGS
, NULL
},
5571 {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny
, METH_VARARGS
, NULL
},
5572 {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback
, METH_VARARGS
, NULL
},
5573 {(char *) "virStreamRecv", libvirt_virStreamRecv
, METH_VARARGS
, NULL
},
5574 {(char *) "virStreamSend", libvirt_virStreamSend
, METH_VARARGS
, NULL
},
5575 {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo
, METH_VARARGS
, NULL
},
5576 {(char *) "virDomainGetState", libvirt_virDomainGetState
, METH_VARARGS
, NULL
},
5577 {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo
, METH_VARARGS
, NULL
},
5578 {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo
, METH_VARARGS
, NULL
},
5579 {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo
, METH_VARARGS
, NULL
},
5580 {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats
, METH_VARARGS
, NULL
},
5581 {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats
, METH_VARARGS
, NULL
},
5582 {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID
, METH_VARARGS
, NULL
},
5583 {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString
, METH_VARARGS
, NULL
},
5584 {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID
, METH_VARARGS
, NULL
},
5585 {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler
, METH_VARARGS
, NULL
},
5586 {(char *) "virGetLastError", libvirt_virGetLastError
, METH_VARARGS
, NULL
},
5587 {(char *) "virConnGetLastError", libvirt_virConnGetLastError
, METH_VARARGS
, NULL
},
5588 {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks
, METH_VARARGS
, NULL
},
5589 {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks
, METH_VARARGS
, NULL
},
5590 {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID
, METH_VARARGS
, NULL
},
5591 {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString
, METH_VARARGS
, NULL
},
5592 {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID
, METH_VARARGS
, NULL
},
5593 {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart
, METH_VARARGS
, NULL
},
5594 {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart
, METH_VARARGS
, NULL
},
5595 {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats
, METH_VARARGS
, NULL
},
5596 {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags
, METH_VARARGS
, NULL
},
5597 {(char *) "virDomainGetCPUStats", libvirt_virDomainGetCPUStats
, METH_VARARGS
, NULL
},
5598 {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats
, METH_VARARGS
, NULL
},
5599 {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats
, METH_VARARGS
, NULL
},
5600 {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory
, METH_VARARGS
, NULL
},
5601 {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType
, METH_VARARGS
, NULL
},
5602 {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters
, METH_VARARGS
, NULL
},
5603 {(char *) "virDomainGetSchedulerParametersFlags", libvirt_virDomainGetSchedulerParametersFlags
, METH_VARARGS
, NULL
},
5604 {(char *) "virDomainSetSchedulerParameters", libvirt_virDomainSetSchedulerParameters
, METH_VARARGS
, NULL
},
5605 {(char *) "virDomainSetSchedulerParametersFlags", libvirt_virDomainSetSchedulerParametersFlags
, METH_VARARGS
, NULL
},
5606 {(char *) "virDomainSetBlkioParameters", libvirt_virDomainSetBlkioParameters
, METH_VARARGS
, NULL
},
5607 {(char *) "virDomainGetBlkioParameters", libvirt_virDomainGetBlkioParameters
, METH_VARARGS
, NULL
},
5608 {(char *) "virDomainSetMemoryParameters", libvirt_virDomainSetMemoryParameters
, METH_VARARGS
, NULL
},
5609 {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters
, METH_VARARGS
, NULL
},
5610 {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters
, METH_VARARGS
, NULL
},
5611 {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters
, METH_VARARGS
, NULL
},
5612 {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters
, METH_VARARGS
, NULL
},
5613 {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters
, METH_VARARGS
, NULL
},
5614 {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus
, METH_VARARGS
, NULL
},
5615 {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu
, METH_VARARGS
, NULL
},
5616 {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags
, METH_VARARGS
, NULL
},
5617 {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo
, METH_VARARGS
, NULL
},
5618 {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools
, METH_VARARGS
, NULL
},
5619 {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools
, METH_VARARGS
, NULL
},
5620 {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart
, METH_VARARGS
, NULL
},
5621 {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes
, METH_VARARGS
, NULL
},
5622 {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo
, METH_VARARGS
, NULL
},
5623 {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo
, METH_VARARGS
, NULL
},
5624 {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID
, METH_VARARGS
, NULL
},
5625 {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString
, METH_VARARGS
, NULL
},
5626 {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID
, METH_VARARGS
, NULL
},
5627 {(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl
, METH_VARARGS
, NULL
},
5628 {(char *) "virEventAddHandle", libvirt_virEventAddHandle
, METH_VARARGS
, NULL
},
5629 {(char *) "virEventAddTimeout", libvirt_virEventAddTimeout
, METH_VARARGS
, NULL
},
5630 {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback
, METH_VARARGS
, NULL
},
5631 {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback
, METH_VARARGS
, NULL
},
5632 {(char *) "virNodeListDevices", libvirt_virNodeListDevices
, METH_VARARGS
, NULL
},
5633 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps
, METH_VARARGS
, NULL
},
5634 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID
, METH_VARARGS
, NULL
},
5635 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString
, METH_VARARGS
, NULL
},
5636 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID
, METH_VARARGS
, NULL
},
5637 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets
, METH_VARARGS
, NULL
},
5638 {(char *) "virSecretGetValue", libvirt_virSecretGetValue
, METH_VARARGS
, NULL
},
5639 {(char *) "virSecretSetValue", libvirt_virSecretSetValue
, METH_VARARGS
, NULL
},
5640 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID
, METH_VARARGS
, NULL
},
5641 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString
, METH_VARARGS
, NULL
},
5642 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID
, METH_VARARGS
, NULL
},
5643 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters
, METH_VARARGS
, NULL
},
5644 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces
, METH_VARARGS
, NULL
},
5645 {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces
, METH_VARARGS
, NULL
},
5646 {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU
, METH_VARARGS
, NULL
},
5647 {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo
, METH_VARARGS
, NULL
},
5648 {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames
, METH_VARARGS
, NULL
},
5649 {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames
, METH_VARARGS
, NULL
},
5650 {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot
, METH_VARARGS
, NULL
},
5651 {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo
, METH_VARARGS
, NULL
},
5652 {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune
, METH_VARARGS
, NULL
},
5653 {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune
, METH_VARARGS
, NULL
},
5654 {(char *) "virDomainSendKey", libvirt_virDomainSendKey
, METH_VARARGS
, NULL
},
5655 {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed
, METH_VARARGS
, NULL
},
5656 {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek
, METH_VARARGS
, NULL
},
5657 {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek
, METH_VARARGS
, NULL
},
5658 {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors
, METH_VARARGS
, NULL
},
5659 {NULL
, NULL
, 0, NULL
}
5670 static int initialized
= 0;
5672 if (initialized
!= 0)
5675 if (virInitialize() < 0)
5678 /* initialize the python extension module */
5679 Py_InitModule((char *)