OpenVZ is a container based virtualization for Linux. This API will allow you to easily write tools to manipulate containers on a host.

Full and up to date ruby doc available at:


Here are some examples on how you can use the API.

container ='110')

UBC Access

To get the current value of privvmpages you can use the config accessor.

container ='110')
puts container.config.privvmpages

Also in case you would like to update a UBC, use the same config accessor.

 container ='110')
 container.config.kmemsize = '5505024:5872024'


 # Create an inventoy of all containers
 inventory =
 inventory.load # Print a certain containers configuration option

 inventory['110'].config.privvmpages # Restart



You can as well use the build in functions to provision a new container.

 container ='110')

 container.create( :ostemplate => 'centos-5-x86_64-minimal',
                   :config     => 'vps.basic' )


Debootstrapping Containers

If your host is running Debian and you want to bootstrap a new Debian container, you do not have to use a template, just use debootstrap.

 container ='110')

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

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

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

 container.file( '/etc/bash.bashrc', :source => '/etc/vz/template/bashrc' )


 # 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')

NOTE: You need to create an empty template for this to work. Here is how you do that:

 mkdir /tmp/empty-template
 # We need a file in the tarball since vzcreate barfs on empty tarballs
 touch /tmp/empty-template/BOOSTRAPPED
 tar -zc -C /tmp/empty-template . -f debian-6.0-bootstrap.tar
 gzip debian-6.0-bootstrap.tar
 mv debian-6.0-bootstrap.tar.gz /var/lib/vz/template/cache


For bugs or feature requests, please use the GitHub issue tracker.


Stefan Schlesinger / [email protected] / @stsonoat /