rhc 0.80.5 → 0.81.14

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.
@@ -78,8 +78,11 @@ libra_server = get_var('libra_server')
78
78
  debug = get_var('debug') == 'false' ? nil : get_var('debug')
79
79
 
80
80
 
81
- libra_kfile = get_kfile(false)
82
- libra_kpfile = get_kpfile(libra_kfile, opt['alter'])
81
+ ssh_key_file_path = get_kfile(false)
82
+ ssh_pub_key_file_path = get_kpfile(ssh_key_file_path, opt['alter'])
83
+
84
+ ssh_config = "#{ENV['HOME']}/.ssh/config"
85
+ ssh_config_d = "#{ENV['HOME']}/.ssh/"
83
86
 
84
87
  if opt["help"]
85
88
  p_usage
@@ -113,7 +116,6 @@ end
113
116
  #
114
117
  # Add a new namespace to configs
115
118
  #
116
-
117
119
  def add_rhlogin_config(rhlogin, uuid)
118
120
  f = open(File.expand_path(config_path), 'a')
119
121
  unless config.get_value('default_rhlogin')
@@ -124,32 +126,108 @@ def add_rhlogin_config(rhlogin, uuid)
124
126
  f.close
125
127
  end
126
128
 
129
+ #
130
+ # Check / add new host to ~/.ssh/config
131
+ #
132
+ def add_ssh_config_host(rhc_domain, ssh_key_file_path, ssh_config, ssh_config_d)
133
+
134
+ puts "Checking ~/.ssh/config"
135
+ ssh_key_file_name = File.basename(ssh_key_file_path)
136
+ if ssh_key_file_path =~ /^#{ENV['HOME']}/
137
+ ssh_key_file_path = ssh_key_file_path[ENV['HOME'].length..-1]
138
+ if ssh_key_file_path =~ /^\// || ssh_key_file_path =~ /^\\/
139
+ ssh_key_file_path = '~' + ssh_key_file_path
140
+ else
141
+ ssh_key_file_path = '~/' + ssh_key_file_path
142
+ end
143
+ end
144
+ if (ssh_key_file_name != 'id_rsa')
145
+ found = false
146
+
147
+ begin
148
+ File.open(ssh_config, "r") do |sline|
149
+ while(line = sline.gets)
150
+ if line.to_s.index("Host *.#{rhc_domain}") == 0
151
+ found = true
152
+ break
153
+ end
154
+ end
155
+ end
156
+ rescue Errno::EACCES
157
+ puts "Could not read from #{ssh_config}"
158
+ puts "Reason: " + $!
159
+ puts
160
+ puts "Please correct this first. Then run rerun."
161
+ puts
162
+ exit 213
163
+ rescue Errno::ENOENT
164
+ puts "Could not find #{ssh_config}. This is ok, continuing"
165
+ end
166
+ if found
167
+ puts "Found #{rhc_domain} in ~/.ssh/config... No need to adjust"
168
+ else
169
+ puts " Adding #{rhc_domain} to ~/.ssh/config"
170
+ begin
171
+ f = File.open(ssh_config, "a")
172
+ f.puts <<SSH
173
+
174
+ # Added by rhc-create-domain on #{`date`}
175
+ Host *.#{rhc_domain}
176
+ IdentityFile #{ssh_key_file_path}
177
+ VerifyHostKeyDNS yes
178
+ StrictHostKeyChecking no
179
+ UserKnownHostsFile ~/.ssh/libra_known_hosts
180
+
181
+ SSH
182
+ f.close
183
+ rescue Errno::EACCES
184
+ puts "Could not write to #{ssh_config}"
185
+ puts "Reason: " + $!
186
+ puts
187
+ puts "Please correct this first. Then run rerun."
188
+ puts
189
+ exit 214
190
+ rescue Errno::ENOENT
191
+ # Make directory and config if they do not exist
192
+ puts "Could not find directory: " + $!
193
+ puts "creating"
194
+ FileUtils.mkdir_p ssh_config_d
195
+ file = File.open(ssh_config, 'w')
196
+ file.close
197
+ retry
198
+ end
199
+ end
200
+
201
+ File.chmod(0700, ssh_config_d)
202
+ File.chmod(0600, ssh_config)
203
+ end
204
+ end
205
+
127
206
 
128
207
  #
129
- # Check to see if a libra_kfile exists, if not create it.
208
+ # Check to see if a ssh_key_file_path exists, if not create it.
130
209
  #
131
210
 
132
- if File.readable?(libra_kfile)
133
- puts "OpenShift Express key found at #{libra_kfile}. Reusing..."
211
+ if File.readable?(ssh_key_file_path)
212
+ puts "OpenShift Express key found at #{ssh_key_file_path}. Reusing..."
134
213
  else
135
- puts "Generating OpenShift Express ssh key to #{libra_kfile}"
214
+ puts "Generating OpenShift Express ssh key to #{ssh_key_file_path}"
136
215
  # Use system for interaction
137
- system("ssh-keygen -t rsa -f '#{libra_kfile}'")
216
+ system("ssh-keygen -t rsa -f '#{ssh_key_file_path}'")
138
217
  end
139
218
 
140
- ssh_key = File.open(libra_kpfile).gets.chomp.split(' ')[1]
219
+ ssh_key = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')[1]
141
220
 
142
- puts "Contacting https://#{libra_server}"
143
221
  data = {'namespace' => opt['namespace'],
144
- 'rhlogin' => opt['rhlogin'],
145
- 'ssh' => ssh_key}
222
+ 'rhlogin' => opt['rhlogin'],
223
+ 'ssh' => ssh_key}
146
224
  if (opt['alter'])
147
- data['alter'] = "true"
225
+ data[:alter] = true
148
226
  not_found_message = "A user with rhlogin '#{opt['rhlogin']}' does not have a registered domain. Be sure to run rhc-create-domain without -a|--alter first."
149
227
  user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, true, not_found_message)
150
228
  end
151
229
  if debug
152
- data['debug'] = "true"
230
+ data[:debug] = true
153
231
  end
154
232
  RHC::print_post_data(data)
155
233
  json_data = RHC::generate_json(data)
@@ -163,6 +241,7 @@ if response.code == '200'
163
241
  RHC::print_response_success(json_resp)
164
242
  json_rhlogininfo = JSON.parse(json_resp['data'])
165
243
  add_rhlogin_config(json_rhlogininfo['rhlogin'], json_rhlogininfo['uuid'])
244
+ add_ssh_config_host(json_rhlogininfo['rhc_domain'], ssh_key_file_path, ssh_config, ssh_config_d)
166
245
 
167
246
  if opt['alter'] != ''
168
247
  puts <<EOF
@@ -199,11 +278,13 @@ EOF
199
278
  dns_success = false
200
279
  end
201
280
  end
281
+ puts "You can use rhc-user-info to view any url changes. Be sure to update any links"
282
+ puts "including the url in your local git config: <local_git_repo>/.git/config"
202
283
  end
203
284
  if dns_success
204
- puts "Alteration successful. You can use rhc-user-info to view any url changes."
285
+ puts "Alteration successful."
205
286
  else
206
- puts "Alteration successful but at least one of the urls is still updating in DNS. You can use rhc-user-info to view any url changes."
287
+ puts "Alteration successful but at least one of the urls is still updating in DNS."
207
288
  end
208
289
  puts ""
209
290
  end
@@ -214,4 +295,4 @@ EOF
214
295
  else
215
296
  RHC::print_response_err(response)
216
297
  end
217
- exit 254
298
+ exit 1
@@ -35,12 +35,13 @@ Control an OpenShift express app
35
35
  -a|--app application Application name (alphanumeric) (required)
36
36
  -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (#{rhlogin})
37
37
  -p|--password password RHLogin password (optional, will prompt)
38
- -c|--command command (start|stop|force-stop|restart|reload|status|destroy)
38
+ -c|--command command (start|stop|force-stop|restart|reload|status|destroy|add-alias|remove-alias)
39
39
  -L|--embedded-list List supported embedded cartridges
40
40
  -e|--embed (add|remove|stop|start|restart|status|reload)-$cartridge eg: add-mysql-5.1
41
41
  -b|--bypass Bypass warnings
42
42
  -d|--debug Print Debug info
43
43
  -h|--help Show Usage info
44
+ --alias Specify server alias (when using add/remove-alias)
44
45
  --config path Path of alternate config file
45
46
  --timeout # Timeout, in seconds, for connection
46
47
 
@@ -69,6 +70,7 @@ begin
69
70
  ["--embed", "-e", GetoptLong::REQUIRED_ARGUMENT],
70
71
  ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
71
72
  ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
73
+ ["--alias", GetoptLong::REQUIRED_ARGUMENT],
72
74
  ["--config", GetoptLong::REQUIRED_ARGUMENT],
73
75
  ["--command", "-c", GetoptLong::REQUIRED_ARGUMENT],
74
76
  ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
@@ -121,14 +123,14 @@ unless opt["embed"] or opt["command"]
121
123
  end
122
124
 
123
125
  if opt["command"]
124
- unless opt["command"] =~ /^(start|stop|force-stop|restart|reload|status|destroy)$/
125
- puts "Invalid command '#{opt["command"]}' specified. Valid commands are (start|stop|force-stop|restart|reload|status|destroy)"
126
+ unless opt["command"] =~ /^(start|stop|force-stop|restart|reload|status|destroy|add-alias|remove-alias)$/
127
+ puts "Invalid command '#{opt["command"]}' specified. Valid commands are (start|stop|force-stop|restart|reload|status|destroy|add-alias|remove-alias)"
126
128
  p_usage
127
129
  end
128
130
  elsif opt["embed"]
129
131
  action = opt['embed'].split('-')[0]
130
132
  unless action =~ /^(add|remove|start|stop|restart|status|reload)$/
131
- puts "Invalid embed action '#{action}' specified. Valid embed actions are (add|remove|start|stop|restart|status|reload)"
133
+ puts "Invalid embed action '#{action}' specified. Valid embed actions are (add|remove|start|stop|restart|status|reload|add-alias|remove-alias)"
132
134
  p_usage
133
135
  end
134
136
  end
@@ -137,23 +139,17 @@ unless opt['rhlogin'] && opt['app'] && (opt['command'] || opt['embed'])
137
139
  p_usage
138
140
  end
139
141
 
142
+ if opt['command'] and (opt['alias'] and !(opt['command'] =~ /-alias$/)) || ((opt['command'] =~ /-alias$/) and ! opt['alias'])
143
+ puts "When specifying alias make sure to use -c add-alias or -c remove-alias"
144
+ p_usage
145
+ end
146
+
147
+
140
148
  password = opt['password']
141
149
  if !password
142
150
  password = RHC::get_password
143
151
  end
144
152
 
145
- user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, debug, false)
146
- app = user_info['app_info'][opt['app']]
147
- if app
148
- framework = app['framework']
149
- else
150
- puts "Application not found: #{opt['app']}"
151
- exit 101
152
- end
153
- #
154
- # Send Warning
155
- #
156
-
157
153
  opt["command"] = "deconfigure" if opt["command"] == "destroy"
158
154
 
159
155
  if !opt["bypass"] and opt["command"] == "deconfigure"
@@ -176,6 +172,7 @@ WARNING
176
172
  end
177
173
  end
178
174
 
175
+ framework = nil
179
176
  if opt['embed']
180
177
  action = opt['embed'].split('-')[0]
181
178
  # override action if it's in the mapper
@@ -187,25 +184,4 @@ else
187
184
  url = URI.parse("https://#{libra_server}/broker/cartridge")
188
185
  end
189
186
 
190
- data = {:cartridge => framework,
191
- :action => action,
192
- :app_name => "#{opt['app']}",
193
- :rhlogin => "#{opt['rhlogin']}"
194
- }
195
- if debug
196
- data['debug'] = "true"
197
- end
198
-
199
- json_data = RHC::generate_json(data)
200
- puts "Submitting form: #{json_data}" if debug
201
-
202
- puts "Contacting https://#{libra_server}"
203
-
204
- response = RHC::http_post(@http, url, json_data, password)
205
-
206
- if response.code == '200'
207
- json_resp = JSON.parse(response.body)
208
- RHC::print_response_success(json_resp, true)
209
- else
210
- RHC::print_response_err(response)
211
- end
187
+ RHC::ctl_app(libra_server, @http, opt['app'], opt['rhlogin'], password, action, opt['embed'], framework, opt['alias'])
@@ -153,7 +153,7 @@ end
153
153
  puts
154
154
  puts ssh_cmd
155
155
  puts
156
- exit 254
156
+ exit 1
157
157
  end
158
158
  puts output if opt['restore'] && debug
159
159
  exit 0
@@ -134,7 +134,7 @@ rescue SystemCallError
134
134
  puts
135
135
  puts ssh_cmd
136
136
  puts
137
- exit 254
137
+ exit 1
138
138
  end
139
139
  # this should never happen
140
140
  exit 1
@@ -102,7 +102,7 @@ if opt['info']
102
102
  puts "User Info"
103
103
  puts "========="
104
104
  puts "Namespace: #{user_info['user_info']['namespace']}"
105
- puts " UUID: #{user_info['user_info']['uuid']}"
105
+ #puts " UUID: #{user_info['user_info']['uuid']}"
106
106
  puts " RHLogin: #{user_info['user_info']['rhlogin']}"
107
107
  puts " ssh_key: #{user_info['user_info']['ssh_key']}"
108
108
  end
@@ -112,27 +112,34 @@ if opt['apps']
112
112
 
113
113
  puts "Application Info"
114
114
  puts "================"
115
- user_info['app_info'].each do |key, val|
116
- puts key
117
- puts " Framework: #{val['framework']}"
118
- puts " Creation: #{val['creation_time']}"
119
- puts " UUID: #{val['uuid']}"
120
- puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
121
- puts " Public URL: http://#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/"
122
- puts ""
123
- puts " Embedded: "
124
- if val['embedded'] && !val['embedded'].empty?
125
- val['embedded'].each do |embed_key, embed_val|
126
- if embed_val.has_key?('info') && !embed_val['info'].empty?
127
- puts " #{embed_key} - #{embed_val['info']}"
128
- else
129
- puts " #{embed_key}"
130
- end
131
- end
132
- else
133
- puts " None"
134
- end
135
- puts ""
115
+ unless user_info['app_info'].empty?
116
+ user_info['app_info'].each do |key, val|
117
+ puts key
118
+ puts " Framework: #{val['framework']}"
119
+ puts " Creation: #{val['creation_time']}"
120
+ puts " UUID: #{val['uuid']}"
121
+ puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
122
+ puts " Public URL: http://#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/"
123
+ if val['aliases'] && !val['aliases'].empty?
124
+ puts " Aliases: #{val['aliases'].join(', ')}"
125
+ end
126
+ puts ""
127
+ puts " Embedded: "
128
+ if val['embedded'] && !val['embedded'].empty?
129
+ val['embedded'].each do |embed_key, embed_val|
130
+ if embed_val.has_key?('info') && !embed_val['info'].empty?
131
+ puts " #{embed_key} - #{embed_val['info']}"
132
+ else
133
+ puts " #{embed_key}"
134
+ end
135
+ end
136
+ else
137
+ puts " None"
138
+ end
139
+ puts ""
140
+ end
141
+ else
142
+ puts "No applications found. You can use rhc-create-app to create new applications."
136
143
  end
137
144
 
138
145
  end
@@ -42,13 +42,23 @@ module RHC
42
42
  @mydebug = false
43
43
  broker_version = "?.?.?"
44
44
  api_version = "?.?.?"
45
+
46
+ DEBUG_INGORE_KEYS = {
47
+ 'result' => nil,
48
+ 'debug' => nil,
49
+ 'exit_code' => nil,
50
+ 'messages' => nil,
51
+ 'data' => nil,
52
+ 'api' => nil,
53
+ 'broker' => nil
54
+ }
45
55
 
46
56
  def self.timeout(val)
47
57
  if val
48
58
  @mytimeout = val.to_i
49
59
  unless @mytimeout > 0
50
60
  puts 'Timeout must be specified as a number greater than 0'
51
- exit 254
61
+ exit 1
52
62
  end
53
63
  end
54
64
  end
@@ -77,11 +87,10 @@ module RHC
77
87
  end
78
88
 
79
89
  def self.get_cartridges_list(libra_server, net_http, cart_type="standalone", print_result=nil)
80
- puts "Contacting https://#{libra_server} to obtain list of cartridges..."
81
- puts " (please excuse the delay)"
90
+ puts "Obtaining list of cartridges (please excuse the delay)..."
82
91
  data = {'cart_type' => cart_type}
83
92
  if @mydebug
84
- data['debug'] = "true"
93
+ data[:debug] = true
85
94
  end
86
95
  print_post_data(data)
87
96
  json_data = generate_json(data)
@@ -96,7 +105,7 @@ module RHC
96
105
  begin
97
106
  json_resp = JSON.parse(response.body)
98
107
  rescue JSON::ParserError
99
- exit 254
108
+ exit 1
100
109
  end
101
110
  update_server_api_v(json_resp)
102
111
  if print_result
@@ -105,7 +114,7 @@ module RHC
105
114
  begin
106
115
  carts = (JSON.parse(json_resp['data']))['carts']
107
116
  rescue JSON::ParserError
108
- exit 254
117
+ exit 1
109
118
  end
110
119
  carts
111
120
  end
@@ -173,11 +182,9 @@ module RHC
173
182
  end
174
183
 
175
184
  def self.get_user_info(libra_server, rhlogin, password, net_http, print_result, not_found_message=nil)
176
-
177
- puts "Contacting https://#{libra_server}"
178
185
  data = {'rhlogin' => rhlogin}
179
186
  if @mydebug
180
- data['debug'] = "true"
187
+ data[:debug] = true
181
188
  end
182
189
  print_post_data(data)
183
190
  json_data = generate_json(data)
@@ -199,12 +206,12 @@ module RHC
199
206
  else
200
207
  print_response_err(response)
201
208
  end
202
- exit 254
209
+ exit 1
203
210
  end
204
211
  begin
205
212
  json_resp = JSON.parse(response.body)
206
213
  rescue JSON::ParserError
207
- exit 254
214
+ exit 1
208
215
  end
209
216
  update_server_api_v(json_resp)
210
217
  if print_result
@@ -213,7 +220,7 @@ module RHC
213
220
  begin
214
221
  user_info = JSON.parse(json_resp['data'].to_s)
215
222
  rescue JSON::ParserError
216
- exit 254
223
+ exit 1
217
224
  end
218
225
  user_info
219
226
  end
@@ -224,6 +231,9 @@ module RHC
224
231
  print "Password: "
225
232
  system "stty -echo"
226
233
  password = gets.chomp
234
+ rescue Interrupt
235
+ puts "\n"
236
+ exit 1
227
237
  ensure
228
238
  system "stty echo"
229
239
  end
@@ -234,6 +244,7 @@ module RHC
234
244
  def self.http_post(http, url, json_data, password)
235
245
  req = http::Post.new(url.path)
236
246
 
247
+ puts "Contacting #{url.scheme}://#{url.host}" if @mydebug
237
248
  req.set_form_data({'json_data' => json_data, 'password' => password})
238
249
  http = http.new(url.host, url.port)
239
250
  http.open_timeout = @mytimeout
@@ -263,14 +274,14 @@ module RHC
263
274
  if (!@mydebug)
264
275
  puts "Re-run with -d for more information."
265
276
  end
266
- exit_code = 254
277
+ exit_code = 1
267
278
  if response.content_type == 'application/json'
268
279
  puts "JSON response:"
269
280
  begin
270
281
  json_resp = JSON.parse(response.body)
271
282
  exit_code = print_json_body(json_resp)
272
283
  rescue JSON::ParserError
273
- exit_code = 254
284
+ exit_code = 1
274
285
  end
275
286
  elsif @mydebug
276
287
  puts "HTTP response from server is #{response.body}"
@@ -288,18 +299,18 @@ module RHC
288
299
  end
289
300
  end
290
301
 
291
- def self.print_response_success(json_resp, always_print_result=false)
302
+ def self.print_response_success(json_resp, print_result=false)
292
303
  if @mydebug
293
304
  puts "Response from server:"
294
- print_json_body(json_resp)
295
- elsif always_print_result
305
+ print_json_body(json_resp, print_result)
306
+ elsif print_result
296
307
  print_json_body(json_resp)
297
308
  else
298
309
  print_response_messages(json_resp)
299
310
  end
300
311
  end
301
312
 
302
- def self.print_json_body(json_resp)
313
+ def self.print_json_body(json_resp, print_result=true)
303
314
  print_response_messages(json_resp)
304
315
  exit_code = json_resp['exit_code']
305
316
  if @mydebug
@@ -311,20 +322,20 @@ module RHC
311
322
  puts "Exit Code: #{exit_code}"
312
323
  if (json_resp.length > 3)
313
324
  json_resp.each do |k,v|
314
- if (k != 'result' && k != 'debug' && k != 'exit_code' && k != 'messages' && k != 'data')
325
+ if !DEBUG_INGORE_KEYS.has_key?(k)
315
326
  puts "#{k.to_s}: #{v.to_s}"
316
327
  end
317
328
  end
318
329
  end
319
330
  end
331
+ if json_resp['api']
332
+ puts "API version: #{json_resp['api']}"
333
+ end
334
+ if json_resp['broker']
335
+ puts "Broker version: #{json_resp['broker']}"
336
+ end
320
337
  end
321
- if json_resp['api']
322
- puts "API version: #{json_resp['api']}"
323
- end
324
- if json_resp['broker']
325
- puts "Broker version: #{json_resp['broker']}"
326
- end
327
- if json_resp['result']
338
+ if print_result && json_resp['result']
328
339
  puts ''
329
340
  puts 'RESULT:'
330
341
  puts json_resp['result']
@@ -341,6 +352,270 @@ module RHC
341
352
  resp = dns.getresources(host, Resolv::DNS::Resource::IN::A)
342
353
  return resp.any?
343
354
  end
355
+
356
+ def self.create_app(libra_server, net_http, user_info, app_name, app_type, rhlogin, password, repo_dir=nil, no_dns=false, no_git=false, no_git_message=nil)
357
+ puts "Attempting to create remote application space: #{app_name}"
358
+
359
+ data = {:cartridge => app_type,
360
+ :action => 'configure',
361
+ :app_name => app_name,
362
+ :rhlogin => rhlogin
363
+ }
364
+ if @mydebug
365
+ data[:debug] = true
366
+ end
367
+ json_data = generate_json(data)
368
+
369
+ url = URI.parse("https://#{libra_server}/broker/cartridge")
370
+ response = http_post(net_http, url, json_data, password)
371
+
372
+ if response.code == '200'
373
+ json_resp = JSON.parse(response.body)
374
+ print_response_success(json_resp)
375
+ json_data = JSON.parse(json_resp['data'])
376
+ health_check_path = json_data['health_check_path']
377
+ app_uuid = json_data['uuid']
378
+ result = json_resp['result']
379
+ puts "DEBUG: '#{app_name}' creation returned success." if @mydebug
380
+ else
381
+ print_response_err(response)
382
+ end
383
+
384
+ #
385
+ # At this point, we need to register a handler to guarantee app
386
+ # cleanup on any exceptions or calls to exit
387
+ #
388
+ at_exit do
389
+ unless $!.nil? || $!.is_a?(SystemExit) && $!.success?
390
+ puts "Cleaning up application"
391
+ destroy_app(libra_server, net_http, app_name, rhlogin, password)
392
+ end
393
+ end
394
+
395
+ namespace = user_info['user_info']['namespace']
396
+ rhc_domain = user_info['user_info']['rhc_domain']
397
+
398
+ fqdn = "#{app_name}-#{namespace}.#{rhc_domain}"
399
+
400
+ loop = 0
401
+ #
402
+ # Confirm that the host exists in DNS
403
+ #
404
+ unless no_dns
405
+ puts "Now your new domain name is being propagated worldwide (this might take a minute)..."
406
+
407
+ # Allow DNS to propogate
408
+ sleep 15
409
+
410
+ # Now start checking for DNS
411
+ sleep_time = 2
412
+ while loop < MAX_RETRIES && !hostexist?(fqdn)
413
+ sleep sleep_time
414
+ loop+=1
415
+ puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
416
+ sleep_time = delay(sleep_time)
417
+ end
418
+ end
419
+
420
+ # If the hostname couldn't be resolved, print out the git URL
421
+ # and exit cleanly. This will help solve issues where DNS times
422
+ # out in APAC, etc on resolution.
423
+ if loop >= MAX_RETRIES
424
+ puts <<WARNING
425
+
426
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
427
+ WARNING: We weren't able to lookup your hostname (#{fqdn})
428
+ in a reasonable amount of time. This can happen periodically and will just
429
+ take an extra minute or two to propagate depending on where you are in the
430
+ world. Once you are able to access your application in a browser, you can then
431
+ clone your git repository.
432
+
433
+ Application URL: http://#{fqdn}
434
+
435
+ Git Repository URL: #{git_url}
436
+
437
+ Git Clone command:
438
+ git clone #{git_url} #{repo_dir}
439
+
440
+ If you can't get your application '#{app_name}' running in the browser, you can
441
+ also try destroying and recreating the application as well using:
442
+
443
+ rhc-ctl-app -c destroy -a #{app_name} -l #{rhlogin}
444
+
445
+ If this doesn't work for you, let us know in the forums or in IRC and we'll
446
+ make sure to get you up and running.
447
+
448
+ Forums: https://www.redhat.com/openshift/forums/express
449
+
450
+ IRC: #openshift (on Freenode)
451
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
452
+
453
+ WARNING
454
+ exit 0
455
+ end
456
+
457
+ #
458
+ # Pull new repo locally
459
+ #
460
+
461
+ git_url = "ssh://#{app_uuid}@#{app_name}-#{namespace}.#{rhc_domain}/~/git/#{app_name}.git/"
462
+
463
+ unless no_git
464
+ puts "Pulling new repo down"
465
+
466
+ puts "git clone --quiet #{git_url} #{repo_dir}" if @mydebug
467
+ quiet = (@mydebug ? ' ' : '--quiet ')
468
+ git_clone = %x<git clone #{quiet} #{git_url} #{repo_dir}>
469
+ if $?.exitstatus != 0
470
+ puts "Error in git clone"
471
+ puts git_clone
472
+ exit 216
473
+ end
474
+ else
475
+ if no_git_message
476
+ puts no_git_message
477
+ else
478
+ puts <<IMPORTANT
479
+
480
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
481
+ IMPORTANT: Since the -n flag was specified, no local repo has been created.
482
+ This means you can't make changes to your published application until after
483
+ you clone the repo yourself. See the git url below for more information.
484
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
485
+
486
+ IMPORTANT
487
+ end
488
+ end
489
+
490
+ #
491
+ # At this point, we need to register a handler to guarantee git
492
+ # repo cleanup on any exceptions or calls to exit
493
+ #
494
+ unless no_git
495
+ at_exit do
496
+ unless $!.nil? || $!.is_a?(SystemExit) && $!.success?
497
+ puts "Cleaning up git repo"
498
+ FileUtils.rm_rf repo_dir
499
+ end
500
+ end
501
+ end
502
+ return {:app_name => app_name,
503
+ :fqdn => fqdn,
504
+ :health_check_path => health_check_path,
505
+ :git_url => git_url,
506
+ :repo_dir => repo_dir,
507
+ :result => result
508
+ }
509
+ end
510
+
511
+ def self.check_app_available(net_http, app_name, fqdn, health_check_path, result, git_url, repo_dir, no_git)
512
+ #
513
+ # Test several times, doubling sleep time between attempts.
514
+ #
515
+ sleep_time = 2
516
+ attempt = 0
517
+ puts "Confirming application '#{app_name}' is available"
518
+ while attempt < MAX_RETRIES
519
+ attempt += 1
520
+ puts " Attempt # #{attempt}"
521
+ url = URI.parse("http://#{fqdn}/#{health_check_path}")
522
+ begin
523
+ response = net_http.get_response(url)
524
+ rescue Exception => e
525
+ response = nil
526
+ end
527
+ if !response.nil? && response.code == "200" && response.body[0,1] == "1"
528
+ puts <<LOOKSGOOD
529
+
530
+ Success! Your application '#{app_name}' is now published here:
531
+
532
+ http://#{fqdn}/
533
+
534
+ The remote repository is located here:
535
+
536
+ #{git_url}
537
+
538
+ LOOKSGOOD
539
+ unless no_git
540
+ puts <<LOOKSGOOD
541
+ To make changes to '#{app_name}', commit to #{repo_dir}/.
542
+ LOOKSGOOD
543
+ else
544
+ puts <<LOOKSGOOD
545
+ To make changes to '#{app_name}', you must first clone it with:
546
+
547
+ git clone #{git_url}
548
+
549
+ LOOKSGOOD
550
+ puts <<LOOKSGOOD
551
+ Then run 'git push' to update your OpenShift Express space.
552
+
553
+ LOOKSGOOD
554
+ end
555
+ if result && !result.empty?
556
+
557
+ puts <<LOOKSGOOD
558
+
559
+ #{result}
560
+
561
+ LOOKSGOOD
562
+ end
563
+ return true
564
+ end
565
+ if !response.nil? && @mydebug
566
+ puts "Server responded with #{response.code}"
567
+ puts response.body unless response.code == '503'
568
+ end
569
+ puts
570
+ puts " sleeping #{sleep_time} seconds"
571
+ sleep sleep_time
572
+ sleep_time = delay(sleep_time)
573
+ end
574
+ return false
575
+ end
576
+
577
+ def self.destroy_app(libra_server, net_http, app_name, rhlogin, password)
578
+ json_data = generate_json(
579
+ {:action => 'deconfigure',
580
+ :app_name => app_name,
581
+ :rhlogin => rhlogin
582
+ })
583
+ url = URI.parse("https://#{libra_server}/broker/cartridge")
584
+ http_post(net_http, url, json_data, password)
585
+ end
586
+
587
+ def self.ctl_app(libra_server, net_http, app_name, rhlogin, password, action, embedded=false, framework=nil, server_alias=nil)
588
+ data = {:action => action,
589
+ :app_name => app_name,
590
+ :rhlogin => rhlogin
591
+ }
592
+
593
+ data[:server_alias] = server_alias if server_alias
594
+ if framework
595
+ data[:cartridge] = framework
596
+ end
597
+
598
+ if @mydebug
599
+ data[:debug] = true
600
+ end
601
+
602
+ json_data = generate_json(data)
603
+
604
+ url = nil
605
+ if embedded
606
+ url = URI.parse("https://#{libra_server}/broker/embed_cartridge")
607
+ else
608
+ url = URI.parse("https://#{libra_server}/broker/cartridge")
609
+ end
610
+ response = http_post(net_http, url, json_data, password)
611
+
612
+ if response.code == '200'
613
+ json_resp = JSON.parse(response.body)
614
+ print_response_success(json_resp, true)
615
+ else
616
+ print_response_err(response)
617
+ end
618
+ end
344
619
 
345
620
  end
346
621