VirtualMachinePool.accounting() method returning error

OpenNebula::VirtualMachinePool.accounting() method is always returns an error (OpenNebula::Error) in all stands with installed opennebula
Please help me

Hi @mykytkad,

You can check /var/log/one/oned.log file after running the API call to see more information regarding the error. Also you should be able to print the error information by doing something like below:

vm_pool = VirtualMachinePool.new(client, -1)

rc = vm_pool.info

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

syntax error, unexpected end-of-input, expecting keyword_end - error on this part of code
It’s a bit weird, because some other API requests working

Yes, that’s looks estrange. In order to keep debugging, could you update the LOG_CALL_FORMAT attribute at you oned.conf file and increase the value of %l to a value big enough to ensure every parameter is printed in the logs.

After changing the configuration, just restart the OpenNebula service and execute the request again. The call with every parameter should be printed in the log.

@cgonzalez
LOG_CALL_FORMAT = “Req:%i UID:%u IP:%A %m invoked 12000” (is 12000 enough?)
in ruby file:
rc = vm_pool.accounting()
if OpenNebula.is_error?(rc)
puts rc.message
end
Message - Wrong type NilClass. Not allowed!
and there is no specific message in oned.log file

Hi @mykytkad,

It looks like there’s some problem at your ruby script before the XML-RPC request is performed, hence no error is printed in the log.

Could you share your script, to check if we can see something weird?

ONE_LOCATION = ENV['ONE_LOCATION']

if !ONE_LOCATION
    RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
    GEMS_LOCATION     = '/usr/share/one/gems'
else
    RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
    GEMS_LOCATION     = ONE_LOCATION + '/share/gems'
end

if File.directory?(GEMS_LOCATION)
    real_gems_path = File.realpath(GEMS_LOCATION)
    if !defined?(Gem) || Gem.path != [real_gems_path]
        $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
        require 'rubygems'
        Gem.use_paths(real_gems_path)
    end
end

$LOAD_PATH << RUBY_LIB_LOCATION

require 'opennebula'

# OpenNebula credentials

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

client_token = OpenNebula::Client.new("oneadmin:Asdf1234",ENDPOINT)
vm_pool = OpenNebula::VirtualMachinePool.new(client_token, -1)
rc = vm_pool.info

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

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



exit 0

Thank you for answers

Hi @mykytkad,

It seems the default value of the arguments of vm_pool.accounting() are not correct. I’ve opened a PR for fixing this.

In the meantime, you can replace your call by this one, as workaround:

accounting = vm_pool.accounting(OpenNebula::Pool::INFO_ALL, :start_time => -1, :end_time => -1)

Ok, thanks you
I launched the accounting() method with start_time and end_time in format 1636725379 and it works
Best regards

1 Like