Blog Article:

New OCA rubygem Available

Daniel Molina

Nov 30, 2010

An OpenNebula user, John Dewey, has just contributed a new oca rubygem that allows developers to make calls to OpenNebula’s Cloud API (OCA) from their Ruby projects without having to install OpenNebula. The Ruby OCA API has been designed as a wrapper for the XML-RPC methods to interact with the OpenNebula Core, with some basic helpers. This gem was built against OpenNebula 2.0 and will be updated in each release.

If you want to use it in your Ruby projects, you can install it by running the following:

$ sudo gem install oca

Here is a short example that shows how you can use this new oca gem from Ruby. More specifically, this program queries all the running VMs and shuts them down.

[ruby]
#!/usr/bin/env ruby

###################################################################
# Required libraries
###################################################################
require ‘rubygems’
require ‘oca’

include OpenNebula

# OpenNebula credentials
CREDENTIALS = "oneuser:onepass"
# XML_RPC endpoint where OpenNebula is listening
ENDPOINT = "http://localhost:2633/RPC2"

client = Client.new(CREDENTIALS, ENDPOINT)

vm_pool = VirtualMachinePool.new(client, -1)

rc = vm_pool.info
if OpenNebula.is_error?(rc)
puts rc.message
exit -1
end

vm_pool.each do |vm|
rc = vm.shutdown
if OpenNebula.is_error?(rc)
puts "Virtual Machine #{vm.id}: #{rc.message}"
else
puts "Virtual Machine #{vm.id}: Shutting down"
end
end

exit 0
[/ruby]

We would like to thank John Dewey for this very useful contribution!

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *