1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Merge branch 'feature-3180'

This commit is contained in:
Ruben S. Montero 2014-10-26 22:27:45 +01:00
commit 13a654bea6
3 changed files with 41 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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])