rhc 0.90.7 → 0.91.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ require 'rhc-common'
4
4
  #
5
5
  # print help
6
6
  #
7
- def p_usage
7
+ def p_usage(exit_code = 255)
8
8
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
9
9
  puts <<USAGE
10
10
 
@@ -25,10 +25,10 @@ List of arguments
25
25
  -d|--debug Print Debug info
26
26
  -h|--help Show Usage info
27
27
  --config path Path of alternate config file
28
- --timeout # Timeout, in seconds, for connection
28
+ --timeout # Timeout, in seconds, for the session
29
29
 
30
30
  USAGE
31
- exit 255
31
+ exit exit_code
32
32
  end
33
33
 
34
34
 
@@ -57,8 +57,9 @@ def validate_args(val_namespace=true, val_timeout=true)
57
57
  debug = $opt["debug"] ? true : false
58
58
  RHC::debug(debug)
59
59
 
60
- RHC::timeout($opt["timeout"] ? $opt["timeout"] : get_var('timeout')) if val_timeout
61
-
60
+ RHC::timeout($opt["timeout"], get_var('timeout')) if val_timeout
61
+ RHC::connect_timeout($opt["timeout"], get_var('timeout')) if val_timeout
62
+
62
63
  $password = $opt['password'] ? $opt['password'] : RHC::get_password
63
64
  end
64
65
 
@@ -299,10 +300,16 @@ begin
299
300
  if ARGV[0].to_s.strip.length == 0
300
301
  opts = []
301
302
  else
302
- puts "Missing or invalid command!" unless ARGV[0] =~ /^(help|-h|--help)$/
303
- # just exit at this point
304
- # printing the usage description will be handled in the rescue
305
- exit 255
303
+ opts = GetoptLong.new(
304
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
305
+ )
306
+
307
+ unless ARGV[0] =~ /^(help|-h|--help)$/
308
+ puts "Missing or invalid command!"
309
+ # just exit at this point
310
+ # printing the usage description will be handled in the rescue
311
+ exit 255
312
+ end
306
313
  end
307
314
  end
308
315
 
@@ -314,7 +321,7 @@ rescue Exception => e
314
321
  p_usage
315
322
  end
316
323
 
317
- p_usage if $opt["help"]
324
+ p_usage 0 if $opt["help"]
318
325
 
319
326
  case argv_c[0]
320
327
  when "create"
@@ -4,7 +4,7 @@ require 'rhc-common'
4
4
  #
5
5
  # print help
6
6
  #
7
- def p_usage
7
+ def p_usage(error_code = 255)
8
8
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
9
9
  puts <<USAGE
10
10
 
@@ -18,10 +18,10 @@ Display information about a user
18
18
  -d|--debug Print Debug info
19
19
  -h|--help Show Usage info
20
20
  --config path Path of alternate config file
21
- --timeout # Timeout, in seconds, for connection
21
+ --timeout # Timeout, in seconds, for the session
22
22
 
23
23
  USAGE
24
- exit 255
24
+ exit error_code
25
25
  end
26
26
 
27
27
  begin
@@ -51,16 +51,16 @@ check_cpath(opt)
51
51
  libra_server = get_var('libra_server')
52
52
  debug = get_var('debug') == 'false' ? nil : get_var('debug')
53
53
 
54
- if opt["help"] || 0 != ARGV.length
55
- p_usage
56
- end
54
+ p_usage 0 if opt["help"]
55
+
56
+ p_usage if 0 != ARGV.length
57
+
58
+ debug = true if opt["debug"]
57
59
 
58
- if opt["debug"]
59
- debug = true
60
- end
61
60
  RHC::debug(debug)
62
61
 
63
- RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
62
+ RHC::timeout(opt["timeout"], get_var('timeout'))
63
+ RHC::connect_timeout(opt["timeout"], get_var('timeout'))
64
64
 
65
65
  opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
66
66
 
@@ -4,7 +4,7 @@ require 'rhc-common'
4
4
  #
5
5
  # print help
6
6
  #
7
- def p_usage
7
+ def p_usage(exit_code = 255)
8
8
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
9
9
  puts <<USAGE
10
10
 
@@ -17,10 +17,10 @@ Forward remote ports to the workstation
17
17
  -d|--debug Print Debug info
18
18
  -h|--help Show Usage info
19
19
  --config path Path of alternate config file
20
- --timeout # Timeout, in seconds, for connection
20
+ --timeout # Timeout, in seconds, for the session
21
21
 
22
22
  USAGE
23
- exit 255
23
+ exit exit_code
24
24
  end
25
25
 
26
26
  begin
@@ -49,16 +49,16 @@ check_cpath(opt)
49
49
  libra_server = get_var('libra_server')
50
50
  debug = get_var('debug') == 'false' ? nil : get_var('debug')
51
51
 
52
- if opt['help'] || !opt['app'] || 0 != ARGV.length
53
- p_usage
54
- end
52
+ p_usage 0 if opt['help']
53
+
54
+ p_usage if !opt['app'] || 0 != ARGV.length
55
+
56
+ debug = true if opt['debug']
55
57
 
56
- if opt['debug']
57
- debug = true
58
- end
59
58
  RHC::debug(debug)
60
59
 
61
- RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
60
+ RHC::timeout(opt["timeout"], get_var('timeout'))
61
+ RHC::connect_timeout(opt["timeout"], get_var('timeout'))
62
62
 
63
63
  opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
64
64
 
@@ -4,7 +4,7 @@ require 'rhc-common'
4
4
  #
5
5
  # print help
6
6
  #
7
- def p_usage
7
+ def p_usage(exit_code = 255)
8
8
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
9
9
  puts <<USAGE
10
10
 
@@ -19,10 +19,10 @@ Pull down application snapshot for a user
19
19
  -d|--debug Print Debug info
20
20
  -h|--help Show Usage info
21
21
  --config path Path of alternate config file
22
- --timeout # Timeout, in seconds, for connection
22
+ --timeout # Timeout, in seconds, for the session
23
23
 
24
24
  USAGE
25
- exit 255
25
+ exit exit_code
26
26
  end
27
27
 
28
28
  begin
@@ -58,16 +58,16 @@ check_cpath(opt)
58
58
  libra_server = get_var('libra_server')
59
59
  debug = get_var('debug') == 'false' ? nil : get_var('debug')
60
60
 
61
- if opt["help"] || !opt['app'] || 0 != ARGV.length
62
- p_usage
63
- end
61
+ p_usage 0 if opt["help"]
62
+
63
+ p_usage if !opt['app'] || 0 != ARGV.length
64
+
65
+ debug = true if opt["debug"]
64
66
 
65
- if opt["debug"]
66
- debug = true
67
- end
68
67
  RHC::debug(debug)
69
68
 
70
- RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
69
+ RHC::timeout(opt["timeout"], get_var('timeout'))
70
+ RHC::connect_timeout(opt["timeout"], get_var('timeout'))
71
71
 
72
72
  opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
73
73
 
@@ -4,7 +4,7 @@ require 'rhc-common'
4
4
  #
5
5
  # print help
6
6
  #
7
- def p_usage
7
+ def p_usage(exit_code = 255)
8
8
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
9
9
  puts <<USAGE
10
10
 
@@ -25,10 +25,10 @@ List of arguments
25
25
  -d|--debug Print Debug info
26
26
  -h|--help Show Usage info
27
27
  --config path Path of alternate config file
28
- --timeout # Timeout, in seconds, for connection
28
+ --timeout # Timeout, in seconds, for the session
29
29
 
30
30
  USAGE
31
- exit 255
31
+ exit exit_code
32
32
  end
33
33
 
34
34
 
@@ -48,7 +48,8 @@ def validate_args(val_id=true)
48
48
 
49
49
  p_usage if val_id && !RHC::check_key($opt['identifier'])
50
50
 
51
- RHC::timeout($opt["timeout"] ? $opt["timeout"] : get_var('timeout'))
51
+ RHC::timeout($opt["timeout"], get_var('timeout'))
52
+ RHC::connect_timeout($opt["timeout"], get_var('timeout'))
52
53
  $password = $opt['password'] ? $opt['password'] : RHC::get_password
53
54
  end
54
55
 
@@ -163,7 +164,7 @@ end
163
164
 
164
165
  begin
165
166
  argv_c = ARGV.clone
166
-
167
+
167
168
  if ARGV[0] =~ /^(add|update)$/
168
169
  ARGV.shift
169
170
  opts = GetoptLong.new(
@@ -198,12 +199,17 @@ begin
198
199
  ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
199
200
  )
200
201
  else
201
- puts "Missing or invalid command!" unless ARGV[0] =~ /^(help|-h|--help)$/
202
- # just exit at this point
203
- # printing the usage description will be handled in the rescue
204
- exit 255
202
+ opts = GetoptLong.new(
203
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
204
+ )
205
+ unless ARGV[0] =~ /^(help|-h|--help)$/
206
+ puts "Missing or invalid command!"
207
+ # just exit at this point
208
+ # printing the usage description will be handled in the rescue
209
+ exit 255
210
+ end
205
211
  end
206
-
212
+
207
213
  $opt = {}
208
214
  opts.each do |o, a|
209
215
  $opt[o[2..-1]] = a.to_s
@@ -213,7 +219,7 @@ rescue Exception => e
213
219
  p_usage
214
220
  end
215
221
 
216
- p_usage if $opt["help"]
222
+ p_usage 0 if $opt["help"]
217
223
 
218
224
  case argv_c[0]
219
225
  when "add", "update"
@@ -223,7 +229,7 @@ when "remove"
223
229
  when "list", nil
224
230
  show_key_list
225
231
  when "-h", "--help", "help", nil
226
- p_usage
232
+ p_usage 0
227
233
  else
228
234
  puts "Invalid command!"
229
235
  p_usage
@@ -5,7 +5,7 @@ require 'base64'
5
5
  #
6
6
  # print help
7
7
  #
8
- def p_usage
8
+ def p_usage(exit_code = 255)
9
9
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
10
10
  puts <<USAGE
11
11
 
@@ -20,10 +20,10 @@ Tail the logs of an application
20
20
  -d|--debug Print Debug info
21
21
  -h|--help Show Usage info
22
22
  --config path Path of alternate config file
23
- --timeout # Timeout, in seconds, for connection
23
+ --timeout # Timeout, in seconds, for the session
24
24
 
25
25
  USAGE
26
- exit 255
26
+ exit exit_code
27
27
  end
28
28
 
29
29
  begin
@@ -54,16 +54,16 @@ check_cpath(opt)
54
54
  libra_server = get_var('libra_server')
55
55
  debug = get_var('debug') == 'false' ? nil : get_var('debug')
56
56
 
57
- if opt['help'] || !opt['app'] || 0 != ARGV.length
58
- p_usage
59
- end
57
+ p_usage 0 if opt['help']
58
+
59
+ p_usage if !opt['app'] || 0 != ARGV.length
60
+
61
+ debug = true if opt['debug']
60
62
 
61
- if opt['debug']
62
- debug = true
63
- end
64
63
  RHC::debug(debug)
65
64
 
66
- RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
65
+ RHC::timeout(opt["timeout"], get_var('timeout'))
66
+ RHC::connect_timeout(opt["timeout"], get_var('timeout'))
67
67
 
68
68
  opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
69
69
 
@@ -10,8 +10,6 @@ ARGV.each do|a|
10
10
  end
11
11
 
12
12
  system("rhc-domain-info #{args} 2>&1")
13
- retcode = $?
13
+ retcode = $?.exitstatus
14
14
 
15
- exit 1 if retcode != 0
16
-
17
- exit 0
15
+ exit retcode
@@ -1,19 +1,58 @@
1
- require 'rubygems'
2
- require 'rubygems/command.rb'
3
- require 'rubygems/dependency_installer.rb'
4
- begin
5
- Gem::Command.build_args = ARGV
6
- rescue NoMethodError
7
- end
8
- inst = Gem::DependencyInstaller.new
9
- begin
10
- if RUBY_VERSION > "1.9"
11
- inst.install "test-unit"
1
+ ## Add some testing for when we are building a rpm and when we're not
2
+ msg = ''
3
+
4
+ unless ENV['RHC_RPMBUILD']
5
+ require 'rubygems'
6
+ require 'rubygems/command.rb'
7
+ require 'rubygems/dependency_installer.rb'
8
+ require 'rubygems/uninstaller.rb'
9
+ begin
10
+ Gem::Command.build_args = ARGV
11
+ rescue NoMethodError
12
+ end
13
+ inst = Gem::DependencyInstaller.new
14
+ begin
15
+ if RUBY_VERSION > "1.9"
16
+ inst.install "test-unit"
17
+ end
18
+
19
+ # Attempt native json installation (unless JSON_PURE is specified)
20
+ # - fall back to json_pure if it fails
21
+ # - Known failure conditions
22
+ # - Ubuntu: using ruby and not ruby-dev
23
+ begin
24
+ throw if ENV['JSON_PURE']
25
+ inst.install('json')
26
+ rescue
27
+ inst.install('json_pure')
28
+ end
29
+
30
+ rescue
31
+ exit(1)
32
+ end
33
+
34
+ # Remove rhc-rest if it's installed
35
+ begin
36
+ Gem::Uninstaller.new('rhc-rest').uninstall
37
+
38
+ # This only gets printed if verbose is specified
39
+ # TODO: Need to figure out how to get it always shown
40
+ msg = <<-MSG
41
+ ===================================================
42
+ rhc-rest is no longer needed as an external gem
43
+ - If it is installed, it will be removed
44
+ - Its libraries are now included in rhc
45
+ - Any applications requiring rhc-rest will
46
+ still function as expected
47
+ ===================================================
48
+ MSG
49
+ rescue Gem::LoadError,Gem::InstallError
50
+ # This means that rhc-rest was not installed, not a problem
12
51
  end
13
- rescue
14
- exit(1)
15
- end
52
+ end
16
53
 
17
54
  f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
18
- f.write("task :default\n")
55
+ f.write("task :default do\n")
56
+ f.write("\tputs '%s'\n" % msg) if msg
57
+ f.write("end\n")
19
58
  f.close
@@ -19,7 +19,8 @@ module RHC
19
19
  DEFAULT_DELAY = 2
20
20
  API = "1.1.3"
21
21
  PATTERN_VERSION=/\A\d+\.\d+\.\d+\z/
22
- @mytimeout = 10
22
+ @read_timeout = 120
23
+ @connect_timeout = 20
23
24
  @mydebug = false
24
25
  @@api_version = "?.?.?"
25
26
 
@@ -39,12 +40,28 @@ module RHC
39
40
  'api' => nil
40
41
  }
41
42
 
42
- def self.timeout(val)
43
- if val
44
- @mytimeout = val.to_i
45
- unless @mytimeout > 0
46
- puts 'Timeout must be specified as a number greater than 0'
47
- exit 1
43
+ def self.timeout(*vals)
44
+ vals.each do |val|
45
+ if val
46
+ unless val.to_i > 0
47
+ puts 'Timeout must be specified as a number greater than 0'
48
+ exit 1
49
+ end
50
+ @read_timeout = [val.to_i, @read_timeout].max
51
+ return @read_timeout
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.connect_timeout(*vals)
57
+ vals.each do |val|
58
+ if val
59
+ unless val.to_i > 0
60
+ puts 'Timeout must be specified as a number greater than 0'
61
+ exit 1
62
+ end
63
+ @connect_timeout = [val.to_i, @connect_timeout].max
64
+ return @connect_timeout
48
65
  end
49
66
  end
50
67
  end
@@ -278,7 +295,8 @@ module RHC
278
295
  puts "Contacting #{url.scheme}://#{url.host}" if @mydebug
279
296
  req.set_form_data({'json_data' => json_data, 'password' => password})
280
297
  http = http.new(url.host, url.port)
281
- http.open_timeout = @mytimeout
298
+ http.open_timeout = @connect_timeout
299
+ http.read_timeout = @read_timeout
282
300
  if url.scheme == "https"
283
301
  http.use_ssl = true
284
302
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -444,7 +462,7 @@ module RHC
444
462
  rescue Rhc::Rest::ValidationException => e
445
463
  print_response_err(Struct::FakeResponse.new(e.message,406))
446
464
  rescue Rhc::Rest::ServerErrorException => e
447
- if e.message =~ /^Failed to create application testscale due to:Scalable app cannot be of type/
465
+ if e.message =~ /^Failed to create application .* due to:Scalable app cannot be of type/
448
466
  puts "Can not create a scaling app of type #{app_type}, either disable scaling or choose another app type"
449
467
  exit 1
450
468
  else