rhc 1.14.7 → 1.15.6
Sign up to get free protection for your applications and to get access to all the features.
- data/autocomplete/rhc_bash +260 -124
- data/features/core_feature.rb +143 -0
- data/features/domains_feature.rb +49 -0
- data/features/members_feature.rb +131 -0
- data/lib/rhc/auth/token_store.rb +2 -0
- data/lib/rhc/command_runner.rb +7 -5
- data/lib/rhc/commands.rb +111 -68
- data/lib/rhc/commands/account.rb +3 -4
- data/lib/rhc/commands/alias.rb +10 -15
- data/lib/rhc/commands/app.rb +36 -64
- data/lib/rhc/commands/authorization.rb +1 -1
- data/lib/rhc/commands/base.rb +13 -8
- data/lib/rhc/commands/cartridge.rb +21 -29
- data/lib/rhc/commands/domain.rb +96 -47
- data/lib/rhc/commands/env.rb +11 -15
- data/lib/rhc/commands/git_clone.rb +2 -3
- data/lib/rhc/commands/member.rb +148 -0
- data/lib/rhc/commands/port_forward.rb +2 -3
- data/lib/rhc/commands/setup.rb +8 -8
- data/lib/rhc/commands/snapshot.rb +23 -20
- data/lib/rhc/commands/ssh.rb +12 -17
- data/lib/rhc/commands/tail.rb +2 -3
- data/lib/rhc/commands/threaddump.rb +2 -3
- data/lib/rhc/config.rb +1 -0
- data/lib/rhc/context_helper.rb +94 -19
- data/lib/rhc/core_ext.rb +6 -0
- data/lib/rhc/coverage_helper.rb +1 -1
- data/lib/rhc/exceptions.rb +24 -0
- data/lib/rhc/git_helpers.rb +5 -6
- data/lib/rhc/helpers.rb +23 -6
- data/lib/rhc/highline_extensions.rb +3 -2
- data/lib/rhc/output_helpers.rb +9 -6
- data/lib/rhc/rest.rb +1 -0
- data/lib/rhc/rest/application.rb +10 -4
- data/lib/rhc/rest/attributes.rb +4 -0
- data/lib/rhc/rest/base.rb +2 -1
- data/lib/rhc/rest/cartridge.rb +4 -0
- data/lib/rhc/rest/client.rb +41 -25
- data/lib/rhc/rest/domain.rb +29 -9
- data/lib/rhc/rest/membership.rb +105 -0
- data/lib/rhc/rest/mock.rb +45 -12
- data/lib/rhc/rest/user.rb +5 -1
- data/lib/rhc/ssh_helpers.rb +14 -0
- data/lib/rhc/usage_templates/command_syntax_help.erb +2 -0
- data/lib/rhc/wizard.rb +3 -3
- data/spec/coverage_helper.rb +31 -9
- data/spec/direct_execution_helper.rb +256 -0
- data/spec/rhc/command_spec.rb +86 -15
- data/spec/rhc/commands/account_spec.rb +2 -1
- data/spec/rhc/commands/alias_spec.rb +7 -0
- data/spec/rhc/commands/app_spec.rb +73 -90
- data/spec/rhc/commands/cartridge_spec.rb +61 -59
- data/spec/rhc/commands/domain_spec.rb +179 -43
- data/spec/rhc/commands/member_spec.rb +228 -0
- data/spec/rhc/commands/port_forward_spec.rb +7 -7
- data/spec/rhc/commands/snapshot_spec.rb +45 -24
- data/spec/rhc/commands/ssh_spec.rb +16 -3
- data/spec/rhc/commands/tail_spec.rb +1 -1
- data/spec/rhc/helpers_spec.rb +9 -0
- data/spec/rhc/rest_client_spec.rb +75 -7
- data/spec/rhc/rest_spec.rb +1 -1
- metadata +57 -107
- data/features/README.md +0 -198
- data/features/application.feature +0 -28
- data/features/cartridge.feature +0 -48
- data/features/client.feature +0 -11
- data/features/domain.feature +0 -30
- data/features/env.feature +0 -35
- data/features/geared_application.feature +0 -8
- data/features/lib/rhc_helper.rb +0 -21
- data/features/lib/rhc_helper/api.rb +0 -7
- data/features/lib/rhc_helper/app.rb +0 -137
- data/features/lib/rhc_helper/cartridge.rb +0 -97
- data/features/lib/rhc_helper/commandify.rb +0 -251
- data/features/lib/rhc_helper/domain.rb +0 -65
- data/features/lib/rhc_helper/env.rb +0 -29
- data/features/lib/rhc_helper/httpify.rb +0 -186
- data/features/lib/rhc_helper/loggable.rb +0 -37
- data/features/lib/rhc_helper/persistable.rb +0 -51
- data/features/lib/rhc_helper/runnable.rb +0 -55
- data/features/lib/rhc_helper/sshkey.rb +0 -33
- data/features/multiple_cartridge.feature +0 -19
- data/features/scaled_application.feature +0 -48
- data/features/sshkey.feature +0 -63
- data/features/step_definitions/application_steps.rb +0 -120
- data/features/step_definitions/cartridge_steps.rb +0 -95
- data/features/step_definitions/client_steps.rb +0 -41
- data/features/step_definitions/domain_steps.rb +0 -73
- data/features/step_definitions/env_steps.rb +0 -32
- data/features/step_definitions/sshkey_steps.rb +0 -56
- data/features/support/assumptions.rb +0 -49
- data/features/support/before_hooks.rb +0 -81
- data/features/support/env.rb +0 -208
- data/features/support/key1 +0 -27
- data/features/support/key1.pub +0 -1
- data/features/support/key2 +0 -27
- data/features/support/key2.pub +0 -1
- data/features/support/key3.pub +0 -1
- data/features/support/platform_support.rb +0 -29
- data/features/verify.feature +0 -18
- data/spec/rhc/context_spec.rb +0 -53
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'rhc/rest'
|
2
|
-
|
3
|
-
module RHCHelper
|
4
|
-
#
|
5
|
-
# A class to help maintain the state from rhc calls and helper
|
6
|
-
# methods around cartridge management.
|
7
|
-
#
|
8
|
-
class Cartridge
|
9
|
-
extend Runnable
|
10
|
-
extend Commandify
|
11
|
-
extend Persistable
|
12
|
-
include Loggable
|
13
|
-
include Runnable
|
14
|
-
include Httpify
|
15
|
-
include Persistify
|
16
|
-
|
17
|
-
# attributes to represent the general information of the cartridge
|
18
|
-
attr_accessor :name
|
19
|
-
|
20
|
-
# Create the data structure for a test cartridge
|
21
|
-
def initialize(app, name)
|
22
|
-
@name = name
|
23
|
-
@app_name = app.name unless app.nil?
|
24
|
-
@hostname = "#{@app_name}-#{$namespace}.#{$domain}"
|
25
|
-
@file = "#{TEMP_DIR}/#{$namespace}.json"
|
26
|
-
end
|
27
|
-
|
28
|
-
def rhc_cartridge(cmd)
|
29
|
-
full_cmd = "rhc cartridge #{cmd} -l #{$username} -p #{$password} #{@app_name ? "-a #{@app_name}" : ""}"
|
30
|
-
full_cmd += " #{@name}" if cmd != "list"
|
31
|
-
run(full_cmd, nil) do |exitstatus, out, err, arg|
|
32
|
-
yield exitstatus, out, err, arg if block_given?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.list
|
37
|
-
rhc_cartridge_list do |exitstatus, out, err, arg|
|
38
|
-
return [exitstatus, out, err, arg]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def add
|
43
|
-
rhc_cartridge('add') do |exitstatus, out, err, arg|
|
44
|
-
yield exitstatus, out, err, arg if block_given?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def status
|
49
|
-
result = ""
|
50
|
-
rhc_cartridge('status') do |exitstatus, out, err, arg|
|
51
|
-
result = out
|
52
|
-
end
|
53
|
-
|
54
|
-
result
|
55
|
-
end
|
56
|
-
|
57
|
-
def start
|
58
|
-
rhc_cartridge('start')
|
59
|
-
end
|
60
|
-
|
61
|
-
def stop
|
62
|
-
rhc_cartridge('stop')
|
63
|
-
end
|
64
|
-
|
65
|
-
def restart
|
66
|
-
rhc_cartridge('restart')
|
67
|
-
end
|
68
|
-
|
69
|
-
def remove
|
70
|
-
rhc_cartridge('remove --confirm')
|
71
|
-
end
|
72
|
-
|
73
|
-
def scale(values)
|
74
|
-
status = nil
|
75
|
-
rhc_cartridge("scale #{values}") do |exitstatus, out, err, arg|
|
76
|
-
status = exitstatus
|
77
|
-
end
|
78
|
-
status
|
79
|
-
end
|
80
|
-
|
81
|
-
def storage(cartridge, args)
|
82
|
-
output = nil
|
83
|
-
rhc_cartridge("storage #{cartridge} #{args}") do |exitstatus, out, err, arg|
|
84
|
-
output = out.split(" ")[-1]
|
85
|
-
end
|
86
|
-
output
|
87
|
-
end
|
88
|
-
|
89
|
-
def show
|
90
|
-
result = ""
|
91
|
-
rhc_cartridge('show') do |exitstatus, out, err, arg|
|
92
|
-
result = out
|
93
|
-
end
|
94
|
-
result
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,251 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module RHCHelper
|
5
|
-
module Commandify
|
6
|
-
# Implements a method missing approach that will convert calls
|
7
|
-
# like rhc_app_create into 'rhc app create' on the command line
|
8
|
-
def method_missing(sym, *args, &block)
|
9
|
-
if sym.to_s.start_with?("rhc")
|
10
|
-
# Build up the command
|
11
|
-
cmd = get_cmd(sym)
|
12
|
-
|
13
|
-
# Get any blocks that should be run after processing
|
14
|
-
cmd_callback = get_cmd_callback(cmd, args[0]) || block
|
15
|
-
|
16
|
-
# Add arguments to the command
|
17
|
-
cmd << get_args(cmd, args[0])
|
18
|
-
|
19
|
-
exitcode = nil
|
20
|
-
# Run the command, timing it
|
21
|
-
time = Benchmark.realtime do
|
22
|
-
exitcode = run(cmd, args[0], &cmd_callback)
|
23
|
-
end
|
24
|
-
|
25
|
-
# if there is a callback let it take care of validating the results
|
26
|
-
exitcode.should == 0 unless cmd_callback
|
27
|
-
|
28
|
-
# Log the benchmarking info
|
29
|
-
perf_logger.info "#{time} #{sym.to_s.upcase} #{$namespace} #{$login}"
|
30
|
-
else
|
31
|
-
super(sym, *args, &block)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Given a method name, convert to an equivalent
|
36
|
-
# rhc command line string. This method handles
|
37
|
-
# exceptions like converting rhc_app_add_alias
|
38
|
-
# to rhc app add-alias.
|
39
|
-
def get_cmd(method_sym)
|
40
|
-
cmd = method_sym.to_s.gsub('_', ' ')
|
41
|
-
|
42
|
-
# Handle parameters with a dash
|
43
|
-
cmd.gsub!('add alias', 'add-alias')
|
44
|
-
cmd.gsub!('remove alias', 'remove-alias')
|
45
|
-
cmd.gsub!('force stop', 'force-stop')
|
46
|
-
cmd.gsub!('show gears', 'show --gears')
|
47
|
-
|
48
|
-
cmd
|
49
|
-
end
|
50
|
-
|
51
|
-
# Print out the command arguments based on the state of the application instance
|
52
|
-
def get_args(cmd, arg0=nil, debug=true)
|
53
|
-
args = " "
|
54
|
-
args << "-l #{$username} "
|
55
|
-
args << "-p \"#{$password}\" "
|
56
|
-
args << "--debug " if debug
|
57
|
-
|
58
|
-
# Add the application name for all application commands
|
59
|
-
if cmd =~ /app/
|
60
|
-
raise "No application name" unless @name
|
61
|
-
args << "-a #{@name} "
|
62
|
-
end
|
63
|
-
|
64
|
-
# Command specific arguments
|
65
|
-
case cmd
|
66
|
-
when /app delete/
|
67
|
-
args << "--confirm "
|
68
|
-
when /domain list/
|
69
|
-
# domain list doesn't take arguments
|
70
|
-
when /domain show/
|
71
|
-
# domain show doesn't take arguments
|
72
|
-
when /domain update/
|
73
|
-
args << "#{$old_namespace} #{$namespace}"
|
74
|
-
when /domain /
|
75
|
-
raise "No namespace set" unless $namespace
|
76
|
-
# use legacy switch for specifying namespace to verify older interface
|
77
|
-
# should switch to using argument once all commands are moved over
|
78
|
-
args << "#{$namespace} "
|
79
|
-
when /snapshot/
|
80
|
-
args << "-f #{@snapshot} "
|
81
|
-
when /create/
|
82
|
-
args << "-r #{@repo} "
|
83
|
-
args << "-t #{@type} "
|
84
|
-
args << "-s " unless @scalable.nil?
|
85
|
-
args << "-g #{@gear_profile} " unless @gear_profile.nil?
|
86
|
-
args << "--noprompt "
|
87
|
-
when /add-alias/
|
88
|
-
raise "No alias set" unless @alias
|
89
|
-
args << "--alias #{@alias} "
|
90
|
-
when /cartridge/
|
91
|
-
args << "-c #{arg0}" if arg0
|
92
|
-
when /sshkey/
|
93
|
-
# in RHCHelper::Sshkey, we pass *args to method_missing here, so that
|
94
|
-
# we _know_ that arg0 is an Array.
|
95
|
-
args << arg0.first if arg0.first
|
96
|
-
when /env/
|
97
|
-
args << arg0.first if arg0.first
|
98
|
-
end
|
99
|
-
|
100
|
-
args.rstrip.gsub(/([\\\$])/, "\\\\\\1")
|
101
|
-
end
|
102
|
-
|
103
|
-
# This looks for a callback method that is defined for the command.
|
104
|
-
# For example, a command with rhc_app_create_callback will match
|
105
|
-
# and be returned for the 'rhc app create' command. The most specific
|
106
|
-
# callback will be matched, so rhc_app_create_callback being more
|
107
|
-
# specific than rhc_app_callback.
|
108
|
-
def get_cmd_callback(cmd, cartridge=nil)
|
109
|
-
# Break the command up on spaces
|
110
|
-
cmd_parts = cmd.split
|
111
|
-
|
112
|
-
# Drop the 'rhc' portion from the array
|
113
|
-
cmd_parts.shift
|
114
|
-
|
115
|
-
# Look for a method match ending in _callback
|
116
|
-
cmd_parts.length.times do
|
117
|
-
begin
|
118
|
-
# Look for a callback match and return on any find
|
119
|
-
return method((cmd_parts.join("_") + "_callback").to_sym)
|
120
|
-
rescue NameError
|
121
|
-
# Remove one of the parts to see if there is a more
|
122
|
-
# generic match defined
|
123
|
-
cmd_parts.pop
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
return nil
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# The regex to parse the UUID output from the create app results
|
132
|
-
UUID_OUTPUT_PATTERN = /UUID\s*(?:\:|=)\s*(.+)/i unless const_defined?(:UUID_OUTPUT_PATTERN)
|
133
|
-
# The regex to parse the Gear Profile output from the create app results
|
134
|
-
GEAR_PROFILE_OUTPUT_PATTERN = /Gear Size\s*(?:\:|=)\s*(\w+)/m unless const_defined?(:GEAR_PROFILE_OUTPUT_PATTERN)
|
135
|
-
|
136
|
-
#
|
137
|
-
# Begin Post Processing Callbacks
|
138
|
-
#
|
139
|
-
def app_create_callback(exitcode, stdout, stderr, arg)
|
140
|
-
stdout.should =~ /Your application '([^']+)' is now available./
|
141
|
-
|
142
|
-
persist
|
143
|
-
end
|
144
|
-
|
145
|
-
def app_destroy_callback(exitcode, stdout, stderr, arg)
|
146
|
-
FileUtils.rm_rf @repo
|
147
|
-
FileUtils.rm_rf @file
|
148
|
-
@repo, @file = nil
|
149
|
-
end
|
150
|
-
|
151
|
-
def cartridge_add_callback(exitcode, stdout, stderr, cartridge)
|
152
|
-
if cartridge.start_with?('mysql-')
|
153
|
-
@mysql_hostname = /^Connection URL: mysql:\/\/(.*)\/$/.match(stdout)[1]
|
154
|
-
@mysql_user = /^ +Root User: (.*)$/.match(stdout)[1]
|
155
|
-
@mysql_password = /^ +Root Password: (.*)$/.match(stdout)[1]
|
156
|
-
@mysql_database = /^ +Database Name: (.*)$/.match(stdout)[1]
|
157
|
-
|
158
|
-
@mysql_hostname.should_not be_nil
|
159
|
-
@mysql_user.should_not be_nil
|
160
|
-
@mysql_password.should_not be_nil
|
161
|
-
@mysql_database.should_not be_nil
|
162
|
-
end
|
163
|
-
|
164
|
-
@embed << cartridge
|
165
|
-
persist
|
166
|
-
end
|
167
|
-
|
168
|
-
def cartridge_remove_callback(exitcode, stdout, stderr, cartridge)
|
169
|
-
@mysql_hostname = nil
|
170
|
-
@mysql_user = nil
|
171
|
-
@mysql_password = nil
|
172
|
-
@mysql_database = nil
|
173
|
-
@embed.delete(cartridge)
|
174
|
-
persist
|
175
|
-
end
|
176
|
-
|
177
|
-
def domain_callback(exitcode, stdout, stderr, arg)
|
178
|
-
@domain_output = stdout
|
179
|
-
end
|
180
|
-
|
181
|
-
def domain_list_callback(exitcode, stdout, stderr, arg)
|
182
|
-
@domain_list_output = stdout
|
183
|
-
end
|
184
|
-
|
185
|
-
def domain_show_callback(exitcode, stdout, stderr, arg)
|
186
|
-
@domain_show_output = stdout
|
187
|
-
end
|
188
|
-
|
189
|
-
def domain_create_callback(exitcode, stdout, stderr, arg)
|
190
|
-
@exitcode = exitcode
|
191
|
-
end
|
192
|
-
|
193
|
-
def domain_update_callback(exitcode, stdout, stderr, arg)
|
194
|
-
@exitcode = exitcode
|
195
|
-
end
|
196
|
-
|
197
|
-
def domain_delete_callback(exitcode, stdout, stderr, arg)
|
198
|
-
@exitcode = exitcode
|
199
|
-
end
|
200
|
-
|
201
|
-
def sshkey_callback(exitcode, stdout, stderr, arg)
|
202
|
-
@sshkey_output = stdout
|
203
|
-
@exitcode = exitcode
|
204
|
-
end
|
205
|
-
|
206
|
-
def sshkey_add_callback(exitcode, stdout, stderr, arg)
|
207
|
-
@sshkey_output = stdout
|
208
|
-
@exitcode = exitcode
|
209
|
-
end
|
210
|
-
|
211
|
-
def sshkey_list_callback(exitcode, stdout, stderr, arg)
|
212
|
-
@sshkey_output = stdout
|
213
|
-
@exitcode = exitcode
|
214
|
-
end
|
215
|
-
|
216
|
-
def sshkey_show_callback(exitcode, stdout, stderr, arg)
|
217
|
-
@sshkey_output = stdout
|
218
|
-
@exitcode = exitcode
|
219
|
-
end
|
220
|
-
|
221
|
-
def sshkey_update_callback(exitcode, stdout, stderr, arg)
|
222
|
-
@sshkey_output = stdout
|
223
|
-
@exitcode = exitcode
|
224
|
-
end
|
225
|
-
|
226
|
-
def sshkey_delete_callback(exitcode, stdout, stderr, arg)
|
227
|
-
@sshkey_output = stdout
|
228
|
-
@exitcode = exitcode
|
229
|
-
end
|
230
|
-
|
231
|
-
def env_list_callback(exitcode, stdout, stderr, arg)
|
232
|
-
@env_output = stdout
|
233
|
-
@exitcode = exitcode
|
234
|
-
end
|
235
|
-
|
236
|
-
def env_show_callback(exitcode, stdout, stderr, arg)
|
237
|
-
@env_output = stdout
|
238
|
-
@exitcode = exitcode
|
239
|
-
end
|
240
|
-
|
241
|
-
def env_set_callback(exitcode, stdout, stderr, arg)
|
242
|
-
@env_output = stdout
|
243
|
-
@exitcode = exitcode
|
244
|
-
end
|
245
|
-
|
246
|
-
def env_unset_callback(exitcode, stdout, stderr, arg)
|
247
|
-
@env_output = stdout
|
248
|
-
@exitcode = exitcode
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'rhc/rest'
|
2
|
-
|
3
|
-
module RHCHelper
|
4
|
-
#
|
5
|
-
# A class to help maintain the state from rhc calls
|
6
|
-
#
|
7
|
-
class Domain
|
8
|
-
extend Runnable
|
9
|
-
extend Commandify
|
10
|
-
extend API
|
11
|
-
|
12
|
-
class << self
|
13
|
-
attr_reader :domain_output, :domain_list_output, :domain_show_output, :exitcode
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.unique_namespace(prefix)
|
17
|
-
# TODO: Due to DNS changes with the model refactor,
|
18
|
-
# the namespace is not checked here - see #reserved?
|
19
|
-
chars = ("1".."9").to_a
|
20
|
-
prefix + Array.new(8, '').collect{chars[rand(chars.size)]}.join
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.create_if_needed(prefix="test")
|
24
|
-
unless $namespace
|
25
|
-
client = new_client
|
26
|
-
domain = client.domains.first
|
27
|
-
if domain
|
28
|
-
$namespace = domain.id
|
29
|
-
else
|
30
|
-
$namespace = unique_namespace(prefix)
|
31
|
-
# Create the domain
|
32
|
-
rhc_domain_create
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.create
|
38
|
-
rhc_domain_create
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.delete
|
42
|
-
rhc_domain_delete
|
43
|
-
$namespace = nil
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.update(prefix="update")
|
47
|
-
$old_namespace = $namespace
|
48
|
-
$namespace = unique_namespace(prefix)
|
49
|
-
rhc_domain_update
|
50
|
-
|
51
|
-
if @exitcode == 0
|
52
|
-
else
|
53
|
-
$namespace = $old_namespace
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.reserved?(namespace=$namespace)
|
58
|
-
# With the recent model refactoring, we no longer create
|
59
|
-
# TXT DNS records.
|
60
|
-
# Here, we return 'true', since this is the only code that is
|
61
|
-
# used in 'Then' clauses of 2 Cucumber scenarios.
|
62
|
-
true
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "rhc/rest"
|
2
|
-
|
3
|
-
module RHCHelper
|
4
|
-
|
5
|
-
class Env
|
6
|
-
extend Runnable
|
7
|
-
extend Commandify
|
8
|
-
|
9
|
-
class << self
|
10
|
-
attr_accessor :env_output, :exitcode
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.list(*args)
|
14
|
-
rhc_env_list args
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.show(*args)
|
18
|
-
rhc_env_show args
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.set(*args)
|
22
|
-
rhc_env_set args
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.unset(*args)
|
26
|
-
rhc_env_unset args
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,186 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'uri'
|
3
|
-
require 'net/https'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
module RHCHelper
|
7
|
-
module Httpify
|
8
|
-
include Loggable
|
9
|
-
|
10
|
-
# attributes that contain statistics based on calls to connect
|
11
|
-
attr_accessor :response_code, :response_time
|
12
|
-
|
13
|
-
def http_instance(uri, timeout=30)
|
14
|
-
proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
|
15
|
-
http = Net::HTTP.new(uri.host, uri.port, proxy.host, proxy.port)
|
16
|
-
http.open_timeout = timeout
|
17
|
-
http.read_timeout = timeout
|
18
|
-
if (uri.scheme == "https")
|
19
|
-
http.use_ssl = true
|
20
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
-
end
|
22
|
-
return http.start
|
23
|
-
end
|
24
|
-
|
25
|
-
def do_http(options)
|
26
|
-
# Generate the URL if it doesn't exist
|
27
|
-
options[:url] ||= "http%s://%s" % [options[:use_https] ? 's' : '', hostname]
|
28
|
-
|
29
|
-
# Set some default options
|
30
|
-
http_defaults = {
|
31
|
-
:method => :head,
|
32
|
-
:host => nil,
|
33
|
-
:expected => Net::HTTPSuccess,
|
34
|
-
:sleep => 5,
|
35
|
-
:timeout => 1200,
|
36
|
-
:http_timeout => 30,
|
37
|
-
:follow_redirects => true,
|
38
|
-
:redirects => 0,
|
39
|
-
:max_redirects => 10
|
40
|
-
}
|
41
|
-
options = http_defaults.merge(options)
|
42
|
-
|
43
|
-
# Parse the URI
|
44
|
-
uri = URI.parse(options[:url])
|
45
|
-
# Start with a nil response
|
46
|
-
response = nil
|
47
|
-
|
48
|
-
# Set some headers
|
49
|
-
headers = {}
|
50
|
-
headers['Host'] = host if options[:host]
|
51
|
-
|
52
|
-
# Keep retrying, and let Ruby handle the timeout
|
53
|
-
start = Time.now
|
54
|
-
|
55
|
-
# Helper function to log message and sleep
|
56
|
-
def my_sleep(status,expected,start,options)
|
57
|
-
[
|
58
|
-
["Expecting", expected.class],
|
59
|
-
["Received", status.class ],
|
60
|
-
["Elapsed", Time.now - start ],
|
61
|
-
].each do |values|
|
62
|
-
logger.info "%10s: %s" % values
|
63
|
-
end
|
64
|
-
sleep options[:sleep]
|
65
|
-
end
|
66
|
-
|
67
|
-
expected = options[:expected]
|
68
|
-
expected = (expected.to_s =~ /^Net/) ? expected.new(nil,nil,nil) : expected.new
|
69
|
-
|
70
|
-
begin
|
71
|
-
timeout(options[:timeout]) do
|
72
|
-
loop do
|
73
|
-
logger.debug "HTTP_CHECK: Requesting: #{uri}"
|
74
|
-
# Send the HTTP request
|
75
|
-
response = begin
|
76
|
-
http = http_instance(uri,options[:http_timeout])
|
77
|
-
http.send_request(
|
78
|
-
options[:method].to_s.upcase, # Allow options to be a symbol
|
79
|
-
uri.request_uri, nil, headers
|
80
|
-
)
|
81
|
-
rescue Exception => e
|
82
|
-
# Pass these up so we can check them
|
83
|
-
e
|
84
|
-
end
|
85
|
-
logger.debug "HTTP_CHECK: Response: #{response.class}"
|
86
|
-
case response
|
87
|
-
# Catch any response if we're expecting it or redirection
|
88
|
-
when expected.class, Net::HTTPRedirection
|
89
|
-
break
|
90
|
-
# Retry these responses
|
91
|
-
when Net::HTTPServiceUnavailable, SocketError, Timeout::Error
|
92
|
-
logger.debug "HTTP_CHECK: Error #{response.message}"
|
93
|
-
my_sleep(response,expected,start,options)
|
94
|
-
else
|
95
|
-
case expected
|
96
|
-
when Net::HTTPServiceUnavailable
|
97
|
-
my_sleep(response,expected,start,options)
|
98
|
-
else
|
99
|
-
break
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
rescue Timeout::Error => e
|
105
|
-
puts "Did not receive an acceptable response in %d seconds" % options[:timeout]
|
106
|
-
end
|
107
|
-
|
108
|
-
# Test to see if we should follow redirect
|
109
|
-
if options[:follow_redirects] && response.is_a?(Net::HTTPRedirection) && !(response.is_a?(options[:expected]))
|
110
|
-
logger.debug "Response was a redirect, we will attempt to follow"
|
111
|
-
logger.debug "We've been redirected #{options[:redirects]} times"
|
112
|
-
if options[:redirects] < options[:max_redirects]
|
113
|
-
options[:redirects] += 1
|
114
|
-
response = do_http(options.merge({
|
115
|
-
:url => response.header['location']
|
116
|
-
}))
|
117
|
-
else
|
118
|
-
logger.debug "Too many redirects"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
return response
|
123
|
-
end
|
124
|
-
|
125
|
-
def is_inaccessible?(options = {})
|
126
|
-
check_response(options.merge({
|
127
|
-
:expected => Net::HTTPServiceUnavailable,
|
128
|
-
:http_timeout => 2,
|
129
|
-
:timeout => 60,
|
130
|
-
}))
|
131
|
-
end
|
132
|
-
|
133
|
-
def is_accessible?(options = {})
|
134
|
-
check_response(options.merge({
|
135
|
-
:expected => Net::HTTPSuccess,
|
136
|
-
:http_timeout => 20,
|
137
|
-
:timeout => 180,
|
138
|
-
}))
|
139
|
-
end
|
140
|
-
|
141
|
-
def doesnt_exist?
|
142
|
-
check_response({
|
143
|
-
:expected => SocketError,
|
144
|
-
}) do |response|
|
145
|
-
return !(response.is_a?(Net::HTTPSuccess))
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def check_response(options)
|
150
|
-
response = do_http(options)
|
151
|
-
|
152
|
-
if block_given?
|
153
|
-
# Use the custom check for this response
|
154
|
-
yield response
|
155
|
-
else
|
156
|
-
# Compare the response against :expected or Net::HTTPSuccess
|
157
|
-
response.is_a?(options[:expected] || Net::HTTPSuccess)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def connect(use_https=false, max_retries=30)
|
162
|
-
prefix = use_https ? "https://" : "http://"
|
163
|
-
url = prefix + hostname
|
164
|
-
|
165
|
-
logger.info("Connecting to #{url}")
|
166
|
-
beginning_time = Time.now
|
167
|
-
|
168
|
-
response = do_http({
|
169
|
-
:method => :get,
|
170
|
-
:url => url,
|
171
|
-
:http_timeout => 1
|
172
|
-
})
|
173
|
-
|
174
|
-
if response.is_a? Net::HTTPSuccess
|
175
|
-
@response_code = response.code
|
176
|
-
@response_time = Time.now - beginning_time
|
177
|
-
logger.info("Connection result = #{@response_code} / #{url}")
|
178
|
-
logger.info("Connection response time = #{@response_time} / #{url}")
|
179
|
-
return response.body
|
180
|
-
else
|
181
|
-
logger.info("Connection failed / #{url}")
|
182
|
-
return nil
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|