1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

feature #195: Do not set timeout by default

This commit is contained in:
Ruben S. Montero 2010-07-08 00:29:32 +02:00
parent 54134bd13f
commit 2957a99168

View File

@ -33,7 +33,7 @@ rescue LoadError
end
###############################################################################
# The CloudClient module contains general functionality to implement a
# The CloudClient module contains general functionality to implement a
# Cloud Client
###############################################################################
module CloudClient
@ -41,7 +41,7 @@ module CloudClient
# Default location for the authentication file
# #########################################################################
DEFAULT_AUTH_FILE = ENV["HOME"]+"/.one/one_auth"
# #########################################################################
# Gets authorization credentials from ONE_AUTH or default
# auth file.
@ -49,7 +49,7 @@ module CloudClient
# Raises an error if authorization is not found
# #########################################################################
def self.get_one_auth
if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
File.file?(ENV["ONE_AUTH"])
one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':')
elsif File.file?(DEFAULT_AUTH_FILE)
@ -57,30 +57,28 @@ module CloudClient
else
raise "No authorization data present"
end
raise "Authorization data malformed" if one_auth.length < 2
one_auth
end
# #########################################################################
# Starts an http connection and calls the block provided. SSL flag
# is set if needed.
# #########################################################################
def self.http_start(url, timeout, &block)
http = Net::HTTP.new(url.host, url.port)
if timeout
http.read_timeout = timeout.to_i
else
http.read_timeout = 600
end
if url.scheme=='https'
http.use_ssl = true
http.verify_mode=OpenSSL::SSL::VERIFY_NONE
end
begin
http.start do |connection|
block.call(connection)
@ -88,18 +86,18 @@ module CloudClient
rescue Errno::ECONNREFUSED => e
str = "Error connecting to server (#{e.to_s}).\n"
str << "Server: #{url.host}:#{url.port}"
return CloudClient::Error.new(str)
rescue Errno::ETIMEDOUT => e
str = "Error timeout connecting to server (#{e.to_s}).\n"
str << "Server: #{url.host}:#{url.port}"
return CloudClient::Error.new(str)
rescue Timeout::Error => e
str = "Error timeout while connected to server (#{e.to_s}).\n"
str << "Server: #{url.host}:#{url.port}"
return CloudClient::Error.new(str)
return CloudClient::Error.new(str)
end
end
@ -109,7 +107,7 @@ module CloudClient
# #########################################################################
class Error
attr_reader :message
# +message+ a description of the error
def initialize(message=nil)
@message=message
@ -120,7 +118,7 @@ module CloudClient
end
end
# #########################################################################
# #########################################################################
# Returns true if the object returned by a method of the OpenNebula
# library is an Error
# #########################################################################
@ -128,7 +126,7 @@ module CloudClient
value.class==CloudClient::Error
end
end
# Command line help functions
module CloudCLI
# Returns the command name