rhc 0.68.5

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.
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rhc-common'
25
+
26
+ #
27
+ # print help
28
+ #
29
+ def p_usage
30
+ puts <<USAGE
31
+
32
+ Usage: #{$0}
33
+ Bind a registered rhcloud user to a domain in rhcloud.
34
+
35
+ NOTE: to change ssh key, please alter your ~/.ssh/libra_id_rsa and
36
+ ~/.ssh/libra_id_rsa.pub key, then re-run with --alter
37
+
38
+ -n|--namespace namespace Opensift Express namespace (alphanumeric - max #{RHC::Maxdlen} chars) (required)
39
+ -l|--rhlogin rhlogin Red Hat login (required)
40
+ -p|--password password RHLogin password (optional, will prompt)
41
+ -a|--alter Alter ssh key
42
+ -d|--debug Print Debug info
43
+ -h|--help Show Usage info
44
+
45
+ USAGE
46
+ exit 255
47
+ end
48
+
49
+ begin
50
+ opts = GetoptLong.new(
51
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT],
52
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
53
+ ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
54
+ ["--password", "-p", GetoptLong::OPTIONAL_ARGUMENT],
55
+ ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
56
+ ["--alter", "-a", GetoptLong::NO_ARGUMENT]
57
+ )
58
+
59
+ opt = {}
60
+ opts.each do |o, a|
61
+ opt[o[2..-1]] = a.to_s
62
+ end
63
+ rescue Exception => e
64
+ #puts e.message
65
+ p_usage
66
+ end
67
+
68
+ # Pull in configs from files
69
+ libra_server = get_var('libra_server')
70
+ debug = get_var('debug') == 'false' ? nil : get_var('debug')
71
+
72
+
73
+ libra_kfile = "#{ENV['HOME']}/.ssh/libra_id_rsa"
74
+ libra_kpfile = "#{ENV['HOME']}/.ssh/libra_id_rsa.pub"
75
+
76
+ if opt["help"]
77
+ p_usage
78
+ end
79
+
80
+ if opt["debug"]
81
+ debug = true
82
+ end
83
+
84
+ if !RHC::check_namespace(opt['namespace'])
85
+ p_usage
86
+ end
87
+
88
+ if !RHC::check_rhlogin(opt['rhlogin'])
89
+ p_usage
90
+ end
91
+
92
+
93
+ if !opt["rhlogin"] || !opt["namespace"]
94
+ p_usage
95
+ end
96
+
97
+ password = opt['password']
98
+ if !password
99
+ password = RHC::get_password
100
+ end
101
+
102
+ #
103
+ # Add a new namespace to configs
104
+ #
105
+
106
+ def add_rhlogin_config(rhlogin, uuid)
107
+ f = open(File.expand_path(@local_config_path), 'a')
108
+ unless @local_config.get_value('default_rhlogin')
109
+ f.puts("# Default rhlogin to use if none is specified")
110
+ f.puts("default_rhlogin=#{rhlogin}")
111
+ f.puts("")
112
+ end
113
+ unless @local_config.get_value(rhlogin)
114
+ puts "Adding rhlogin to #{@local_config_path}"
115
+ f.puts("#{rhlogin}=#{uuid}")
116
+ end
117
+ f.close
118
+ end
119
+
120
+
121
+ #
122
+ # Check to see if a libra_id_rsa key exists, if not create it.
123
+ #
124
+
125
+ if File.readable?(libra_kfile)
126
+ puts "Openshift Express key found at #{libra_kfile}. Reusing..."
127
+ else
128
+ puts "Generating Openshift Express ssh key to #{libra_kfile}"
129
+ # Use system for interaction
130
+ system("ssh-keygen -t rsa -f #{libra_kfile}")
131
+ end
132
+
133
+ ssh_key = File.open(libra_kpfile).gets.chomp.split(' ')[1]
134
+
135
+ puts "Contacting https://#{libra_server}"
136
+ data = {'namespace' => opt['namespace'],
137
+ 'rhlogin' => opt['rhlogin'],
138
+ 'ssh' => ssh_key}
139
+ if (opt['alter'])
140
+ data['alter'] = "true"
141
+ end
142
+ if debug
143
+ data['debug'] = "true"
144
+ end
145
+ RHC::print_post_data(data, debug)
146
+ json_data = JSON.generate(data)
147
+
148
+ url = URI.parse("https://#{libra_server}/app/broker/domain")
149
+ response = RHC::http_post(@http, url, json_data, password)
150
+
151
+ if response.code == '200'
152
+ begin
153
+ RHC::print_response_success(response, debug)
154
+ json_resp = JSON.parse(response.body);
155
+ json_rhlogininfo = JSON.parse(json_resp['result'])
156
+ add_rhlogin_config(json_rhlogininfo['rhlogin'], json_rhlogininfo['uuid'])
157
+
158
+ if opt['alter'] != ''
159
+ puts <<EOF
160
+ Creation successful
161
+
162
+ You may now create an application. Please make note of your local config file
163
+ in #{@local_config_path} which has been created and populated for you.
164
+
165
+ EOF
166
+ else
167
+ puts "RHLogin alteration successful."
168
+ puts
169
+ end
170
+ exit 0
171
+ rescue JSON::ParserError
172
+ RHC::print_response_err(response, debug)
173
+ end
174
+ else
175
+ RHC::print_response_err(response, debug)
176
+ end
177
+ exit 254
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rhc-common'
25
+
26
+ def p_usage
27
+ rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "(required)"
28
+ puts <<USAGE
29
+
30
+ Usage: #{$0}
31
+ Control an OpenShift express app
32
+
33
+ -a|--app application Application name (alphanumeric) (required)
34
+ -l|--rhlogin rhlogin Red Hat login (#{rhlogin})
35
+ -p|--password password RHLogin password (optional, will prompt)
36
+ -c|--command command (start|stop|restart|reload|status|destroy)
37
+ -b|--bypass Bypass warnings
38
+ -d|--debug Print Debug info
39
+ -h|--help Show Usage info
40
+
41
+ USAGE
42
+ exit 255
43
+ end
44
+
45
+ begin
46
+ opts = GetoptLong.new(
47
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT],
48
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
49
+ ["--bypass", "-b", GetoptLong::NO_ARGUMENT],
50
+ ["--rhlogin", "-l", GetoptLong::OPTIONAL_ARGUMENT],
51
+ ["--password", "-p", GetoptLong::OPTIONAL_ARGUMENT],
52
+ ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
53
+ ["--command", "-c", GetoptLong::REQUIRED_ARGUMENT]
54
+ )
55
+ opt = {}
56
+ opts.each do |o, a|
57
+ opt[o[2..-1]] = a.to_s
58
+ end
59
+ rescue Exception => e
60
+ #puts e.message
61
+ p_usage
62
+ end
63
+
64
+ # Pull in configs from files
65
+ libra_domain = get_var('libra_domain')
66
+ libra_server = get_var('libra_server')
67
+ debug = get_var('debug') == 'false' ? nil : get_var('debug')
68
+ ssh_config = "#{ENV['HOME']}/.ssh/config"
69
+ ssh_config_d = "#{ENV['HOME']}/.ssh/"
70
+
71
+ if opt["help"]
72
+ p_usage
73
+ end
74
+
75
+ if opt["debug"]
76
+ debug = true
77
+ end
78
+
79
+ opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
80
+
81
+ if !RHC::check_rhlogin(opt['rhlogin'])
82
+ p_usage
83
+ end
84
+
85
+ if !RHC::check_app(opt['app'])
86
+ p_usage
87
+ end
88
+
89
+ unless defined? opt["command"] and opt["command"] =~ /(start|stop|restart|reload|status|destroy)/
90
+ puts "Command is required"
91
+ p_usage
92
+ end
93
+
94
+ if !opt['rhlogin'] || !opt['app'] || !opt['command']
95
+ p_usage
96
+ end
97
+
98
+ password = opt['password']
99
+ if !password
100
+ password = RHC::get_password
101
+ end
102
+
103
+ user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, debug, false)
104
+ app = user_info['app_info'][opt['app']]
105
+ if app
106
+ framework = app['framework']
107
+ else
108
+ puts "Application not found: #{opt['app']}"
109
+ exit 101
110
+ end
111
+ #
112
+ # Send Warning
113
+ #
114
+
115
+ opt["command"] = "deconfigure" if opt["command"] == "destroy"
116
+
117
+ if !opt["bypass"] and opt["command"] == "deconfigure"
118
+ # deconfigure is the actual hook called on 'destroy'
119
+ # destroy is used for clarity
120
+
121
+
122
+ puts <<WARNING
123
+ !!!! WARNING !!!! WARNING !!!! WARNING !!!!
124
+ You are about to destroy the #{opt['app']} application.
125
+
126
+ This is NOT reversable, all remote data for this application will be removed.
127
+ WARNING
128
+
129
+ print "Do you want to destroy this application (y/n): "
130
+ agree = gets.chomp
131
+ if agree != 'y'
132
+ puts "Destroy aborted"
133
+ exit 217
134
+ end
135
+ end
136
+
137
+ data = {:cartridge => framework,
138
+ :action => opt['command'],
139
+ :app_name => "#{opt['app']}",
140
+ :rhlogin => "#{opt['rhlogin']}"
141
+ }
142
+ if debug
143
+ data['debug'] = "true"
144
+ end
145
+
146
+ json_data = JSON.generate(data)
147
+
148
+ puts "Contacting https://#{libra_server}"
149
+
150
+ url = URI.parse("https://#{libra_server}/app/broker/cartridge")
151
+ response = RHC::http_post(@http, url, json_data, password)
152
+
153
+ if response.code == '200'
154
+ RHC::print_response_success(response, debug, true)
155
+ else
156
+ RHC::print_response_err(response, debug)
157
+ end
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rhc-common'
25
+
26
+ #
27
+ # print help
28
+ #
29
+ def p_usage
30
+ rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "(required)"
31
+ puts <<USAGE
32
+
33
+ Usage: rhc-snapshot
34
+ Pull down application snapshot for a user
35
+
36
+ -l|--rhlogin rhlogin RHCloud rhlogin (#{rhlogin})
37
+ -a|--app Target application to snapshot (required)
38
+ -s|--save Local path to save tarball (default: ./$APPNAME.tar.gz)
39
+ -p|--password password RHLogin password (optional, will prompt)
40
+ -d|--debug Print Debug info
41
+ -h|--help Show Usage info
42
+
43
+ USAGE
44
+ exit 255
45
+ end
46
+
47
+ begin
48
+ opts = GetoptLong.new(
49
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT],
50
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
51
+ ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
52
+ ["--save", "-s", GetoptLong::OPTIONAL_ARGUMENT],
53
+ ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
54
+ ["--password", "-p", GetoptLong::OPTIONAL_ARGUMENT]
55
+ )
56
+ opt = {}
57
+ opts.each do |o, a|
58
+ opt[o[2..-1]] = a.to_s
59
+ end
60
+ rescue Exception => e
61
+ #puts e.message
62
+ p_usage
63
+ end
64
+
65
+ # Pull in configs from files
66
+ libra_server = get_var('libra_server')
67
+ debug = get_var('debug') == 'false' ? nil : get_var('debug')
68
+ libra_domain = get_var('libra_domain')
69
+
70
+ libra_kfile = "#{ENV['HOME']}/.ssh/libra_id_rsa"
71
+ libra_kpfile = "#{ENV['HOME']}/.ssh/libra_id_rsa.pub"
72
+
73
+ if opt["help"] || !opt['app']
74
+ p_usage
75
+ end
76
+
77
+ if opt["debug"]
78
+ debug = true
79
+ end
80
+
81
+ opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
82
+
83
+ if !RHC::check_rhlogin(opt['rhlogin'])
84
+ p_usage
85
+ end
86
+
87
+ password = opt['password']
88
+ if !password
89
+ password = RHC::get_password
90
+ end
91
+
92
+ user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, debug, false)
93
+
94
+ app = opt['app']
95
+ opt['save'] = "#{opt['app']}.tar.gz" unless opt['save']
96
+
97
+ begin
98
+ framework = user_info['app_info'][app]['framework'].split('-')[0]
99
+ rescue NoMethodError
100
+ puts
101
+ puts "Could not find app '#{opt['app']}'. Please run rhc-user-info to get a list"
102
+ puts "of your current running applications"
103
+ puts
104
+ exit 101
105
+ end
106
+
107
+ puts "Pulling down a snapshot to #{opt['save']}"
108
+ puts
109
+ puts "ssh #{user_info['user_info']['uuid']}@#{app}-#{user_info['user_info']['namespace']}.#{libra_domain} 'snapshot #{framework} #{app}' > #{opt['save']}" if debug
110
+ git_pull = `ssh #{user_info['user_info']['uuid']}@#{app}-#{user_info['user_info']['namespace']}.#{libra_domain} 'snapshot #{framework} #{app}' > #{opt['save']}`
111
+ if $?.exitstatus != 0
112
+ puts
113
+ puts "Error in trying to save snapshot. You can try to save manually by running:"
114
+ puts
115
+ puts "ssh #{user_info['user_info']['uuid']}@#{app}-#{user_info['user_info']['namespace']}.#{libra_domain} 'snapshot #{framework} #{app}' > #{opt['save']}"
116
+ puts
117
+ exit 254
118
+ end
119
+ exit 0