LLXC: My little python3-lxc based project

My foray into the world of LXC and RLXC

A few months ago, I started trying out LXC (Linux Containers). Before that I used to use OpenVZ, which is an older and more mature contextualization implementation. I was pleased with how well LXC worked and started replacing my personal OpenVZ hosts with LXC.

It worked great, but it had a few quirks. While LXC itself works well, the user scripts that ship with it has some space for improvement. The lxc-list command lists anything that’s a directory in /var/lib/lxc, so if you have a lost+found directory, it will list it as a container (This has since been fixed upstream). Also, in some cases it would list containers twice or not at all. I was a bit annoyed with that, since OpenVZ’s “vzlist” tool prints out a nice table of your containers along with their IP addresses and other information. Since it’s very trivial to implement what I want in a shell script, I went ahead and did just that and called it RLXC.

I also missed the “vzctl exec <containername> command” to execute commands in containers and “vzctl enter <containername>” to gain a shell inside the container, so I added some more functionality to it so that I could configure ssh keys for these containers and use “rlxc enter” and “rlxc exec” like I used to do with the OpenVZ tools, but by using SSH.

I also realised that there are others too who wanted similar improvements in the LXC scripts and decided to continue improving RLXC and making it public.

Enter LLXC

I spoke to Stéphane about my ideas at the time and he introduced me to python3-lxc that he introduced on his blog yesterday. It provides Python bindings for liblxc, so I took the advantage of that and mostly re-implemented RLXC in Python and called it LLXC. The name doesn’t particularly mean anything, I’m open to suggestions for what to call it, if anyone cares.

Here are some screenshots that explains some of it better than I could do in words:

How to get it

As Stéphane mentioned in the python3-lxc blog entry, the API hasn’t yet been finalized and llxc itself is in an early state and many changes are planned, so it’s definitely not meant for production use yet, but since we believe in “release early, release often” in the free software community, here goes…

Currently, llxc.py itself is *very* Ubuntu specific and its only been tested on Ubuntu 12.04, but that will be fixed once more of its kinks have been ironed out. Some people are also working on getting python3-lxc on other distributions, which will help a lot.

The llxc.py script itself is hosted on Github: https://github.com/highvoltage/llxc

For python3-lxc and friends, you need to enable Stéphane’s experimental PPA: https://launchpad.net/~stgraber/+archive/experimental

You will then need to install the following packages: lxc, python3-lxc, python3-crypto, lvm, btrfs-tools

To generate the ssh keys used for ssh interaction between the containers, you need to run “llxc gensshkeys”.  The “enter” and “exec” commands also rely on your containers being in dns or in your /etc/hosts file, at least for now, which you may have to configure manually.

The Future

There is a lot that I’m planning to add, mostly to scratch my own itches. These include:

  • Awareness of other hosts, so that the list command can show you all containers in the “awareness”. You’d also be able to clone, move, etc containers between hosts.
  • Easily modify container configuration
  • Hooks everywhere, and at least one hook for configuring a configuration management system such as salt, bcfg2, puppet or chef.
  • More checks and tips everywhere. Is the host running low on memory? Disk space? Perhaps list available resources on variable hosts and make some suggestions based on that.
  • There a not-very-descriptive ROADMAP file in the distribution, check that for more details.

I’ll have some packaging for this available soon and work on making more things work right out of the box, updates will follow. Also, feedback and patches are very welcome!

You may also like...

9 Responses

  1. Serge says:

    Looks very nice :)

    Thanks!

  2. Guido says:

    Great article, good work.

    Could you please elaborate about how to install python3-lxc? I am using ubuntu 12.04 and I am having problems with it, I can not find it using apt-get, I have also tried to download the sources from github but it still gives me errors when I try to execute the code.

    Thank you in advance.

  3. jonathan says:

    Hey Guido, I’m putting together some packaging for it and will put it in a PPA, that should make it a lot easier to install. I’ll post an update on how to install it step by step as well.

  4. Steven C says:

    It would be really, really neat if this tool could support jails on GNU/kFreeBSD! I’m so accustomed to vzlist/vzctl enter/exec.

  5. Guido says:

    Thank you very much, Jonathan.

  6. xagaba says:

    You need to see http://www.serfdom.io/ I’m testing with a script like yours to make some light personal paas

  7. susheel teja says:

    you can use lxc-ls –fancy will list the containers status with running IP addresses and name of the container.
    sorry if it is irrelevant.

  8. jonathan says:

    @Susheel that’s correct. This blog entry was written 5 years ago before lxc-ls –fancy was there :)

  1. 1 October 2012

    […] http://jonathancarter.org/2012/09/29/llxc-my-little-python3-lxc-based-project/ Share this:TwitterFacebookLike this:LikeBe the first to like this. […]

Leave a Reply

Only people in my network can comment.