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) 2011-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. */
20 #include <libvirt/libvirt-qemu.h>
21 #include <libvirt/virterror.h>
22 #include "typewrappers.h"
23 #include "libvirt-qemu.h"
26 extern void initlibvirtmod_qemu(void);
28 extern void initcygvirtmod_qemu(void);
32 # define DEBUG_ERROR 1
36 # define DEBUG(fmt, ...) \
37 printf(fmt, __VA_ARGS__)
39 # define DEBUG(fmt, ...) \
43 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
44 is so common that we encapsulate it here. Now, each use is simply
45 return VIR_PY_NONE; */
46 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
47 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
48 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
50 /************************************************************************
54 ************************************************************************/
57 libvirt_qemu_virDomainQemuMonitorCommand(PyObject
*self ATTRIBUTE_UNUSED
,
62 PyObject
*pyobj_domain
;
67 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainQemuMonitorCommand",
68 &pyobj_domain
, &cmd
, &flags
))
70 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
74 LIBVIRT_BEGIN_ALLOW_THREADS
;
75 c_retval
= virDomainQemuMonitorCommand(domain
, cmd
, &result
, flags
);
76 LIBVIRT_END_ALLOW_THREADS
;
81 py_retval
= PyString_FromString(result
);
86 libvirt_qemu_virDomainQemuAgentCommand(PyObject
*self ATTRIBUTE_UNUSED
, PyObject
*args
)
91 PyObject
*pyobj_domain
;
96 if (!PyArg_ParseTuple(args
, (char *)"Ozii:virDomainQemuAgentCommand",
97 &pyobj_domain
, &cmd
, &timeout
, &flags
))
99 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
103 LIBVIRT_BEGIN_ALLOW_THREADS
;
104 result
= virDomainQemuAgentCommand(domain
, cmd
, timeout
, flags
);
105 LIBVIRT_END_ALLOW_THREADS
;
110 py_retval
= PyString_FromString(result
);
113 /************************************************************************
115 * The registration stuff *
117 ************************************************************************/
118 static PyMethodDef libvirtQemuMethods
[] = {
119 #include "libvirt-qemu-export.c"
120 {(char *) "virDomainQemuMonitorCommand", libvirt_qemu_virDomainQemuMonitorCommand
, METH_VARARGS
, NULL
},
121 {(char *) "virDomainQemuAgentCommand", libvirt_qemu_virDomainQemuAgentCommand
, METH_VARARGS
, NULL
},
122 {NULL
, NULL
, 0, NULL
}
133 static int initialized
= 0;
135 if (initialized
!= 0)
138 if (virInitialize() < 0)
141 /* initialize the python extension module */
142 Py_InitModule((char *)
148 , libvirtQemuMethods
);