mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Request #195 fulfilled, now occi commands may timeout while connected to server
Additionally, commands help section has been homogeneously tabbed.
This commit is contained in:
parent
6a566251fc
commit
494ac47372
@ -67,8 +67,15 @@ module CloudClient
|
||||
# Starts an http connection and calls the block provided. SSL flag
|
||||
# is set if needed.
|
||||
# #########################################################################
|
||||
def self.http_start(url, &block)
|
||||
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
|
||||
@ -79,10 +86,20 @@ module CloudClient
|
||||
block.call(connection)
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
str = "Error connecting to server (#{e.to_s})."
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,51 +29,54 @@ $: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
** Synopsis
|
||||
occi-compute
|
||||
|
||||
Manages compute resources
|
||||
** Synopsis
|
||||
occi-compute
|
||||
|
||||
** Usage
|
||||
occi-compute <COMMAND> [OPTIONS] [ARGUMENTS]
|
||||
Manages compute resources
|
||||
|
||||
COMMANDS
|
||||
** Usage
|
||||
occi-compute <COMMAND> [OPTIONS] [ARGUMENTS]
|
||||
|
||||
create <occi xml file>
|
||||
creates a new compute resource described by the provided
|
||||
<occi xml file>
|
||||
COMMANDS
|
||||
|
||||
list
|
||||
lists available compute resources
|
||||
create <occi xml file>
|
||||
creates a new compute resource described by the provided
|
||||
<occi xml file>
|
||||
|
||||
show <compute id>
|
||||
retrieves the OCCI XML representation of the compute resource
|
||||
identified by <compute id>
|
||||
list
|
||||
lists available compute resources
|
||||
|
||||
update <occi xml file>
|
||||
updates the representation of the compute resource represented by the
|
||||
provided <occi xml file>
|
||||
show <compute id>
|
||||
retrieves the OCCI XML representation of the compute resource
|
||||
identified by <compute id>
|
||||
|
||||
delete <compute id>
|
||||
deletes the compute resource idenfitied by <compute id>
|
||||
update <occi xml file>
|
||||
updates the representation of the compute resource represented by the
|
||||
provided <occi xml file>
|
||||
|
||||
delete <compute id>
|
||||
deletes the compute resource idenfitied by <compute id>
|
||||
|
||||
|
||||
OPTIONS
|
||||
OPTIONS
|
||||
|
||||
--help, -h:
|
||||
Show help
|
||||
--help, -h:
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>:
|
||||
The username of the user
|
||||
--username <id>, -U <id>:
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>:
|
||||
The password of the user
|
||||
--password <key>, -P <key>:
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>:
|
||||
Set url as the web service url to use
|
||||
--url <url>, -R <url>:
|
||||
Set url as the web service url to use
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
EOT
|
||||
|
||||
@ -88,6 +91,7 @@ opts = GetoptLong.new(
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
@ -95,6 +99,7 @@ url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
@ -109,6 +114,8 @@ begin
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
@ -118,7 +125,7 @@ rescue Exception => e
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
occi_client = OCCIClient::Client.new(url,username,password, timeout, debug)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
|
@ -29,51 +29,54 @@ $: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
** Synopsis
|
||||
occi-network
|
||||
|
||||
Manages virtual networks
|
||||
** Synopsis
|
||||
occi-network
|
||||
|
||||
** Usage
|
||||
occi-network <COMMAND> [OPTIONS] [ARGUMENTS]
|
||||
Manages virtual networks
|
||||
|
||||
COMMANDS
|
||||
** Usage
|
||||
occi-network <COMMAND> [OPTIONS] [ARGUMENTS]
|
||||
|
||||
create <occi xml file>
|
||||
creates a new virtual network described by the provided
|
||||
<occi xml file>
|
||||
COMMANDS
|
||||
|
||||
list
|
||||
lists available virtual networks
|
||||
create <occi xml file>
|
||||
creates a new virtual network described by the provided
|
||||
<occi xml file>
|
||||
|
||||
show <network id>
|
||||
retrieves the OCCI XML representation of the virtual network
|
||||
identified by <network id>
|
||||
list
|
||||
lists available virtual networks
|
||||
|
||||
delete <network id>
|
||||
deletes the virtual network idenfitied by <network id>
|
||||
show <network id>
|
||||
retrieves the OCCI XML representation of the virtual network
|
||||
identified by <network id>
|
||||
|
||||
delete <network id>
|
||||
deletes the virtual network idenfitied by <network id>
|
||||
|
||||
|
||||
|
||||
OPTIONS
|
||||
OPTIONS
|
||||
|
||||
--help, -h:
|
||||
Show help
|
||||
--help, -h:
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>:
|
||||
The username of the user
|
||||
--username <id>, -U <id>:
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>:
|
||||
The password of the user
|
||||
--password <key>, -P <key>:
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>:
|
||||
Set url as the web service url to use
|
||||
--url <url>, -R <url>:
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
--multipart, -M:
|
||||
Use 'multipart-post' library instead of Curb/Curl
|
||||
--multipart, -M:
|
||||
Use 'multipart-post' library instead of Curb/Curl
|
||||
|
||||
EOT
|
||||
|
||||
@ -89,6 +92,7 @@ opts = GetoptLong.new(
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
@ -96,6 +100,7 @@ url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
@ -110,6 +115,8 @@ begin
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
@ -120,7 +127,7 @@ end
|
||||
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
occi_client = OCCIClient::Client.new(url,username,password,timeout,debug)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
|
@ -67,6 +67,9 @@ OPTIONS
|
||||
--url <url>, -R <url>:
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
@ -88,6 +91,7 @@ opts = GetoptLong.new(
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--multipart', '-M',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
@ -95,6 +99,7 @@ url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
curb = true
|
||||
|
||||
@ -110,6 +115,8 @@ begin
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
when '--multipart'
|
||||
@ -128,7 +135,7 @@ end
|
||||
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
occi_client = OCCIClient::Client.new(url,username,password,timeout,debug)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
|
@ -33,8 +33,10 @@ module OCCIClient
|
||||
######################################################################
|
||||
# Initialize client library
|
||||
######################################################################
|
||||
def initialize(endpoint_str=nil, user=nil, pass=nil, debug_flag=true)
|
||||
@debug = debug_flag
|
||||
def initialize(endpoint_str=nil, user=nil, pass=nil,
|
||||
timeout=nil, debug_flag=true)
|
||||
@debug = debug_flag
|
||||
@timeout = timeout
|
||||
|
||||
# Server location
|
||||
if endpoint_str
|
||||
@ -78,7 +80,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) do |http|
|
||||
res = CloudClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
@ -98,7 +100,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -123,7 +125,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) do |http|
|
||||
res = CloudClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
@ -143,7 +145,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -203,7 +205,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) do |http|
|
||||
res = CloudClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
@ -226,7 +228,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -250,7 +252,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -276,7 +278,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) do |http|
|
||||
res = CloudClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
@ -296,7 +298,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -317,7 +319,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -337,7 +339,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
@ -358,7 +360,7 @@ module OCCIClient
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url) {|http|
|
||||
res = CloudClient::http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user