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,306 @@
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-create-environemnt: Creates a new OpenShift Express or OpenShift Flex environemnt.
31
+
32
+ == Usage
33
+
34
+ os create-environment [options] [NAME]
35
+
36
+ -u|--username
37
+ Redhat Login (RHN or OpenShift login with OpenShift Express access)
38
+
39
+ -p|--password
40
+ Redhat Password
41
+
42
+ -t|--target flex|express
43
+ Choose the cloud platform to create the environment on.
44
+
45
+ -h|--help
46
+ Prints this message
47
+
48
+ === Openshift Flex options
49
+
50
+ -c|--cloud
51
+ The cloud ID account to create the environment. (See os-list-clouds)
52
+
53
+ -l|--location
54
+ The cloud provider specific location.
55
+
56
+ --num-nodes
57
+ Number of nodes to start for the environment.
58
+
59
+ --min-memory
60
+ Minumim memory for each node.
61
+
62
+ --min-disk
63
+ Minumim disk size for each node.
64
+
65
+ --load-balanced
66
+ Enables load-balancing for the envionment.
67
+
68
+ --64
69
+ Create a 64 bit instance
70
+
71
+ === Openshift Express options
72
+
73
+ -d|--domain
74
+ The domain namespace for the environment. This argument is only valid for Express
75
+
76
+ NAME: The name of the new environment
77
+ USAGE
78
+ end
79
+
80
+ def create_flex_cloud(args,name,cookie)
81
+ args.delete('--target')
82
+ args.delete('--username')
83
+ args.delete('--password')
84
+ args.delete('--cloud')
85
+ args.delete('--sso')
86
+ args = JSON.generate(args)
87
+ args.gsub!(/(["\\])/, '\\\\\1')
88
+ exec( "os-register-cloud --sso \"#{cookie}\" --new-environment \"#{args} #{name}\"" )
89
+ end
90
+
91
+ begin
92
+ opts = GetoptLong.new(
93
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
94
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
95
+ ["--target", "-t", GetoptLong::REQUIRED_ARGUMENT],
96
+ ["--cloud", "-c", GetoptLong::REQUIRED_ARGUMENT],
97
+ ["--location", "-l", GetoptLong::REQUIRED_ARGUMENT],
98
+ ["--domain", "-d", GetoptLong::REQUIRED_ARGUMENT],
99
+ ["--num-nodes", GetoptLong::REQUIRED_ARGUMENT],
100
+ ["--min-memory", GetoptLong::REQUIRED_ARGUMENT],
101
+ ["--min-disk", GetoptLong::REQUIRED_ARGUMENT],
102
+ ["--load-balanced", GetoptLong::NO_ARGUMENT],
103
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT],
104
+ ["--porcelin", GetoptLong::NO_ARGUMENT],
105
+ ["--new-application", GetoptLong::REQUIRED_ARGUMENT],
106
+ ["--64", GetoptLong::NO_ARGUMENT],
107
+ ["--debug", GetoptLong::NO_ARGUMENT],
108
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
109
+ )
110
+ rescue Exception => e
111
+ puts e.message
112
+ end
113
+
114
+ args = {}
115
+ begin
116
+ opts.each{ |k,v| args[k]=v }
117
+ rescue GetoptLong::Error => e
118
+ usage
119
+ exit -100
120
+ end
121
+
122
+ if args['--help']
123
+ usage
124
+ exit
125
+ end
126
+
127
+ name = ARGV.shift
128
+ @debug = true if args['--debug']
129
+ debug "Environment name: #{name}"
130
+
131
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
132
+ debug "Target platform #{args['--target']}"
133
+
134
+ if args['--target'] == 'flex'
135
+ flex_server = conf('flex_server')
136
+ cookie = args['--sso']
137
+ if !cookie
138
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
139
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
140
+ csay("Logging into Openshift Flex as #{username}\n",:message)
141
+ cookie=Openshift.login(@http,username,password)
142
+ #Openshift::add_rhlogin_config(username)
143
+ end
144
+
145
+ clouds = JSON.parse(`os-list-clouds --sso "#{cookie}" --porcelin`)
146
+ cloud_id = args['--cloud']
147
+ cloud_candidates = clouds.find_all{ |cloud| cloud["id"].to_s == cloud_id.to_s }
148
+ if cloud_id and cloud_candidates.size < 1
149
+ csay("Cloud account with id #{cloud_id} was not found",:warn)
150
+ cloud_id = nil
151
+ end
152
+
153
+ if not cloud_id
154
+ if clouds.size == 0
155
+ create_flex_cloud(args,name,cookie)
156
+ end
157
+
158
+ menu = clouds + [{'id'=>'n', 'name'=>'New cloud'}]
159
+ csay("Please select a cloud account for the new environment or select #{clouds.size+1} to create a new cloud account",:message)
160
+ Openshift::Formatter.table(["Cloud Id","Name","Type"],
161
+ ['id','name','type'],
162
+ [10,15,20],
163
+ menu)
164
+ cloud_id = Openshift::IO.prompt("Cloud ID",menu.map{|c| c['id'].to_s})
165
+ end
166
+ create_flex_cloud(args,name,cookie) if cloud_id.downcase == 'n'
167
+
168
+ cloud_candidates = clouds.find_all{ |cloud| cloud["id"].to_s == cloud_id.to_s }
169
+ cloud = cloud_candidates[0]
170
+
171
+ print "Creating a new Openshift Flex cloud environment\n"
172
+ if not Openshift::Validation.check_field(name,"environment name",8)
173
+ name = Openshift::IO.prompt("Environment name",nil,lambda{|p| Openshift::Validation.check_field(p,"environment name",8)},true)
174
+ end
175
+ location = args['--location'] || 'us-east-1'
176
+ env_pass = Openshift::IO.prompt("Admin password",nil,lambda{|p| Openshift::Validation.check_field(p,"password")},true,false)
177
+ num_nodes = args['--num-nodes'] || "1"
178
+ min_memory = args['--min-memory'] || "1024"
179
+ min_disk_size = args['--min-disk'] || "10"
180
+
181
+ if args['--load-balanced']
182
+ loadbalanced = "true"
183
+ else
184
+ loadbalanced = "false"
185
+ end
186
+
187
+ csay("Contacting Openshift Flex server... ") if not @porcelin
188
+ uri = URI.parse("#{flex_server}/rest/api")
189
+ response = Openshift::Rest.get(@http, uri, nil, cookie, nil)
190
+ case response
191
+ when Net::HTTPSuccess
192
+ csay("[OK]",:conf) if not @porcelin
193
+ else
194
+ debug "HTTP code: #{response.code}"
195
+ debug response.body
196
+ csay("[ERROR]",:error) if not @porcelin
197
+ csay("Unable to contact Flex server",:error)
198
+ exit -301
199
+ end
200
+ data = JSON.parse(response.body)
201
+ create_env_url = data['links']['create-cluster']
202
+
203
+ uri = URI.parse("#{flex_server}/rest/#{create_env_url['href']}")
204
+ csay("Creating a new environment can take upto 5 minutes.",:message)
205
+ csay("Creating the environment... ")
206
+
207
+ architecture = 32
208
+ architecture = 64 if args['--64']
209
+
210
+ response = Openshift::Rest.doHttp(@http, create_env_url['method'], uri, {"cloud-account-id" => cloud['id'], "name" => name, "location" => location, "admin-password" => env_pass,
211
+ "min-cores-per-node" => "1", "min-memory-per-node" => min_memory, "loadbalanced" => loadbalanced, "number-of-nodes" => num_nodes, "architecture" => architecture }, cookie, nil)
212
+
213
+ case response
214
+ when Net::HTTPSuccess
215
+ csay("[OK]",:conf)
216
+ else
217
+ debug "HTTP code: #{response.code}"
218
+ debug response.body
219
+ csay("[ERROR]",:error)
220
+ exit -301
221
+ end
222
+ data = JSON.parse(response.body)
223
+ environment = data['cluster']
224
+
225
+ ssh_key = Openshift::SSH::gen_ssh_keys(@libra_kfile,@libra_kpfile)
226
+ Openshift::SSH::setup_ssh_config(conf('domain'))
227
+ csay("Uploading SSH key to environment... ")
228
+ uri = URI.parse("https://#{environment['dns']}:4242/security/keys")
229
+ response = Openshift::Rest.post(@http, uri, {'type'=>'ssh-rsa','identifier'=>'', 'key'=>ssh_key}, nil, {'user' => environment['username'], 'password' => environment['password']})
230
+ case response
231
+ when Net::HTTPSuccess
232
+ csay("[OK]",:conf)
233
+ else
234
+ debug "HTTP code: #{response.code}"
235
+ debug response.body
236
+ csay("[ERROR]",:error)
237
+ csay("Unable to update ssh keys on environment.",:error)
238
+ exit -301
239
+ end
240
+
241
+ if args['--porcelin']
242
+ print JSON.generate(environment)
243
+ else
244
+ csay("Openshift Flex environment created",:message)
245
+ Openshift::Formatter.table(["Environment Id","Name","Cloud", "DNS", "Load balanced", "Location", "State"],
246
+ ['id','name','cloud-account-name', 'dns', 'loadbalanced','location','cluster-status'],
247
+ [15,15,20,40,20,15,10],
248
+ [environment])
249
+ end
250
+
251
+ if args['--new-application']
252
+ new_args = JSON.parse(args['--new-application'])
253
+ cmd = "os-create-application --target flex --environment #{environment['id']} --sso \"#{cookie}\" "
254
+ new_args.each{ |k,v|
255
+ cmd += "#{k} \"#{v}\" "
256
+ }
257
+ exec(cmd)
258
+ end
259
+ else #express
260
+ sso_data = args['--sso']
261
+ if !sso_data
262
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
263
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
264
+ sso_data = JSON.generate({"username"=>username, "password"=>password})
265
+ else
266
+ sso_data = JSON.parse(sso_data)
267
+ username = sso_data['username']
268
+ password = sso_data['password']
269
+ end
270
+
271
+ ssh_key = Openshift::SSH::gen_ssh_keys(@libra_kfile,@libra_kpfile)
272
+
273
+ csay("Creating new Openshift Express environment... ")
274
+ data = {'namespace' => opt['namespace'], 'rhlogin' => username, 'ssh' => ssh_key}
275
+ json_data = JSON.generate(data)
276
+ url = URI.parse("https://#{libra_server}/broker/domain")
277
+ params = {'json_data' => json_data, 'password' => password}
278
+ response = Openshift::Rest.post(@http, uri, params)
279
+ case response
280
+ when Net::HTTPNotFound
281
+ csay("[ERROR]",:error)
282
+ csay("RHCloud server not found. You might want to try updating your os client tools.",:error)
283
+ exit -218
284
+ when Net::HTTPSuccess
285
+ csay("[OK]",:conf)
286
+ else
287
+ csay("[ERROR]",:error)
288
+ csay("There was a problem communicating with the server. Response message: #{response.code}",:error)
289
+ csay("If you were disconnected it is possible the operation finished without being able to report success.")
290
+ csay("You can use os-list-environments and os-inspect-application to learn about the status of your")
291
+ csay("Openshift Express environment and application(s).")
292
+ exit -219
293
+ end
294
+
295
+ json_resp = JSON.parse(response.body)
296
+ json_rhlogininfo = JSON.parse(json_resp['data'])
297
+ Openshift::add_rhlogin_config(json_rhlogininfo['rhlogin'], json_rhlogininfo['uuid'])
298
+
299
+ puts <<EOF
300
+ Creation successful
301
+
302
+ You may now create an application. Please make note of your local config file
303
+ in #{@local_config_path} which has been created and populated for you.
304
+
305
+ EOF
306
+ end
@@ -0,0 +1,141 @@
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
+ def usage
26
+ puts <<USAGE
27
+ == Synopsis
28
+
29
+ os-delete-application: Deletes an application.
30
+
31
+ == Usage
32
+
33
+ os delete-application [options] [NAME]
34
+
35
+ -u|--username
36
+ Redhat Login (RHN or OpenShift login with OpenShift Express access)
37
+
38
+ -p|--password
39
+ Redhat Password
40
+
41
+ -t|--target flex|express
42
+ Choose the cloud platform to delete the application from.
43
+
44
+ -e|--environment CLUSTER_ID:
45
+ The ID of the environment that is hoting the application.
46
+
47
+ -h|--help
48
+ Prints this message
49
+
50
+ NAME: The name or GUID of the application to delete.
51
+ USAGE
52
+ end
53
+
54
+ opts = GetoptLong.new(
55
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
56
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
57
+ ["--environment", "-e", GetoptLong::REQUIRED_ARGUMENT],
58
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT],
59
+ ["--debug", GetoptLong::NO_ARGUMENT],
60
+ ["--help", GetoptLong::NO_ARGUMENT],
61
+ ["--target", "-t", GetoptLong::REQUIRED_ARGUMENT]
62
+ )
63
+
64
+ args = {}
65
+ begin
66
+ opts.each{ |k,v| args[k]=v }
67
+ rescue GetoptLong::Error => e
68
+ usage
69
+ exit -100
70
+ end
71
+
72
+ if args['--help']
73
+ usage
74
+ exit
75
+ end
76
+
77
+ app_name = ARGV.shift
78
+ @debug = true if args['--debug']
79
+ debug "Deleting application name: #{app_name}"
80
+
81
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
82
+ debug "Target platform #{args['--target']}"
83
+ if args['--target'] == 'flex'
84
+ flex_server = conf('flex_server')
85
+ cookie = args['--sso']
86
+ if !cookie
87
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
88
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
89
+ csay("Logging into Openshift Flex as #{username}\n",:message)
90
+ cookie=Openshift.login(@http,username,password)
91
+ end
92
+
93
+ environment_id = args['--environment']
94
+
95
+ csay("\nRetrieving application details... ")
96
+ environmentInfo = "--environment #{environment_id}" if environment_id
97
+ cmd = "os-inspect-application --sso \"#{cookie}\" --porcelin #{environmentInfo} #{app_name}"
98
+ candidates=nil
99
+ begin
100
+ candidates=`#{cmd}`
101
+ candidates=JSON.parse(candidates)
102
+ csay("[OK]",:conf)
103
+ rescue Exception => e
104
+ debug candidates
105
+ debug e
106
+ csay("[ERROR]",:error)
107
+ exit -400
108
+ end
109
+
110
+ if candidates.size == 0
111
+ csay("No application found with specified name or guid.",:error)
112
+ exit -200
113
+ end
114
+ if candidates.size > 1
115
+ csay("Ambiguous application. Please specify environment id and/or application guid.",:error)
116
+ exit -201
117
+ end
118
+
119
+ environment = candidates[0]["environment"]
120
+ app = candidates[0]["application"]
121
+
122
+ csay("Deleting application ")
123
+ csay("#{app_name} ",:emphasis)
124
+ csay("on Flex environment ")
125
+ csay("#{environment['name']} ",:emphasis)
126
+ csay("... ")
127
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}")
128
+ response = Openshift::Rest.delete(@http, uri, nil, nil, {'user' => environment['username'], 'password' => environment['password']})
129
+ case response
130
+ when Net::HTTPSuccess
131
+ csay("[OK]",:conf)
132
+ else
133
+ debug "HTTP code: #{response.code}"
134
+ debug response.body
135
+ csay("[ERROR]",:error)
136
+ csay("Unable to delete application.",:error)
137
+ exit -301
138
+ end
139
+ else
140
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
141
+ end
@@ -0,0 +1,140 @@
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-delete-environemnt: Deletes an OpenShift Flex environment
31
+
32
+ == Usage
33
+
34
+ os delete-environment [options] [NAME]
35
+
36
+ -u|--username
37
+ Redhat Login (RHN or OpenShift login with OpenShift Express access)
38
+
39
+ -p|--password
40
+ Redhat Password
41
+
42
+ -t|--target flex|express
43
+ The cloud platform the environment is running on.
44
+
45
+ -h|--help
46
+ Prints this message
47
+
48
+ NAME: The name or GUID of the environment to delete.
49
+ USAGE
50
+ end
51
+
52
+ opts = GetoptLong.new(
53
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
54
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
55
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT],
56
+ ["--debug", GetoptLong::NO_ARGUMENT],
57
+ ["--help", GetoptLong::NO_ARGUMENT],
58
+ ["--porcelin", GetoptLong::NO_ARGUMENT]
59
+ )
60
+
61
+ args = {}
62
+ begin
63
+ opts.each{ |k,v| args[k]=v }
64
+ rescue GetoptLong::Error => e
65
+ usage
66
+ exit -100
67
+ end
68
+
69
+ @debug = true if args['--debug']
70
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
71
+ debug "Target platform #{args['--target']}"
72
+
73
+ if args['--help']
74
+ usage
75
+ exit
76
+ end
77
+
78
+ if args['--target'] == 'flex'
79
+ flex_server = conf('flex_server')
80
+ cookie = args['--sso']
81
+ if !cookie
82
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
83
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
84
+ csay("Logging into Openshift Flex as #{username}\n",:message)
85
+ cookie=Openshift.login(@http,username,password)
86
+ end
87
+
88
+ environment_id = ARGV.shift
89
+ debug "Deleting application name: #{environment_id}"
90
+ if not environment_id
91
+ csay("No environment specified.",:error)
92
+ exit
93
+ end
94
+
95
+ csay("Fetching environment list... ")
96
+ environments=nil
97
+ begin
98
+ environments=`os-list-environments --sso "#{cookie}" --porcelin`
99
+ environments = JSON.parse(environments)
100
+ csay("[OK]",:conf)
101
+ rescue Exception => e
102
+ debug environments
103
+ debug e
104
+ csay("[ERROR]",:error)
105
+ csay("Error retrieving environment list.")
106
+ exit -400
107
+ end
108
+ candidates = environments.find_all{ |c| c["name"]==environment_id or c["id"]==environment_id }
109
+
110
+ if candidates.size == 0
111
+ csay("Unable to find environment identified by #{environment_id}",:error)
112
+ exit -200
113
+ end
114
+
115
+ if candidates.size > 1
116
+ csay("Multiple environments are named #{environment_id}. Please provide the environment Id",:error)
117
+ exit -201
118
+ end
119
+
120
+ env = candidates[0]
121
+ del_env_url = env['links']['delete']
122
+
123
+ uri = URI.parse("#{flex_server}/rest/#{del_env_url['href']}")
124
+ csay("Deleting environment ")
125
+ csay("#{candidates[0]["name"]} ",:emphasis)
126
+ csay("... ")
127
+ response = Openshift::Rest.doHttp(@http, del_env_url['method'], uri, nil, cookie, nil)
128
+ case response
129
+ when Net::HTTPSuccess
130
+ csay("[OK]",:conf)
131
+ else
132
+ debug "HTTP code: #{response.code}"
133
+ debug response.body
134
+ csay("[ERROR]",:error)
135
+ csay("Unable to delete environment.",:error)
136
+ exit -301
137
+ end
138
+ else
139
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
140
+ end