I did not use virtualization for years, because managing virtual machines seemed to be complicated, clumsy and I did not want to waste my time with them. From time to time I downloaded some manager program, played with it and decided that I have no time for them, I have more productive things on my plate. It was a mistake.
Maybe those management applications were quite ok, but for sure they did not provide the things I really needed. Because you know here is how they felt to me:
Download, install, configure, then create a virtual machine from an image. Then, you can go and read a gazillion page documentation that tells you at some paragraph deep inside that there is default username and a password, but there is no way to log in, so you need to do magic, then more magic, then you will be able to log in, then create an account, then maybe try install ssh, then realize that the network is not running, you will need to do more magic, more, maybe some ork blood and crystals... but we all know you will give up at the end.
While I wanted something like this:
Gimme a VM, Ubuntu, the whatyacallit, the new one, gimme fast, I want to continue working, I want to SSH and continue, because I'm in the zone!
Well, at the end I really needed virtualization for tests, there was no excuse so I started to use LXC. But it was of course complicated and clumsy, so I wrote a few scripts to do the dirty details. I practically used BASH scripts as notes, figured out what to do, then I wrote down the know-how in BASH format. Fortunately you can use my scripts, so you don't need to fight your way through.
I use these scripts for testing the s9s-tools open source package, that is the command line client software for the Severalnines ClusterControl system. You can find the scripts in the s9s-tools source under the pipscripts/ directory. The pipscripts is a set of shell scripts that lives in the s9s-tools source like mitochondria in the human cell; it was born separately, it has its own history, but they need each other, so they live in a strong symbiotic relationship. The s9s-tools needs containers and other stuff for testing and the pipscripts are now lives mostly for this reason. You can go and install the scripts independently and use them, you don't actually need the whole s9s-tools or ClusterControl to run these scripts, but when these are tested, the scripts will be used and so the scripts are tested every day themselves too.
So here is what I would do... well, here is what I actually do:
- When you have the server for the containers set up as described in the previous post, go and configure passwordless ssh and passwordless sudo on the server.
- Go and install the pipscripts scripts on both the server and the desktop. Well, they can be the same, but if you have multiple servers all of them should have the scripts installed.
When the scripts are installed on bot end you will be able to create containers on your server from your desktop using the command line.
You can also print out what distributions and what versions are available. These are provided by the server's own distribution, so the list changes as you upgrade your server.
Here is a trick what I do in my tests:
- I created a container called ubuntu on the server a long time ago. I use it as a template.
- I stopped this container. I did it by hand, with the lxc-stop, sorry about that (the command is sudo lxc-stop -n container-name for stopping a container).
- Whenever I need a container fast, I simply omit the distribution and version so my script will automatically choose the stopped ubuntu container as a template and create a new container by making a copy. New MAC address, new IP, new instance, but otherwise it is an exact duplicate of my ubuntu container.
I do this in my test scripts, it is fast and I can control the test environment on the long term by updating the template container if I have to. I just start it up, ssh, then do whatever I want and finally stop the container. For my scripts a template is just a container that is not running at the moment.
And that's it, that shows how easy the every day life can be. Here is a screenshot for a reminder, create, use, view and destroy a container in a few seconds using only a few command line options.