diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index c9a2ffebe4..cc3eaa22d2 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -370,7 +370,7 @@ EOT endpoint=options[:endpoint] end - @@client=OpenNebula::Client.new(secret, endpoint) + @@client=OpenNebula::Client.new(secret, endpoint, :sync => true) end end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 463b253e18..d53e190c10 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -163,7 +163,9 @@ class OneUserHelper < OpenNebulaHelper::OneHelper # authentication token for the user #----------------------------------------------------------------------- token = auth.login_token(username, options[:time]) - login_client = OpenNebula::Client.new("#{username}:#{token}") + login_client = OpenNebula::Client.new("#{username}:#{token}", + nil, + :sync => true) user = OpenNebula::User.new(User.build_xml, login_client) diff --git a/src/oca/ruby/opennebula/client.rb b/src/oca/ruby/opennebula/client.rb index f202fc1f9a..c4cf6458f4 100644 --- a/src/oca/ruby/opennebula/client.rb +++ b/src/oca/ruby/opennebula/client.rb @@ -17,6 +17,7 @@ require 'xmlrpc/client' require 'bigdecimal' require 'stringio' +require 'openssl' module OpenNebula @@ -105,6 +106,14 @@ module OpenNebula # defaults to 30 # @option params [String] :http_proxy HTTP proxy string used for # connecting to the endpoint; defaults to no proxy + # @option params [Boolean] :sync Use only one http connection for + # all calls. It should not be used for multithreaded programs. + # It's the only mode that can be used with :cert_dir and + # :disable_ssl_verify + # @option params [String] :cert_dir Extra directory where to import + # trusted issuer certificates. Use with :sync = true + # @option params [String] :disable_ssl_verify Disable SSL certificate + # verification. Use only for testing and with :sync = true # # @return [OpenNebula::Client] def initialize(secret=nil, endpoint=nil, options={}) @@ -135,6 +144,8 @@ module OpenNebula @one_endpoint = "http://localhost:2633/RPC2" end + @async = !options[:sync] + timeout=nil timeout=options[:timeout] if options[:timeout] @@ -144,6 +155,27 @@ module OpenNebula @server = XMLRPC::Client.new2(@one_endpoint, http_proxy, timeout) @server.http_header_extra = {'accept-encoding' => 'identity'} + http = @server.instance_variable_get("@http") + + if options[:cert_dir] || ENV['ONE_CERT_DIR'] + raise "SSL options don't work in async mode" if @async + + cert_dir = options[: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 options[: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 @@ -155,7 +187,11 @@ module OpenNebula def call(action, *args) begin - response = @server.call_async("one."+action, @one_auth, *args) + 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])