rhc 0.98.16 → 1.0.4

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.
Files changed (94) hide show
  1. data/bin/rhc +7 -49
  2. data/bin/rhc-app +14 -3
  3. data/bin/rhc-chk +16 -16
  4. data/bin/rhc-create-app +2 -0
  5. data/bin/rhc-create-domain +1 -2
  6. data/bin/rhc-ctl-app +12 -3
  7. data/bin/rhc-ctl-domain +1 -2
  8. data/bin/rhc-domain +1 -2
  9. data/bin/rhc-domain-info +1 -2
  10. data/bin/rhc-port-forward +1 -2
  11. data/bin/rhc-snapshot +3 -0
  12. data/bin/rhc-sshkey +1 -2
  13. data/bin/rhc-tail-files +1 -1
  14. data/bin/rhc-user-info +1 -3
  15. data/features/application.feature +4 -1
  16. data/features/domain.feature +0 -4
  17. data/features/geared_application.feature +11 -0
  18. data/features/lib/rhc_helper/app.rb +16 -5
  19. data/features/lib/rhc_helper/cartridge.rb +25 -9
  20. data/features/lib/rhc_helper/commandify.rb +34 -7
  21. data/features/lib/rhc_helper/domain.rb +2 -2
  22. data/features/lib/rhc_helper/httpify.rb +24 -14
  23. data/features/lib/rhc_helper/persistable.rb +1 -1
  24. data/features/lib/rhc_helper/sshkey.rb +11 -7
  25. data/features/lib/rhc_helper.rb +5 -3
  26. data/features/multiple_cartridge.feature +1 -1
  27. data/features/scaled_application.feature +48 -0
  28. data/features/sshkey.feature +37 -31
  29. data/features/step_definitions/application_steps.rb +18 -7
  30. data/features/step_definitions/cartridge_steps.rb +29 -3
  31. data/features/step_definitions/domain_steps.rb +2 -2
  32. data/features/step_definitions/sshkey_steps.rb +34 -34
  33. data/features/support/assumptions.rb +21 -9
  34. data/features/support/before_hooks.rb +24 -6
  35. data/features/support/env.rb +45 -19
  36. data/lib/rhc/cartridge_helper.rb +27 -0
  37. data/lib/rhc/cli.rb +1 -1
  38. data/lib/rhc/command_runner.rb +31 -3
  39. data/lib/rhc/commands/alias.rb +38 -0
  40. data/lib/rhc/commands/app.rb +478 -0
  41. data/lib/rhc/commands/base.rb +42 -12
  42. data/lib/rhc/commands/cartridge.rb +189 -0
  43. data/lib/rhc/commands/domain.rb +11 -49
  44. data/lib/rhc/commands/port-forward.rb +0 -1
  45. data/lib/rhc/commands/setup.rb +2 -1
  46. data/lib/rhc/commands/snapshot.rb +118 -0
  47. data/lib/rhc/commands/sshkey.rb +24 -38
  48. data/lib/rhc/commands/tail.rb +24 -0
  49. data/lib/rhc/commands/threaddump.rb +16 -0
  50. data/lib/rhc/commands.rb +33 -7
  51. data/lib/rhc/config.rb +28 -12
  52. data/lib/rhc/context_helper.rb +19 -5
  53. data/lib/rhc/core_ext.rb +86 -0
  54. data/lib/rhc/exceptions.rb +44 -0
  55. data/lib/rhc/git_helper.rb +59 -0
  56. data/lib/rhc/helpers.rb +86 -5
  57. data/lib/rhc/output_helpers.rb +213 -0
  58. data/lib/rhc/rest/application.rb +134 -67
  59. data/lib/rhc/rest/base.rb +48 -0
  60. data/lib/rhc/rest/cartridge.rb +40 -44
  61. data/lib/rhc/rest/client.rb +127 -59
  62. data/lib/rhc/rest/domain.rb +29 -39
  63. data/lib/rhc/rest/gear_group.rb +10 -0
  64. data/lib/rhc/rest/key.rb +8 -23
  65. data/lib/rhc/rest/user.rb +8 -24
  66. data/lib/rhc/rest.rb +22 -11
  67. data/lib/rhc/ssh_key_helpers.rb +47 -0
  68. data/lib/rhc/usage_templates/help.erb +0 -1
  69. data/lib/rhc/version.rb +3 -3
  70. data/lib/rhc/wizard.rb +123 -225
  71. data/lib/rhc-common.rb +43 -62
  72. data/spec/rest_spec_helper.rb +159 -36
  73. data/spec/rhc/cli_spec.rb +29 -1
  74. data/spec/rhc/command_spec.rb +32 -35
  75. data/spec/rhc/commands/alias_spec.rb +123 -0
  76. data/spec/rhc/commands/app_spec.rb +414 -0
  77. data/spec/rhc/commands/cartridge_spec.rb +342 -0
  78. data/spec/rhc/commands/domain_spec.rb +8 -8
  79. data/spec/rhc/commands/setup_spec.rb +17 -6
  80. data/spec/rhc/commands/snapshot_spec.rb +140 -0
  81. data/spec/rhc/commands/sshkey_spec.rb +26 -4
  82. data/spec/rhc/commands/tail_spec.rb +34 -0
  83. data/spec/rhc/commands/threaddump_spec.rb +83 -0
  84. data/spec/rhc/config_spec.rb +39 -13
  85. data/spec/rhc/context_spec.rb +51 -0
  86. data/spec/rhc/helpers_spec.rb +52 -12
  87. data/spec/rhc/rest_application_spec.rb +16 -3
  88. data/spec/rhc/rest_client_spec.rb +144 -36
  89. data/spec/rhc/rest_spec.rb +1 -1
  90. data/spec/rhc/wizard_spec.rb +133 -232
  91. data/spec/spec_helper.rb +4 -3
  92. metadata +56 -31
  93. data/features/support/ssh.sh +0 -2
  94. data/spec/rhc/common_spec.rb +0 -49
data/bin/rhc CHANGED
@@ -1,33 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- # print help
4
- #
5
2
  require 'rhc/coverage_helper'
6
3
 
7
4
  # Require rhc-common for wizard invocation
8
5
  require 'rhc-common'
9
6
 
10
- def p_usage(exit_code = 255)
11
- puts <<USAGE
12
-
13
- Usage: rhc (<resource> | --help) [<command>] [<args>]
14
- Command line tool for performing operations related to your rhcloud account.
15
-
16
- List of resources
17
- domain Manage the namespace for the registered rhcloud user.
18
- app Manage applications within the rhcloud account.
19
- sshkey Manage multiple keys for the registered rhcloud user.
20
- port-forward Forward remote ports to the workstation
21
- server Display information about the status of the service.
22
- setup Run the setup wizard to configure your account.
23
-
24
- See 'rhc <resource> --help' for more applicable commands and argumments on a specific resource.
25
- USAGE
26
-
27
- exit exit_code
28
- end
29
-
30
-
31
7
  def get_args
32
8
  ARGV.shift
33
9
  args = ""
@@ -38,32 +14,14 @@ def get_args
38
14
  args
39
15
  end
40
16
 
41
- def run_setup_wizard_if_needed
42
- if not (RHC::Config.has_local_config? or
43
- RHC::Config.has_opts_config? or
44
- ARGV.include?('--noprompt') or
45
- ARGV.include?('--help') or
46
- ARGV.include?('-h'))
47
- RHC::Wizard.new(RHC::Config).run
48
- end
49
- ARGV.delete('--noprompt')
50
- end
51
-
52
17
  begin
53
- case ARGV[0]
54
- when "app"
55
- run_setup_wizard_if_needed
56
- system("rhc-app #{get_args} 2>&1")
57
- retcode = $?.exitstatus
58
- else
59
- begin
60
- require 'rhc/cli'
61
- RHC::CLI.set_terminal
62
- RHC::CLI.start(ARGV)
63
- retcode = 0
64
- rescue SystemExit => e
65
- retcode = e.status
66
- end
18
+ begin
19
+ require 'rhc/cli'
20
+ RHC::CLI.set_terminal
21
+ RHC::CLI.start(ARGV)
22
+ retcode = 0
23
+ rescue SystemExit => e
24
+ retcode = e.status
67
25
  end
68
26
 
69
27
  if retcode == nil
data/bin/rhc-app CHANGED
@@ -5,6 +5,18 @@ require 'rhc/coverage_helper'
5
5
  require 'rhc-common'
6
6
  require 'base64'
7
7
 
8
+ if ["add-alias", "remove-alias"].include? ARGV[0]
9
+ RHC::Helpers.deprecated_command('rhc alias (add|remove)',true)
10
+ elsif "snapshot" == ARGV[0]
11
+ RHC::Helpers.deprecated_command('rhc snapshot (save|restore)',true)
12
+ elsif "tail" == ARGV[0]
13
+ RHC::Helpers.deprecated_command('rhc tail',true)
14
+ elsif "cartridge" == ARGV[0]
15
+ RHC::Helpers.deprecated_command('rhc cartridge (add|remove|status|stop|start|restart|reload)',true)
16
+ else
17
+ RHC::Helpers.deprecated_command('rhc app (create|delete|show|stop|force-stop|start|restart|reload|tidy)',true)
18
+ end
19
+
8
20
  $embed_mapper = { 'add' => 'configure', 'remove' => 'deconfigure' }
9
21
 
10
22
  #
@@ -32,7 +44,6 @@ List of commands
32
44
  tidy Garbage collects the git repo and empties log/tmp dirs
33
45
  add-alias Add a custom domain name for the application
34
46
  remove-alias Remove a custom domain name for the application
35
- threaddump Trigger a thread dump for jbossas, jbosseap, and ruby applications
36
47
  tail Tail the logs of an application
37
48
  snapshot [save|restore] Saves/Restores an application snapshot to/from a tarball at the location specified using --filepath (default: ./$APPNAME.tar.gz)
38
49
  cartridge <action> Manage a cartridge running in this application
@@ -425,7 +436,7 @@ begin
425
436
  ["--config", GetoptLong::REQUIRED_ARGUMENT],
426
437
  ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
427
438
  )
428
- elsif ARGV[0] =~ /^(show|start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|threaddump|destroy)$/
439
+ elsif ARGV[0] =~ /^(show|start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|destroy)$/
429
440
  ARGV.shift
430
441
  opts = GetoptLong.new(
431
442
  ["--debug", "-d", GetoptLong::NO_ARGUMENT],
@@ -505,7 +516,7 @@ case argv_c[0]
505
516
  create_app
506
517
  when "show"
507
518
  show_app
508
- when "start", "stop", "force-stop", "restart", "reload", "status", "tidy", "add-alias", "remove-alias", "threaddump", "destroy"
519
+ when "start", "stop", "force-stop", "restart", "reload", "status", "tidy", "add-alias", "remove-alias", "destroy"
509
520
  control_app(argv_c[0])
510
521
  when "tail"
511
522
  system("rhc-tail-files #{get_args argv_c} 2>&1")
data/bin/rhc-chk CHANGED
@@ -5,6 +5,7 @@ require 'rhc/coverage_helper'
5
5
  require 'rhc-common'
6
6
  require 'net/http'
7
7
  require 'net/https'
8
+ require 'net/ssh'
8
9
  require 'rbconfig'
9
10
  require 'yaml'
10
11
  require 'tempfile'
@@ -129,17 +130,8 @@ end
129
130
  #
130
131
  # Check for proxy environment
131
132
  #
132
- if ENV['http_proxy']
133
- if ENV['http_proxy']!~/^(\w+):\/\// then
134
- ENV['http_proxy']="http://" + ENV['http_proxy']
135
- end
136
- proxy_uri=URI.parse(ENV['http_proxy'])
137
- $http = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
138
- $debuginfo['environment']['proxy'] = "#{proxy_uri.user}:#{proxy_uri.password}@#{proxy_uri.host}:#{proxy_uri.port}"
139
- else
140
- $http = Net::HTTP
141
- $debuginfo['environment']['proxy'] = "none"
142
- end
133
+ $http = RHC::Config.default_proxy
134
+ $debuginfo['environment']['proxy'] = (RHC::Config.using_proxy? ? ENV['http_proxy'] : "none")
143
135
 
144
136
  #####################################
145
137
  # Done setting up environment #
@@ -366,18 +358,26 @@ class Test3_SSH < Test::Unit::TestCase
366
358
  end
367
359
 
368
360
  def agent_key_fingerprints
369
- @@agent_keys.nil? ? nil : @@agent_keys.map{|x| x.to_s.split("\n")[1..-2].join('') }
361
+ @@agent_keys.nil? ? nil : @@agent_keys.map{|x| x.fingerprint }
370
362
  end
371
363
 
372
364
  def libra_public_key
373
- @@local_ssh_pubkey ||= (
374
- fp = File.open(@libra_kpfile)
375
- fp.gets.split(' ')[1]
365
+ @@local_ssh_pubkey ||= libra_public_key_content.split(' ')[1]
366
+ end
367
+
368
+ def libra_public_key_content
369
+ @@local_ssh_pubkey_content ||= (
370
+ fp = File.open(@libra_kpfile)
371
+ fp.gets
376
372
  )
377
373
  ensure
378
374
  fp.close if fp
379
375
  end
380
376
 
377
+ def libra_public_key_fingerprint
378
+ @@local_ssh_pubkey_fingerprint ||= Net::SSH::KeyFactory.load_data_public_key(libra_public_key_content).fingerprint
379
+ end
380
+
381
381
  def test_01_local_files
382
382
  [
383
383
  [@libra_kfile, /[4-7]00/], # Needs to at least be readable by user and nobody else
@@ -390,7 +390,7 @@ class Test3_SSH < Test::Unit::TestCase
390
390
  def test_02_ssh_agent
391
391
  require_agent_keys
392
392
 
393
- assert agent_key_names.include?(File.expand_path(@libra_kfile)) ,error_for(:pubkey_not_loaded, ": #{@libra_kpfile}")
393
+ assert agent_key_fingerprints.include?(libra_public_key_fingerprint) ,error_for(:pubkey_not_loaded, ": #{@libra_kpfile}")
394
394
  end
395
395
 
396
396
  def test_03_remote_ssh_keys
data/bin/rhc-create-app CHANGED
@@ -4,6 +4,8 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
+ RHC::Helpers.deprecated_command('rhc app create',true)
8
+
7
9
  def p_usage(error_code = 255)
8
10
  libra_server = get_var('libra_server')
9
11
  rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
@@ -4,8 +4,7 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
- puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc domain (create|update)' instead."
8
- puts""
7
+ RHC::Helpers.deprecated_command('rhc domain (create|update)',true)
9
8
 
10
9
  #
11
10
  # print help
data/bin/rhc-ctl-app CHANGED
@@ -3,6 +3,15 @@
3
3
  require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
+ if ARGV.include? "--alias"
7
+ RHC::Helpers.deprecated_command('rhc alias (add|remove)',true)
8
+ elsif ARGV.include? "-e" or ARGV.include? "--embed"
9
+ RHC::Helpers.deprecated_command('rhc cartridge (add|remove)',true)
10
+ elsif ARGV.include? "-L" or ARGV.include? "--embed-list"
11
+ RHC::Helpers.deprecated_command('rhc cartridge list',true)
12
+ else
13
+ RHC::Helpers.deprecated_command('rhc app (start|stop|force-stop|restart|reload|status|destroy|tidy)',true)
14
+ end
6
15
 
7
16
  embed_mapper = { 'add' => 'configure', 'remove' => 'deconfigure' }
8
17
 
@@ -16,7 +25,7 @@ Control an OpenShift express app
16
25
  -a|--app application Application name (alphanumeric) (required)
17
26
  -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
18
27
  -p|--password password Password (optional, will prompt)
19
- -c|--command command (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|threaddump)
28
+ -c|--command command (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)
20
29
  -L|--embedded-list List supported embedded cartridges
21
30
  -e|--embed (add|remove|stop|start|restart|status|reload)-$cartridge eg: add-mysql-5.1
22
31
  -b|--bypass Bypass warnings
@@ -103,8 +112,8 @@ unless opt["embed"] or opt["command"]
103
112
  end
104
113
 
105
114
  if opt["command"]
106
- unless opt["command"] =~ /^(start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|threaddump)$/
107
- puts "Invalid command '#{opt["command"]}' specified. Valid commands are (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|threaddump)"
115
+ unless opt["command"] =~ /^(start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)$/
116
+ puts "Invalid command '#{opt["command"]}' specified. Valid commands are (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)"
108
117
  p_usage
109
118
  end
110
119
  elsif opt["embed"]
data/bin/rhc-ctl-domain CHANGED
@@ -4,8 +4,7 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
- puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc sshkey' instead."
8
- puts""
7
+ RHC::Helpers.deprecated_command('rhc sshkey',true)
9
8
 
10
9
  #
11
10
  # print help
data/bin/rhc-domain CHANGED
@@ -4,8 +4,7 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
- puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc domain' instead."
8
- puts""
7
+ RHC::Helpers.deprecated_command('rhc domain',true)
9
8
 
10
9
  #
11
10
  # print help
data/bin/rhc-domain-info CHANGED
@@ -4,8 +4,7 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
- puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc domain show' instead."
8
- puts""
7
+ RHC::Helpers.deprecated_command('rhc domain show',true)
9
8
 
10
9
  #
11
10
  # print help
data/bin/rhc-port-forward CHANGED
@@ -4,8 +4,7 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
- puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc port-forward' instead."
8
- puts""
7
+ RHC::Helpers.deprecated_command('rhc port-forward',true)
9
8
 
10
9
  #
11
10
  # print help
data/bin/rhc-snapshot CHANGED
@@ -4,6 +4,9 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
+ puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc snapshot' instead."
8
+ puts""
9
+
7
10
  #
8
11
  # print help
9
12
  #
data/bin/rhc-sshkey CHANGED
@@ -4,8 +4,7 @@ require 'rhc/coverage_helper'
4
4
 
5
5
  require 'rhc-common'
6
6
 
7
- puts "Warning: This command is deprecated and will be removed in the future. Please use 'rhc sshkey' instead."
8
- puts""
7
+ RHC::Helpers.deprecated_command('rhc sshkey',true)
9
8
 
10
9
  #
11
10
  # print help
data/bin/rhc-tail-files CHANGED
@@ -91,7 +91,7 @@ unless user_info['app_info'][app]
91
91
  exit 101
92
92
  end
93
93
 
94
- opt['files'] = "#{opt['app']}/logs/*" unless opt['files']
94
+ opt['files'] = "*/log*/*" unless opt['files']
95
95
  file_glob = "#{opt['files']}"
96
96
  app_uuid = user_info['app_info'][app]['uuid']
97
97
  namespace = user_info['user_info']['domains'][0]['namespace']
data/bin/rhc-user-info CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # print deprecation warning
3
-
4
- puts "Warning: This command is deprecated. Please use rhc-domain-info instead."
5
- puts""
3
+ RHC::Helpers.deprecated_command('rhc-domain-info',true)
6
4
 
7
5
  args = ""
8
6
  ARGV.each do|a|
@@ -21,4 +21,7 @@ Feature: Application Operations
21
21
  | running | shown | it | succeed |
22
22
  | running | stopped | the application | not be accessible |
23
23
  | stopped | started | the application | be accessible |
24
- | running | destroyed | the application | not exist |
24
+ # After the app is deleted, it is resolving to the OpenShift server
25
+ # I think it's because of US2108
26
+ # TODO: This needs to be fixed by "not exist" checking DNS instead of HTTP
27
+ | running | deleted | it | succeed |
@@ -23,7 +23,3 @@ Feature: Existing Domain Operations
23
23
  When domain is deleted
24
24
  Then domains should be empty
25
25
 
26
- Scenario: Domain Update Fails
27
- When domain is deleted
28
- When domain is updated
29
- Then the domain command should fail with an exitcode of 127
@@ -0,0 +1,11 @@
1
+ @geared_application @geared_user_required @domain_required
2
+ Feature: Scaled Application Operations
3
+
4
+ @init
5
+ Scenario: Geared Application Creation
6
+ When a php-5.3 application is created with a medium gear
7
+ Then the application should be accessible
8
+ Then the application should have a medium gear
9
+
10
+
11
+
@@ -15,14 +15,14 @@ module RHCHelper
15
15
  include Httpify
16
16
 
17
17
  # attributes to represent the general information of the application
18
- attr_accessor :name, :type, :hostname, :repo, :embed, :snapshot, :uid, :alias
18
+ attr_accessor :name, :type, :hostname, :repo, :embed, :snapshot, :uid, :alias, :scalable, :gear_profile
19
19
 
20
20
  # mysql connection information
21
21
  attr_accessor :mysql_hostname, :mysql_user, :mysql_password, :mysql_database
22
22
 
23
23
  # Create the data structure for a test application
24
- def initialize(type, name)
25
- @name, @type = name, type
24
+ def initialize(type, name, scalable=false, gear_profile=nil)
25
+ @name, @type, @scalable, @gear_profile = name, type, scalable, gear_profile
26
26
  @hostname = "#{name}-#{$namespace}.#{$domain}"
27
27
  @repo = "#{TEMP_DIR}/#{$namespace}_#{name}_repo"
28
28
  @file = "#{TEMP_DIR}/#{$namespace}.json"
@@ -47,7 +47,7 @@ module RHCHelper
47
47
  end
48
48
  end
49
49
 
50
- def self.create_unique(type, prefix="test")
50
+ def self.create_unique(type, scalable, gear_profile=nil, prefix="test")
51
51
  # Get a REST client to verify the application name
52
52
  client = RHC::Rest::Client.new($end_point, $username, $password)
53
53
 
@@ -68,7 +68,7 @@ module RHCHelper
68
68
  next if test_names.index(name)
69
69
 
70
70
  # Create the app
71
- app = App.new(type, name)
71
+ app = App.new(type, name, scalable, gear_profile)
72
72
  app.persist
73
73
  return app
74
74
  end
@@ -92,6 +92,17 @@ module RHCHelper
92
92
  persist
93
93
  end
94
94
 
95
+ def is_created?
96
+ # Get a REST client to verify the application is on the server
97
+ client = RHC::Rest::Client.new($end_point, $username, $password)
98
+ begin
99
+ client.domains[0].find_application(name)
100
+ rescue
101
+ return false
102
+ end
103
+ true
104
+ end
105
+
95
106
  def cartridge(name)
96
107
  @embed_helpers[name] = RHCHelper::Cartridge.new(self, name) unless @embed_helpers.include?(name)
97
108
  @embed_helpers[name]
@@ -24,23 +24,23 @@ module RHCHelper
24
24
  @file = "#{TEMP_DIR}/#{$namespace}.json"
25
25
  end
26
26
 
27
- def rhc_app_cartridge(cmd)
28
- full_cmd = "rhc app cartridge #{cmd} -l #{$username} -p #{$password} -a #{@app_name}"
29
- full_cmd += " -c #{@name}" if cmd != "list"
27
+ def rhc_cartridge(cmd)
28
+ full_cmd = "rhc cartridge #{cmd} -l #{$username} -p #{$password} -a #{@app_name}"
29
+ full_cmd += " #{@name}" if cmd != "list"
30
30
  run(full_cmd, nil) do |exitstatus, out, err, arg|
31
31
  yield exitstatus, out, err, arg if block_given?
32
32
  end
33
33
  end
34
34
 
35
35
  def add
36
- rhc_app_cartridge('add') do |exitstatus, out, err, arg|
36
+ rhc_cartridge('add') do |exitstatus, out, err, arg|
37
37
  yield exitstatus, out, err, arg if block_given?
38
38
  end
39
39
  end
40
40
 
41
41
  def status
42
42
  result = ""
43
- rhc_app_cartridge('status') do |exitstatus, out, err, arg|
43
+ rhc_cartridge('status') do |exitstatus, out, err, arg|
44
44
  result = out
45
45
  end
46
46
 
@@ -48,19 +48,35 @@ module RHCHelper
48
48
  end
49
49
 
50
50
  def start
51
- rhc_app_cartridge('start')
51
+ rhc_cartridge('start')
52
52
  end
53
53
 
54
54
  def stop
55
- rhc_app_cartridge('stop')
55
+ rhc_cartridge('stop')
56
56
  end
57
57
 
58
58
  def restart
59
- rhc_app_cartridge('restart')
59
+ rhc_cartridge('restart')
60
60
  end
61
61
 
62
62
  def remove
63
- rhc_app_cartridge('remove')
63
+ rhc_cartridge('remove --confirm')
64
+ end
65
+
66
+ def scale(values)
67
+ status = nil
68
+ rhc_cartridge("scale #{values}") do |exitstatus, out, err, arg|
69
+ status = exitstatus
70
+ end
71
+ status
72
+ end
73
+
74
+ def show
75
+ result = ""
76
+ rhc_cartridge('show') do |exitstatus, out, err, arg|
77
+ result = out
78
+ end
79
+ result
64
80
  end
65
81
  end
66
82
  end
@@ -51,8 +51,8 @@ module RHCHelper
51
51
  def get_args(cmd, arg0=nil, debug=true)
52
52
  args = " "
53
53
  args << "-l #{$username} "
54
- args << "-p #{$password} "
55
- args << "-d " if debug
54
+ args << "-p \"#{$password}\" "
55
+ args << "--debug " if debug
56
56
 
57
57
  # Add the application name for all application commands
58
58
  if cmd =~ /app/
@@ -62,20 +62,25 @@ module RHCHelper
62
62
 
63
63
  # Command specific arguments
64
64
  case cmd
65
+ when /app delete/
66
+ args << "--confirm "
65
67
  when /domain show/
66
68
  # domain show doesn't take arguments
69
+ when /domain update/
70
+ args << "#{$old_namespace} #{$namespace}"
67
71
  when /domain /
68
72
  raise "No namespace set" unless $namespace
69
73
  # use legacy switch for specifying namespace to verify older interface
70
74
  # should switch to using argument once all commands are moved over
71
- args << "-n #{$namespace} "
72
- when /destroy/
73
- args << "-b "
75
+ args << "#{$namespace} "
74
76
  when /snapshot/
75
77
  args << "-f #{@snapshot} "
76
78
  when /create/
77
79
  args << "-r #{@repo} "
78
80
  args << "-t #{@type} "
81
+ args << "-s " unless @scalable.nil?
82
+ args << "-g #{@gear_profile} " unless @gear_profile.nil?
83
+ args << "--noprompt "
79
84
  when /add-alias/
80
85
  raise "No alias set" unless @alias
81
86
  args << "--alias #{@alias} "
@@ -123,9 +128,31 @@ module RHCHelper
123
128
  # Begin Post Processing Callbacks
124
129
  #
125
130
  def app_create_callback(exitcode, stdout, stderr, arg)
126
- match = stdout.split.map {|line| line.match(SSH_OUTPUT_PATTERN)}.compact[0]
131
+ match = stdout.match(UUID_OUTPUT_PATTERN)
127
132
  @uid = match[1] if match
128
- raise "UID not parsed from app create output" unless @uid
133
+ match = stdout.match(GEAR_PROFILE_OUTPUT_PATTERN)
134
+ @gear_profile = nil
135
+ @gear_profile = match[1] if match
136
+
137
+ def no_match(msg,expected,actual)
138
+ [ msg,
139
+ "-"*20,
140
+ ("Expected: %s" % expected),
141
+ ("Actual:\n%s" % actual),
142
+ "-"*20,
143
+ ].join("\n")
144
+ end
145
+
146
+ raise no_match(
147
+ "UID not parsed from app create output",
148
+ UUID_OUTPUT_PATTERN, stdout
149
+ ) unless @uid
150
+
151
+ raise no_match(
152
+ "Gear Profile not parsed from app create output",
153
+ GEAR_PROFILE_OUTPUT_PATTERN, stdout
154
+ ) unless @gear_profile
155
+
129
156
  persist
130
157
  end
131
158
 
@@ -51,7 +51,7 @@ module RHCHelper
51
51
  end
52
52
 
53
53
  def self.update(prefix="update")
54
- old_namespace = $namespace
54
+ $old_namespace = $namespace
55
55
  $namespace = unique_namespace(prefix)
56
56
  rhc_domain_update
57
57
 
@@ -62,7 +62,7 @@ module RHCHelper
62
62
  f.write($namespace)
63
63
  end
64
64
  else
65
- $namespace = old_namespace
65
+ $namespace = $old_namespace
66
66
  end
67
67
  end
68
68
 
@@ -53,13 +53,20 @@ module RHCHelper
53
53
  start = Time.now
54
54
 
55
55
  # Helper function to log message and sleep
56
- def my_sleep(start,uri,e,options)
57
- err_str = "Connection inacessible for %s (%s) - %.2f seconds"
58
- logger.info(err_str % [uri,e.class,Time.now - start])
59
- logger.info "Sleeping for %d seconds, retrying" % options[:sleep]
56
+ def my_sleep(status,expected,start,options)
57
+ [
58
+ ["Expecting", expected.class],
59
+ ["Received", status.class ],
60
+ ["Elapsed", Time.now - start ],
61
+ ].each do |values|
62
+ logger.info "%10s: %s" % values
63
+ end
60
64
  sleep options[:sleep]
61
65
  end
62
66
 
67
+ expected = options[:expected]
68
+ expected = (expected.to_s =~ /^Net/) ? expected.new(nil,nil,nil) : expected.new
69
+
63
70
  begin
64
71
  timeout(options[:timeout]) do
65
72
  loop do
@@ -75,18 +82,21 @@ module RHCHelper
75
82
  # Pass these up so we can check them
76
83
  return e
77
84
  end
78
- logger.debug "Received: %s" % response
79
85
 
80
86
  case response
81
- # Catch any response if we're expecting it
82
- when options[:expected]
87
+ # Catch any response if we're expecting it or redirection
88
+ when expected.class, Net::HTTPRedirection
83
89
  break
84
- # Retry these responses
90
+ # Retry these responses
85
91
  when Net::HTTPServiceUnavailable, SocketError
86
- my_sleep(start,uri,response,options)
92
+ my_sleep(response,expected,start,options)
87
93
  else
88
- # Some other response
89
- break
94
+ case expected
95
+ when Net::HTTPServiceUnavailable
96
+ my_sleep(response,expected,start,options)
97
+ else
98
+ break
99
+ end
90
100
  end
91
101
  end
92
102
  end
@@ -111,10 +121,10 @@ module RHCHelper
111
121
  return response
112
122
  end
113
123
 
114
- def is_inaccessible?
115
- check_response({
124
+ def is_inaccessible?(options = {})
125
+ check_response(options.merge({
116
126
  :expected => Net::HTTPServiceUnavailable
117
- })
127
+ }))
118
128
  end
119
129
 
120
130
  def is_accessible?(options = {})
@@ -25,7 +25,7 @@ module RHCHelper
25
25
  end
26
26
 
27
27
  def from_json(json)
28
- app = App.new(json['type'], json['name'])
28
+ app = App.new(json['type'], json['name'], json['scalable'])
29
29
  app.embed = json['embed']
30
30
  app.mysql_user = json['mysql_user']
31
31
  app.mysql_password = json['mysql_password']