2005-12-19 16:34:11 +00:00
|
|
|
/*
|
|
|
|
* types.c: converter functions between the internal representation
|
|
|
|
* and the Python objects
|
|
|
|
*
|
2007-12-07 10:08:06 +00:00
|
|
|
* Copyright (C) 2005, 2007 Red Hat, Inc.
|
2005-12-19 16:34:11 +00:00
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-12-07 10:08:06 +00:00
|
|
|
|
2008-04-18 18:31:32 +00: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 13:03:53 +00:00
|
|
|
#include "typewrappers.h"
|
2005-12-19 16:34:11 +00:00
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_intWrap(int val)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyInt_FromLong((long) val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_longWrap(long val)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyInt_FromLong(val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2006-11-15 19:40:00 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_ulongWrap(unsigned long val)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromLong(val);
|
|
|
|
return (ret);
|
2008-02-05 19:27:37 +00:00
|
|
|
}
|
2006-11-15 19:40:00 +00:00
|
|
|
|
2006-01-31 10:24:12 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_longlongWrap(long long val)
|
2006-01-31 10:24:12 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromUnsignedLongLong((unsigned long long) val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-02-03 11:31:45 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_ulonglongWrap(unsigned long long val)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromUnsignedLongLong(val);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2005-12-19 16:34:11 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_charPtrWrap(char *str)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
|
|
|
free(str);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_constcharPtrWrap(const char *str)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_charPtrConstWrap(const char *str)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_virDomainPtrWrap(virDomainPtr node)
|
2005-12-19 16:34:11 +00: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 15:42:50 +00: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 10:57:05 +00: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 15:26:22 +00: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-19 16:34:11 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_virConnectPtrWrap(virConnectPtr node)
|
2005-12-19 16:34:11 +00: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 10:13:45 +00:00
|
|
|
|
2008-11-21 12:41:15 +00: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-04 18:38:21 +00: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 10:46:01 +00: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-04 18:38:21 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2009-07-10 11:18:12 +00: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-03-31 20:33:13 +00: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 10:13:45 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2008-12-18 12:25:11 +00:00
|
|
|
printf("%s: WARNING - Wrapping None\n", __func__);
|
2008-10-31 10:13:45 +00: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 12:25:11 +00:00
|
|
|
printf("%s: WARNING - Wrapping None\n", __func__);
|
2008-10-31 10:13:45 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return (Py_None);
|
|
|
|
}
|
|
|
|
ret =
|
|
|
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback",
|
|
|
|
NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:24:01 +00: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 10:13:45 +00: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);
|
|
|
|
}
|