Project Source

I love OpenVZ, I think its one of the easiest to use virtualisation technologies on the market and it adds almost no overhead compared to other technologies.

I’ve been using it for a couple of years now and I always wanted to have a nicer way to automate container creation, configuration or actions than writing shell scripts. There are already a couple of webinterfaces around, but none of them I liked.

Another possibility would be to use libvirt - but libvirt always felt a bit too complex, since its a general API implementation for several hypervisors.

So I started to implement my own API, which should rather be a simple and minimalistic approach. The project is hosted on GitHub but you can as well install it by Rubygems.

gem install openvz

Restart a container

A small example to restart the container.

require 'rubygems'
require 'openvz'

container ='109')

Provisioning Example

Here is an example about how a whole provisioning for a new container could look like.

The script creates the container configuration and runs deboostrap, sets the nameserver, ip address and hostname. Afterwards it will run a couple of commands to update it and install Puppet.

require 'rubygems'
require 'openvz'

container ='110')

container.create(:ostemplate => 'debain-6.0-boostrap',
                 :config     => 'vps.basic')

container.deboostrap(:dist   => 'squeeze',
                     :mirror => '')

container.set(:nameserver => '',
              :ipadd      => '',
              :hostname   => '')


# Update the system
container.command('aptitude update ; aptitude -y upgrade ; apt-key update')

# Install puppet
container.command('aptitude -o Aptitude::Cmdline::ignore-trust-violations=true -y install puppet')

# Run puppet
container.command('puppetd -t')
read more