Class: OpenNebula::Client
- Inherits:
-
Object
- Object
- OpenNebula::Client
- Defined in:
- lib/OpenNebula.rb
Overview
The client class, represents the connection with the core and handles the xml-rpc calls.
Instance Attribute Summary collapse
-
#one_auth ⇒ Object
Returns the value of attribute one_auth.
Instance Method Summary collapse
- #call(action, *args) ⇒ Object
-
#initialize(secret = nil, endpoint = nil, hash = true) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(secret = nil, endpoint = nil, hash = true) ⇒ Client
Returns a new instance of Client.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/OpenNebula.rb', line 88 def initialize(secret=nil, endpoint=nil, hash=true) if secret one_secret = secret elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"]) one_secret=File.read(ENV["ONE_AUTH"]) elsif File.file?(ENV["HOME"]+"/.one/one_auth") one_secret=File.read(ENV["HOME"]+"/.one/one_auth") else raise "ONE_AUTH file not present" end tokens = one_secret.chomp.split(':') if tokens.length > 2 @one_auth = one_secret elsif tokens.length == 2 if hash pass = Digest::SHA1.hexdigest(tokens[1]) else pass = tokens[1] end @one_auth = "#{tokens[0]}:#{pass}" else raise "Authorization file malformed" end 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) end |
Instance Attribute Details
#one_auth ⇒ Object
Returns the value of attribute one_auth.
79 80 81 |
# File 'lib/OpenNebula.rb', line 79 def one_auth @one_auth end |
Instance Method Details
#call(action, *args) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/OpenNebula.rb', line 125 def call(action, *args) if XMLPARSER @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) end begin response = @server.call_async("one."+action, @one_auth, *args) if response[0] == false Error.new(response[1]) else response[1] #response[1..-1] end rescue Exception => e Error.new(e.) end end |