openshift 0.60.3

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,181 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2010 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
+ def usage
25
+ puts <<USAGE
26
+ == Synopsis
27
+
28
+ os-register-cloud: Registers a new cloud account with Openshift Flex.
29
+
30
+ == Usage
31
+
32
+ os register-cartridge [options] [NAME]
33
+
34
+ -u|--username USERNAME:
35
+ Redhat Login (RHN or OpenShift login with OpenShift Flex access).
36
+
37
+ -p|--password PASSWORD:
38
+ Redhat Password.
39
+
40
+ -t|--target flex|express
41
+ Choose the cloud platform for the cloud account.
42
+
43
+ -r|--provider PROVIDER:
44
+ The IaaS Cloud provider
45
+
46
+ -a|--account ACCOUNT
47
+ The cloud account number
48
+
49
+ -c|--credentials CREDS:
50
+ The cloud account credentials.
51
+
52
+ -s|--secret KEY:
53
+ The cloud account secret key
54
+
55
+ -h|--help:
56
+ Prints this message
57
+
58
+ NAME: The name of the new cloud account
59
+ USAGE
60
+ end
61
+
62
+ require 'openshift'
63
+
64
+ opts = GetoptLong.new(
65
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
66
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
67
+ ["--provider", "-r", GetoptLong::REQUIRED_ARGUMENT],
68
+ ["--credentials", "-c", GetoptLong::REQUIRED_ARGUMENT],
69
+ ["--secret", "-s", GetoptLong::REQUIRED_ARGUMENT],
70
+ ["--account", "-a", GetoptLong::REQUIRED_ARGUMENT],
71
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT], #Internal use only
72
+ ["--porcelin", GetoptLong::NO_ARGUMENT], #Internal use only
73
+ ["--debug", GetoptLong::NO_ARGUMENT],
74
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
75
+ ["--new-environment", GetoptLong::REQUIRED_ARGUMENT], #Internal use only
76
+ ["--target", "-t", GetoptLong::REQUIRED_ARGUMENT]
77
+ )
78
+
79
+ args = {}
80
+ begin
81
+ opts.each{ |k,v| args[k]=v }
82
+ rescue GetoptLong::Error => e
83
+ usage
84
+ exit -100
85
+ end
86
+
87
+ if args['--help']
88
+ usage
89
+ exit -101
90
+ end
91
+
92
+ @debug = true if args['--debug']
93
+ porcelin = args['--porcelin'] ? true : false
94
+
95
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
96
+ debug args['--target']
97
+
98
+ if args['--target'] == 'flex'
99
+ flex_server = conf('flex_server')
100
+ cookie = args['--sso']
101
+
102
+ if !cookie
103
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
104
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
105
+ csay("Logging into Openshift Flex as #{username}\n",:message)
106
+ cookie=Openshift.login(@http,username,password)
107
+ end
108
+
109
+ providers = ["EC2"]
110
+ uri = URI.parse("#{flex_server}/rest/cloud-providers")
111
+ response = Openshift::Rest.get(@http, uri, nil, cookie, nil)
112
+ if response.code.to_s != "200"
113
+ debug response.body
114
+ debug "Unable to retrieve list of cloud providers.\n"
115
+ else
116
+ providers = JSON.parse(response.body)
117
+ end
118
+
119
+ cloud_name = ARGV.shift || Openshift::IO.prompt("Cloud name",[],lambda{|n| Openshift::Validation.check_field(n,"cloud name",16,true)})
120
+ provider = args['--provider'] || Openshift::IO.prompt("Cloud provider",["EC2"])
121
+ account = args['--account'] || Openshift::IO.prompt("Cloud Account")
122
+ credentials = args['--credentials'] || Openshift::IO.prompt("Cloud account credentials",nil,nil,true)
123
+ secret = args['--secret'] || Openshift::IO.prompt("Cloud account secret key",nil,nil,true,false)
124
+
125
+ csay("Contacting Openshift Flex server... ") if not @porcelin
126
+ uri = URI.parse("#{flex_server}/rest/api")
127
+ response = Openshift::Rest.get(@http, uri, nil, cookie, nil)
128
+ case response
129
+ when Net::HTTPSuccess
130
+ csay("[OK]",:conf) if not @porcelin
131
+ else
132
+ debug "HTTP code: #{response.code}"
133
+ debug response.body
134
+ csay("[ERROR]",:error) if not @porcelin
135
+ csay("Unable to contact Flex server",:error)
136
+ exit -301
137
+ end
138
+ data = JSON.parse(response.body)
139
+ create_cloud_url = data['links']['create-cloud-account']
140
+
141
+ say("\nCreating #{provider} cloud named ")
142
+ csay("#{cloud_name} ",:emphasis)
143
+ say("... ")
144
+
145
+ uri = URI.parse("#{flex_server}/rest/#{create_cloud_url['href']}")
146
+ response = Openshift::Rest.doHttp(@http, create_cloud_url['method'], uri, {"name" => cloud_name, "type" => provider,
147
+ "identity" => credentials, "credentials" => secret, "account-id" => account}, cookie, nil)
148
+ case response
149
+ when Net::HTTPSuccess
150
+ say("[<%=color('OK',[GREEN,BOLD])%>]\n")
151
+ else
152
+ debug "HTTP code: #{response.code}"
153
+ debug response.body
154
+ say("[<%=color('ERROR',[RED,BOLD])%>]\n")
155
+ csay("Please verify your cloud credentials an try again.\n",:error)
156
+ exit -301
157
+ end
158
+
159
+ data = JSON.parse(response.body)
160
+ data = data['cloud-account']
161
+
162
+ if args['--porcelin']
163
+ print JSON.generate(data)
164
+ else
165
+ Openshift::Formatter.table(["Id","Name","Type"],
166
+ ['id','name','provider-type'],
167
+ [10,15,20],
168
+ [data])
169
+ end
170
+
171
+ if args['--new-environment']
172
+ new_args = JSON.parse(args['--new-environment'])
173
+ cmd = "os-create-environment --target flex --cloud #{data['id']} --sso \"#{cookie}\" "
174
+ new_args.each{ |k,v|
175
+ cmd += "#{k} \"#{v}\" "
176
+ }
177
+ exec(cmd)
178
+ end
179
+ else
180
+ csay("Cloud account can only be created for the Openshift Flex platform.\n",:error)
181
+ end
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2010 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 'openshift'
25
+
26
+ def usage
27
+ puts <<USAGE
28
+ == Synopsis
29
+
30
+ os-remove-cartridge: Removes a software cartridge and configuration
31
+ from the application.
32
+
33
+ == Usage
34
+
35
+ os remove-cartridge [options] APP CARTRIDGES
36
+
37
+ -u|--username USERNAME:
38
+ Redhat Login (RHN or OpenShift login with OpenShift Flex access).
39
+
40
+ -p|--password PASSWORD:
41
+ Redhat Password.
42
+
43
+ -e|--environment ID:
44
+ The ID of the environment that is hosting the application. This is an optional
45
+ argument to disambiguate the application name.
46
+
47
+ -h|--help:
48
+ Prints this message
49
+
50
+ APP: The application name or application GUID
51
+
52
+ CARTRIDGES: Comma seperated list of cartridges to remove from the application
53
+ USAGE
54
+ end
55
+
56
+ opts = GetoptLong.new(
57
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
58
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
59
+ ["--environment", "-e", GetoptLong::REQUIRED_ARGUMENT],
60
+ ["--debug", GetoptLong::NO_ARGUMENT],
61
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
62
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT],
63
+ ["--target", "-t", GetoptLong::REQUIRED_ARGUMENT]
64
+ )
65
+ args = {}
66
+ begin
67
+ opts.each{ |k,v| args[k]=v }
68
+ rescue GetoptLong::Error => e
69
+ usage
70
+ exit -100
71
+ end
72
+
73
+ flex_server = conf('flex_server')
74
+ app_name = ARGV.shift
75
+ environment_id = args['--environment']
76
+ @debug = true if args['--debug']
77
+ carts = ARGV.shift
78
+
79
+ if args['--help'] or app_name.nil? or app_name == "" or carts.nil? or carts == ""
80
+ usage
81
+ exit -101
82
+ end
83
+
84
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
85
+ debug args['--target']
86
+
87
+ if args['--target'] == 'flex'
88
+ cookie = args['--sso']
89
+ if !cookie
90
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
91
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
92
+ csay("Logging into Openshift Flex as #{username}\n",:message)
93
+ cookie=Openshift.login(@http,username,password)
94
+ end
95
+
96
+ candidates=nil
97
+ begin
98
+ environment_info = "--environment #{environment_id}" if environment_id
99
+ debug "Invoking os-inspect-application --sso \"#{cookie}\" --porcelin #{environment_info} #{app_name}"
100
+ candidates = JSON.parse(`os-inspect-application --sso \"#{cookie}\" --porcelin #{environment_info} #{app_name}`)
101
+ rescue JSON::ParserError => e
102
+ debug e.message
103
+ csay("Unable to load application data from server\n.",:error)
104
+ exit -400
105
+ end
106
+
107
+ if candidates.size == 0
108
+ csay("No application found with specified name or guid.\n",:error)
109
+ usage
110
+ exit -200
111
+ end
112
+
113
+ if candidates.size > 1
114
+ csay("Ambiguous application. Please consider specifing environment id and/or application guid.\n",:warn)
115
+ usage
116
+ exit -201
117
+ end
118
+
119
+ environment = candidates[0]["environment"]
120
+ app = candidates[0]["application"]
121
+
122
+ cart_data = nil
123
+ begin
124
+ debug 'Invoking os-list-cartridges --sso "#{cookie}" --porcelin --environment #{environment["id"]} #{app["guid"]}"'
125
+ cart_data = JSON.parse(`os-list-cartridges --sso "#{cookie}" --porcelin --environment #{environment['id']} #{app['guid']}`)
126
+ rescue JSON::ParserError => e
127
+ debug e.message
128
+ csay("Unable to retrieve a list of cartridges from the server\n.",:error)
129
+ exit -400
130
+ end
131
+
132
+ avail = cart_data['available']
133
+ installed = cart_data['installed']
134
+
135
+ del_carts = carts.split(",")
136
+ installed.delete_if { |cart| del_carts.index(cart["name"]) != nil }
137
+
138
+ say("Configuring dependencies for application ")
139
+ csay("#{app['name']} ",:emphasis)
140
+ say("... ")
141
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}/cartridges")
142
+ response = Openshift::Rest.put(@http, uri, { "cartridges" => JSON.generate(installed) },
143
+ nil, {'user' => environment['username'], 'password' => environment['password']})
144
+ case response
145
+ when Net::HTTPSuccess
146
+ csay("[OK]",:conf)
147
+ else
148
+ debug "HTTP code: #{response.code}"
149
+ debug response.body
150
+ csay("[ERROR]",:error)
151
+ csay("Unable to set application cartridges due to error. Message: #{data['error']}",:error)
152
+ exit -301
153
+ end
154
+
155
+ say("Committing changes to git... ")
156
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}/tree/.vostok/revisions")
157
+ response = Openshift::Rest.post(@http, uri, {"untracked" => "true"}, nil, {'user' => environment['username'], 'password' => environment['password']})
158
+ case response
159
+ when Net::HTTPSuccess
160
+ csay("[OK]",:conf)
161
+ else
162
+ debug "HTTP code: #{response.code}"
163
+ debug response.body
164
+ csay("[ERROR]",:error)
165
+ csay("Unable to commit configuration file changes. Message: #{data['error']}",:error)
166
+ exit -301
167
+ end
168
+ else
169
+ csay("Application dependencies can only be added for the Openshift Flex application.\n",:red)
170
+ end
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2010 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 'openshift'
25
+
26
+ def usage
27
+ puts <<USAGE
28
+ == Synopsis
29
+
30
+ os-restart-application: Restart an application.
31
+
32
+ == Usage
33
+
34
+ os restart-application [options] [APP]
35
+
36
+ -u|--username USERNAME:
37
+ Redhat Login (RHN or OpenShift login).
38
+
39
+ -p|--password PASSWORD:
40
+ Redhat Password.
41
+
42
+ -t|--target flex|express
43
+ Choose the cloud platform to clone the application from.
44
+
45
+ -e|--environment ID:
46
+ The ID of the environment that is hosting the application. This is an optional
47
+ argument to disambiguate the application name. This argument only applies
48
+ to Openshift Flex environments
49
+
50
+ -h|--help:
51
+ Prints this message
52
+
53
+ APP: The application name or application GUID
54
+ USAGE
55
+ end
56
+
57
+ begin
58
+ opts = GetoptLong.new(
59
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
60
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
61
+ ["--environment", "-e", GetoptLong::REQUIRED_ARGUMENT],
62
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
63
+ ["--debug", GetoptLong::NO_ARGUMENT],
64
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT]
65
+ )
66
+ rescue Exception => e
67
+ puts e.message
68
+ end
69
+
70
+ args = {}
71
+ begin
72
+ opts.each{ |k,v| args[k]=v }
73
+ rescue GetoptLong::Error => e
74
+ usage
75
+ exit -100
76
+ end
77
+
78
+ app_name = ARGV.shift
79
+ @debug = true if args['--debug']
80
+
81
+ if args['--help'] or app_name.nil? or app_name == ""
82
+ usage
83
+ exit -101
84
+ end
85
+
86
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
87
+ debug args['--target']
88
+
89
+ if args['--target'] == 'flex'
90
+ flex_server = conf('flex_server')
91
+ environment_id = args['--environment']
92
+ cookie = args['--sso']
93
+
94
+ if !cookie
95
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
96
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
97
+ csay("Logging into Openshift Flex as #{username}\n",:message)
98
+ cookie=Openshift.login(@http,username,password)
99
+ end
100
+
101
+ candidates=nil
102
+ begin
103
+ environment_info = "--environment #{environment_id}" if environment_id
104
+ csay("Loading application state... ")
105
+ debug "Invoking os-inspect-application --sso \"#{cookie}\" --porcelin #{environment_info} #{app_name}"
106
+ candidates = JSON.parse(`os-inspect-application --sso \"#{cookie}\" --porcelin #{environment_info} #{app_name}`)
107
+ csay("[OK]",:conf)
108
+ rescue JSON::ParserError => e
109
+ debug e.message
110
+ csay("[ERROR]",:conf)
111
+ csay("Unable to load application data from server\n.",:error)
112
+ exit -400
113
+ end
114
+
115
+ if candidates.size == 0
116
+ csay("No application found with specified name or guid.\n",:error)
117
+ usage
118
+ exit -200
119
+ end
120
+
121
+ if candidates.size > 1
122
+ csay("Ambiguous application. Please consider specifing environment id and/or application guid.\n",:error)
123
+ usage
124
+ exit -201
125
+ end
126
+
127
+ environment = candidates[0]["environment"]
128
+ app = candidates[0]["application"]
129
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}")
130
+ csay("Restarting application... ")
131
+ response = Openshift::Rest.post(@http, uri, { "operation" => "restart", "blocking" => "true" }, nil, {'user' => environment['username'], 'password' => environment['password']})
132
+ case response
133
+ when Net::HTTPSuccess
134
+ csay("[OK]",:conf)
135
+ else
136
+ debug "HTTP code: #{response.code}"
137
+ debug response.body
138
+ csay("[ERROR]",:error)
139
+ csay("Unable to restart application",:error)
140
+ end
141
+
142
+ csay("Loading application state...")
143
+ cmd = "os-inspect-application --sso \"#{cookie}\" #{environment_info} #{app_name}"
144
+ exec(cmd)
145
+ else
146
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
147
+ end