I’m starting to dive into choosing from a variety of server virtualization options for work in order to determine which solution to roll into our environments. First up is XenServer, with which I’ll stand up a pool of a couple machines and test out provisioning new servers, live migration, network isolation, and other cool features. While these tasks are more straightforward using the GUI (official GUI is Windows-only, but there are alternatives), I’m spiking out tooling that does as much as possible via the API (since we’ll want to automate it).
The default toolstack for XenServer and XCP is XAPI (aka XenAPI). In addition to being command-line driven (all commands are available using
xe), this toolstack exposes an RPC webservice which can be used to completely configure the system.
Building on top of a ruby SDK for XAPI, I have released xencap, which is a light-weight wrapper around the API, intended for use as a capistrano plugin. This library isn’t meant to hide the complexity of Xen (which is considerable), so you still need to understand the underlying system to use it, but once you understand what you want to do, putting it in xencap shouldn’t be hard. For instance, in order to create a VM from scratch on xen, you need to do several things:
- Clone a blank template
- Set the new VM’s install options, so it knows where to find the installation material
- Choose a storage repository to host the VM’s disks
- Create a VDI (virtual disk) on the chosen storage repository
- Create a VBD (virtual block device) on the VDI
- Choose a network to connect the VM to
- Create a VIF (virtual network interface) on the chosen network
- Start the VM, and install the OS
This is a long list, but fairly straightforward once you understand the various parts. There is a great deal of opportunity for flexibility, but also for human error. Many of these options also take a slew of parameters.
Putting this into xencap is not succinct (remember, the idea here isn’t to hide complexity), but allows you to automate the whole process (and programmatically change things as you see fit). For example, this capistrano task will build an Ubuntu 12.04 box with bridged networking and a 10G hard drive:
I’ll be adding to this as I test out various features of Xen, so if you’re interested, check out the code, install the gem (
gem install xencap), watch this blog for updates, or send me a pull request.