[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] setup.py:



ChangeSet 1.1662.1.17, 2005/06/07 14:21:38+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        setup.py:
          Add xenstore python bindings.
        xs.c:
          new file
        params.py:
          XSDAEMON_DEBUG -> XENSTORED_DEBUG
        Makefile:
          xenstore is also a library -- build it before python.
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 Makefile                         |    1 
 python/setup.py                  |   15 
 python/xen/lowlevel/xs/xs.c      |  617 +++++++++++++++++++++++++++++++++++++++
 python/xen/xend/server/params.py |    2 
 4 files changed, 631 insertions(+), 4 deletions(-)


diff -Nru a/tools/Makefile b/tools/Makefile
--- a/tools/Makefile    2005-06-09 13:09:08 -04:00
+++ b/tools/Makefile    2005-06-09 13:09:08 -04:00
@@ -3,6 +3,7 @@
 
 SUBDIRS :=
 SUBDIRS += libxc
+SUBDIRS += xenstore
 SUBDIRS += misc
 SUBDIRS += examples
 SUBDIRS += xentrace
diff -Nru a/tools/python/setup.py b/tools/python/setup.py
--- a/tools/python/setup.py     2005-06-09 13:09:08 -04:00
+++ b/tools/python/setup.py     2005-06-09 13:09:08 -04:00
@@ -9,13 +9,15 @@
 
 include_dirs = [ XEN_ROOT + "/tools/python/xen/lowlevel/xu",
                  XEN_ROOT + "/tools/libxc",
+                 XEN_ROOT + "/tools/xenstore",
                  XEN_ROOT + "/tools/xcs",
                  ]
 
 library_dirs = [ XEN_ROOT + "/tools/libxc",
+                 XEN_ROOT + "/tools/xenstore",
                  ]
 
-libraries = [ "xc" ]
+libraries = [ "xc", "xenstore" ]
 
 xc = Extension("xc",
                extra_compile_args = extra_compile_args,
@@ -30,7 +32,14 @@
                library_dirs       = library_dirs,
                libraries          = libraries,
                sources            = [ "xen/lowlevel/xu/xu.c" ])
-               
+
+xs = Extension("xs",
+               extra_compile_args = extra_compile_args,
+               include_dirs       = include_dirs + [ "xen/lowlevel/xs" ],
+               library_dirs       = library_dirs,
+               libraries          = libraries,
+               sources            = [ "xen/lowlevel/xs/xs.c" ])
+
 setup(name            = 'xen',
       version         = '2.0',
       description     = 'Xen',
@@ -43,7 +52,7 @@
                          'xen.web',
                          ],
       ext_package = "xen.lowlevel",
-      ext_modules = [ xc, xu ]
+      ext_modules = [ xc, xu, xs ]
       )
 
 os.chdir('logging')
diff -Nru a/tools/python/xen/lowlevel/xs/xs.c 
b/tools/python/xen/lowlevel/xs/xs.c
--- /dev/null   Wed Dec 31 16:00:00 196900
+++ b/tools/python/xen/lowlevel/xs/xs.c 2005-06-09 13:09:08 -04:00
@@ -0,0 +1,617 @@
+#include <Python.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "xs.h"
+
+/** @file
+ * Python interface to the Xen Store Daemon (xs).
+ */
+
+/* Needed for Python versions earlier than 2.3. */
+//#ifndef PyMODINIT_FUNC
+//#define PyMODINIT_FUNC DL_EXPORT(void)
+//#endif
+
+#define PYPKG    "xen.lowlevel.xs"
+
+/** Python wrapper round an xs handle.
+ */
+typedef struct XsHandle {
+    PyObject_HEAD;
+    struct xs_handle *xh;
+} XsHandle;
+
+static inline struct xs_handle *xshandle(PyObject *self)
+{
+    struct xs_handle *xh = ((XsHandle*)self)->xh;
+    if (!xh)
+        PyErr_SetString(PyExc_RuntimeError, "invalid xenstore daemon handle");
+    return xh;
+}
+
+static inline PyObject *pyvalue_int(int val) {
+    return (val
+            ? PyInt_FromLong(val)
+            : PyErr_SetFromErrno(PyExc_RuntimeError));
+}
+
+static inline PyObject *pyvalue_str(char *val) {
+    return (val
+            ? PyString_FromString(val)
+            : PyErr_SetFromErrno(PyExc_RuntimeError));
+}
+
+static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
+{
+    static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
+    static char *arg_spec = "ss#|ii";
+    char *path = NULL;
+    char *data = NULL;
+    int data_n = 0;
+    int create = 0;
+    int excl = 0;
+
+    struct xs_handle *xh = xshandle(self);
+    PyObject *val = NULL;
+    int flags = 0;
+    int xsval = 0;
+
+    if (!xh)
+       goto exit;
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
+                                     &path, &data, &data_n, &create, &excl))
+        goto exit;
+    if (create)
+       flags |= O_CREAT;
+    if (excl)
+       flags |= O_EXCL;
+    xsval = xs_write(xh, path, data, data_n, flags);
+    val = pyvalue_int(xsval);
+ exit:
+    return val;
+}
+
+static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
+{
+    static char *kwd_spec[] = { "path", NULL };
+    static char *arg_spec = "s|";
+    char *path = NULL;
+
+    struct xs_handle *xh = xshandle(self);
+    char *xsval = NULL;
+    int xsval_n = 0;
+    PyObject *val = NULL;
+
+    if (!xh)
+       goto exit;
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
+                                     &path))
+        goto exit;
+    xsval = xs_read(xh, path, &xsval_n);
+    if (!xsval) {
+        val = pyvalue_int(0);
+        goto exit;
+    }
+    val = PyString_FromStringAndSize(xsval, xsval_n);
+ exit:
+    if (xsval)
+       free(xsval);
+    return val;
+}
+
+static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
+{
+    static char *kwd_spec[] = { "path", NULL };
+    static char *arg_spec = "s|";
+    char *path = NULL;
+
+    struct xs_handle *xh = xshandle(self);
+    PyObject *val = NULL;
+    int xsval = 0;
+
+    if (!xh)
+       goto exit;
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
+        goto exit;
+    xsval = xs_mkdir(xh, path);
+    val = pyvalue_int(xsval);
+ exit:
+    return val;
+}
+
+static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
+{
+    static char *kwd_spec[] = { "path", NULL };
+    static char *arg_spec = "s|";
+    char *path = NULL;
+
+    struct xs_handle *xh = xshandle(self);
+    PyObject *val = NULL;
+    char **xsval = NULL;
+    int xsval_n = 0;
+    int i;
+
+    if (!xh)
+       goto exit;
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
+        goto exit;
+    xsval = xs_directory(xh, path, &xsval_n);
+    if (!xsval) {
+        val = pyvalue_int(0);
+        goto exit;
+    }
+    val = PyList_New(xsval_n);
+    for (i = 0; i < xsval_n; i++)
+        PyList_SetItem(val, i, PyString_FromString(xsval[i]));
+ exit:
+    return val;
+}
+
+static PyObject *xspy_rm(PyObject *self, PyObject *args, PyObject *kwds)
+{
+    static char *kwd_spec[] = { "path", NULL };
+    static char *arg_spec = "s|";
+    char *path = NULL;
+
+    struct xs_handle *xh = xshandle(self);
+    PyObject *val = NULL;
+    int xsval = 0;
+
+    if (!xh)
+       goto exit;
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
+        goto exit;
+    xsval = xs_rm(xh, path);
+    val = pyvalue_int(xsval);
+ exit:
+    return val;
+}
+
+static PyObject *xspy_get_permissions(PyObject *self, PyObject *args,
+                                     PyObject *kwds)
+{
+    static char *kwd_spec[] = { "path", NULL };
+    static char *arg_spec = "s|";
+    char *path = NULL;
+
+    struct xs_handle *xh = xshandle(self);
+    PyObject *val = NULL;
+    struct xs_permissions *perms;
+    int perms_n = 0;
+    int i;
+
+    if (!xh)
+       goto exit;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.