rhc 0.80.5 → 0.81.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -123,18 +123,36 @@ def test_url_json(uri, data)
123
123
  req.set_form_data({'json_data' => json_data, 'password' => @password})
124
124
  http = @http.new(url.host, url.port)
125
125
  http.open_timeout = 10
126
- if url.scheme == "https"
127
- http.use_ssl = true
128
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
129
- end
126
+ http.use_ssl = true
127
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
128
+ response = nil
130
129
  begin
131
130
  response = http.start {|http| http.request(req)}
132
131
  puts " Raw Response: #{response.body}" if @debug
133
132
  rescue Exception => e
134
133
  puts " ERROR: #{e.message}"
135
- return nil
136
134
  end
137
- return response
135
+ if response
136
+ puts " Code: #{response.code}"
137
+ puts " Message: #{response.message}"
138
+ if response.code == '200'
139
+ puts response.body
140
+ resp_json = JSON.parse(response.body)
141
+ return resp_json
142
+ elsif response.code == '404' && data['rhlogin']
143
+ puts "A user with rhlogin '#{data['rhlogin']}' does not have a registered domain."
144
+ exit 99
145
+ elsif response.code == '401'
146
+ puts "Invalid user credentials"
147
+ exit 97
148
+ else
149
+ puts "Exiting due to error!"
150
+ exit 1
151
+ end
152
+ else
153
+ puts "Unable to connect to: https://#{@libra_server}"
154
+ exit 1
155
+ end
138
156
  end
139
157
 
140
158
  #
@@ -144,32 +162,21 @@ puts
144
162
  puts "TEST1: Confirming connection to OpenShift"
145
163
  data = {'cart_type' => 'standalone'}
146
164
 
147
- response = test_url_json("/broker/cartlist", data)
148
- if response
149
- puts " Code: #{response.code}"
150
- puts " Message: #{response.message}"
151
- resp_json = JSON.parse(response.body)
152
- puts " Cart Info: #{resp_json["data"]}"
153
- end
165
+ resp_json = test_url_json("/broker/cartlist", data)
166
+ puts " Cart Info: #{resp_json["data"]}"
154
167
 
155
168
 
156
169
  #
157
170
  # Checking Authentication
158
171
  #
159
-
160
172
  puts
161
173
  puts "TEST2: Authentication (RHN account) / user info"
162
174
  data = {'rhlogin' => @rhlogin}
163
175
 
164
- response = test_url_json("/broker/userinfo", data)
165
- if response
166
- puts " Code: #{response.code}"
167
- puts " Message: #{response.message}"
168
- body = JSON.parse(response.body)
169
- @user_info = JSON.parse(body['data'].to_s)
170
- puts " rhlogin: #{@user_info["user_info"]["rhlogin"]}"
171
- puts " namespace: #{@user_info["user_info"]["namespace"]}"
172
- end
176
+ resp_json = test_url_json("/broker/userinfo", data)
177
+ @user_info = JSON.parse(resp_json['data'].to_s)
178
+ puts " rhlogin: #{@user_info["user_info"]["rhlogin"]}"
179
+ puts " namespace: #{@user_info["user_info"]["namespace"]}"
173
180
 
174
181
  #
175
182
  # Checking ssh key
@@ -177,7 +184,7 @@ end
177
184
  puts
178
185
  puts "TEST3: SSH Key check"
179
186
  remote_ssh_pubkey = @user_info["user_info"]["ssh_key"]
180
- libra_kfile = get_kfile(false)
187
+ libra_kfile = get_kfile()
181
188
  libra_kpfile = get_kpfile(libra_kfile, false)
182
189
 
183
190
  if File.exists?(libra_kfile)
@@ -40,8 +40,13 @@ Create an OpenShift Express app.
40
40
  -n|--nogit Only create remote space, don't pull it locally
41
41
  -d|--debug Print Debug info
42
42
  -h|--help Show Usage info
43
+ --no-dns Skip DNS check
43
44
  --config path Path of alternate config file
44
45
  --timeout # Timeout, in seconds, for connection
46
+ --enable-jenkins [name] Indicates to create a Jenkins application (if not already available)
47
+ and embed the Jenkins client into this application. The default
48
+ name will be 'jenkins' if not specified. Note that --no-dns is ignored
49
+ for the creation of the Jenkins application.
45
50
 
46
51
  USAGE
47
52
  exit 255
@@ -51,6 +56,7 @@ begin
51
56
  opts = GetoptLong.new(
52
57
  ["--debug", "-d", GetoptLong::NO_ARGUMENT],
53
58
  ["--help", "-h", GetoptLong::NO_ARGUMENT],
59
+ ["--no-dns", GetoptLong::NO_ARGUMENT],
54
60
  ["--nogit", "-n", GetoptLong::NO_ARGUMENT],
55
61
  ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
56
62
  ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
@@ -58,7 +64,8 @@ begin
58
64
  ["--repo", "-r", GetoptLong::REQUIRED_ARGUMENT],
59
65
  ["--config", GetoptLong::REQUIRED_ARGUMENT],
60
66
  ["--type", "-t", GetoptLong::REQUIRED_ARGUMENT],
61
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
67
+ ["--timeout", GetoptLong::REQUIRED_ARGUMENT],
68
+ ["--enable-jenkins", GetoptLong::OPTIONAL_ARGUMENT]
62
69
  )
63
70
  opt = {}
64
71
  opts.each do |o, a|
@@ -76,9 +83,6 @@ check_cpath(opt)
76
83
  libra_server = get_var('libra_server')
77
84
  debug = get_var('debug') == 'false' ? nil : get_var('debug')
78
85
 
79
- ssh_config = "#{ENV['HOME']}/.ssh/config"
80
- ssh_config_d = "#{ENV['HOME']}/.ssh/"
81
-
82
86
  if opt["help"]
83
87
  p_usage
84
88
  end
@@ -88,9 +92,9 @@ if opt["debug"]
88
92
  end
89
93
  RHC::debug(debug)
90
94
 
91
- RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
95
+ RHC::timeout(opt['timeout'] ? opt['timeout'] : get_var('timeout'))
92
96
 
93
- opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
97
+ opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
94
98
 
95
99
  if !RHC::check_rhlogin(opt['rhlogin'])
96
100
  p_usage
@@ -105,7 +109,7 @@ if !opt['type']
105
109
  p_usage
106
110
  end
107
111
 
108
- if !opt["rhlogin"] || !opt["app"] || !opt["type"]
112
+ if !opt['rhlogin'] || !opt['app'] || !opt['type']
109
113
  p_usage
110
114
  end
111
115
 
@@ -114,7 +118,68 @@ if !password
114
118
  password = RHC::get_password
115
119
  end
116
120
 
117
- opt["repo"] = opt["app"] unless opt["repo"]
121
+ user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, false)
122
+ jenkins_app_name = nil
123
+ has_jenkins = false
124
+ if opt['enable-jenkins']
125
+ app_info = user_info['app_info']
126
+ app_info.each do |app_name, app|
127
+ if app['framework'] == 'jenkins-1.4'
128
+ jenkins_app_name = app_name
129
+ has_jenkins = true
130
+ puts "
131
+ Found existing Jenkins application: #{jenkins_app_name}
132
+ "
133
+ if !opt['enable-jenkins'].empty?
134
+ puts "Ignoring specified Jenkins app name: #{opt['enable-jenkins']}"
135
+ end
136
+ end
137
+ end
138
+ if !has_jenkins
139
+ if opt['type'] =~ /^jenkins-/
140
+ has_jenkins = true
141
+ if opt['no-dns']
142
+ puts "
143
+ The --no-dns option can't be used in conjunction with --enable-jenkins
144
+ when creating a #{opt['type']} application. Either remove the --no-dns
145
+ option or first install your #{opt['type']} application with --no-dns
146
+ and then use rhc-ctl-app to embed the Jenkins client.
147
+ "
148
+ exit 255
149
+ end
150
+ jenkins_app_name = opt['app']
151
+ puts "
152
+ The Jenkins client will be embedded into the Jenkins application
153
+ currently being created: '#{opt['app']}'
154
+ "
155
+ end
156
+ end
157
+ if !has_jenkins
158
+ if !opt['enable-jenkins'].empty?
159
+ jenkins_app_name = opt['enable-jenkins']
160
+ else
161
+ jenkins_app_name = 'jenkins'
162
+ end
163
+
164
+ if !RHC::check_app(jenkins_app_name)
165
+ p_usage
166
+ end
167
+
168
+ if jenkins_app_name == opt['app']
169
+ puts "You must specify a different name for your application and Jenkins ('#{opt['app']}')."
170
+ exit 100
171
+ end
172
+
173
+ if app_info.has_key?(jenkins_app_name)
174
+ puts "You already have an application named '#{jenkins_app_name}'."
175
+ puts "In order to continue you'll need to specify a different name"
176
+ puts "with --enable-jenkins or destroy the existing application."
177
+ exit 100
178
+ end
179
+ end
180
+ end
181
+
182
+ opt['repo'] = opt['app'] unless opt['repo']
118
183
 
119
184
  puts "
120
185
  Found a bug? Post to the forum and we'll get right on it.
@@ -138,9 +203,9 @@ unless opt['nogit']
138
203
  # Create the parent directory for the git repo
139
204
  @git_parent = File.expand_path(opt['repo'] + "/../")
140
205
  FileUtils.mkdir_p(@git_parent)
141
- rescue Errno::EACCES
206
+ rescue Exception => e
142
207
  puts "Could not write to #{@git_parent}"
143
- puts "Reason: " + $!
208
+ puts "Reason: #{e.message}"
144
209
  puts
145
210
  puts "Please re-run from a directory you have write access to or specify -r with a"
146
211
  puts "path you have write access to"
@@ -150,269 +215,38 @@ unless opt['nogit']
150
215
  end
151
216
  end
152
217
 
153
- #
154
- # Create remote application space
155
- #
156
-
157
- puts "Attempting to create remote application space: " + opt['app']
158
-
159
- data = {:cartridge => opt['type'],
160
- :action => 'configure',
161
- :app_name => opt['app'],
162
- :rhlogin => opt['rhlogin']
163
- }
164
- if debug
165
- data['debug'] = "true"
166
- end
167
- json_data = RHC::generate_json(data)
168
-
169
- puts "Contacting https://#{libra_server}"
170
-
171
- url = URI.parse("https://#{libra_server}/broker/cartridge")
172
- response = RHC::http_post(@http, url, json_data, password)
173
-
174
- if response.code == '200'
175
- json_resp = JSON.parse(response.body)
176
- RHC::print_response_success(json_resp, true)
177
- json_data = JSON.parse(json_resp['data'])
178
- health_check_path = json_data['health_check_path']
179
- else
180
- RHC::print_response_err(response)
181
- end
182
-
183
- #
184
- # At this point, we need to register a handler to guarantee app
185
- # cleanup on any exceptions or calls to exit
186
- #
187
- at_exit do
188
- unless $!.nil? || $!.is_a?(SystemExit) && $!.success?
189
- json_data = RHC::generate_json(
190
- {:cartridge => opt['type'],
191
- :action => 'deconfigure',
192
- :app_name => opt['app'],
193
- :rhlogin => opt['rhlogin']
194
- })
195
- puts "Cleaning up application"
196
- url = URI.parse("https://#{libra_server}/broker/cartridge")
197
- RHC::http_post(@http, url, json_data, password)
198
- end
199
- end
200
-
201
- #
202
- # Check / add new host to ~/.ssh/config
203
- #
204
-
205
- puts "Checking ~/.ssh/config"
206
-
207
- user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, false)
218
+ if jenkins_app_name && !has_jenkins
219
+ jenkins_no_git_message = "
208
220
 
209
- fqdn = "#{opt['app']}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}"
210
-
211
- ssh_key_file_name = File.basename(get_kfile())
212
- if (ssh_key_file_name != 'id_rsa')
213
- found = false
214
-
215
- begin
216
- File.open(ssh_config, "r") do |sline|
217
- while(line = sline.gets)
218
- if line.to_s.index("Host *.#{user_info['user_info']['rhc_domain']}") == 0
219
- found = true
220
- break
221
- end
222
- end
223
- end
224
- rescue Errno::EACCES
225
- puts "Could not read from #{ssh_config}"
226
- puts "Reason: " + $!
227
- puts
228
- puts "Please correct this first. Then run rerun."
229
- puts
230
- exit 213
231
- rescue Errno::ENOENT
232
- puts "Could not find #{ssh_config}. This is ok, continuing"
233
- end
234
- if found
235
- puts "Found #{user_info['user_info']['rhc_domain']} in ~/.ssh/config... No need to adjust"
236
- else
237
- puts " Adding #{user_info['user_info']['rhc_domain']} to ~/.ssh/config"
238
- begin
239
- f = File.open(ssh_config, "a")
240
- f.puts <<SSH
241
-
242
- # Added by rhc-create-app on #{`date`}
243
- Host *.#{user_info['user_info']['rhc_domain']}
244
- IdentityFile ~/.ssh/#{ssh_key_file_name}
245
- VerifyHostKeyDNS yes
246
- StrictHostKeyChecking no
247
- UserKnownHostsFile ~/.ssh/libra_known_hosts
221
+ Note: There is a git repo for your Jenkins application '#{jenkins_app_name}'
222
+ but it isn't being downloaded as part of this process. In most cases
223
+ it isn't needed but you can always clone it later.
248
224
 
249
- SSH
250
- f.close
251
- rescue Errno::EACCES
252
- puts "Could not write to #{ssh_config}"
253
- puts "Reason: " + $!
254
- puts
255
- puts "Please correct this first. Then run rerun."
256
- puts
257
- exit 214
258
- rescue Errno::ENOENT
259
- # Make directory and config if they do not exist
260
- puts "Could not find directory: " + $!
261
- puts "creating"
262
- FileUtils.mkdir_p ssh_config_d
263
- file = File.open(ssh_config, 'w')
264
- file.close
265
- retry
266
- end
225
+ "
226
+ jenkins_app = RHC::create_app(libra_server, @http, user_info, jenkins_app_name, 'jenkins-1.4', opt['rhlogin'], password, nil, false, true, jenkins_no_git_message)
227
+ available = RHC::check_app_available(@http, jenkins_app[:app_name], jenkins_app[:fqdn], jenkins_app[:health_check_path], jenkins_app[:result], jenkins_app[:git_url], nil, true)
228
+ if !available
229
+ puts "Unable to access your new Jenkins application."
230
+ exit 1
267
231
  end
268
-
269
- File.chmod(0700, ssh_config_d)
270
- File.chmod(0600, ssh_config)
271
- end
272
-
273
- #
274
- # Confirm that the host exists in DNS
275
- #
276
- puts "Now your new domain name is being propagated worldwide (this might take a minute)..."
277
-
278
- # Allow DNS to propogate
279
- sleep 15
280
-
281
- # Now start checking for DNS
282
- loop = 0
283
- sleep_time = 2
284
- while loop < RHC::MAX_RETRIES && !RHC::hostexist?(fqdn)
285
- sleep sleep_time
286
- loop+=1
287
- puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
288
- sleep_time = RHC::delay(sleep_time)
289
232
  end
290
233
 
291
- sleep_time = 2
292
- attempt = 0
293
-
294
234
  #
295
- # Pull new repo locally
235
+ # Create remote application space
296
236
  #
237
+ main_app = RHC::create_app(libra_server, @http, user_info, opt['app'], opt['type'], opt['rhlogin'], password, opt['repo'], opt['no-dns'], opt['nogit'])
238
+ if jenkins_app_name
239
+ puts "
240
+ Now embedding the jenkins client into '#{opt['app']}'...
297
241
 
298
- app_name = opt['app']
299
- namespace = user_info['user_info']['namespace']
300
- rhc_domain = user_info['user_info']['rhc_domain']
301
- app_uuid = user_info['app_info'][app_name]['uuid']
302
-
303
- git_url = "ssh://#{app_uuid}@#{app_name}-#{namespace}.#{rhc_domain}/~/git/#{app_name}.git/"
304
-
305
- # If the hostname couldn't be resolved, print out the git URL
306
- # and exit cleanly. This will help solve issues where DNS times
307
- # out in APAC, etc on resolution.
308
- if loop >= RHC::MAX_RETRIES
309
- puts <<WARNING
310
-
311
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
312
- WARNING: We weren't able to lookup your hostname (#{fqdn})
313
- in a reasonable amount of time. This can happen periodically and will just
314
- take an extra minute or two to propagate depending on where you are in the
315
- world. Once you are able to access your application in a browser, you can then
316
- clone your git repository.
317
-
318
- Application URL: http://#{fqdn}
319
-
320
- Git Repository URL: #{git_url}
321
-
322
- Git Clone command:
323
- git clone #{git_url} #{opt['repo']}
324
-
325
- If you can't get your application running in the browser, you can also try
326
- destroying and recreating the application as well using:
327
-
328
- rhc-ctl-app -c destroy -a #{opt['app']} -l #{opt["rhlogin"]}
329
-
330
- If this doesn't work for you, let us know in the forums or in IRC and we'll
331
- make sure to get you up and running.
332
-
333
- Forums: https://www.redhat.com/openshift/forums/express
334
-
335
- IRC: #openshift (on Freenode)
336
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
337
-
338
- WARNING
339
- exit 0
340
- end
341
-
342
- unless opt['nogit']
343
- puts "Pulling new repo down"
344
-
345
- puts "git clone --quiet #{git_url} #{opt['repo']}" if debug
346
- quiet = (debug ? ' ' : '--quiet ')
347
- git_clone = %x<git clone #{quiet} #{git_url} #{opt['repo']}>
348
- if $?.exitstatus != 0
349
- puts "Error in git clone"
350
- puts git_clone
351
- exit 216
352
- end
353
- else
354
- puts <<IMPORTANT
355
-
356
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
357
- IMPORTANT: Since the -n flag was specified, no local repo has been created.
358
- This means you can't make changes to your published application until after
359
- you clone the repo yourself. See the git url below for more information.
360
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
361
-
362
- IMPORTANT
363
- end
364
-
365
- #
366
- # At this point, we need to register a handler to guarantee git
367
- # repo cleanup on any exceptions or calls to exit
368
- #
369
- at_exit do
370
- unless $!.nil? || $!.is_a?(SystemExit) && $!.success?
371
- puts "Cleaning up git repo"
372
- FileUtils.rm_rf opt['repo']
373
- end
242
+ "
243
+ RHC::ctl_app(libra_server, @http, opt['app'], opt['rhlogin'], password, 'configure', true, 'jenkins-client-1.4')
374
244
  end
375
245
 
376
- #
377
- # Test several times, doubling sleep time between attempts.
378
- #
379
- sleep_time = 2
380
- attempt = 0
381
- puts "Confirming application #{opt['app']} is available"
382
- while attempt < RHC::MAX_RETRIES
383
- attempt+=1
384
- puts " Attempt # #{attempt}"
385
- url = URI.parse("http://#{fqdn}/#{health_check_path}")
386
- begin
387
- response = @http.get_response(url)
388
- rescue Exception => e
389
- response = nil
390
- end
391
- if !response.nil? && response.code == "200" && response.body[0,1] == "1"
392
- puts <<LOOKSGOOD
393
-
394
- Success! Your application is now published here:
395
-
396
- http://#{fqdn}/
397
-
398
- The remote repository is located here:
399
-
400
- #{git_url}
401
-
402
- To make changes to your application, commit to #{opt['repo']}/.
403
- Then run 'git push' to update your OpenShift Express space
404
-
405
- LOOKSGOOD
406
- exit 0
407
- end
408
- if !response.nil? && debug
409
- puts "Server responded with #{response.code}"
410
- puts response.body unless response.code == '503'
411
- end
412
- puts
413
- puts " sleeping #{sleep_time} seconds"
414
- sleep sleep_time
415
- sleep_time = RHC::delay(sleep_time)
246
+ unless opt['no-dns']
247
+ available = RHC::check_app_available(@http, main_app[:app_name], main_app[:fqdn], main_app[:health_check_path], main_app[:result], main_app[:git_url], opt['repo'], opt['nogit'])
248
+ if !available
249
+ puts "Unable to access your new application."
250
+ exit 1
251
+ end
416
252
  end
417
- puts "Unable to find or access the site... problems"
418
- exit 254