rhc 1.3.8 → 1.4.7

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.
@@ -1,191 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rhc/coverage_helper'
4
-
5
- require 'rhc-common'
6
-
7
- RHC::Helpers.deprecated_command('rhc sshkey',true)
8
-
9
- #
10
- # print help
11
- #
12
- def p_usage(exit_code = 255)
13
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
14
- puts <<USAGE
15
-
16
- Usage: #{$0}
17
- Manage multiple keys for the registered rhcloud user.
18
-
19
- rhc-ctl-domain [-l rhlogin] [-p password] [-d] [-h] [-n namespace] (-a key-name [-k ssh-pubkey] | -u key-name [-k ssh-pubkey] | -r key-name | --destroy)
20
-
21
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
22
- -p|--password password Password (optional, will prompt)
23
- -n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required for destroying domain)
24
- -a|--add-ssh-key key-name Add SSH key to the user account (key-name is the user-specified identifier for the key)
25
- -r|--remove-ssh-key key-name Remove SSH key from the user account
26
- -u|--update-ssh-key key-name Update SSH key for the user account
27
- --destroy Destroys the domain and any added ssh keys
28
- -k|--ssh key-filepath SSH public key filepath
29
- --config path Path of alternate config file
30
- -d|--debug Print Debug info
31
- -h|--help Show Usage info
32
-
33
- USAGE
34
- exit exit_code
35
- end
36
-
37
- begin
38
- opts = GetoptLong.new(
39
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
40
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
41
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
42
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
43
- ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
44
- ["--add-ssh-key", "-a", GetoptLong::REQUIRED_ARGUMENT],
45
- ["--remove-ssh-key", "-r", GetoptLong::REQUIRED_ARGUMENT],
46
- ["--update-ssh-key", "-u", GetoptLong::REQUIRED_ARGUMENT],
47
- ["--destroy", GetoptLong::NO_ARGUMENT],
48
- ["--ssh", "-k", GetoptLong::REQUIRED_ARGUMENT],
49
- ["--config", GetoptLong::REQUIRED_ARGUMENT]
50
- )
51
-
52
- command_list = ['add-ssh-key', 'remove-ssh-key', 'update-ssh-key', 'destroy']
53
- command_count = 0
54
- opt = {}
55
- opts.each do |o, a|
56
- opt[o[2..-1]] = a.to_s
57
-
58
- # check to see if there are multiple commands
59
- if command_list.include?(o[2..-1])
60
- command_count += 1
61
- end
62
- end
63
- rescue Exception => e
64
- #puts e.message
65
- p_usage
66
- end
67
-
68
- # If provided a config path, check it
69
- RHC::Config.check_cpath(opt)
70
-
71
- # Pull in configs from files
72
- libra_server = get_var('libra_server')
73
- debug = get_var('debug') == 'false' ? nil : get_var('debug')
74
- opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
75
-
76
- p_usage 0 if opt['help']
77
- p_usage if 0 != ARGV.length
78
-
79
- debug = true if opt['debug']
80
-
81
- RHC::debug(debug)
82
-
83
- # Validate for no command or multiple commands being specified
84
- if command_count == 0
85
- puts "Missing command! You must specify the operation to perform."
86
- p_usage
87
- elsif command_count > 1
88
- puts "Multiple commands specified! You can only perform one operation at a time."
89
- p_usage
90
- end
91
-
92
- if opt['destroy'] && !RHC::check_namespace(opt['namespace'])
93
- puts "Missing or invalid namespace! You must specify the namespace in order to destroy it."
94
- p_usage
95
- end
96
-
97
-
98
- # This is taken care of by the command_count validation performed earlier
99
- #if !opt['rhlogin'] || !(opt['add-key'] || opt['remove-key'] || opt['update-key'] || opt['list-keys']) || \
100
- # (opt['add-key'] && (opt['remove-key'] || opt['update-key'] || opt['list-keys'])) || \
101
- # (opt['remove-key'] && (opt['add-key'] || opt['update-key'] || opt['list-keys'])) || \
102
- # (opt['update-key'] && (opt['add-key'] || opt['remove-key'] || opt['list-keys'])) || \
103
- # (opt['list-keys'] && (opt['add-key'] || opt['remove-key'] || opt['update-key']))
104
- # p_usage
105
- #end
106
-
107
- if !RHC::check_rhlogin(opt['rhlogin']) || \
108
- (opt['add-ssh-key'] && !RHC::check_key(opt['add-ssh-key'])) || \
109
- (opt['remove-ssh-key'] && !RHC::check_key(opt['remove-ssh-key'])) || \
110
- (opt['update-ssh-key'] && !RHC::check_key(opt['update-ssh-key']))
111
- p_usage
112
- end
113
-
114
- password = opt['password']
115
- if !password
116
- password = RHC::get_password
117
- end
118
-
119
- #
120
- # Read user public ssh key
121
- if opt['add-ssh-key'] || opt['update-ssh-key']
122
- if opt['ssh']
123
- if File.readable?(opt['ssh'])
124
- begin
125
- ssh_keyfile_contents = File.open(opt['ssh']).gets.chomp.split(' ')
126
- ssh_key = ssh_keyfile_contents[1]
127
- ssh_key_type = ssh_keyfile_contents[0]
128
- rescue Exception => e
129
- puts "Invalid public keyfile format! Please specify a valid user public keyfile."
130
- exit 1
131
- end
132
- else
133
- puts "Unable to read user public keyfile #{opt['ssh']}"
134
- exit 1
135
- end
136
- else # create key
137
- key_name = opt['add-ssh-key'] ? opt['add-ssh-key'] : opt['update-ssh-key']
138
- puts "Generating ssh key pair for user '#{key_name}' in the dir '#{Dir.pwd}/'"
139
- # Use system for interaction
140
- system("ssh-keygen -t rsa -f '#{key_name}'")
141
- ssh_pub_key_file = Dir.pwd + '/' + key_name + '.pub'
142
- ssh_keyfile_contents = File.open(ssh_pub_key_file).gets.chomp.split(' ')
143
- ssh_key = ssh_keyfile_contents[1]
144
- ssh_key_type = ssh_keyfile_contents[0]
145
- end
146
- end
147
-
148
- data = {}
149
- data[:rhlogin] = opt['rhlogin']
150
- if opt['add-ssh-key']
151
- url = URI.parse("https://#{libra_server}/broker/ssh_keys")
152
- data[:key_name] = opt['add-ssh-key']
153
- data[:ssh] = ssh_key
154
- data[:action] = 'add-key'
155
- data[:key_type] = ssh_key_type
156
- elsif opt['remove-ssh-key']
157
- url = URI.parse("https://#{libra_server}/broker/ssh_keys")
158
- data[:key_name] = opt['remove-ssh-key']
159
- data[:action] = 'remove-key'
160
- elsif opt['update-ssh-key']
161
- url = URI.parse("https://#{libra_server}/broker/ssh_keys")
162
- data[:key_name] = opt['update-ssh-key']
163
- data[:ssh] = ssh_key
164
- data[:action] = 'update-key'
165
- data[:key_type] = ssh_key_type
166
- elsif opt['destroy']
167
- url = URI.parse("https://#{libra_server}/broker/domain")
168
- data[:delete] = true
169
- data[:namespace] = opt['namespace']
170
- end
171
-
172
- RHC::print_post_data(data)
173
- json_data = RHC::generate_json(data)
174
-
175
- response = RHC::http_post(RHC::Config.default_proxy, url, json_data, password)
176
-
177
- if response.code == '200'
178
- begin
179
- json_resp = RHC::json_decode(response.body)
180
- RHC::update_server_api_v(json_resp)
181
- RHC::print_response_success(json_resp)
182
- puts "Success"
183
- exit 0
184
- rescue RHC::JsonError
185
- RHC::print_response_err(response)
186
- end
187
- else
188
- RHC::print_response_err(response)
189
- end
190
- puts "Failure"
191
- exit 1
@@ -1,347 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rhc/coverage_helper'
4
-
5
- require 'rhc-common'
6
-
7
- RHC::Helpers.deprecated_command('rhc domain',true)
8
-
9
- #
10
- # print help
11
- #
12
- def p_usage(exit_code = 255)
13
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
14
- puts <<USAGE
15
-
16
- Usage: rhc domain (<command> | --help) [<args>]
17
- Manage a domain in rhcloud for a registered rhcloud user.
18
-
19
- List of commands
20
- create Bind a registered rhcloud user to a domain in rhcloud.
21
- show Display domain information and list the applications within the domain
22
- alter Alter namespace (will change urls).
23
- status Run a simple check on local configs and credentials to confirm tools are properly setup.
24
- destroy Destroys the domain and any added ssh keys
25
-
26
- List of arguments
27
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
28
- -p|--password password Password (optional, will prompt)
29
- -n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required for creating or destroying domain)
30
- -d|--debug Print Debug info
31
- -h|--help Show Usage info
32
- --config path Path of alternate config file
33
- --timeout # Timeout, in seconds, for the session
34
-
35
- USAGE
36
- exit exit_code
37
- end
38
-
39
-
40
- def get_args()
41
- args = ""
42
- $opt.each do |o, a|
43
- if a.length > 0 && a.to_s.strip.length == 0; a = "'#{a}'" end
44
- args += " --#{o} #{a}"
45
- end
46
- args
47
- end
48
-
49
- def validate_args(val_namespace=true, val_timeout=true)
50
- # If provided a config path, check it
51
- RHC::Config.check_cpath($opt)
52
-
53
- # Pull in configs from files
54
- $libra_server = get_var('libra_server')
55
- debug = get_var('debug') == 'false' ? nil : get_var('debug')
56
-
57
- $opt['rhlogin'] = get_var('default_rhlogin') unless $opt['rhlogin']
58
- p_usage if !RHC::check_rhlogin($opt['rhlogin'])
59
-
60
- p_usage if (val_namespace && !RHC::check_namespace($opt['namespace']))
61
-
62
- debug = $opt["debug"] ? true : false
63
- RHC::debug(debug)
64
-
65
- RHC::timeout($opt["timeout"], get_var('timeout')) if val_timeout
66
- RHC::connect_timeout($opt["timeout"], get_var('timeout')) if val_timeout
67
-
68
- $password = $opt['password'] ? $opt['password'] : RHC::get_password
69
- end
70
-
71
- def create_or_alter_domain(alter=false)
72
- validate_args()
73
-
74
- ssh_key_file_path = get_kfile(false)
75
- ssh_pub_key_file_path = get_kpfile(ssh_key_file_path, alter)
76
-
77
- ssh_config = "#{ENV['HOME']}/.ssh/config"
78
- ssh_config_d = "#{ENV['HOME']}/.ssh/"
79
-
80
- # Check to see if a ssh_key_file_path exists, if not create it.
81
- if File.readable?(ssh_key_file_path)
82
- puts "OpenShift key found at #{ssh_key_file_path}. Reusing..."
83
- else
84
- puts "Generating OpenShift ssh key to #{ssh_key_file_path}"
85
- w = RHC::SSHWizard.new($opt['rhlogin'], $password)
86
- w.run
87
- end
88
-
89
- ssh_keyfile_contents = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')
90
- ssh_key = ssh_keyfile_contents[1]
91
- ssh_key_type = ssh_keyfile_contents[0]
92
-
93
- data = {'namespace' => $opt['namespace'],
94
- 'rhlogin' => $opt['rhlogin']}
95
-
96
- # send the ssh key and key type only in case of domain creation
97
- # key updates will be handled by the 'rhc sshkey update' command
98
- if !alter
99
- data[:ssh] = ssh_key
100
- data[:key_type] = ssh_key_type
101
- end
102
-
103
- if alter
104
- data[:alter] = true
105
- not_found_message = "A user with rhlogin '#{$opt['rhlogin']}' does not have a registered domain. Be sure to run 'rhc domain create' first."
106
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, true, not_found_message)
107
- end
108
- if @mydebug
109
- data[:debug] = true
110
- end
111
- RHC::print_post_data(data)
112
- json_data = RHC::generate_json(data)
113
-
114
- url = URI.parse("https://#{$libra_server}/broker/domain")
115
- response = RHC::http_post(RHC::Config.default_proxy, url, json_data, $password)
116
-
117
- if response.code == '200'
118
- begin
119
- json_resp = RHC::json_decode(response.body)
120
- RHC::print_response_success(json_resp)
121
- json_rhlogininfo = RHC::json_decode(json_resp['data'])
122
- add_rhlogin_config(json_rhlogininfo['rhlogin'], json_rhlogininfo['uuid'])
123
- if !alter
124
- puts <<EOF
125
- Creation successful
126
-
127
- You may now create an application.
128
-
129
- EOF
130
- else
131
- app_info = user_info['app_info']
132
- dns_success = true
133
- if !app_info.empty? && $opt['namespace'] != user_info['user_info']['domains'][0]['namespace']
134
- #
135
- # Confirm that the host(s) exist in DNS
136
- #
137
- puts "Now your new domain name(s) are being propagated worldwide (this might take a minute)..."
138
- # Allow DNS to propogate
139
- sleep 15
140
- app_info.each_key do |appname|
141
- fqdn = "#{appname}-#{$opt['namespace']}.#{user_info['user_info']['rhc_domain']}"
142
-
143
- # Now start checking for DNS
144
- loop = 0
145
- sleep_time = 2
146
- while loop < RHC::MAX_RETRIES && !RHC::hostexist?(fqdn)
147
- sleep sleep_time
148
- loop+=1
149
- puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
150
- sleep_time = RHC::delay(sleep_time)
151
- end
152
-
153
- if loop >= RHC::MAX_RETRIES
154
- puts "Host could not be found: #{fqdn}"
155
- dns_success = false
156
- end
157
- end
158
- puts "You can use 'rhc domain show' to view any url changes. Be sure to update any links"
159
- puts "including the url in your local git config: <local_git_repo>/.git/config"
160
- end
161
- if dns_success
162
- puts "Alteration successful."
163
- else
164
- puts "Alteration successful but at least one of the urls is still updating in DNS."
165
- end
166
- puts ""
167
- end
168
- exit 0
169
- rescue RHC::JsonError
170
- RHC::print_response_err(response)
171
- end
172
- else
173
- RHC::print_response_err(response)
174
- end
175
- exit 1
176
- end
177
-
178
- def destroy_domain()
179
- validate_args(true, false)
180
-
181
- url = URI.parse("https://#{$libra_server}/broker/domain")
182
- data = {}
183
- data[:rhlogin] = $opt['rhlogin']
184
- data[:delete] = true
185
- data[:namespace] = $opt['namespace']
186
-
187
- RHC::print_post_data(data)
188
- json_data = RHC::generate_json(data)
189
-
190
- response = RHC::http_post(RHC::Config.default_proxy, url, json_data, $password)
191
-
192
- if response.code == '200'
193
- begin
194
- json_resp = RHC::json_decode(response.body)
195
- RHC::update_server_api_v(json_resp)
196
- RHC::print_response_success(json_resp)
197
- puts "Success"
198
- exit 0
199
- rescue RHC::JsonError
200
- RHC::print_response_err(response)
201
- end
202
- else
203
- RHC::print_response_err(response)
204
- end
205
- puts "Failure"
206
- exit 1
207
- end
208
-
209
- def show_domain_info()
210
- validate_args(false, true)
211
-
212
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, true)
213
-
214
- domains = user_info['user_info']['domains']
215
- num_domains = domains.length
216
-
217
- puts ""
218
- puts "User Info"
219
- puts "========="
220
-
221
- if num_domains == 0
222
- puts "Namespace: No namespaces found. You can use 'rhc domain create -n <namespace>' to create a namespace for your applications."
223
- elsif num_domains == 1
224
- puts "Namespace: #{domains[0]['namespace']}"
225
- else
226
- domains.each_index { |i| puts "Namespace(#{i}): #{domains[i]['namespace']}" }
227
- end
228
-
229
- #puts " UUID: #{user_info['user_info']['uuid']}"
230
- puts " OpenShift login: #{user_info['user_info']['rhlogin']}"
231
-
232
- puts "\n\n"
233
-
234
- puts "Application Info"
235
- puts "================"
236
- unless user_info['app_info'].empty?
237
- user_info['app_info'].each do |key, val|
238
- puts key
239
- puts " Framework: #{val['framework']}"
240
- puts " Creation: #{val['creation_time']}"
241
- puts " UUID: #{val['uuid']}"
242
- puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
243
- puts " Public URL: http://#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/"
244
- if val['aliases'] && !val['aliases'].empty?
245
- puts " Aliases: #{val['aliases'].join(', ')}"
246
- end
247
- puts ""
248
- puts " Embedded: "
249
- if val['embedded'] && !val['embedded'].empty?
250
- val['embedded'].each do |embed_key, embed_val|
251
- if embed_val.has_key?('info') && !embed_val['info'].empty?
252
- puts " #{embed_key} - #{embed_val['info']}"
253
- else
254
- puts " #{embed_key}"
255
- end
256
- end
257
- else
258
- puts " None"
259
- end
260
- puts ""
261
- end
262
- else
263
- puts "No applications found. You can use 'rhc app create' to create new applications."
264
- end
265
- end
266
-
267
- def check_domain_status
268
- $opt['rhlogin'] = get_var('default_rhlogin') unless $opt['rhlogin']
269
- p_usage if !RHC::check_rhlogin($opt['rhlogin'])
270
-
271
- system("rhc-chk #{get_args} 2>&1")
272
- if ($? != 0); exit 1 end
273
- end
274
-
275
-
276
- begin
277
- argv_c = ARGV.clone
278
-
279
- if ARGV[0] =~ /^(create|alter|destroy)$/
280
- ARGV.shift
281
- opts = GetoptLong.new(
282
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
283
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
284
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
285
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
286
- ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
287
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
288
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
289
- )
290
- elsif ARGV[0] =~ /^(status|show)$/
291
- ARGV.shift
292
- opts = GetoptLong.new(
293
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
294
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
295
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
296
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
297
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
298
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
299
- )
300
- else
301
- # if the user just enters "rhc domain", don't throw an error
302
- # let it be handled by the "rhc domain show" command
303
- if ARGV[0].to_s.strip.length == 0
304
- opts = []
305
- else
306
- opts = GetoptLong.new(
307
- ["--help", "-h", GetoptLong::NO_ARGUMENT]
308
- )
309
-
310
- unless ARGV[0] =~ /^(help|-h|--help)$/
311
- puts "Missing or invalid command!"
312
- # just exit at this point
313
- # printing the usage description will be handled in the rescue
314
- exit 255
315
- end
316
- end
317
- end
318
-
319
- $opt = {}
320
- opts.each do |o, a|
321
- $opt[o[2..-1]] = a.to_s
322
- end
323
- rescue Exception => e
324
- p_usage
325
- end
326
-
327
- p_usage 0 if $opt["help"]
328
-
329
- case argv_c[0]
330
- when "create"
331
- create_or_alter_domain(false)
332
- when "alter"
333
- create_or_alter_domain(true)
334
- when "status"
335
- check_domain_status
336
- when "show", nil
337
- show_domain_info
338
- when "destroy"
339
- destroy_domain
340
- when "-h", "--help", "help", nil
341
- p_usage
342
- else
343
- puts "Invalid command!"
344
- p_usage
345
- end
346
-
347
- exit 0