Xen – Ruby interface to the Xen API.

Xen strives to be the Ruby interface talking to the Xen API. It grew from our own need to talk to Xen Servers with Ruby.

Install:

xen is a registered rubygem, so you can just do

sudo gem install xen

And you’re good to go.

Usage:

# Connect to xenhost
xenhost = Xen::Host.new('xenhost.example.com')

# Get status of each VM running
xenhost.vms.each do |vm|

puts vm.state unless vm.is_dom0?

end

# Restart a certain VM
xenhost.find_vm('example_vm').clean_reboot!

Creating a new VM:

h = Xen::Host.new('10.1.10.200')

network =Xen::Network.find_by_name 'xenbr101', h

vm = h.create_vm 'slice', 128*1024*1024

vdi_hda1 = h.create_vdi 'vdi1', 'phy:/dev/xendomains/slice-root'
vdi_hda2 = h.create_vdi 'vdi2', 'phy:/dev/xendomains/slice-swap'

vbd1 = h.create_vbd 'hda1', vm, vdi_hda1
vbd2 = h.create_vbd 'hda2', vm, vdi_hda2

vif = h.create_vif vm, network, '00:30:48:88:81:03'

vm.start!