#include <lxc/lxccontainer.h>
#include <lxc/utils.h>
#include <lxc/namespace.h>
+#include <lxc/confile.h>
#include <stdio.h>
#include <sys/wait.h>
return PyLong_FromLong(rv);
}
+static PyObject *
+LXC_arch_to_personality(PyObject *self, PyObject *arg)
+{
+ long rv = -1;
+ PyObject *pystr;
+ char *str;
+
+ if (!PyUnicode_Check(arg)) {
+ PyErr_SetString(PyExc_ValueError, "Expected a string");
+ return NULL;
+ }
+
+ pystr = PyUnicode_AsUTF8String(arg);
+ if (!pystr)
+ return NULL;
+
+ str = PyBytes_AsString(pystr);
+ if (!str)
+ goto out;
+
+ rv = lxc_config_parse_arch(str);
+ if (rv == -1)
+ PyErr_SetString(PyExc_KeyError, "Failed to lookup architecture.");
+
+out:
+ Py_DECREF(pystr);
+ return rv == -1 ? NULL : PyLong_FromLong(rv);
+}
+
static PyObject *
LXC_attach_run_command(PyObject *self, PyObject *arg)
{
"Starts up a shell when attaching, to use as the run parameter for attach or attach_wait"},
{"attach_run_command", (PyCFunction)LXC_attach_run_command, METH_O,
"Runs a command when attaching, to use as the run parameter for attach or attach_wait"},
+ {"arch_to_personality", (PyCFunction)LXC_arch_to_personality, METH_O,
+ "Returns the process personality of the corresponding architecture"},
{"get_default_config_path", (PyCFunction)LXC_get_default_config_path, METH_NOARGS,
"Returns the current LXC config path"},
{"get_version", (PyCFunction)LXC_get_version, METH_NOARGS,
"""
return _lxc.attach_run_shell(None)
+def arch_to_personality(arch):
+ """
+ Determine the process personality corresponding to the architecture
+ """
+ if isinstance(arch, bytes):
+ arch = str(arch, 'utf-8')
+ return _lxc.arch_to_personality(arch)
+
# Some constants for attach
LXC_ATTACH_KEEP_ENV = _lxc.LXC_ATTACH_KEEP_ENV
LXC_ATTACH_CLEAR_ENV = _lxc.LXC_ATTACH_CLEAR_ENV