
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 85 85: def initialize(secret=nil, endpoint=nil) 86: if secret 87: one_secret = secret 88: elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"]) 89: one_secret=File.read(ENV["ONE_AUTH"]) 90: elsif File.file?(ENV["HOME"]+"/.one/one_auth") 91: one_secret=File.read(ENV["HOME"]+"/.one/one_auth") 92: else 93: raise "ONE_AUTH file not present" 94: end 95: 96: if !one_secret.match(".+:.+") 97: raise "Authorization file malformed" 98: end 99: 100: 101: one_secret=~/^(.+?):(.+)$/ 102: user=$1 103: password=$2 104: 105: if password.match(/^plain:/) 106: @one_auth = "#{user}:#{password.split(':').last}" 107: else 108: @one_auth = "#{user}:#{Digest::SHA1.hexdigest(password)}" 109: end 110: 111: if endpoint 112: @one_endpoint=endpoint 113: elsif ENV["ONE_XMLRPC"] 114: @one_endpoint=ENV["ONE_XMLRPC"] 115: else 116: @one_endpoint="http://localhost:2633/RPC2" 117: end 118: 119: @server=XMLRPC::Client.new2(@one_endpoint) 120: end
Public instance methods
call
(action, *args)
[show source]
# File OpenNebula.rb, line 122 122: def call(action, *args) 123: 124: if XMLPARSER 125: @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) 126: end 127: 128: begin 129: response = @server.call_async("one."+action, @one_auth, *args) 130: 131: if response[0] == false 132: Error.new(response[1]) 133: else 134: response[1] #response[1..-1] 135: end 136: rescue Exception => e 137: Error.new(e.message) 138: end 139: end