[lxc-devel] liblxc api

Serge Hallyn serge.hallyn at canonical.com
Thu Jun 7 21:57:47 UTC 2012


Hi,

we've been talking (including a session at UDS) about getting a nice
API out of liblxc, with exports to python etc.  This could be used: to
easily replace some of the tools which are currently scripts;  to
increase code sharing with other projects - most immediately arkose and
libvirt;  and to make automated testing easier.

I tried my hand at implementing the start of that at
https://code.launchpad.net/~serge-hallyn/+junk/lxcwithapi .
The api is in src/lxc/lxccontainer.h, and the testcases in src/tests show
how to use it.  For instance, you could

	struct lxc_container *c;
	c = lxc_container_new("p1");
	if (!c->load_config(c, NULL)) {
		EXIT_FAIL("Loading configuration file %s for %s\n",
		    c->configfile, c->name);
	}

	c->want_daemonize(c);
	if (!c->start(c, 0, NULL)) {
		EXIT_FAIL("failed to start container %s\n", c->name);
	}

	if (!c->wait(c, "RUNNING")) {
		EXIT_FAIL("failed waiting for %s to be RUNNING\n",
		c->name);
	}

	INFO("container %s is running\n", c->name);
	lxc_container_put(c);

or, presumably in python (once the wrappers are there)

	c = LXC.lxc()
	c->want_daemonize()
	c->start()
	c->wait("RUNNING")

The bits of the api i've implemented may be all we need for arkose to
switch from using lxc-start etc binaries to using the api (not sure,
Stéphane can yell at me if not).

I had to do a little bit of shuffling liblxc code around to let me
reuse it, but far less so than I'd expected!

Does this seem worthwhile?  Comments - or competing implementations -
greatly appreciated.

thanks,
-serge




More information about the lxc-devel mailing list