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.
- data/features/lib/rhc_helper/domain.rb +9 -18
- data/features/scaled_application.feature +1 -1
- data/features/step_definitions/cartridge_steps.rb +1 -1
- data/lib/rhc.rb +3 -0
- data/lib/rhc/cartridge_helpers.rb +85 -27
- data/lib/rhc/command_runner.rb +1 -1
- data/lib/rhc/commands/app.rb +64 -52
- data/lib/rhc/commands/cartridge.rb +19 -32
- data/lib/rhc/commands/port_forward.rb +4 -2
- data/lib/rhc/coverage_helper.rb +2 -4
- data/lib/rhc/exceptions.rb +0 -3
- data/lib/rhc/git_helpers.rb +1 -1
- data/lib/rhc/helpers.rb +25 -11
- data/lib/rhc/output_helpers.rb +1 -7
- data/lib/rhc/rest/cartridge.rb +1 -1
- data/lib/rhc/rest/client.rb +3 -3
- data/lib/rhc/rest/mock.rb +8 -2
- data/lib/rhc/wizard.rb +29 -22
- data/spec/coverage_helper.rb +5 -8
- data/spec/rhc/commands/app_spec.rb +95 -8
- data/spec/rhc/commands/cartridge_spec.rb +2 -4
- data/spec/rhc/commands/port_forward_spec.rb +16 -7
- data/spec/rhc/helpers_spec.rb +52 -16
- data/spec/rhc/wizard_spec.rb +1 -6
- data/spec/spec_helper.rb +0 -1
- metadata +2 -61
- data/bin/rhc-app +0 -549
- data/bin/rhc-chk +0 -595
- data/bin/rhc-create-app +0 -249
- data/bin/rhc-create-domain +0 -190
- data/bin/rhc-ctl-app +0 -180
- data/bin/rhc-ctl-domain +0 -191
- data/bin/rhc-domain +0 -347
- data/bin/rhc-domain-info +0 -156
- data/bin/rhc-port-forward +0 -234
- data/bin/rhc-snapshot +0 -109
- data/bin/rhc-sshkey +0 -177
- data/bin/rhc-tail-files +0 -133
- data/bin/rhc-user-info +0 -12
- data/lib/rhc-common.rb +0 -1205
data/bin/rhc-create-app
DELETED
@@ -1,249 +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 app create',true)
|
8
|
-
|
9
|
-
def p_usage(error_code = 255)
|
10
|
-
libra_server = get_var('libra_server')
|
11
|
-
rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
|
12
|
-
type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'standalone', false)
|
13
|
-
puts <<USAGE
|
14
|
-
|
15
|
-
Usage: #{$0}
|
16
|
-
Create an OpenShift app.
|
17
|
-
|
18
|
-
-a|--app application Application name (alphanumeric - max #{RHC::APP_NAME_MAX_LENGTH} chars) (required)
|
19
|
-
-t|--type type Type of app to create (#{type_keys}) (required)
|
20
|
-
-g|--gear-size size The size of the gear for this app ([small|medium], defaults to small)
|
21
|
-
-s|--scaling Enable scaling for this app
|
22
|
-
-l|--rhlogin rhlogin OpenShift login (#{rhlogin})
|
23
|
-
-p|--password password Password (optional, will prompt)
|
24
|
-
-r|--repo path Git Repo path (defaults to ./$app_name)
|
25
|
-
-n|--nogit Only create remote space, don't pull it locally
|
26
|
-
-d|--debug Print Debug info
|
27
|
-
-h|--help Show Usage info
|
28
|
-
--no-dns Skip DNS check. Must be used in combination with --nogit
|
29
|
-
--config path Path of alternate config file
|
30
|
-
--timeout # Timeout, in seconds, for the session
|
31
|
-
--enable-jenkins [name] Create a Jenkins application (see Note 1)
|
32
|
-
|
33
|
-
Notes:
|
34
|
-
1. Jenkins applications will have Jenkins embedded. Their default name will be 'jenkins' if not specified and the '--no-dns' flag is ignored.
|
35
|
-
|
36
|
-
USAGE
|
37
|
-
exit error_code
|
38
|
-
end
|
39
|
-
|
40
|
-
begin
|
41
|
-
opts = GetoptLong.new(
|
42
|
-
["--debug", "-d", GetoptLong::NO_ARGUMENT],
|
43
|
-
["--help", "-h", GetoptLong::NO_ARGUMENT],
|
44
|
-
["--no-dns", GetoptLong::NO_ARGUMENT],
|
45
|
-
["--nogit", "-n", GetoptLong::NO_ARGUMENT],
|
46
|
-
["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
|
47
|
-
["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
48
|
-
["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
|
49
|
-
["--repo", "-r", GetoptLong::REQUIRED_ARGUMENT],
|
50
|
-
["--config", GetoptLong::REQUIRED_ARGUMENT],
|
51
|
-
["--type", "-t", GetoptLong::REQUIRED_ARGUMENT],
|
52
|
-
["--gear-size", "-g", GetoptLong::REQUIRED_ARGUMENT],
|
53
|
-
["--timeout", GetoptLong::REQUIRED_ARGUMENT],
|
54
|
-
["--enable-jenkins", GetoptLong::OPTIONAL_ARGUMENT],
|
55
|
-
["--scaling", "-s", GetoptLong::OPTIONAL_ARGUMENT]
|
56
|
-
)
|
57
|
-
opt = {}
|
58
|
-
opts.each do |o, a|
|
59
|
-
opt[o[2..-1]] = a.to_s
|
60
|
-
end
|
61
|
-
rescue Exception => e
|
62
|
-
#puts e.message
|
63
|
-
p_usage
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
# If provided a config path, check it
|
68
|
-
RHC::Config.check_cpath(opt)
|
69
|
-
|
70
|
-
# Pull in configs from files
|
71
|
-
libra_server = get_var('libra_server')
|
72
|
-
debug = get_var('debug') == 'false' ? nil : get_var('debug')
|
73
|
-
|
74
|
-
p_usage 0 if opt["help"]
|
75
|
-
|
76
|
-
p_usage if 0 != ARGV.length
|
77
|
-
|
78
|
-
debug = true if opt["debug"]
|
79
|
-
|
80
|
-
RHC::debug(debug)
|
81
|
-
|
82
|
-
RHC::timeout(opt['timeout'], get_var('timeout'))
|
83
|
-
RHC::connect_timeout(opt["timeout"], get_var('timeout'))
|
84
|
-
|
85
|
-
opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
|
86
|
-
|
87
|
-
if !RHC::check_rhlogin(opt['rhlogin'])
|
88
|
-
p_usage
|
89
|
-
end
|
90
|
-
|
91
|
-
if !RHC::check_app(opt['app'])
|
92
|
-
p_usage
|
93
|
-
end
|
94
|
-
|
95
|
-
if !opt['type']
|
96
|
-
puts 'Type is required'
|
97
|
-
p_usage
|
98
|
-
end
|
99
|
-
|
100
|
-
if !opt['rhlogin'] || !opt['app'] || !opt['type']
|
101
|
-
p_usage
|
102
|
-
end
|
103
|
-
|
104
|
-
# Default gear size is small
|
105
|
-
gear_size = opt['gear-size']
|
106
|
-
gear_size = 'small' if !gear_size
|
107
|
-
|
108
|
-
|
109
|
-
password = opt['password']
|
110
|
-
if !password
|
111
|
-
password = RHC::get_password
|
112
|
-
end
|
113
|
-
|
114
|
-
user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, RHC::Config.default_proxy, false)
|
115
|
-
app_info = user_info['app_info']
|
116
|
-
|
117
|
-
if app_info[opt['app']]
|
118
|
-
puts "An application named '#{opt['app']}' in namespace '#{user_info['user_info']['domains'][0]['namespace']}' already exists"
|
119
|
-
exit 255
|
120
|
-
end
|
121
|
-
|
122
|
-
jenkins_app_name = nil
|
123
|
-
has_jenkins = false
|
124
|
-
if opt['enable-jenkins']
|
125
|
-
app_info.each do |app_name, app|
|
126
|
-
if app['framework'] == 'jenkins-1.4'
|
127
|
-
jenkins_app_name = app_name
|
128
|
-
has_jenkins = true
|
129
|
-
puts "
|
130
|
-
Found existing Jenkins application: #{jenkins_app_name}
|
131
|
-
"
|
132
|
-
if !opt['enable-jenkins'].empty?
|
133
|
-
puts "Ignoring specified Jenkins app name: #{opt['enable-jenkins']}"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
if !has_jenkins
|
138
|
-
if opt['type'] =~ /^jenkins-/
|
139
|
-
has_jenkins = true
|
140
|
-
if opt['no-dns']
|
141
|
-
puts "
|
142
|
-
The --no-dns option can't be used in conjunction with --enable-jenkins
|
143
|
-
when creating a #{opt['type']} application. Either remove the --no-dns
|
144
|
-
option or first install your #{opt['type']} application with --no-dns
|
145
|
-
and then use rhc-ctl-app to embed the Jenkins client.
|
146
|
-
"
|
147
|
-
exit 255
|
148
|
-
end
|
149
|
-
jenkins_app_name = opt['app']
|
150
|
-
puts "
|
151
|
-
The Jenkins client will be embedded into the Jenkins application
|
152
|
-
currently being created: '#{opt['app']}'
|
153
|
-
"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
if !has_jenkins
|
157
|
-
if !opt['enable-jenkins'].empty?
|
158
|
-
jenkins_app_name = opt['enable-jenkins']
|
159
|
-
else
|
160
|
-
jenkins_app_name = 'jenkins'
|
161
|
-
end
|
162
|
-
|
163
|
-
if !RHC::check_app(jenkins_app_name)
|
164
|
-
p_usage
|
165
|
-
end
|
166
|
-
|
167
|
-
if jenkins_app_name == opt['app']
|
168
|
-
puts "You must specify a different name for your application and Jenkins ('#{opt['app']}')."
|
169
|
-
exit 100
|
170
|
-
end
|
171
|
-
|
172
|
-
if app_info.has_key?(jenkins_app_name)
|
173
|
-
puts "You already have an application named '#{jenkins_app_name}'."
|
174
|
-
puts "In order to continue you'll need to specify a different name"
|
175
|
-
puts "with --enable-jenkins or destroy the existing application."
|
176
|
-
exit 100
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
opt['repo'] = opt['app'] unless opt['repo']
|
182
|
-
|
183
|
-
if @mydebug
|
184
|
-
puts "
|
185
|
-
Found a bug? Post to the forum and we'll get right on it.
|
186
|
-
IRC: #openshift on freenode
|
187
|
-
Forums: https://openshift.redhat.com/community/forums/openshift
|
188
|
-
|
189
|
-
"
|
190
|
-
end
|
191
|
-
|
192
|
-
#
|
193
|
-
# Confirm local git repo exists
|
194
|
-
#
|
195
|
-
unless opt['nogit']
|
196
|
-
if File.exists?(opt['repo'])
|
197
|
-
puts "We will not overwrite an existing git repo. Please remove:"
|
198
|
-
puts " #{File.expand_path(opt['repo'])}"
|
199
|
-
puts "Then try again."
|
200
|
-
puts
|
201
|
-
exit 210
|
202
|
-
else
|
203
|
-
begin
|
204
|
-
# Create the parent directory for the git repo
|
205
|
-
@git_parent = File.expand_path(opt['repo'] + "/../")
|
206
|
-
FileUtils.mkdir_p(@git_parent)
|
207
|
-
rescue Exception => e
|
208
|
-
puts "Could not write to #{@git_parent}"
|
209
|
-
puts "Reason: #{e.message}"
|
210
|
-
puts
|
211
|
-
puts "Please re-run from a directory you have write access to or specify -r with a"
|
212
|
-
puts "path you have write access to"
|
213
|
-
puts
|
214
|
-
exit 211
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
if jenkins_app_name && !has_jenkins
|
220
|
-
jenkins_app = RHC::create_app(libra_server, RHC::Config.default_proxy, user_info, jenkins_app_name, 'jenkins-1.4', opt['rhlogin'], password, nil, false, true, true)
|
221
|
-
available = RHC::check_app_available(RHC::Config.default_proxy, jenkins_app[:app_name], jenkins_app[:fqdn], jenkins_app[:health_check_path], jenkins_app[:result], jenkins_app[:git_url], nil, true)
|
222
|
-
if !available
|
223
|
-
puts "Unable to access your new Jenkins application."
|
224
|
-
exit 1
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
#
|
229
|
-
# Create remote application space
|
230
|
-
#
|
231
|
-
main_app = RHC::create_app(libra_server, RHC::Config.default_proxy, user_info, opt['app'], opt['type'], opt['rhlogin'], password, opt['repo'], opt['no-dns'], opt['nogit'], false, gear_size, opt['scaling'])
|
232
|
-
|
233
|
-
if !main_app
|
234
|
-
puts "Create app failed"
|
235
|
-
exit 1
|
236
|
-
end
|
237
|
-
|
238
|
-
if jenkins_app_name
|
239
|
-
puts "Now embedding the jenkins client into '#{opt['app']}'..."
|
240
|
-
RHC::ctl_app(libra_server, RHC::Config.default_proxy, opt['app'], opt['rhlogin'], password, 'configure', true, 'jenkins-client-1.4', nil, false)
|
241
|
-
end
|
242
|
-
|
243
|
-
unless opt['no-dns']
|
244
|
-
available = RHC::check_app_available(RHC::Config.default_proxy, main_app[:app_name], main_app[:fqdn], main_app[:health_check_path], main_app[:result], main_app[:git_url], opt['repo'], opt['nogit'])
|
245
|
-
if !available
|
246
|
-
puts "Unable to access your new application."
|
247
|
-
exit 1
|
248
|
-
end
|
249
|
-
end
|
data/bin/rhc-create-domain
DELETED
@@ -1,190 +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 (create|update)',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
|
-
Bind a registered rhcloud user to a domain in rhcloud.
|
18
|
-
|
19
|
-
NOTE: to change ssh key, alter your openshift <id_rsa> and
|
20
|
-
<id_rsa>.pub keys, then re-run with --alter
|
21
|
-
|
22
|
-
-n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required)
|
23
|
-
-l|--rhlogin rhlogin OpenShift login (#{rhlogin})
|
24
|
-
-p|--password password Password (optional, will prompt)
|
25
|
-
-a|--alter Alter namespace (will change urls) and/or ssh key
|
26
|
-
-d|--debug Print Debug info
|
27
|
-
-h|--help Show Usage info
|
28
|
-
--config path Path of alternate config file
|
29
|
-
--timeout # Timeout, in seconds, for the session
|
30
|
-
|
31
|
-
USAGE
|
32
|
-
exit exit_code
|
33
|
-
end
|
34
|
-
|
35
|
-
begin
|
36
|
-
opts = GetoptLong.new(
|
37
|
-
["--debug", "-d", GetoptLong::NO_ARGUMENT],
|
38
|
-
["--help", "-h", GetoptLong::NO_ARGUMENT],
|
39
|
-
["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
|
40
|
-
["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
41
|
-
["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
|
42
|
-
["--config", GetoptLong::REQUIRED_ARGUMENT],
|
43
|
-
["--alter", "-a", GetoptLong::NO_ARGUMENT],
|
44
|
-
["--timeout", GetoptLong::REQUIRED_ARGUMENT]
|
45
|
-
)
|
46
|
-
|
47
|
-
opt = {}
|
48
|
-
opts.each do |o, a|
|
49
|
-
opt[o[2..-1]] = a.to_s
|
50
|
-
end
|
51
|
-
rescue Exception => e
|
52
|
-
#puts e.message
|
53
|
-
p_usage
|
54
|
-
end
|
55
|
-
|
56
|
-
# If provided a config path, check it
|
57
|
-
RHC::Config.check_cpath(opt)
|
58
|
-
|
59
|
-
# Pull in configs from files
|
60
|
-
libra_server = get_var('libra_server')
|
61
|
-
debug = get_var('debug') == 'false' ? nil : get_var('debug')
|
62
|
-
opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
|
63
|
-
|
64
|
-
ssh_key_file_path = get_kfile(false)
|
65
|
-
ssh_pub_key_file_path = get_kpfile(ssh_key_file_path, opt['alter'])
|
66
|
-
|
67
|
-
ssh_config = "#{ENV['HOME']}/.ssh/config"
|
68
|
-
ssh_config_d = "#{ENV['HOME']}/.ssh/"
|
69
|
-
|
70
|
-
p_usage 0 if opt["help"]
|
71
|
-
p_usage if 0 != ARGV.length
|
72
|
-
|
73
|
-
|
74
|
-
debug = true if opt["debug"]
|
75
|
-
|
76
|
-
RHC::debug(debug)
|
77
|
-
|
78
|
-
RHC::timeout(opt["timeout"], get_var('timeout'))
|
79
|
-
RHC::connect_timeout(opt["timeout"], get_var('timeout'))
|
80
|
-
|
81
|
-
if !RHC::check_namespace(opt['namespace'])
|
82
|
-
p_usage
|
83
|
-
end
|
84
|
-
|
85
|
-
if !RHC::check_rhlogin(opt['rhlogin'])
|
86
|
-
p_usage
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
if !opt["rhlogin"] || !opt["namespace"]
|
91
|
-
p_usage
|
92
|
-
end
|
93
|
-
|
94
|
-
password = opt['password']
|
95
|
-
if !password
|
96
|
-
password = RHC::get_password
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# Check to see if a ssh_key_file_path exists, if not create it.
|
101
|
-
#
|
102
|
-
|
103
|
-
if File.readable?(ssh_key_file_path)
|
104
|
-
puts "OpenShift key found at #{ssh_key_file_path}. Reusing..."
|
105
|
-
else
|
106
|
-
puts "Generating OpenShift ssh key to #{ssh_key_file_path}"
|
107
|
-
# Use system for interaction
|
108
|
-
system("ssh-keygen -t rsa -f '#{ssh_key_file_path}'")
|
109
|
-
end
|
110
|
-
|
111
|
-
ssh_keyfile_contents = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')
|
112
|
-
ssh_key = ssh_keyfile_contents[1]
|
113
|
-
ssh_key_type = ssh_keyfile_contents[0]
|
114
|
-
|
115
|
-
data = {'namespace' => opt['namespace'],
|
116
|
-
'rhlogin' => opt['rhlogin'],
|
117
|
-
'ssh' => ssh_key,
|
118
|
-
'key_type' => ssh_key_type}
|
119
|
-
|
120
|
-
if (opt['alter'])
|
121
|
-
data[:alter] = true
|
122
|
-
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."
|
123
|
-
user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, RHC::Config.default_proxy, true, not_found_message)
|
124
|
-
end
|
125
|
-
if debug
|
126
|
-
data[:debug] = true
|
127
|
-
end
|
128
|
-
RHC::print_post_data(data)
|
129
|
-
json_data = RHC::generate_json(data)
|
130
|
-
|
131
|
-
url = URI.parse("https://#{libra_server}/broker/domain")
|
132
|
-
response = RHC::http_post(RHC::Config.default_proxy, url, json_data, password)
|
133
|
-
|
134
|
-
if response.code == '200'
|
135
|
-
begin
|
136
|
-
json_resp = RHC::json_decode(response.body)
|
137
|
-
RHC::print_response_success(json_resp)
|
138
|
-
if opt['alter'] != ''
|
139
|
-
puts <<EOF
|
140
|
-
Creation successful
|
141
|
-
|
142
|
-
You may now create an application.
|
143
|
-
|
144
|
-
EOF
|
145
|
-
else
|
146
|
-
app_info = user_info['app_info']
|
147
|
-
dns_success = true
|
148
|
-
if !app_info.empty? && opt['namespace'] != user_info['user_info']['domains'][0]['namespace']
|
149
|
-
#
|
150
|
-
# Confirm that the host(s) exist in DNS
|
151
|
-
#
|
152
|
-
puts "Now your new domain name(s) are being propagated worldwide (this might take a minute)..."
|
153
|
-
# Allow DNS to propogate
|
154
|
-
sleep 15
|
155
|
-
app_info.each_key do |appname|
|
156
|
-
fqdn = "#{appname}-#{opt['namespace']}.#{user_info['user_info']['rhc_domain']}"
|
157
|
-
|
158
|
-
# Now start checking for DNS
|
159
|
-
loop = 0
|
160
|
-
sleep_time = 2
|
161
|
-
while loop < RHC::MAX_RETRIES && !RHC::hostexist?(fqdn)
|
162
|
-
sleep sleep_time
|
163
|
-
loop+=1
|
164
|
-
puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
|
165
|
-
sleep_time = RHC::delay(sleep_time)
|
166
|
-
end
|
167
|
-
|
168
|
-
if loop >= RHC::MAX_RETRIES
|
169
|
-
puts "Host could not be found: #{fqdn}"
|
170
|
-
dns_success = false
|
171
|
-
end
|
172
|
-
end
|
173
|
-
puts "You can use rhc-domain-info to view any url changes. Be sure to update any links"
|
174
|
-
puts "including the url in your local git config: <local_git_repo>/.git/config"
|
175
|
-
end
|
176
|
-
if dns_success
|
177
|
-
puts "Alteration successful."
|
178
|
-
else
|
179
|
-
puts "Alteration successful but at least one of the urls is still updating in DNS."
|
180
|
-
end
|
181
|
-
puts ""
|
182
|
-
end
|
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
|
-
exit 1
|
data/bin/rhc-ctl-app
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rhc/coverage_helper'
|
4
|
-
|
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
|
15
|
-
|
16
|
-
embed_mapper = { 'add' => 'configure', 'remove' => 'deconfigure' }
|
17
|
-
|
18
|
-
def p_usage(exit_code = 255)
|
19
|
-
rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
|
20
|
-
puts <<USAGE
|
21
|
-
|
22
|
-
Usage: #{$0}
|
23
|
-
Control an OpenShift express app
|
24
|
-
|
25
|
-
-a|--app application Application name (alphanumeric) (required)
|
26
|
-
-l|--rhlogin rhlogin OpenShift login (#{rhlogin})
|
27
|
-
-p|--password password Password (optional, will prompt)
|
28
|
-
-c|--command command (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)
|
29
|
-
-L|--embedded-list List supported embedded cartridges
|
30
|
-
-e|--embed (add|remove|stop|start|restart|status|reload)-$cartridge eg: add-mysql-5.1
|
31
|
-
-b|--bypass Bypass warnings
|
32
|
-
-d|--debug Print Debug info
|
33
|
-
-h|--help Show Usage info
|
34
|
-
--alias Specify server alias (when using add/remove-alias)
|
35
|
-
--config path Path of alternate config file
|
36
|
-
--timeout # Timeout, in seconds, for the session
|
37
|
-
|
38
|
-
USAGE
|
39
|
-
exit exit_code
|
40
|
-
end
|
41
|
-
|
42
|
-
def p_embedded_list
|
43
|
-
libra_server = get_var('libra_server')
|
44
|
-
puts ""
|
45
|
-
puts "List of supported embedded cartridges:"
|
46
|
-
puts ""
|
47
|
-
type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'embedded', false)
|
48
|
-
puts type_keys
|
49
|
-
puts ""
|
50
|
-
exit 255
|
51
|
-
end
|
52
|
-
|
53
|
-
begin
|
54
|
-
opts = GetoptLong.new(
|
55
|
-
["--debug", "-d", GetoptLong::NO_ARGUMENT],
|
56
|
-
["--help", "-h", GetoptLong::NO_ARGUMENT],
|
57
|
-
["--bypass", "-b", GetoptLong::NO_ARGUMENT],
|
58
|
-
["--embedded-list", "-L", GetoptLong::NO_ARGUMENT],
|
59
|
-
["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
|
60
|
-
["--embed", "-e", GetoptLong::REQUIRED_ARGUMENT],
|
61
|
-
["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
62
|
-
["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
|
63
|
-
["--alias", GetoptLong::REQUIRED_ARGUMENT],
|
64
|
-
["--config", GetoptLong::REQUIRED_ARGUMENT],
|
65
|
-
["--command", "-c", GetoptLong::REQUIRED_ARGUMENT],
|
66
|
-
["--timeout", GetoptLong::REQUIRED_ARGUMENT]
|
67
|
-
)
|
68
|
-
opt = {}
|
69
|
-
opts.each do |o, a|
|
70
|
-
opt[o[2..-1]] = a.to_s
|
71
|
-
end
|
72
|
-
rescue Exception => e
|
73
|
-
#puts e.message
|
74
|
-
p_usage
|
75
|
-
end
|
76
|
-
|
77
|
-
# If provided a config path, check it
|
78
|
-
RHC::Config.check_cpath(opt)
|
79
|
-
|
80
|
-
# Pull in configs from files
|
81
|
-
libra_server = get_var('libra_server')
|
82
|
-
debug = get_var('debug') == 'false' ? nil : get_var('debug')
|
83
|
-
ssh_config = "#{ENV['HOME']}/.ssh/config"
|
84
|
-
ssh_config_d = "#{ENV['HOME']}/.ssh/"
|
85
|
-
|
86
|
-
if opt["embedded-list"]
|
87
|
-
p_embedded_list
|
88
|
-
end
|
89
|
-
p_usage 0 if opt["help"]
|
90
|
-
p_usage if 0 != ARGV.length
|
91
|
-
|
92
|
-
debug = true if opt["debug"]
|
93
|
-
|
94
|
-
RHC::debug(debug)
|
95
|
-
|
96
|
-
RHC::timeout(opt["timeout"], get_var('timeout'))
|
97
|
-
RHC::connect_timeout(opt["timeout"], get_var('timeout'))
|
98
|
-
|
99
|
-
opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
|
100
|
-
|
101
|
-
if !RHC::check_rhlogin(opt['rhlogin'])
|
102
|
-
p_usage
|
103
|
-
end
|
104
|
-
|
105
|
-
if !RHC::check_app(opt['app'])
|
106
|
-
p_usage
|
107
|
-
end
|
108
|
-
|
109
|
-
unless opt["embed"] or opt["command"]
|
110
|
-
puts "Command or embed is required"
|
111
|
-
p_usage
|
112
|
-
end
|
113
|
-
|
114
|
-
if opt["command"]
|
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)"
|
117
|
-
p_usage
|
118
|
-
end
|
119
|
-
elsif opt["embed"]
|
120
|
-
action = opt['embed'].split('-')[0]
|
121
|
-
unless action =~ /^(add|remove|start|stop|restart|status|reload)$/
|
122
|
-
puts "Invalid embed action '#{action}' specified. Valid embed actions are (add|remove|start|stop|restart|status|reload)"
|
123
|
-
p_usage
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
unless opt['rhlogin'] && opt['app'] && (opt['command'] || opt['embed'])
|
128
|
-
p_usage
|
129
|
-
end
|
130
|
-
|
131
|
-
if opt['command'] and (opt['alias'] and !(opt['command'] =~ /-alias$/)) || ((opt['command'] =~ /-alias$/) and ! opt['alias'])
|
132
|
-
puts "When specifying alias make sure to use -c add-alias or -c remove-alias"
|
133
|
-
p_usage
|
134
|
-
end
|
135
|
-
|
136
|
-
password = opt['password']
|
137
|
-
if !password
|
138
|
-
password = RHC::get_password
|
139
|
-
end
|
140
|
-
|
141
|
-
opt["command"] = "deconfigure" if opt["command"] == "destroy"
|
142
|
-
|
143
|
-
if !opt["bypass"] and opt["command"] == "deconfigure"
|
144
|
-
# deconfigure is the actual hook called on 'destroy'
|
145
|
-
# destroy is used for clarity
|
146
|
-
|
147
|
-
|
148
|
-
puts <<WARNING
|
149
|
-
!!!! WARNING !!!! WARNING !!!! WARNING !!!!
|
150
|
-
You are about to destroy the #{opt['app']} application.
|
151
|
-
|
152
|
-
This is NOT reversible, all remote data for this application will be removed.
|
153
|
-
WARNING
|
154
|
-
|
155
|
-
print "Do you want to destroy this application (y/n): "
|
156
|
-
begin
|
157
|
-
agree = gets.chomp
|
158
|
-
if agree != 'y'
|
159
|
-
puts "\n"
|
160
|
-
exit 217
|
161
|
-
end
|
162
|
-
rescue Interrupt
|
163
|
-
puts "\n"
|
164
|
-
exit 217
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
framework = nil
|
169
|
-
if opt['embed']
|
170
|
-
action = opt['embed'].split('-')[0]
|
171
|
-
# override action if it's in the mapper
|
172
|
-
action = embed_mapper[opt['embed'].split('-')[0]] if embed_mapper[opt['embed'].split('-')[0]]
|
173
|
-
framework = opt['embed'].split('-')[1..-1].join('-')
|
174
|
-
url = URI.parse("https://#{libra_server}/broker/embed_cartridge")
|
175
|
-
else
|
176
|
-
action = opt['command']
|
177
|
-
url = URI.parse("https://#{libra_server}/broker/cartridge")
|
178
|
-
end
|
179
|
-
|
180
|
-
RHC::ctl_app(libra_server, RHC::Config.default_proxy, opt['app'], opt['rhlogin'], password, action, opt['embed'], framework, opt['alias'])
|