[lxc-devel] liblxc api

Matthew Franz mdfranz at gmail.com
Fri Jun 8 00:30:31 UTC 2012


Absolutely, especially the Python bit!  I wrote a psuedo-OO wrapper
for OpenVZ (basically makes a bunch of vzctl calls at a higher layer
of abstraction so you can/start/stop/configure large numbers of
containers) and was thinking about writing something similar for LXC
that called the lxc-* BUT always I'm always a feel a little weird
about calling .sh from .py so the .c wrappers would be awesome.

- mdf

On Thu, Jun 7, 2012 at 5:57 PM, Serge Hallyn <serge.hallyn at canonical.com> wrote:
> 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
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel



-- 
--
Matthew Franz
mdfranz at gmail.com




More information about the lxc-devel mailing list