Class: OpenNebula::Client

Inherits:
Object
  • Object
show all
Defined in:
opennebula/client.rb

Overview

The client class, represents the connection with the core and handles the xml-rpc calls.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (OpenNebula::Client) initialize(secret = nil, endpoint = nil, options = {})

Creates a new client object that will be used to call OpenNebula functions.

Parameters:

  • secret (String, nil) (defaults to: nil)

    user credentials ("user:password") or nil to get the credentials from user auth file

  • endpoint (String, nil) (defaults to: nil)

    OpenNebula server endpoint (host:2633/RPC2) or nil to get it form the environment variable ONE_XMLRPC or use the default endpoint

  • options (Hash) (defaults to: {})
  • params (Hash)

    a customizable set of options



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'opennebula/client.rb', line 67

def initialize(secret=nil, endpoint=nil, options={})
    if secret
        @one_auth = secret
    elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
            File.file?(ENV["ONE_AUTH"])
        @one_auth = File.read(ENV["ONE_AUTH"])
    elsif File.file?(ENV["HOME"]+"/.one/one_auth")
        @one_auth = File.read(ENV["HOME"]+"/.one/one_auth")
    else
        raise "ONE_AUTH file not present"
    end

    @one_auth.rstrip!

    if endpoint
        @one_endpoint = endpoint
    elsif ENV["ONE_XMLRPC"]
        @one_endpoint = ENV["ONE_XMLRPC"]
    else
        @one_endpoint = "http://localhost:2633/RPC2"
    end

    timeout=nil
    timeout=options[:timeout] if options[:timeout]

    @server = XMLRPC::Client.new2(@one_endpoint, nil, timeout)

    if OpenNebula::NOKOGIRI
        @server.set_parser(NokogiriStreamParser.new)
    elsif XMLPARSER
        @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
    end
end

Instance Attribute Details

- (Object) one_auth

Returns the value of attribute one_auth



45
46
47
# File 'opennebula/client.rb', line 45

def one_auth
  @one_auth
end

Instance Method Details

- (Object) call(action, *args)



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'opennebula/client.rb', line 101

def call(action, *args)
    begin
        response = @server.call_async("one."+action, @one_auth, *args)

        if response[0] == false
            Error.new(response[1], response[2])
        else
            response[1] #response[1..-1]
        end
    rescue Exception => e
        Error.new(e.message)
    end
end

- (Object) get_version



115
116
117
# File 'opennebula/client.rb', line 115

def get_version()
    call("system.version")
end