Class: OpenNebula::Client
- Inherits:
-
Object
- Object
- OpenNebula::Client
- Defined in:
- lib/opennebula/client.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.
-
#one_endpoint ⇒ Object
readonly
Returns the value of attribute one_endpoint.
Instance Method Summary collapse
- #call(action, *args) ⇒ Object
- #get_version ⇒ Object
-
#initialize(secret = nil, endpoint = nil, options = {}) ⇒ OpenNebula::Client
constructor
Creates a new client object that will be used to call OpenNebula functions.
Constructor Details
#initialize(secret = nil, endpoint = nil, options = {}) ⇒ OpenNebula::Client
Creates a new client object that will be used to call OpenNebula functions.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/opennebula/client.rb', line 110 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"] elsif File.exists?(ENV['HOME']+"/.one/one_endpoint") @one_endpoint = File.read(ENV['HOME']+"/.one/one_endpoint") else @one_endpoint = "http://localhost:2633/RPC2" end timeout=nil timeout=[:timeout] if [:timeout] http_proxy=nil http_proxy=[:http_proxy] if [:http_proxy] @server = XMLRPC::Client.new2(@one_endpoint, http_proxy, timeout) if defined?(OxStreamParser) @server.set_parser(OxStreamParser.new) elsif OpenNebula::NOKOGIRI @server.set_parser(NokogiriStreamParser.new) elsif XMLPARSER @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) end end |
Instance Attribute Details
#one_auth ⇒ Object
Returns the value of attribute one_auth.
85 86 87 |
# File 'lib/opennebula/client.rb', line 85 def one_auth @one_auth end |
#one_endpoint ⇒ Object (readonly)
Returns the value of attribute one_endpoint.
86 87 88 |
# File 'lib/opennebula/client.rb', line 86 def one_endpoint @one_endpoint end |
Instance Method Details
#call(action, *args) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/opennebula/client.rb', line 151 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.) end end |
#get_version ⇒ Object
165 166 167 |
# File 'lib/opennebula/client.rb', line 165 def get_version() call("system.version") end |