2005-12-20 00:34:11 +08:00
|
|
|
/*
|
|
|
|
* types.c: converter functions between the internal representation
|
|
|
|
* and the Python objects
|
|
|
|
*
|
2007-12-07 18:08:06 +08:00
|
|
|
* Copyright (C) 2005, 2007 Red Hat, Inc.
|
2005-12-20 00:34:11 +08:00
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-30 02:15:54 +08:00
|
|
|
#include <config.h>
|
2007-12-07 18:08:06 +08:00
|
|
|
|
2008-04-19 02:31:32 +08:00
|
|
|
/* Horrible kludge to work around even more horrible name-space pollution
|
|
|
|
* via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
|
|
|
|
* which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
|
|
|
|
#undef HAVE_PTHREAD_H
|
|
|
|
|
2009-09-16 21:03:53 +08:00
|
|
|
#include "typewrappers.h"
|
2005-12-20 00:34:11 +08:00
|
|
|
|
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_intWrap(int val)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyInt_FromLong((long) val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_longWrap(long val)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyInt_FromLong(val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2006-11-16 03:40:00 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_ulongWrap(unsigned long val)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromLong(val);
|
|
|
|
return (ret);
|
2008-02-06 03:27:37 +08:00
|
|
|
}
|
2006-11-16 03:40:00 +08:00
|
|
|
|
2006-01-31 18:24:12 +08:00
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_longlongWrap(long long val)
|
2006-01-31 18:24:12 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromUnsignedLongLong((unsigned long long) val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-02-03 19:31:45 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_ulonglongWrap(unsigned long long val)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromUnsignedLongLong(val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2005-12-20 00:34:11 +08:00
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_charPtrWrap(char *str)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
|
|
|
free(str);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_constcharPtrWrap(const char *str)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_charPtrConstWrap(const char *str)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_virDomainPtrWrap(virDomainPtr node)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainPtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2007-03-09 23:42:50 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virNetworkPtrWrap(virNetworkPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNetworkPtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2009-05-21 18:57:05 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virInterfacePtrWrap(virInterfacePtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virInterfacePtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-02-20 23:26:22 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStoragePoolPtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
libvirt_virStorageVolPtrWrap(virStorageVolPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStorageVolPtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2005-12-20 00:34:11 +08:00
|
|
|
PyObject *
|
2006-02-10 01:45:11 +08:00
|
|
|
libvirt_virConnectPtrWrap(virConnectPtr node)
|
2005-12-20 00:34:11 +08:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virConnectPtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
2008-10-31 18:13:45 +08:00
|
|
|
|
2008-11-21 20:41:15 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNodeDevicePtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
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-05 02:38:21 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virSecretPtrWrap(virSecretPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virSecretPtr", NULL);
|
2010-04-29 18:46:01 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
libvirt_virNWFilterPtrWrap(virNWFilterPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virNWFilterPtr", NULL);
|
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-05 02:38:21 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2009-07-10 19:18:12 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virStreamPtrWrap(virStreamPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virStreamPtr", NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-04-01 04:33:13 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainSnapshotPtr",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-10-31 18:13:45 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2008-12-18 20:25:11 +08:00
|
|
|
printf("%s: WARNING - Wrapping None\n", __func__);
|
2008-10-31 18:13:45 +08:00
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventHandleCallback",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
2008-12-18 20:25:11 +08:00
|
|
|
printf("%s: WARNING - Wrapping None\n", __func__);
|
2008-10-31 18:13:45 +08:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-11-20 00:24:01 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virFreeCallbackWrap(virFreeCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-10-31 18:13:45 +08:00
|
|
|
PyObject *
|
|
|
|
libvirt_virVoidPtrWrap(void* node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "void*",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|