Skip to contentSkip to conversation

Python Bindings Status

PATCH James Dingwall 2 participants 2 messages Mar 12, 2015

lore
Share & tools
lore
#0 lore raw

Hi,

I am trying to use the libxl python bindings but having mixed levels of success. I assume that the current status of this is unsupported as the build of the xl.so is disabled by default but perhaps completing the missing parts could be quite trivial? I have managed to enabled the build with the patch the follow below.

I can for example:

from __future__ import print_function
from xen.lowlevel import xl
xlctx = xl.ctx()
for domu in xlctx.list_domains():
print(xlctx.domid_to_name(domu.domid))

However other parts such as xl.version_info() do not seem to work. Looking at the wrapper code which is generated in the build it seems that the object which would store the version information is allocated and initialised but never populated:

xen-4.5.0/tools/python/xen/lowlevel/xl/_pyxl_types.c:
static int Pyversion_info_init(Py_version_info *self, PyObject *args, PyObject *kwds)

{
    memset(&self->obj, 0, sizeof(self->obj));
    return genwrap__obj_init((PyObject *)self, args, kwds);
}

static PyObject *Pyversion_info_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

{
    Py_version_info *self = (Py_version_info *)type->tp_alloc(type, 0);
    if (self == NULL)
        return NULL;
    memset(&self->obj, 0, sizeof(self->obj));
    return (PyObject *)self;
}

I can see that the version_info libxl function takes a ctx argument but passing in xl.ctx() to xl.version_info() does not change anything, i.e. print(xl.version_info().xen_version_major) always shows 0.

What level of experience/effort would be required to address this?

Thanks,
James

tools/python/setup.py +3 -3
index 439c429..029869e 100644
@@ -31,13 +31,13 @@ xl = Extension("xl",
                extra_compile_args = extra_compile_args,
                include_dirs       = [ PATH_XEN, PATH_LIBXL, PATH_LIBXC + "/include", "xen/lowlevel/xl" ],
                library_dirs       = [ PATH_LIBXL ],
-               libraries          = [ "xenlight" ],
-               depends            = [ PATH_LIBXL + "/libxenlight.so" ],
+               libraries          = [ "xenlight", "xlutil" ],
+               depends            = [ PATH_LIBXL + "/libxenlight.so", PATH_LIBXL + "/libxlutil.so" ],
                sources            = [ "xen/lowlevel/xl/xl.c", "xen/lowlevel/xl/_pyxl_types.c" ])
 
 plat = os.uname()[0]
 modules = [ xc, xs ]
-#modules.extend([ xl ])
+modules.extend([ xl ])
 
 setup(name            = 'xen',
       version         = '3.0',
#1 lore raw
Quoted 5 lines · James Dingwall

Hi,

I am trying to use the libxl python bindings but having mixed levels of success. I assume that the current status of this is unsupported as the build of the xl.so is disabled by default but perhaps completing the missing parts could be quite trivial?

IMHO they are architecturally broken and should be redone from scratch.

In particular the "live update of the backing C struct" aspect is broken in various respects IIRC and difficult to fix (the original author is also long gone).

I expect this brokenness relates to why things appear to return 0 for you.

IMHO a much more sensible approach would be to follow what the ocaml bindings do and do on demand translation between Python<->C as you call the libxl functions.

Quoted 1 line

What level of experience/effort would be required to address this?

Not much Xen experience, mostly Python bindings experience (the generator itself is in Python too as it happens).

I think it would be a fair effort though.

Ian.