summaryrefslogtreecommitdiffstats
path: root/libvir.c
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2009-08-04 20:38:21 +0200
committerDaniel P. Berrange <berrange@redhat.com>2009-09-01 18:27:06 +0100
commit11bca8e4d912f360926c29981b6faf9dba45bf86 (patch)
tree23ece52527088a0c09b8ee8e02d1e339b0c26402 /libvir.c
parenta5d4455ba21721b4739aab09b2c8116d138b29f3 (diff)
downloadlibvirt-python-v6-11bca8e4d912f360926c29981b6faf9dba45bf86.tar.gz
libvirt-python-v6-11bca8e4d912f360926c29981b6faf9dba45bf86.tar.xz
libvirt-python-v6-11bca8e4d912f360926c29981b6faf9dba45bf86.zip
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'
Diffstat (limited to 'libvir.c')
-rw-r--r--libvir.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/libvir.c b/libvir.c
index e210597..e2c196a 100644
--- a/libvir.c
+++ b/libvir.c
@@ -1562,6 +1562,103 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
return(py_retval);
}
+static PyObject *
+libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ PyObject *py_retval;
+ char **uuids = NULL;
+ virConnectPtr conn;
+ int c_retval, i;
+ PyObject *pyobj_conn;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSecrets", &pyobj_conn))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectNumOfSecrets(conn);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0)
+ return VIR_PY_NONE;
+
+ if (c_retval) {
+ uuids = malloc(sizeof(*uuids) * c_retval);
+ if (!uuids)
+ return VIR_PY_NONE;
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectListSecrets(conn, uuids, c_retval);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0) {
+ free(uuids);
+ return VIR_PY_NONE;
+ }
+ }
+ py_retval = PyList_New(c_retval);
+
+ if (uuids) {
+ for (i = 0;i < c_retval;i++) {
+ PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
+ free(uuids[i]);
+ }
+ free(uuids);
+ }
+
+ return py_retval;
+}
+
+static PyObject *
+libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ PyObject *py_retval;
+ unsigned char *c_retval;
+ size_t size;
+ virSecretPtr secret;
+ PyObject *pyobj_secret;
+ unsigned int flags;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virSecretGetValue", &pyobj_secret,
+ &flags))
+ return NULL;
+ secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virSecretGetValue(secret, &size, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (c_retval == NULL)
+ return VIR_PY_NONE;
+
+ py_retval = PyString_FromStringAndSize((const char *)c_retval, size);
+ memset(c_retval, 0, size);
+ free(c_retval);
+
+ return py_retval;
+}
+
+static PyObject *
+libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ PyObject *py_retval;
+ int c_retval;
+ virSecretPtr secret;
+ PyObject *pyobj_secret;
+ const char *value;
+ int size;
+ unsigned int flags;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oz#i:virSecretSetValue", &pyobj_secret,
+ &value, &size, &flags))
+ return NULL;
+ secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
+ flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ py_retval = libvirt_intWrap(c_retval);
+ return py_retval;
+}
/*******************************************
* Helper functions to avoid importing modules
@@ -2261,6 +2358,9 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
{(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
{(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
+ {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL},
+ {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL},
+ {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};