Request #4987

Permit to access all classes from OpenNebula::Client

Added by EOLE Team over 4 years ago.

Status:PendingStart date:01/18/2017
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Client API & Library
Target version:-
Pull request:

Description

Hello,

To manage resources I usually do:

ONE_LOCATION=ENV["ONE_LOCATION"]

if !ONE_LOCATION
    RUBY_LIB_LOCATION="/usr/lib/one/ruby" 
    VMDIR="/var/lib/one" 
    CONFIG_FILE="/var/lib/one/config" 
else
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" 
    VMDIR=ONE_LOCATION+"/var" 
    CONFIG_FILE=ONE_LOCATION+"/var/config" 
end

$: << RUBY_LIB_LOCATION

require 'opennebula'
include OpenNebula

begin
    client = Client.new()
rescue Exception => error
    puts "Error: #{error}" 
    exit(-1)
end

image_pool = OpenNebula::ImagePool.new(client, OpenNebula::Pool::INFO_ALL)
rc = image_pool.info

if OpenNebula.is_error?(rc)
  raise "Error contacting OpenNebula #{rc.message}" 
end

Is is possible to make all resources accessible from OpenNebula::Client directly?

Something like:

ONE_LOCATION=ENV["ONE_LOCATION"]

if !ONE_LOCATION
    RUBY_LIB_LOCATION="/usr/lib/one/ruby" 
    VMDIR="/var/lib/one" 
    CONFIG_FILE="/var/lib/one/config" 
else
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" 
    VMDIR=ONE_LOCATION+"/var" 
    CONFIG_FILE=ONE_LOCATION+"/var/config" 
end

$: << RUBY_LIB_LOCATION

require 'opennebula'
include OpenNebula

begin
    client = Client.new()
rescue Exception => error
    puts "Error: #{error}" 
    exit(-1)
end

client.ImagePool.each do |image|
  image.info
  puts image.name
end

In wich case the client instance is responsible to raise any error, this will avoid to many checks like:

if OpenNebula.is_error?(rc)
  raise "Error contacting OpenNebula #{rc.message}" 
end

It seems that how it's done in the Java library.

Regards.

Also available in: Atom PDF