Putting it all together – building a simple RESTful API to LXC with Python
With all the knowledge we have in hand by experimenting with the LXC bindings for Python earlier, we can write a simple RESTful API that will build, manage, and destroy LXC containers.
Note
To keep the code as simple as possible, we are going to skip all error and exception handling and any input validation from the program.
One of the simplest Python web frameworks for building APIs is Bottle. Let's install it first:
root@ubuntu:~# source lxc_python/bin/activate (lxc_python) root@ubuntu:~# pip install bottle Collecting bottle Downloading bottle-0.12.9.tar.gz (69kB) 100% |████████████████████████████████| 71kB 7.1MB/s Building wheels for collected packages: bottle Running ...
Get Containerization with LXC now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.