
The client class, represents the connection with the core and handles the xml-rpc calls.
Constants
XMLPARSER | = | true |
XMLPARSER | = | false |
Attributes
one_auth | [RW] |
Public class methods
new
(secret=nil, endpoint=nil)
[show source]
# File OpenNebula.rb, line 69 69: def initialize(secret=nil, endpoint=nil) 70: if secret 71: one_secret = secret 72: elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"]) 73: one_secret=File.read(ENV["ONE_AUTH"]) 74: elsif File.file?(ENV["HOME"]+"/.one/one_auth") 75: one_secret=File.read(ENV["HOME"]+"/.one/one_auth") 76: else 77: raise "ONE_AUTH file not present" 78: end 79: 80: if !one_secret.match(".+:.+") 81: raise "Authorization file malformed" 82: end 83: 84: 85: one_secret=~/^(.+?):(.+)$/ 86: user=$1 87: password=$2 88: 89: if password.match(/^plain:/) 90: @one_auth = "#{user}:#{password.split(':').last}" 91: else 92: @one_auth = "#{user}:#{Digest::SHA1.hexdigest(password)}" 93: end 94: 95: if endpoint 96: @one_endpoint=endpoint 97: elsif ENV["ONE_XMLRPC"] 98: @one_endpoint=ENV["ONE_XMLRPC"] 99: else 100: @one_endpoint="http://localhost:2633/RPC2" 101: end 102: 103: @server=XMLRPC::Client.new2(@one_endpoint) 104: end
Public instance methods
call
(action, *args)
[show source]
# File OpenNebula.rb, line 106 106: def call(action, *args) 107: 108: if XMLPARSER 109: @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) 110: end 111: 112: begin 113: response = @server.call_async("one."+action, @one_auth, *args) 114: 115: if response[0] == false 116: Error.new(response[1]) 117: else 118: response[1] #response[1..-1] 119: end 120: rescue Exception => e 121: Error.new(e.message) 122: end 123: end