Commit be2e4e54 by Stéphane Graber

Add python-lxc based on the new liblxc API.

This adds a basic python binding done in C and a python overlay to extend some features and provide a user-friendlier API. This python API only supports python 3.x and was tested with >= 3.2. It's disabled by default in configure and can be turned on by using --enable-python. A basic example of the API can be found in src/python-lxc/test.py. More documentation and examples will be added soon.
parent 7a44c8b4
...@@ -12,6 +12,11 @@ AM_PROG_CC_C_O ...@@ -12,6 +12,11 @@ AM_PROG_CC_C_O
AC_GNU_SOURCE AC_GNU_SOURCE
AC_CHECK_PROG(SETCAP, setcap, yes, no, $PATH$PATH_SEPARATOR/sbin) AC_CHECK_PROG(SETCAP, setcap, yes, no, $PATH$PATH_SEPARATOR/sbin)
if test -f /etc/debian_version; then
osname="debian"
fi
AM_CONDITIONAL([HAVE_DEBIAN], [test x"$osname" == xdebian])
AC_ARG_ENABLE([rpath], AC_ARG_ENABLE([rpath],
[AC_HELP_STRING([--disable-rpath], [do not set rpath in executables])], [AC_HELP_STRING([--disable-rpath], [do not set rpath in executables])],
[], [enable_rpath=yes]) [], [enable_rpath=yes])
...@@ -67,6 +72,17 @@ AC_ARG_ENABLE([examples], ...@@ -67,6 +72,17 @@ AC_ARG_ENABLE([examples],
AM_CONDITIONAL([ENABLE_EXAMPLES], [test "x$enable_examples" = "xyes"]) AM_CONDITIONAL([ENABLE_EXAMPLES], [test "x$enable_examples" = "xyes"])
AC_ARG_ENABLE([python],
[AC_HELP_STRING([--enable-python], [enable python binding])],
[enable_python=yes], [enable_python=no])
AM_CONDITIONAL([ENABLE_PYTHON], [test "x$enable_python" = "xyes"])
AM_COND_IF([ENABLE_PYTHON],
[AM_PATH_PYTHON([3.2], [], [AC_MSG_ERROR([You must install python3])])
AC_CHECK_HEADER([python$PYTHON_VERSION/Python.h],[],[AC_MSG_ERROR([You must install python3-dev])])
AC_DEFINE_UNQUOTED([ENABLE_PYTHON], 1, [Python3 is available])])
AS_AC_EXPAND(PREFIX, $prefix) AS_AC_EXPAND(PREFIX, $prefix)
AS_AC_EXPAND(LIBDIR, $libdir) AS_AC_EXPAND(LIBDIR, $libdir)
AS_AC_EXPAND(BINDIR, $bindir) AS_AC_EXPAND(BINDIR, $bindir)
...@@ -192,6 +208,8 @@ AC_CONFIG_FILES([ ...@@ -192,6 +208,8 @@ AC_CONFIG_FILES([
src/lxc/lxc-shutdown src/lxc/lxc-shutdown
src/lxc/lxc-destroy src/lxc/lxc-destroy
src/python-lxc/Makefile
src/tests/Makefile src/tests/Makefile
]) ])
......
SUBDIRS = lxc tests SUBDIRS = lxc tests python-lxc
if ENABLE_PYTHON
if HAVE_DEBIAN
DISTSETUPOPTS=--install-layout=deb
else
DISTSETUPOPTS=
endif
all:
CFLAGS="$(CFLAGS) -I ../../src -L../../src/lxc/" $(PYTHON) setup.py build
install:
python3 setup.py install --root=$(DESTDIR) --prefix=$(PREFIX) --no-compile $(DISTSETUPOPTS)
clean:
rm -rf build
endif
from distutils.core import setup, Extension
module = Extension('_lxc', sources = ['lxc.c'], libraries = ['lxc'])
setup (name = '_lxc',
version = '0.1',
description = 'LXC',
packages = ['lxc'],
package_dir = {'lxc':'lxc'},
ext_modules = [module])
import lxc
t1 = lxc.Container("test")
print("Name set properly: %s" % (t1.name == "test"))
print("Test config loaded properly: %s" % t1.load_config("/etc/lxc/lxc.conf"))
print("Real config loaded properly: %s" % t1.load_config())
print("Test config path: %s" % (t1.config_file_name == "/var/lib/lxc/test/config"))
print("Set config item: %s" % t1.set_config_item("lxc.utsname", "blabla"))
print("Container defined: %s" % (t1.defined))
print("Started properly: %s" % t1.start())
print("Container running: %s" % t1.wait("RUNNING"))
print("Container state: %s" % t1.state)
print("Container running: %s" % t1.running)
print("Container init process: %s" % t1.init_pid)
print("Freezing: %s" % t1.freeze())
print("Container frozen: %s" % t1.wait("FROZEN"))
print("Container state: %s" % t1.state)
print("Unfreezing: %s" % t1.unfreeze())
print("Container running: %s" % t1.wait("RUNNING"))
print("Container state: %s" % t1.state)
print("Stopped properly: %s" % t1.stop())
print("Container state: %s" % t1.state)
#print("Started properly: %s" % t1.start(useinit=True))
#print("Container running: %s" % t1.wait("RUNNING"))
#print("Container state: %s" % t1.state)
#print("Stopped properly: %s" % t1.stop())
#print("Container state: %s" % t1.state)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment