Feb 022014

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:

  1. Clone a blank template
  2. Set the new VM’s install options, so it knows where to find the installation material
  3. Choose a storage repository to host the VM’s disks
  4. Create a VDI (virtual disk) on the chosen storage repository
  5. Create a VBD (virtual block device) on the VDI
  6. Choose a network to connect the VM to
  7. Create a VIF (virtual network interface) on the chosen network
  8. 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:

What’s Next
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.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>