In part of my work for nova-compute-lxd, we use a combination of httplib, UNIX domain sockets, and JSON to talk to the LXD daemon via the REST API. Talking to various people involved in the LXD project, I have decided to split this part of nova-compute-lxd into its own project called pylxd. Pylxd is a general python library that you can use to interact with LXD in order to do container operations.
Right now, it is about 80% complete, the bits that are missing is that it needs more unit tests and needs more container operations (snapshots, running commands in the container, etc). That functionality will be coming in later releases of pylxd. I intend to use pylxd in the next version of nova-compute-lxd for the Liberty release of OpenStack as well. I am sure that there is other use cases that developers and users can use pylxd for.
To use pylxd, you just have to clone the git tree and build it. An example usage of pylxd is that you need a way to display the ‘/etc/hosts’ from your running ‘test1’ container. With pylxd this is pretty simple to do:
from pylxd import api
c = api.API()
print c.get_container_file(‘test1′, ‘/etc/hosts’)
The result of the above snippet is that the ‘/etc/hosts’ from the ‘test1’ container will be displayed. Pretty simple eh?
The code for pylxd is available on github here. Please report give it a a twirl, please report bugs, and would love to get feedback.
LXD is a lightweight container hypervisor for full system containers, unlike Docker and Rocket which is for application containers. This means that the container will look and feel like a regular VM – but will act like a container. LXD uses the same container technology found in the Linux kernel (cgroups, namespaces, LSM, etc). The LXD project has a 2 week development cycle which many more features are coming in the future. Stéphane Graber’s blog post is a very good introduction about LXD.
I have been focusing on LXD with OpenStack integration. In order to facilitate the OpenStack integration with LXD we have created a plugin called nova-compute-lxd (nclxd). The plugin uses the REST API to interact with OpenStack to provide common container operations to OpenStack. An high level example of how nclxd creates a container is the following:
- Download the tarball image from glance.
- Untar the tarball image into its own directory.
- Create a rootfs of the tarball that have been just created.
- Craft the appropriate json needed by the LXD rest api
- Tell the LXD daemon to create a container by generating a “put” request.
There is a couple of ways where one can install nclxd and use it with OpenStack:
Installing the plugin from source
The source for nclxd is available via Github. To install the source
git clone https://github.com/lxc/nova-compute-lxd
After you have installed the source and configured LXD. You will need to configure the compute driver in your /etc/nova/nova.conf to the following:
and configure LXD, configure OpenStack, and restart the nova-compute service.
Installing from the Ubuntu Archive
Since nclxd is still configured to be a technology preview, it is not available via the Ubuntu Cloud Archive. However it is available for Ubuntu 15.04. To install it simply run the following command:
sudo apt-get install nova-compute-lxd
Once you have finished installing you will need to configure LXD, configure your nova user to see the LXD daemon and restart your nova-compute service.
Installing via Juju Charms
Installing nclxd via the nova-compute charm is the easiest way to deploy it. In order for you to use nclxd with the charm, the option is simply the following in the nova-compute charm:
Once you have deployed the nova-compute charm with LXD enable, the users with be created with the correct permissions, and nova-compute will just be simply ready for you to use.
Using LXD with Openstack
Once you have finished downloading and configured nclxd you will need to upload an cloud image to the glance server that LXD can use. In order to do that you simply have to do the following:
wget -O vivid-server-cloudimg-amd64-root.tar.gz \
glance image-create --name='lxc' --container-format=bare --disk-format=raw \
After you upload the image to glance then you will be ready to go. If you have any questions please don’t hesitate to ask on the LXC mailing, #lxcontainers IRC channel on freenode, or contacting me directly. We always love getting bug reports and feedback!