Launch Virtual Machines Quickly with spinup
For a long time now, I’ve been using Vagrant to quickly launch a VM or
two when I need to. Recently, I’ve been less and less satisfied with
Vagrant. It’s usually slow and needs editing the
Vagrantfile if I
want to change the machine specs. The slowness might be partially due
to using VirtualBox by default. There is a vagrant-libvirt plugin that
lets you use libvirt/KVM but the plugin seems to be a hit-and-miss
affair and I’ve not been able to make it work all the time.
There is always the option of using
virsh and other libvirt
utilities, of course, to launch VMs, but that is not as simple as I’d
like. I finally decided to write some sort of wrapper script for
libvirt and here it is: spinup –a simple utility to launch VMs
as fast as possible.
You need to clone the repository, run
prepare.sh and you’re set to
spinup. I’ll also assume that you’ve made a symlink to
spinup in an appropriate place, and installed the
dependencies, so that the utility is always easily available to
you. There’s of course the option of installing dependencies in a
virtualenv and running
./spinup.py from there. You will obviously
libvirtd available, too.
The easiest way to launch a VM is by running this:
This will create an Ubuntu based VM with 1GiB of RAM and one CPU core, downloading the Ubuntu cloud image the first time you run it. To land inside the VM, simply run:
$ spinup ssh
The created VM is tied to the directory you create it in (although no files are created in that directory). So you need to be in that directory in order to have access to the VM.
In order to destroy the VM, simply run:
$ spinup destroy
You can create a VM with different specs like this:
$ spinup coreos 4G 2cpus
This will create a CoreOS based VM with 4GiB of RAM and two CPU cores.
It’s also possible to launch multiple VMs at the same time:
$ spinup :foo ubuntu 2G -- :bar coreos 4G 2cpus
Here we have created two VMs, naming them
respectively. In order to ssh into
bar simply run:
$ spinup ssh bar
spinup destroy will destroy both VMs.
One area in which
spinup is sorely lacking at the moment is
networking. The created VMs are connected to libvirt’s default
network, but there are no other options. I’m hoping to fix this in the
near future. (Update: configuring network is now available, although
you might need to create the appropriate libvirt networks first.)
spinup is in its very early stages of development, released in the
“release early, release often” spirit. If you have any questions, you
can send me an email at mostafa(at)sepent.com or create an issue or
send a pull request over at github.