Class: OpenNebula::XMLClient
- Inherits:
-
Object
- Object
- OpenNebula::XMLClient
- Defined in:
- lib/opennebula/lib/xml_client.rb
Overview
The openNebula XMLRPC client class, represents the connection with the core and handles the xml-rpc calls.
Instance Method Summary collapse
- #call(action, *args) ⇒ Object
-
#initialize(secret, endpoint, options = {}) ⇒ OpenNebula::XMLClient
constructor
Creates a new XMLRPC client object that will be used to call OpenNebula functions.
Constructor Details
#initialize(secret, endpoint, options = {}) ⇒ OpenNebula::XMLClient
Creates a new XMLRPC client object that will be used to call OpenNebula functions.
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 150 151 152 153 154 |
# File 'lib/opennebula/lib/xml_client.rb', line 114 def initialize(secret, endpoint, = {}) @one_auth = secret @one_endpoint = endpoint @async = ![:sync] http_proxy = [:http_proxy] timeout = [:timeout] || ENV['ONE_XMLRPC_TIMEOUT']&.to_i @server = XMLRPC::Client.new2(@one_endpoint, http_proxy, timeout) @server.http_header_extra = { 'accept-encoding' => 'identity' } http = @server.instance_variable_get('@http') if [:cert_dir] || ENV['ONE_CERT_DIR'] raise "SSL options don't work in async mode" if @async cert_dir = [:cert_dir] || ENV['ONE_CERT_DIR'] cert_files = Dir["#{cert_dir}/*"] cert_store = OpenSSL::X509::Store.new cert_store.set_default_paths cert_files.each {|cert| cert_store.add_file(cert) } http.cert_store = cert_store end if [:disable_ssl_verify] || ENV['ONE_DISABLE_SSL_VERIFY'] raise "SSL options don't work in async mode" if @async http.verify_mode = OpenSSL::SSL::VERIFY_NONE end 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 Method Details
#call(action, *args) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/opennebula/lib/xml_client.rb', line 156 def call(action, *args) begin if @async response = @server.call_async("one.#{action}", @one_auth, *args) else response = @server.call("one.#{action}", @one_auth, *args) end if response[0] == false Error.new(response[1], response[2]) else response[1] # response[1..-1] end rescue StandardError => e Error.new(e., Error::EXML_RPC_CALL) end end |