openshift 0.60.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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-start-application: Restart an application.
31
+
32
+ == Usage
33
+
34
+ os start-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
+ csay("Starting application... ")
130
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}/state")
131
+ response = Openshift::Rest.put(@http, uri, {"state" => "started"}, 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 start 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
@@ -0,0 +1,144 @@
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-start-environemnt: Starts an OpenShift Flex environment
31
+
32
+ == Usage
33
+
34
+ os start-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 start.
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
+ start_env_url = env['links']['start']
122
+ start_env_url['method'] = 'POST' #override due to bug in Flex REST API
123
+
124
+ csay("Starting environment ")
125
+ csay("#{candidates[0]["name"]} ",:emphasis)
126
+ csay("... ")
127
+ uri = URI.parse("#{flex_server}/rest/#{start_env_url['href']}")
128
+ response = Openshift::Rest.doHttp(@http, start_env_url['method'], uri, {"state" => "started"}, cookie, nil)
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 start environment.",:error)
137
+ exit -301
138
+ end
139
+
140
+ csay("Loading environment states...")
141
+ system( "os-list-environments --sso \"#{cookie}\"" )
142
+ else
143
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
144
+ 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-stop-application: Restart an application.
31
+
32
+ == Usage
33
+
34
+ os stop-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
+ csay("Stopping application... ")
130
+ uri = URI.parse("https://#{environment['dns']}:4242/applications/#{app['guid']}/state")
131
+ response = Openshift::Rest.put(@http, uri, {"state" => "stopped"}, 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 stop 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
@@ -0,0 +1,144 @@
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-stop-environemnt: Stops an OpenShift Flex environment
31
+
32
+ == Usage
33
+
34
+ os stop-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 stop.
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
+ stop_env_url = env['links']['stop']
122
+ stop_env_url['method'] = 'POST' #override due to bug in Flex REST API
123
+
124
+ csay("Stopping environment ")
125
+ csay("#{candidates[0]["name"]} ",:emphasis)
126
+ csay("... ")
127
+ uri = URI.parse("#{flex_server}/rest/#{stop_env_url['href']}")
128
+ response = Openshift::Rest.doHttp(@http, stop_env_url['method'], uri, {"state" => "stopped"}, cookie, nil)
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 stop environment.",:error)
137
+ exit -301
138
+ end
139
+
140
+ csay("Loading environment states...")
141
+ system( "os-list-environments --sso \"#{cookie}\"" )
142
+ else
143
+ csay("This feature is currently not implemented for Openshift Express applications.\n",:red)
144
+ end