Friday, 28 March 2014

Using libvirt domains in Fabric

Fabric is really cool. After using (and getting frustrated with) Vagrant, I decided to write some fabfile routines that help do what Vagrant does, without the headaches.

First up, referencing libvirt domains without knowing the IP address of the machine:

The code is scruffy but you get the idea. Basically, we use the libvirt Python bindings to get some XML information on the domain, then find the MAC address and try to resolve that to an IP using the 'arp' command on Linux. This means you can load up Fabric environments for a libvirt domain using its name:

]$ fab vm:fedora-vm deploy

As an example. In another post i'll pop up some functions for handling NFS mounting and provisioning using libvirt (which in turn supports KVM, LXC container etc)

While the provisioning isn't really in the spirit of Fabric, having Fabric use a virtualization agnostic library such as libvirt has tons of benefits.