2005-12-19 19:34:11 +03:00
/*
2006-02-09 20:45:11 +03:00
* libvirt_wrap . h : type wrappers for libvir python bindings
2005-12-19 19:34:11 +03:00
*
2012-02-03 03:28:26 +04:00
* Copyright ( C ) 2005 , 2011 - 2012 Red Hat , Inc .
2005-12-19 19:34:11 +03:00
*
* Daniel Veillard < veillard @ redhat . com >
*/
# include <Python.h>
2012-03-27 10:06:10 +04:00
# include <stdbool.h>
2013-04-17 14:19:19 +04:00
# include <libvirt/libvirt.h>
# include <libvirt/virterror.h>
2005-12-19 19:34:11 +03:00
# ifdef __GNUC__
2010-03-09 21:22:22 +03:00
# ifdef ATTRIBUTE_UNUSED
# undef ATTRIBUTE_UNUSED
# endif
# ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# endif /* ATTRIBUTE_UNUSED */
2005-12-19 19:34:11 +03:00
# else
2010-03-09 21:22:22 +03:00
# define ATTRIBUTE_UNUSED
2005-12-19 19:34:11 +03:00
# endif
2018-07-09 11:04:23 +03:00
# if !LIBVIR_CHECK_VERSION(4, 5, 0)
typedef struct _virNWFilterBinding * virNWFilterBindingPtr ;
# endif
2019-06-20 14:48:25 +03:00
# if !LIBVIR_CHECK_VERSION(5, 5, 0)
typedef struct _virNetworkPort * virNetworkPortPtr ;
# endif
2019-06-20 14:48:25 +03:00
# if !LIBVIR_CHECK_VERSION(5, 6, 0)
typedef struct _virDomainCheckpoint * virDomainCheckpointPtr ;
# endif
2018-07-09 11:04:23 +03:00
2005-12-19 19:34:11 +03:00
# define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
2008-04-10 20:54:54 +04:00
( ( ( PyvirConnect_Object * ) ( v ) ) - > obj ) )
2005-12-19 19:34:11 +03:00
typedef struct {
PyObject_HEAD
virConnectPtr obj ;
} PyvirConnect_Object ;
# define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
2008-04-10 20:54:54 +04:00
( ( ( PyvirDomain_Object * ) ( v ) ) - > obj ) )
2005-12-19 19:34:11 +03:00
typedef struct {
PyObject_HEAD
virDomainPtr obj ;
} PyvirDomain_Object ;
2007-03-09 18:42:50 +03:00
# define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
2008-04-10 20:54:54 +04:00
( ( ( PyvirNetwork_Object * ) ( v ) ) - > obj ) )
2007-03-09 18:42:50 +03:00
typedef struct {
PyObject_HEAD
virNetworkPtr obj ;
} PyvirNetwork_Object ;
2019-06-18 14:08:32 +03:00
# define PyvirNetworkPort_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirNetworkPort_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virNetworkPortPtr obj ;
} PyvirNetworkPort_Object ;
2009-05-21 14:57:05 +04:00
# define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirInterface_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virInterfacePtr obj ;
} PyvirInterface_Object ;
2008-02-20 18:26:22 +03:00
# define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
2008-04-10 20:54:54 +04:00
( ( ( PyvirStoragePool_Object * ) ( v ) ) - > obj ) )
2008-02-20 18:26:22 +03:00
typedef struct {
PyObject_HEAD
virStoragePoolPtr obj ;
} PyvirStoragePool_Object ;
# define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
2008-04-10 20:54:54 +04:00
( ( ( PyvirStorageVol_Object * ) ( v ) ) - > obj ) )
2008-02-20 18:26:22 +03:00
typedef struct {
PyObject_HEAD
virStorageVolPtr obj ;
} PyvirStorageVol_Object ;
2008-11-21 15:41:15 +03:00
# define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirNodeDevice_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virNodeDevicePtr obj ;
} PyvirNodeDevice_Object ;
Secret manipulation API docs refresh & wire up python generator
Sample session:
>>> import libvirt
>>> c = libvirt.open('qemu:///session')
>>> c.listSecrets()
['12247729-47d2-a783-88ce-b329d4781cd3', 'reee', 'abc']
>>> s = c.secretDefineXML("<secret ephemeral='no' private='no'>\n<description>Something for use</description>\n<volume>/foo/bar</volume>\n</secret>\n")
>>> s.UUIDString()
'340c2dfb-811b-eda8-da9e-25ccd7bfd650'
>>> s.XMLDesc()
"<secret ephemeral='no' private='no'>\n <uuid>340c2dfb-811b-eda8-da9e-25ccd7bfd650</uuid>\n <description>Something for use</description>\n <volume>/foo/bar</volume>\n</secret>\n"
>>> s.setValue('abc\0xx\xffx')
0
>>> s.value()
'abc\x00xx\xffx'
>>> s.undefine()
0
* python/generator.py: Add rules for virSecret APIs
* python/libvir.c, python/libvirt-python-api.xml: Manual impl of
virSecretSetValue, virSecretGetValue$ and virConnectListSecrets APIs
* python/libvirt_wrap.h, python/types.c: Wrapper for virSecret objects
* docs/libvirt-api.xml, docs/libvirt-refs.xml,
docs/html/libvirt-virterror.html, docs/html/libvirt-libvirt.html,
docs/devhelp/libvirt-virterror.html, docs/devhelp/libvirt-libvirt.html:
Re-generate with 'make api'
2009-08-04 22:38:21 +04:00
# define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirSecret_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virSecretPtr obj ;
} PyvirSecret_Object ;
2010-04-29 14:46:01 +04:00
# define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirNWFilter_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virNWFilterPtr obj ;
} PyvirNWFilter_Object ;
2008-11-21 15:41:15 +03:00
2018-06-26 13:18:32 +03:00
# define PyvirNWFilterBinding_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirNWFilterBinding_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virNWFilterBindingPtr obj ;
} PyvirNWFilterBinding_Object ;
2009-07-10 15:18:12 +04:00
# define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirStream_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virStreamPtr obj ;
} PyvirStream_Object ;
2019-02-08 01:36:16 +03:00
# define PyvirDomainCheckpoint_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirDomainCheckpoint_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virDomainCheckpointPtr obj ;
} PyvirDomainCheckpoint_Object ;
2010-04-01 00:33:13 +04:00
# define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirDomainSnapshot_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virDomainSnapshotPtr obj ;
} PyvirDomainSnapshot_Object ;
2008-10-31 13:13:45 +03:00
# define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirEventHandleCallback_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virEventHandleCallback obj ;
} PyvirEventHandleCallback_Object ;
# define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirEventTimeoutCallback_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virEventTimeoutCallback obj ;
} PyvirEventTimeoutCallback_Object ;
2008-11-24 22:28:12 +03:00
# define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirFreeCallback_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
virFreeCallback obj ;
} PyvirFreeCallback_Object ;
2008-10-31 13:13:45 +03:00
# define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
( ( ( PyvirVoidPtr_Object * ) ( v ) ) - > obj ) )
typedef struct {
PyObject_HEAD
void * obj ;
} PyvirVoidPtr_Object ;
2008-02-20 18:26:22 +03:00
2006-02-09 20:45:11 +03:00
PyObject * libvirt_intWrap ( int val ) ;
2013-12-05 20:08:40 +04:00
PyObject * libvirt_uintWrap ( uint val ) ;
2006-02-09 20:45:11 +03:00
PyObject * libvirt_longWrap ( long val ) ;
2006-11-15 22:40:00 +03:00
PyObject * libvirt_ulongWrap ( unsigned long val ) ;
2006-02-09 20:45:11 +03:00
PyObject * libvirt_longlongWrap ( long long val ) ;
2010-02-03 14:31:45 +03:00
PyObject * libvirt_ulonglongWrap ( unsigned long long val ) ;
2006-02-09 20:45:11 +03:00
PyObject * libvirt_charPtrWrap ( char * str ) ;
2011-06-15 00:07:43 +04:00
PyObject * libvirt_charPtrSizeWrap ( char * str , Py_ssize_t size ) ;
2006-02-09 20:45:11 +03:00
PyObject * libvirt_constcharPtrWrap ( const char * str ) ;
2013-11-26 22:31:18 +04:00
PyObject * libvirt_boolWrap ( int val ) ;
2012-03-27 10:06:10 +04:00
int libvirt_intUnwrap ( PyObject * obj , int * val ) ;
int libvirt_uintUnwrap ( PyObject * obj , unsigned int * val ) ;
int libvirt_longUnwrap ( PyObject * obj , long * val ) ;
int libvirt_ulongUnwrap ( PyObject * obj , unsigned long * val ) ;
int libvirt_longlongUnwrap ( PyObject * obj , long long * val ) ;
int libvirt_ulonglongUnwrap ( PyObject * obj , unsigned long long * val ) ;
int libvirt_doubleUnwrap ( PyObject * obj , double * val ) ;
int libvirt_boolUnwrap ( PyObject * obj , bool * val ) ;
2013-12-05 20:36:41 +04:00
int libvirt_charPtrUnwrap ( PyObject * obj , char * * str ) ;
2013-12-09 18:53:34 +04:00
int libvirt_charPtrSizeUnwrap ( PyObject * obj , char * * str , Py_ssize_t * size ) ;
2006-02-09 20:45:11 +03:00
PyObject * libvirt_virConnectPtrWrap ( virConnectPtr node ) ;
PyObject * libvirt_virDomainPtrWrap ( virDomainPtr node ) ;
2007-03-09 18:42:50 +03:00
PyObject * libvirt_virNetworkPtrWrap ( virNetworkPtr node ) ;
2019-06-18 14:08:32 +03:00
PyObject * libvirt_virNetworkPortPtrWrap ( virNetworkPortPtr node ) ;
2009-05-21 14:57:05 +04:00
PyObject * libvirt_virInterfacePtrWrap ( virInterfacePtr node ) ;
2008-02-20 18:26:22 +03:00
PyObject * libvirt_virStoragePoolPtrWrap ( virStoragePoolPtr node ) ;
PyObject * libvirt_virStorageVolPtrWrap ( virStorageVolPtr node ) ;
2008-10-31 13:13:45 +03:00
PyObject * libvirt_virEventHandleCallbackWrap ( virEventHandleCallback node ) ;
PyObject * libvirt_virEventTimeoutCallbackWrap ( virEventTimeoutCallback node ) ;
2008-11-19 19:24:01 +03:00
PyObject * libvirt_virFreeCallbackWrap ( virFreeCallback node ) ;
2008-10-31 13:13:45 +03:00
PyObject * libvirt_virVoidPtrWrap ( void * node ) ;
2008-11-21 15:41:15 +03:00
PyObject * libvirt_virNodeDevicePtrWrap ( virNodeDevicePtr node ) ;
Secret manipulation API docs refresh & wire up python generator
Sample session:
>>> import libvirt
>>> c = libvirt.open('qemu:///session')
>>> c.listSecrets()
['12247729-47d2-a783-88ce-b329d4781cd3', 'reee', 'abc']
>>> s = c.secretDefineXML("<secret ephemeral='no' private='no'>\n<description>Something for use</description>\n<volume>/foo/bar</volume>\n</secret>\n")
>>> s.UUIDString()
'340c2dfb-811b-eda8-da9e-25ccd7bfd650'
>>> s.XMLDesc()
"<secret ephemeral='no' private='no'>\n <uuid>340c2dfb-811b-eda8-da9e-25ccd7bfd650</uuid>\n <description>Something for use</description>\n <volume>/foo/bar</volume>\n</secret>\n"
>>> s.setValue('abc\0xx\xffx')
0
>>> s.value()
'abc\x00xx\xffx'
>>> s.undefine()
0
* python/generator.py: Add rules for virSecret APIs
* python/libvir.c, python/libvirt-python-api.xml: Manual impl of
virSecretSetValue, virSecretGetValue$ and virConnectListSecrets APIs
* python/libvirt_wrap.h, python/types.c: Wrapper for virSecret objects
* docs/libvirt-api.xml, docs/libvirt-refs.xml,
docs/html/libvirt-virterror.html, docs/html/libvirt-libvirt.html,
docs/devhelp/libvirt-virterror.html, docs/devhelp/libvirt-libvirt.html:
Re-generate with 'make api'
2009-08-04 22:38:21 +04:00
PyObject * libvirt_virSecretPtrWrap ( virSecretPtr node ) ;
2010-04-29 14:46:01 +04:00
PyObject * libvirt_virNWFilterPtrWrap ( virNWFilterPtr node ) ;
2018-06-26 13:18:32 +03:00
PyObject * libvirt_virNWFilterBindingPtrWrap ( virNWFilterBindingPtr node ) ;
2009-07-10 15:18:12 +04:00
PyObject * libvirt_virStreamPtrWrap ( virStreamPtr node ) ;
2019-02-08 01:36:16 +03:00
PyObject * libvirt_virDomainCheckpointPtrWrap ( virDomainCheckpointPtr node ) ;
2010-04-01 00:33:13 +04:00
PyObject * libvirt_virDomainSnapshotPtrWrap ( virDomainSnapshotPtr node ) ;
2008-11-21 15:41:15 +03:00
2006-10-25 00:28:16 +04:00
/* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
* LIBVIRT_STMT_START { statements ; } LIBVIRT_STMT_END ;
* can be used as a single statement , as in
* if ( x ) LIBVIRT_STMT_START { . . . } LIBVIRT_STMT_END ; else . . .
*
* When GCC is compiling C code in non - ANSI mode , it will use the
2008-02-29 15:53:10 +03:00
* compiler __extension__ to wrap the statements within ` ( { ' and ' } ) ' braces .
2006-10-25 00:28:16 +04:00
* When compiling on platforms where configure has defined
* HAVE_DOWHILE_MACROS , statements will be wrapped with ` do ' and ` while ( 0 ) ' .
* For any other platforms ( SunOS4 is known to have this issue ) , wrap the
* statements with ` if ( 1 ) ' and ` else ( void ) 0 ' .
*/
# if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
# define LIBVIRT_STMT_START (void) __extension__ (
# define LIBVIRT_STMT_END )
# else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
# if defined (HAVE_DOWHILE_MACROS)
# define LIBVIRT_STMT_START do
# define LIBVIRT_STMT_END while (0)
# else /* !HAVE_DOWHILE_MACROS */
# define LIBVIRT_STMT_START if (1)
# define LIBVIRT_STMT_END else (void) 0
# endif /* !HAVE_DOWHILE_MACROS */
# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
# endif
2020-11-12 16:30:23 +03:00
# if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
# define LIBVIRT_BEGIN_ALLOW_THREADS \
2006-10-25 00:28:16 +04:00
LIBVIRT_STMT_START { \
PyThreadState * _save = NULL ; \
if ( PyEval_ThreadsInitialized ( ) ) \
_save = PyEval_SaveThread ( ) ;
2020-11-12 16:30:23 +03:00
# define LIBVIRT_END_ALLOW_THREADS \
2006-10-25 00:28:16 +04:00
if ( PyEval_ThreadsInitialized ( ) ) \
PyEval_RestoreThread ( _save ) ; \
} LIBVIRT_STMT_END
2020-11-12 16:30:23 +03:00
# define LIBVIRT_ENSURE_THREAD_STATE \
2006-10-25 00:28:16 +04:00
LIBVIRT_STMT_START { \
2007-03-07 00:55:44 +03:00
PyGILState_STATE _save = PyGILState_UNLOCKED ; \
2006-10-25 00:28:16 +04:00
if ( PyEval_ThreadsInitialized ( ) ) \
_save = PyGILState_Ensure ( ) ;
2020-11-12 16:30:23 +03:00
# define LIBVIRT_RELEASE_THREAD_STATE \
2006-10-25 00:28:16 +04:00
if ( PyEval_ThreadsInitialized ( ) ) \
PyGILState_Release ( _save ) ; \
} LIBVIRT_STMT_END
debug: Fix bit-rot in debug output
Let the compiler optimize out the printf() call instead of doing it with the
pre-processor as the later does not catch format string errors or the following
case, where NULLSTR() is used but not defined:
> libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
> libvirt-qemu-override.c:271:34: warning: implicit declaration of function ‘NULLSTR’; did you mean ‘NULL’? [-Wimplicit-function-declaration]
> 271 | pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
> | ^~~~~~~
> libvirt-qemu-override.c:39:28: note: in definition of macro ‘DEBUG’
> 39 | while (0) {printf(fmt, __VA_ARGS__);}
> | ^~~~~~~~~~~
> libvirt-qemu-override.c:270:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
> 270 | DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 271 | pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
> | ~~~~~~~~~~~~~~
> | |
> | int
> libvirt-qemu-override.c:39:23: note: in definition of macro ‘DEBUG’
> 39 | while (0) {printf(fmt, __VA_ARGS__);}
> | ^~~
> libvirt-qemu-override.c:270:73: note: format string is defined here
> 270 | DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
> | ~^
> | |
> | char *
> | %d
Copy the definition of NULLSTR from libvirt/src/internal.h to typewrappers.h
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 08:32:02 +03:00
2020-11-12 16:30:23 +03:00
# else
# define LIBVIRT_BEGIN_ALLOW_THREADS \
LIBVIRT_STMT_START { \
PyThreadState * _save = PyEval_SaveThread ( ) ;
# define LIBVIRT_END_ALLOW_THREADS \
PyEval_RestoreThread ( _save ) ; \
} LIBVIRT_STMT_END
# define LIBVIRT_ENSURE_THREAD_STATE \
LIBVIRT_STMT_START { \
PyGILState_STATE _save = PyGILState_Ensure ( ) ;
# define LIBVIRT_RELEASE_THREAD_STATE \
PyGILState_Release ( _save ) ; \
} LIBVIRT_STMT_END
# endif
debug: Fix bit-rot in debug output
Let the compiler optimize out the printf() call instead of doing it with the
pre-processor as the later does not catch format string errors or the following
case, where NULLSTR() is used but not defined:
> libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
> libvirt-qemu-override.c:271:34: warning: implicit declaration of function ‘NULLSTR’; did you mean ‘NULL’? [-Wimplicit-function-declaration]
> 271 | pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
> | ^~~~~~~
> libvirt-qemu-override.c:39:28: note: in definition of macro ‘DEBUG’
> 39 | while (0) {printf(fmt, __VA_ARGS__);}
> | ^~~~~~~~~~~
> libvirt-qemu-override.c:270:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
> 270 | DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 271 | pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
> | ~~~~~~~~~~~~~~
> | |
> | int
> libvirt-qemu-override.c:39:23: note: in definition of macro ‘DEBUG’
> 39 | while (0) {printf(fmt, __VA_ARGS__);}
> | ^~~
> libvirt-qemu-override.c:270:73: note: format string is defined here
> 270 | DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
> | ~^
> | |
> | char *
> | %d
Copy the definition of NULLSTR from libvirt/src/internal.h to typewrappers.h
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 08:32:02 +03:00
# ifndef NULLSTR
# define NULLSTR(s) ((s) ? (s) : "<null>")
# endif