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,139 @@
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-list-applications: List all applications on all running environments.
31
+
32
+ == Usage
33
+
34
+ os list-application [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 list applications for.
44
+
45
+ -v|--verbose
46
+ Get application deployment history.
47
+
48
+ -h|--help
49
+ Prints this message
50
+
51
+ NAME: The name of the environment to list applications for.
52
+ USAGE
53
+ end
54
+
55
+ opts = GetoptLong.new(
56
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
57
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
58
+ ["--target", "-t", GetoptLong::REQUIRED_ARGUMENT],
59
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
60
+ ["--debug", GetoptLong::NO_ARGUMENT],
61
+ ["--sso", 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
+ @debug = true if args['--debug']
78
+ @porcelin = true if args['--porcelin']
79
+
80
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
81
+ debug "Target platform #{args['--target']}"
82
+
83
+ if args['--target'] == 'flex'
84
+ flex_server = conf('flex_server')
85
+ environment_name = ARGV.shift
86
+ cookie = args['--sso']
87
+ if !cookie
88
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
89
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
90
+ csay("Logging into Openshift Flex as #{username}\n",:message)
91
+ cookie=Openshift.login(@http,username,password)
92
+ end
93
+
94
+ csay("Retrieving environment list... ") if not @porcelin
95
+ environments = JSON.parse(`os-list-environments --sso "#{cookie}" --porcelin`)
96
+ csay("[OK]",:conf) if not @porcelin
97
+
98
+ environments.each{ |environment|
99
+ if not environment_name or environment["name"].strip == environment_name.strip
100
+ if environment['cluster-status'] != 'STOPPED' and environment['cluster-status'] != 'UNRESPONSIVE'
101
+ Openshift::Formatter.table(["Environment Id","Name","Cloud", "DNS", "Load balanced", "Location", "State"],
102
+ ['id','name','cloud-account-name', 'dns', 'loadbalanced','location','cluster-status'],
103
+ [16,15,20,40,20,15,10],
104
+ [environment])
105
+
106
+ uri = URI.parse("https://#{environment['dns']}:4242/api")
107
+ response = Openshift::Rest.get(@http, uri, nil, nil, {'user' => environment['username'], 'password' => environment['password']})
108
+ api = JSON.parse(response.body)
109
+ list_app_link = api['links']['list-applications']
110
+
111
+ uri = URI.parse("https://#{environment['dns']}:4242/#{list_app_link['href']}")
112
+
113
+ response = Openshift::Rest.doHttp(@http, list_app_link['method'], uri, nil, nil, {'user' => environment['username'], 'password' => environment['password']})
114
+ case response
115
+ when Net::HTTPSuccess
116
+ else
117
+ debug "HTTP code: #{response.code}"
118
+ debug response.body
119
+ csay("[ERROR]",:error) if not @porcelin
120
+ csay("Unable to retrieve application list for environment.",:error)
121
+ next
122
+ end
123
+ apps = JSON.parse(response.body)
124
+ debug response.body
125
+ if( apps['applications'].length > 0 )
126
+ csay("Applications",:message)
127
+ Openshift::Formatter.table(["Application GUID","Application name", "Version", "State"],
128
+ ['guid','name','version','status'],
129
+ [39,20,7,10],
130
+ apps["applications"],1)
131
+ else
132
+ csay(" There are no applications on this environment.",:message)
133
+ end
134
+ end
135
+ end
136
+ }
137
+ else
138
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
139
+ end
@@ -0,0 +1,182 @@
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-list-cartridges: List all applications on all running environments.
31
+
32
+ == Usage
33
+
34
+ os list-cartridges [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 hosting the application.
44
+
45
+ -e|--environment ENVIRONMENT_ID:
46
+ The name or ID of the environment that hosts the application.
47
+
48
+ -v|--verbose
49
+ Get application deployment history.
50
+
51
+ -h|--help
52
+ Prints this message
53
+
54
+ NAME: The name or GUID of the application to list cartridges for.
55
+ USAGE
56
+ end
57
+
58
+ opts = GetoptLong.new(
59
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
60
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
61
+ ["--environment", "-e", GetoptLong::REQUIRED_ARGUMENT],
62
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT],
63
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
64
+ ["--debug", GetoptLong::NO_ARGUMENT],
65
+ ["--porcelin", GetoptLong::NO_ARGUMENT]
66
+ )
67
+
68
+ args = {}
69
+ begin
70
+ opts.each{ |k,v| args[k]=v }
71
+ rescue GetoptLong::Error => e
72
+ usage
73
+ exit -100
74
+ end
75
+
76
+ if args['--help']
77
+ usage
78
+ exit
79
+ end
80
+
81
+ app_name = ARGV.shift
82
+ clone_dir = ARGV.shift
83
+ @debug = true if args['--debug']
84
+ debug "Application name: #{app_name}"
85
+
86
+ @porcelin = true if args['--porcelin']
87
+
88
+ args['--target'] = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
89
+ debug "Target platform #{args['--target']}"
90
+
91
+ if args['--target'] == 'flex'
92
+ flex_server = conf('flex_server')
93
+ cookie = args['--sso']
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
+ environment_id = args['--environment']
102
+ csay("\nRetrieving application details... ") if not @porcelin
103
+ environmentInfo = "--environment #{environment_id}" if environment_id
104
+ cmd = "os-inspect-application --sso \"#{cookie}\" --porcelin #{environmentInfo} #{app_name}"
105
+ candidates=nil
106
+ begin
107
+ candidates=`#{cmd}`
108
+ candidates=JSON.parse(candidates)
109
+ csay("[OK]",:conf) if not @porcelin
110
+ rescue Exception => e
111
+ debug candidates
112
+ debug e
113
+ csay("[ERROR]",:error) if not @porcelin
114
+ exit -400
115
+ end
116
+
117
+ if candidates.size == 0
118
+ csay("No application found with specified name or guid.",:error)
119
+ exit -200
120
+ end
121
+ if candidates.size > 1
122
+ csay("Ambiguous application. Please specify environment id and/or application guid.",:error)
123
+ exit -201
124
+ end
125
+
126
+ environment = candidates[0]["environment"]
127
+ app = candidates[0]["application"]
128
+
129
+ uri = URI.parse("https://#{environment['dns']}:4242/cartridges")
130
+ csay("Listing cartridges for application ") if not @porcelin
131
+ csay("#{candidates[0]["application"]["name"]} ",:emphasis) if not @porcelin
132
+ csay("... ") if not @porcelin
133
+ response = Openshift::Rest.get(@http, uri, nil, nil, {'user' => environment['username'], 'password' => environment['password']})
134
+ case response
135
+ when Net::HTTPSuccess
136
+ csay("[OK]",:conf) if not @porcelin
137
+ else
138
+ debug "HTTP code: #{response.code}"
139
+ debug response.body
140
+ csay("[ERROR]",:error) if not @porcelin
141
+ csay("Unable to retrieve application cartridge list",:error)
142
+ exit -301
143
+ end
144
+
145
+ data = JSON.parse(response.body)
146
+ available_carts = data["cartridges"].sort {|x,y| x["name"] <=> y["name"]}
147
+
148
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}/cartridges")
149
+ csay("Listing all available cartridges... ") if not @porcelin
150
+ response = Openshift::Rest.get(@http, uri, nil, nil, {'user' => environment['username'], 'password' => environment['password']})
151
+ case response
152
+ when Net::HTTPSuccess
153
+ csay("[OK]",:conf) if not @porcelin
154
+ else
155
+ debug "HTTP code: #{response.code}"
156
+ debug response.body
157
+ csay("[ERROR]",:error) if not @porcelin
158
+ csay("Unable to available cartridge list",:error)
159
+ exit -301
160
+ end
161
+
162
+ data = JSON.parse(response.body)
163
+ installed_carts = data["cartridges"].sort {|x,y| x["name"] <=> y["name"]}
164
+
165
+ if @porcelin
166
+ print JSON.generate({"available" => available_carts, "installed" => installed_carts})
167
+ else
168
+ print "Installed cartridges:\n"
169
+ Openshift::Formatter.table(["Name","Version", "Arch.", "Vendir"],
170
+ ['name','version','architecture','vendor'],
171
+ [30,20,10,30],
172
+ installed_carts)
173
+
174
+ print "\nAvailable cartridges:\n"
175
+ Openshift::Formatter.table(["Name","Version", "Arch.", "Vendir"],
176
+ ['name','version','architecture','vendor'],
177
+ [30,20,10,30],
178
+ available_carts)
179
+ end
180
+ else
181
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
182
+ end
@@ -0,0 +1,137 @@
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-list-clouds: List all applications on all running environments.
31
+
32
+ == Usage
33
+
34
+ os list-clouds [options]
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 to list cloud accounts for.
44
+
45
+ -h|--help
46
+ Prints this message
47
+ USAGE
48
+ end
49
+
50
+ opts = GetoptLong.new(
51
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT],
52
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
53
+ ["--sso", GetoptLong::REQUIRED_ARGUMENT],
54
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
55
+ ["--debug", GetoptLong::NO_ARGUMENT],
56
+ ["--porcelin", GetoptLong::NO_ARGUMENT]
57
+ )
58
+
59
+ args = {}
60
+ begin
61
+ opts.each{ |k,v| args[k]=v }
62
+ rescue GetoptLong::Error => e
63
+ usage
64
+ exit -100
65
+ end
66
+
67
+ if args['--help']
68
+ usage
69
+ exit
70
+ end
71
+
72
+ @debug = true if args['--debug']
73
+ @porcelin = true if args['--porcelin']
74
+
75
+ target = conf('default_target') || 'flex' if args['--target'].nil? or args['--target']==""
76
+ debug "Target platform #{target}"
77
+
78
+ if target == 'flex'
79
+ flex_server = conf('flex_server')
80
+
81
+ cookie = args['--sso']
82
+ if !cookie
83
+ username = args['--username'] || conf("username") || Openshift::IO.prompt("Redhat username",[],Openshift::Validation.method(:check_login))
84
+ password = args['--password'] || Openshift::IO.prompt("Redhat password",nil,nil,true,false)
85
+ csay("Logging into Openshift Flex as #{username}\n",:message)
86
+ cookie=Openshift.login(@http,username,password)
87
+ end
88
+
89
+ csay("Contacting Openshift Flex server... ") if not @porcelin
90
+ uri = URI.parse("#{flex_server}/rest/api")
91
+ response = Openshift::Rest.get(@http, uri, nil, cookie, nil)
92
+ case response
93
+ when Net::HTTPSuccess
94
+ csay("[OK]",:conf) if not @porcelin
95
+ else
96
+ debug "HTTP code: #{response.code}"
97
+ debug response.body
98
+ csay("[ERROR]",:error) if not @porcelin
99
+ csay("Unable to contact Flex server",:error)
100
+ exit -301
101
+ end
102
+ data = JSON.parse(response.body)
103
+ list_cloud_url = data['links']['list-cloud-accounts']
104
+
105
+ csay("Retrieving list of cloud accounts... ") if not @porcelin
106
+ uri = URI.parse("#{flex_server}/rest/#{list_cloud_url['href']}")
107
+ response = Openshift::Rest.doHttp(@http, list_cloud_url['method'], uri, nil, cookie, nil)
108
+ case response
109
+ when Net::HTTPSuccess
110
+ csay("[OK]",:conf) if not @porcelin
111
+ else
112
+ debug "HTTP code: #{response.code}"
113
+ debug response.body
114
+ csay("[ERROR]",:error) if not @porcelin
115
+ csay("Unable to retrieve cloud account list",:error)
116
+ exit -301
117
+ end
118
+ data = JSON.parse(response.body)
119
+ data = data['cloud-accounts']
120
+ id = 1
121
+ data.each{ |cloud|
122
+ cloud["_id"] = id
123
+ cloud["clusters"] = nil
124
+ id += 1
125
+ }
126
+
127
+ if args['--porcelin']
128
+ print JSON.generate(data)
129
+ else
130
+ Openshift::Formatter.table(["Cloud Id","Name","Type"],
131
+ ['id','name','provider-type'],
132
+ [10,20,20],
133
+ data)
134
+ end
135
+ else
136
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
137
+ end