Class: OpenNebula::Client

Inherits:
Object
  • Object
show all
Defined in:
OpenNebula.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

- (Client) initialize(secret = nil, endpoint = nil)

A new instance of Client



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'OpenNebula.rb', line 127

def initialize(secret=nil, endpoint=nil)
    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

    @server = XMLRPC::Client.new2(@one_endpoint)

    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



118
119
120
# File 'OpenNebula.rb', line 118

def one_auth
  @one_auth
end

Instance Method Details

- (Object) call(action, *args)



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'OpenNebula.rb', line 157

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



171
172
173
# File 'OpenNebula.rb', line 171

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