ktheory-right_aws 2.0.1 → 2.0.2
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.
- data/Rakefile +1 -1
- data/lib/awsbase/right_awsbase.rb +166 -167
- data/lib/ec2/right_ec2.rb +1 -1
- data/lib/rds/right_rds_interface.rb +8 -4
- data/lib/right_aws.rb +2 -1
- metadata +8 -8
data/Rakefile
CHANGED
@@ -27,7 +27,7 @@ Hoe.new('ktheory-right_aws', RightAws::VERSION::STRING) do |p|
|
|
27
27
|
p.email = 'support@rightscale.com'
|
28
28
|
p.summary = 'Interface classes for the Amazon EC2, SQS, and S3 Web Services'
|
29
29
|
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
30
|
-
p.url =
|
30
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
31
31
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
32
32
|
p.remote_rdoc_dir = "/right_aws_gem_doc"
|
33
33
|
p.extra_deps = [['right_http_connection','>= 1.2.1']]
|
@@ -26,7 +26,7 @@ module RightAws
|
|
26
26
|
# require 'md5'
|
27
27
|
require 'digest/md5'
|
28
28
|
require 'pp'
|
29
|
-
|
29
|
+
|
30
30
|
class AwsUtils #:nodoc:
|
31
31
|
@@digest1 = OpenSSL::Digest::Digest.new("sha1")
|
32
32
|
@@digest256 = nil
|
@@ -40,7 +40,7 @@ module RightAws
|
|
40
40
|
end
|
41
41
|
time.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def self.sign(aws_secret_access_key, auth_string)
|
45
45
|
Base64.encode64(OpenSSL::HMAC.digest(@@digest1, aws_secret_access_key, auth_string)).strip
|
46
46
|
end
|
@@ -101,11 +101,11 @@ module RightAws
|
|
101
101
|
end
|
102
102
|
|
103
103
|
# From Amazon's SQS Dev Guide, a brief description of how to escape:
|
104
|
-
# "URL encode the computed signature and other query parameters as specified in
|
105
|
-
# RFC1738, section 2.2. In addition, because the + character is interpreted as a blank space
|
106
|
-
# by Sun Java classes that perform URL decoding, make sure to encode the + character
|
104
|
+
# "URL encode the computed signature and other query parameters as specified in
|
105
|
+
# RFC1738, section 2.2. In addition, because the + character is interpreted as a blank space
|
106
|
+
# by Sun Java classes that perform URL decoding, make sure to encode the + character
|
107
107
|
# although it is not required by RFC1738."
|
108
|
-
# Avoid using CGI::escape to escape URIs.
|
108
|
+
# Avoid using CGI::escape to escape URIs.
|
109
109
|
# CGI::escape will escape characters in the protocol, host, and port
|
110
110
|
# sections of the URI. Only target chars in the query
|
111
111
|
# string should be escaped.
|
@@ -113,19 +113,19 @@ module RightAws
|
|
113
113
|
e = URI.escape(raw)
|
114
114
|
e.gsub(/\+/, "%2b")
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def self.allow_only(allowed_keys, params)
|
118
118
|
bogus_args = []
|
119
119
|
params.keys.each {|p| bogus_args.push(p) unless allowed_keys.include?(p) }
|
120
120
|
raise AwsError.new("The following arguments were given but are not legal for the function call #{caller_method}: #{bogus_args.inspect}") if bogus_args.length > 0
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def self.mandatory_arguments(required_args, params)
|
124
124
|
rargs = required_args.dup
|
125
125
|
params.keys.each {|p| rargs.delete(p)}
|
126
126
|
raise AwsError.new("The following mandatory arguments were not provided to #{caller_method}: #{rargs.inspect}") if rargs.length > 0
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
def self.caller_method
|
130
130
|
caller[1]=~/`(.*?)'/
|
131
131
|
$1
|
@@ -150,14 +150,14 @@ module RightAws
|
|
150
150
|
|
151
151
|
class AwsNoChange < RuntimeError
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
class RightAwsBase
|
155
155
|
|
156
156
|
# Amazon HTTP Error handling
|
157
157
|
|
158
158
|
# Text, if found in an error message returned by AWS, indicates that this may be a transient
|
159
159
|
# error. Transient errors are automatically retried with exponential back-off.
|
160
|
-
AMAZON_PROBLEMS = [ 'internal service error',
|
160
|
+
AMAZON_PROBLEMS = [ 'internal service error',
|
161
161
|
'is currently unavailable',
|
162
162
|
'no response from',
|
163
163
|
'Please try again',
|
@@ -169,24 +169,24 @@ module RightAws
|
|
169
169
|
'InsufficientInstanceCapacity'
|
170
170
|
]
|
171
171
|
@@amazon_problems = AMAZON_PROBLEMS
|
172
|
-
# Returns a list of Amazon service responses which are known to be transient problems.
|
173
|
-
# We have to re-request if we get any of them, because the problem will probably disappear.
|
172
|
+
# Returns a list of Amazon service responses which are known to be transient problems.
|
173
|
+
# We have to re-request if we get any of them, because the problem will probably disappear.
|
174
174
|
# By default this method returns the same value as the AMAZON_PROBLEMS const.
|
175
175
|
def self.amazon_problems
|
176
176
|
@@amazon_problems
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
# Sets the list of Amazon side problems. Use in conjunction with the
|
180
180
|
# getter to append problems.
|
181
181
|
def self.amazon_problems=(problems_list)
|
182
182
|
@@amazon_problems = problems_list
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
end
|
186
186
|
|
187
187
|
module RightAwsBaseInterface
|
188
188
|
DEFAULT_SIGNATURE_VERSION = '2'
|
189
|
-
|
189
|
+
|
190
190
|
@@caching = false
|
191
191
|
def self.caching
|
192
192
|
@@caching
|
@@ -243,15 +243,13 @@ module RightAws
|
|
243
243
|
@params[:service] ||= service_info[:default_service]
|
244
244
|
@params[:protocol] ||= service_info[:default_protocol]
|
245
245
|
end
|
246
|
-
# @params[:multi_thread] ||= defined?(AWS_DAEMON)
|
247
|
-
@params[:connections] ||= :shared # || :dedicated
|
248
|
-
@params[:max_connections] ||= 10
|
249
246
|
@params[:connection_lifetime] ||= 20*60
|
250
247
|
@params[:api_version] ||= service_info[:default_api_version]
|
251
248
|
@logger = @params[:logger]
|
249
|
+
@logger = ::Rails.logger if !@logger && defined?(::Rails) && Rails.respond_to?(:logger)
|
252
250
|
@logger = RAILS_DEFAULT_LOGGER if !@logger && defined?(RAILS_DEFAULT_LOGGER)
|
253
251
|
@logger = Logger.new(STDOUT) if !@logger
|
254
|
-
@logger.info "New #{self.class.name}
|
252
|
+
@logger.info "New #{self.class.name}"
|
255
253
|
@error_handler = nil
|
256
254
|
@cache = {}
|
257
255
|
@signature_version = (params[:signature_version] || DEFAULT_SIGNATURE_VERSION).to_s
|
@@ -266,11 +264,11 @@ module RightAws
|
|
266
264
|
end
|
267
265
|
end
|
268
266
|
|
269
|
-
# Returns +true+ if the describe_xxx responses are being cached
|
267
|
+
# Returns +true+ if the describe_xxx responses are being cached
|
270
268
|
def caching?
|
271
269
|
@params.key?(:cache) ? @params[:cache] : @@caching
|
272
270
|
end
|
273
|
-
|
271
|
+
|
274
272
|
# Check if the aws function response hits the cache or not.
|
275
273
|
# If the cache hits:
|
276
274
|
# - raises an +AwsNoChange+ exception if +do_raise+ == +:raise+.
|
@@ -287,9 +285,9 @@ module RightAws
|
|
287
285
|
# check for changes
|
288
286
|
unless @cache[function] && @cache[function][:response_md5] == response_md5
|
289
287
|
# well, the response is new, reset cache data
|
290
|
-
update_cache(function, {:response_md5 => response_md5,
|
291
|
-
:timestamp => Time.now,
|
292
|
-
:hits => 0,
|
288
|
+
update_cache(function, {:response_md5 => response_md5,
|
289
|
+
:timestamp => Time.now,
|
290
|
+
:hits => 0,
|
293
291
|
:parsed => nil})
|
294
292
|
else
|
295
293
|
# aha, cache hits, update the data and throw an exception if needed
|
@@ -305,16 +303,16 @@ module RightAws
|
|
305
303
|
end
|
306
304
|
result
|
307
305
|
end
|
308
|
-
|
306
|
+
|
309
307
|
def update_cache(function, hash)
|
310
308
|
(@cache[function.to_sym] ||= {}).merge!(hash) if caching?
|
311
309
|
end
|
312
|
-
|
310
|
+
|
313
311
|
def on_exception(options={:raise=>true, :log=>true}) # :nodoc:
|
314
312
|
raise if $!.is_a?(AwsNoChange)
|
315
313
|
AwsError::on_aws_exception(self, options)
|
316
314
|
end
|
317
|
-
|
315
|
+
|
318
316
|
# # Return +true+ if this instance works in multi_thread mode and +false+ otherwise.
|
319
317
|
# def multi_thread
|
320
318
|
# @params[:multi_thread]
|
@@ -360,32 +358,32 @@ module RightAws
|
|
360
358
|
:protocol => @params[:protocol] }
|
361
359
|
end
|
362
360
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
361
|
+
# Expire the connection if it has expired.
|
362
|
+
def get_connection(aws_service, request)
|
363
|
+
connections = get_connections_storage aws_service
|
364
|
+
url = get_server_url request
|
365
|
+
conn = connections[url] ||= {}
|
366
|
+
last_used = conn[:last_used_at]
|
367
|
+
if last_used && (last_used < Time.now - @params[:connection_lifetime])
|
368
|
+
destroy_connection(aws_service, request)
|
371
369
|
end
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
connections =
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
370
|
+
conn[:last_used_at] = Time.now
|
371
|
+
conn[:connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger)
|
372
|
+
end
|
373
|
+
|
374
|
+
def destroy_connection(aws_service, request)
|
375
|
+
connections = get_connections_storage aws_service
|
376
|
+
url = get_server_url request
|
377
|
+
connections[url][:connection].finish('destroyed') if connections[url]
|
378
|
+
connections[url] = nil
|
379
|
+
end
|
380
|
+
|
381
|
+
def get_connections_storage(aws_service)
|
382
|
+
@connections_storage = (Thread.current[aws_service] ||= {})
|
383
|
+
end
|
384
|
+
|
385
|
+
def get_server_url(request)
|
386
|
+
"#{request[:protocol]}://#{request[:server]}:#{request[:port]}}"
|
389
387
|
end
|
390
388
|
|
391
389
|
# All services uses this guy.
|
@@ -417,7 +415,7 @@ module RightAws
|
|
417
415
|
check_result = @error_handler.check(request)
|
418
416
|
if check_result
|
419
417
|
@error_handler = nil
|
420
|
-
return check_result
|
418
|
+
return check_result
|
421
419
|
end
|
422
420
|
raise AwsError.new(@last_errors, @last_response.code, @last_request_id)
|
423
421
|
end
|
@@ -445,11 +443,12 @@ module RightAws
|
|
445
443
|
benchblock.xml.add! { parser.parse(response) }
|
446
444
|
return parser.result
|
447
445
|
else
|
446
|
+
destroy_connection aws_service, request
|
448
447
|
@error_handler = AWSErrorHandler.new(self, parser, :errors_list => self.class.amazon_problems) unless @error_handler
|
449
448
|
check_result = @error_handler.check(request)
|
450
449
|
if check_result
|
451
450
|
@error_handler = nil
|
452
|
-
return check_result
|
451
|
+
return check_result
|
453
452
|
end
|
454
453
|
raise AwsError.new(@last_errors, @last_response.code, @last_request_id)
|
455
454
|
end
|
@@ -554,35 +553,35 @@ module RightAws
|
|
554
553
|
# Attribute inherited by RuntimeError:
|
555
554
|
# message - the text of the error, generally as returned by AWS in its XML response.
|
556
555
|
class AwsError < RuntimeError
|
557
|
-
|
556
|
+
|
558
557
|
# either an array of errors where each item is itself an array of [code, message]),
|
559
558
|
# or an error string if the error was raised manually, as in <tt>AwsError.new('err_text')</tt>
|
560
559
|
attr_reader :errors
|
561
|
-
|
560
|
+
|
562
561
|
# Request id (if exists)
|
563
562
|
attr_reader :request_id
|
564
|
-
|
563
|
+
|
565
564
|
# Response HTTP error code
|
566
565
|
attr_reader :http_code
|
567
|
-
|
566
|
+
|
568
567
|
def initialize(errors=nil, http_code=nil, request_id=nil)
|
569
568
|
@errors = errors
|
570
569
|
@request_id = request_id
|
571
570
|
@http_code = http_code
|
572
571
|
super(@errors.is_a?(Array) ? @errors.map{|code, msg| "#{code}: #{msg}"}.join("; ") : @errors.to_s)
|
573
572
|
end
|
574
|
-
|
573
|
+
|
575
574
|
# Does any of the error messages include the regexp +pattern+?
|
576
575
|
# Used to determine whether to retry request.
|
577
576
|
def include?(pattern)
|
578
577
|
if @errors.is_a?(Array)
|
579
|
-
@errors.each{ |code, msg| return true if code =~ pattern }
|
578
|
+
@errors.each{ |code, msg| return true if code =~ pattern }
|
580
579
|
else
|
581
|
-
return true if @errors_str =~ pattern
|
580
|
+
return true if @errors_str =~ pattern
|
582
581
|
end
|
583
582
|
false
|
584
583
|
end
|
585
|
-
|
584
|
+
|
586
585
|
# Generic handler for AwsErrors. +aws+ is the RightAws::S3, RightAws::EC2, or RightAws::SQS
|
587
586
|
# object that caused the exception (it must provide last_request and last_response). Supported
|
588
587
|
# boolean options are:
|
@@ -606,7 +605,7 @@ module RightAws
|
|
606
605
|
raise if options[:raise] # re-raise an exception
|
607
606
|
return nil
|
608
607
|
end
|
609
|
-
|
608
|
+
|
610
609
|
# True if e is an AWS system error, i.e. something that is for sure not the caller's fault.
|
611
610
|
# Used to force logging.
|
612
611
|
def self.system_error?(e)
|
@@ -617,9 +616,9 @@ module RightAws
|
|
617
616
|
|
618
617
|
|
619
618
|
class AWSErrorHandler
|
620
|
-
# 0-100 (%)
|
621
|
-
DEFAULT_CLOSE_ON_4XX_PROBABILITY = 10
|
622
|
-
|
619
|
+
# 0-100 (%)
|
620
|
+
DEFAULT_CLOSE_ON_4XX_PROBABILITY = 10
|
621
|
+
|
623
622
|
@@reiteration_start_delay = 0.2
|
624
623
|
def self.reiteration_start_delay
|
625
624
|
@@reiteration_start_delay
|
@@ -635,42 +634,42 @@ module RightAws
|
|
635
634
|
def self.reiteration_time=(reiteration_time)
|
636
635
|
@@reiteration_time = reiteration_time
|
637
636
|
end
|
638
|
-
|
639
|
-
@@close_on_error = true
|
640
|
-
def self.close_on_error
|
641
|
-
@@close_on_error
|
642
|
-
end
|
643
|
-
def self.close_on_error=(close_on_error)
|
644
|
-
@@close_on_error = close_on_error
|
645
|
-
end
|
646
|
-
|
647
|
-
@@close_on_4xx_probability = DEFAULT_CLOSE_ON_4XX_PROBABILITY
|
648
|
-
def self.close_on_4xx_probability
|
649
|
-
@@close_on_4xx_probability
|
650
|
-
end
|
651
|
-
def self.close_on_4xx_probability=(close_on_4xx_probability)
|
652
|
-
@@close_on_4xx_probability = close_on_4xx_probability
|
653
|
-
end
|
654
|
-
|
655
|
-
# params:
|
656
|
-
# :reiteration_time
|
657
|
-
# :errors_list
|
658
|
-
# :close_on_error = true | false
|
659
|
-
# :close_on_4xx_probability = 1-100
|
660
|
-
def initialize(aws, parser, params={}) #:nodoc:
|
637
|
+
|
638
|
+
@@close_on_error = true
|
639
|
+
def self.close_on_error
|
640
|
+
@@close_on_error
|
641
|
+
end
|
642
|
+
def self.close_on_error=(close_on_error)
|
643
|
+
@@close_on_error = close_on_error
|
644
|
+
end
|
645
|
+
|
646
|
+
@@close_on_4xx_probability = DEFAULT_CLOSE_ON_4XX_PROBABILITY
|
647
|
+
def self.close_on_4xx_probability
|
648
|
+
@@close_on_4xx_probability
|
649
|
+
end
|
650
|
+
def self.close_on_4xx_probability=(close_on_4xx_probability)
|
651
|
+
@@close_on_4xx_probability = close_on_4xx_probability
|
652
|
+
end
|
653
|
+
|
654
|
+
# params:
|
655
|
+
# :reiteration_time
|
656
|
+
# :errors_list
|
657
|
+
# :close_on_error = true | false
|
658
|
+
# :close_on_4xx_probability = 1-100
|
659
|
+
def initialize(aws, parser, params={}) #:nodoc:
|
661
660
|
@aws = aws # Link to RightEc2 | RightSqs | RightS3 instance
|
662
661
|
@parser = parser # parser to parse Amazon response
|
663
662
|
@started_at = Time.now
|
664
|
-
@stop_at = @started_at + (params[:reiteration_time] || @@reiteration_time)
|
665
|
-
@errors_list = params[:errors_list] || []
|
663
|
+
@stop_at = @started_at + (params[:reiteration_time] || @@reiteration_time)
|
664
|
+
@errors_list = params[:errors_list] || []
|
666
665
|
@reiteration_delay = @@reiteration_start_delay
|
667
666
|
@retries = 0
|
668
|
-
# close current HTTP(S) connection on 5xx, errors from list and 4xx errors
|
669
|
-
@close_on_error = params[:close_on_error].nil? ? @@close_on_error : params[:close_on_error]
|
670
|
-
@close_on_4xx_probability = params[:close_on_4xx_probability] || @@close_on_4xx_probability
|
667
|
+
# close current HTTP(S) connection on 5xx, errors from list and 4xx errors
|
668
|
+
@close_on_error = params[:close_on_error].nil? ? @@close_on_error : params[:close_on_error]
|
669
|
+
@close_on_4xx_probability = params[:close_on_4xx_probability] || @@close_on_4xx_probability
|
671
670
|
end
|
672
|
-
|
673
|
-
# Returns false if
|
671
|
+
|
672
|
+
# Returns false if
|
674
673
|
def check(request) #:nodoc:
|
675
674
|
result = false
|
676
675
|
error_found = false
|
@@ -683,7 +682,7 @@ module RightAws
|
|
683
682
|
# is this a redirect?
|
684
683
|
# yes!
|
685
684
|
if response.is_a?(Net::HTTPRedirection)
|
686
|
-
redirect_detected = true
|
685
|
+
redirect_detected = true
|
687
686
|
else
|
688
687
|
# no, it's an error ...
|
689
688
|
@aws.logger.warn("##### #{@aws.class.name} returned an error: #{response.code} #{response.message}\n#{response.body} #####")
|
@@ -705,7 +704,7 @@ module RightAws
|
|
705
704
|
@aws.last_request_id = '-undefined-'
|
706
705
|
last_errors_text = response.message
|
707
706
|
end
|
708
|
-
|
707
|
+
|
709
708
|
# Ok, it is a redirect, find the new destination location
|
710
709
|
if redirect_detected
|
711
710
|
location = response['location']
|
@@ -728,21 +727,21 @@ module RightAws
|
|
728
727
|
end
|
729
728
|
end
|
730
729
|
end
|
731
|
-
|
730
|
+
|
732
731
|
# check the time has gone from the first error come
|
733
732
|
if redirect_detected || error_found
|
734
|
-
# Close the connection to the server and recreate a new one.
|
735
|
-
# It may have a chance that one server is a semi-down and reconnection
|
736
|
-
# will help us to connect to the other server
|
733
|
+
# Close the connection to the server and recreate a new one.
|
734
|
+
# It may have a chance that one server is a semi-down and reconnection
|
735
|
+
# will help us to connect to the other server
|
737
736
|
if !redirect_detected && @close_on_error
|
738
|
-
@aws.connection.finish "#{self.class.name}: error match to pattern '#{error_match}'"
|
739
|
-
end
|
740
|
-
|
737
|
+
@aws.connection.finish "#{self.class.name}: error match to pattern '#{error_match}'"
|
738
|
+
end
|
739
|
+
|
741
740
|
if (Time.now < @stop_at)
|
742
741
|
@retries += 1
|
743
742
|
unless redirect_detected
|
744
743
|
@aws.logger.warn("##### Retry ##{@retries} is being performed. Sleeping for #{@reiteration_delay} sec. Whole time: #{Time.now-@started_at} sec ####")
|
745
|
-
sleep @reiteration_delay
|
744
|
+
sleep @reiteration_delay
|
746
745
|
@reiteration_delay *= 2
|
747
746
|
|
748
747
|
# Always make sure that the fp is set to point to the beginning(?)
|
@@ -761,69 +760,69 @@ module RightAws
|
|
761
760
|
result = @aws.request_info(request, @parser)
|
762
761
|
else
|
763
762
|
@aws.logger.warn("##### Ooops, time is over... ####")
|
764
|
-
end
|
765
|
-
# aha, this is unhandled error:
|
766
|
-
elsif @close_on_error
|
767
|
-
# Is this a 5xx error ?
|
768
|
-
if @aws.last_response.code.to_s[/^5\d\d$/]
|
769
|
-
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}'"
|
770
|
-
# Is this a 4xx error ?
|
771
|
-
elsif @aws.last_response.code.to_s[/^4\d\d$/] && @close_on_4xx_probability > rand(100)
|
772
|
-
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}', " +
|
773
|
-
"probability: #{@close_on_4xx_probability}%"
|
763
|
+
end
|
764
|
+
# aha, this is unhandled error:
|
765
|
+
elsif @close_on_error
|
766
|
+
# Is this a 5xx error ?
|
767
|
+
if @aws.last_response.code.to_s[/^5\d\d$/]
|
768
|
+
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}'"
|
769
|
+
# Is this a 4xx error ?
|
770
|
+
elsif @aws.last_response.code.to_s[/^4\d\d$/] && @close_on_4xx_probability > rand(100)
|
771
|
+
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}', " +
|
772
|
+
"probability: #{@close_on_4xx_probability}%"
|
774
773
|
end
|
775
774
|
end
|
776
775
|
result
|
777
776
|
end
|
778
|
-
|
777
|
+
|
779
778
|
end
|
780
779
|
|
781
780
|
|
782
781
|
#-----------------------------------------------------------------
|
783
782
|
|
784
783
|
class RightSaxParserCallback #:nodoc:
|
785
|
-
def self.include_callback
|
786
|
-
include XML::SaxParser::Callbacks
|
787
|
-
end
|
788
|
-
def initialize(right_aws_parser)
|
789
|
-
@right_aws_parser = right_aws_parser
|
790
|
-
end
|
791
|
-
def on_start_element(name, attr_hash)
|
792
|
-
@right_aws_parser.tag_start(name, attr_hash)
|
793
|
-
end
|
794
|
-
def on_characters(chars)
|
784
|
+
def self.include_callback
|
785
|
+
include XML::SaxParser::Callbacks
|
786
|
+
end
|
787
|
+
def initialize(right_aws_parser)
|
788
|
+
@right_aws_parser = right_aws_parser
|
789
|
+
end
|
790
|
+
def on_start_element(name, attr_hash)
|
791
|
+
@right_aws_parser.tag_start(name, attr_hash)
|
792
|
+
end
|
793
|
+
def on_characters(chars)
|
795
794
|
@right_aws_parser.text(chars)
|
796
|
-
end
|
797
|
-
def on_end_element(name)
|
798
|
-
@right_aws_parser.tag_end(name)
|
799
|
-
end
|
800
|
-
def on_start_document; end
|
801
|
-
def on_comment(msg); end
|
802
|
-
def on_processing_instruction(target, data); end
|
803
|
-
def on_cdata_block(cdata); end
|
804
|
-
def on_end_document; end
|
805
|
-
end
|
806
|
-
|
795
|
+
end
|
796
|
+
def on_end_element(name)
|
797
|
+
@right_aws_parser.tag_end(name)
|
798
|
+
end
|
799
|
+
def on_start_document; end
|
800
|
+
def on_comment(msg); end
|
801
|
+
def on_processing_instruction(target, data); end
|
802
|
+
def on_cdata_block(cdata); end
|
803
|
+
def on_end_document; end
|
804
|
+
end
|
805
|
+
|
807
806
|
class RightAWSParser #:nodoc:
|
808
|
-
# default parsing library
|
809
|
-
DEFAULT_XML_LIBRARY = 'rexml'
|
810
|
-
# a list of supported parsers
|
811
|
-
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
812
|
-
|
813
|
-
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
807
|
+
# default parsing library
|
808
|
+
DEFAULT_XML_LIBRARY = 'rexml'
|
809
|
+
# a list of supported parsers
|
810
|
+
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
811
|
+
|
812
|
+
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
814
813
|
def self.xml_lib
|
815
814
|
@@xml_lib
|
816
815
|
end
|
817
816
|
def self.xml_lib=(new_lib_name)
|
818
817
|
@@xml_lib = new_lib_name
|
819
818
|
end
|
820
|
-
|
819
|
+
|
821
820
|
attr_accessor :result
|
822
821
|
attr_reader :xmlpath
|
823
822
|
attr_accessor :xml_lib
|
824
823
|
attr_reader :full_tag_name
|
825
824
|
attr_reader :tag
|
826
|
-
|
825
|
+
|
827
826
|
def initialize(params={})
|
828
827
|
@xmlpath = ''
|
829
828
|
@full_tag_name = ''
|
@@ -858,57 +857,57 @@ module RightAws
|
|
858
857
|
# Get response body
|
859
858
|
xml_text = xml_text.body unless xml_text.is_a?(String)
|
860
859
|
@xml_lib = params[:xml_lib] || @xml_lib
|
861
|
-
# check that we had no problems with this library otherwise use default
|
862
|
-
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
860
|
+
# check that we had no problems with this library otherwise use default
|
861
|
+
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
863
862
|
# load xml library
|
864
863
|
if @xml_lib=='libxml' && !defined?(XML::SaxParser)
|
865
864
|
begin
|
866
865
|
require 'xml/libxml'
|
867
|
-
# is it new ? - Setup SaxParserCallback
|
866
|
+
# is it new ? - Setup SaxParserCallback
|
868
867
|
if XML::Parser::VERSION >= '0.5.1.0'
|
869
|
-
RightSaxParserCallback.include_callback
|
870
|
-
end
|
868
|
+
RightSaxParserCallback.include_callback
|
869
|
+
end
|
871
870
|
rescue LoadError => e
|
872
|
-
@@supported_xml_libs.delete(@xml_lib)
|
873
|
-
@xml_lib = DEFAULT_XML_LIBRARY
|
871
|
+
@@supported_xml_libs.delete(@xml_lib)
|
872
|
+
@xml_lib = DEFAULT_XML_LIBRARY
|
874
873
|
if @logger
|
875
874
|
@logger.error e.inspect
|
876
875
|
@logger.error e.backtrace
|
877
|
-
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
876
|
+
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
878
877
|
end
|
879
878
|
end
|
880
879
|
end
|
881
880
|
# Parse the xml text
|
882
881
|
case @xml_lib
|
883
|
-
when 'libxml'
|
882
|
+
when 'libxml'
|
884
883
|
if XML::Parser::VERSION >= '0.9.9'
|
885
884
|
# avoid warning on every usage
|
886
885
|
xml = XML::SaxParser.string(xml_text)
|
887
886
|
else
|
888
|
-
xml = XML::SaxParser.new
|
889
|
-
xml.string = xml_text
|
887
|
+
xml = XML::SaxParser.new
|
888
|
+
xml.string = xml_text
|
890
889
|
end
|
891
|
-
# check libxml-ruby version
|
890
|
+
# check libxml-ruby version
|
892
891
|
if XML::Parser::VERSION >= '0.5.1.0'
|
893
|
-
xml.callbacks = RightSaxParserCallback.new(self)
|
894
|
-
else
|
895
|
-
xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)}
|
892
|
+
xml.callbacks = RightSaxParserCallback.new(self)
|
893
|
+
else
|
894
|
+
xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)}
|
896
895
|
xml.on_characters{ |text| self.text(text)}
|
897
|
-
xml.on_end_element{ |name| self.tag_end(name)}
|
898
|
-
end
|
896
|
+
xml.on_end_element{ |name| self.tag_end(name)}
|
897
|
+
end
|
899
898
|
xml.parse
|
900
899
|
else
|
901
900
|
REXML::Document.parse_stream(xml_text, self)
|
902
901
|
end
|
903
902
|
end
|
904
|
-
# Parser must have a lots of methods
|
903
|
+
# Parser must have a lots of methods
|
905
904
|
# (see /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb)
|
906
905
|
# We dont need most of them in RightAWSParser and method_missing helps us
|
907
906
|
# to skip their definition
|
908
907
|
def method_missing(method, *params)
|
909
908
|
# if the method is one of known - just skip it ...
|
910
|
-
return if [:comment, :attlistdecl, :notationdecl, :elementdecl,
|
911
|
-
:entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction,
|
909
|
+
return if [:comment, :attlistdecl, :notationdecl, :elementdecl,
|
910
|
+
:entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction,
|
912
911
|
:doctype].include?(method)
|
913
912
|
# ... else - call super to raise an exception
|
914
913
|
super(method, params)
|
data/lib/ec2/right_ec2.rb
CHANGED
@@ -27,7 +27,7 @@ module RightAws
|
|
27
27
|
|
28
28
|
include RightAwsBaseInterface
|
29
29
|
|
30
|
-
API_VERSION = "
|
30
|
+
API_VERSION = "2010-07-28"
|
31
31
|
DEFAULT_HOST = 'rds.amazonaws.com'
|
32
32
|
DEFAULT_PORT = 443
|
33
33
|
DEFAULT_PROTOCOL = 'https'
|
@@ -126,7 +126,8 @@ module RightAws
|
|
126
126
|
# :availability_zone=>"us-east-1b",
|
127
127
|
# :master_username=>"username",
|
128
128
|
# :aws_id=>"kd-my-awesome-db-2",
|
129
|
-
# :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"
|
129
|
+
# :preferred_maintenance_window=>"Sun:05:00-Sun:09:00",
|
130
|
+
# :multi_az => false}]
|
130
131
|
#
|
131
132
|
# # Retrieve a custom DB instance.
|
132
133
|
# # The response is an +Array+ with a single instance record.
|
@@ -149,7 +150,8 @@ module RightAws
|
|
149
150
|
# :availability_zone=>"us-east-1b",
|
150
151
|
# :master_username=>"username",
|
151
152
|
# :aws_id=>"kd-my-awesome-db-2",
|
152
|
-
# :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"
|
153
|
+
# :preferred_maintenance_window=>"Sun:05:00-Sun:09:00",
|
154
|
+
# :multi_az => false}]}
|
153
155
|
# true
|
154
156
|
# end
|
155
157
|
#
|
@@ -170,7 +172,7 @@ module RightAws
|
|
170
172
|
# Mandatory arguments: +aws_id+, +master_username+, +master_user_password+
|
171
173
|
# Optional params: +:allocated_storage+ (25 by def), +:instance_class+, +:engine+ ('MySQL5.1' by def),
|
172
174
|
# +:endpoint_port+, +:db_name+, +:db_security_groups+, +:db_parameter_group+, +:availability_zone+, +:preferred_maintenance_window+
|
173
|
-
# +:backup_retention_period+, +:preferred_backup_window
|
175
|
+
# +:backup_retention_period+, +:preferred_backup_window+, :multi_az (false by def)
|
174
176
|
#
|
175
177
|
# ds.create_db_instance('my-awesome-db', 'username', 'password') #=>
|
176
178
|
# {:instance_class=>"Medium",
|
@@ -204,6 +206,7 @@ module RightAws
|
|
204
206
|
request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].blank?
|
205
207
|
request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].blank?
|
206
208
|
request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].blank?
|
209
|
+
request_hash['MultiAZ'] = params[:multi_az] unless params[:multi_az].blank?
|
207
210
|
request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups]))
|
208
211
|
# request_hash.merge!(amazonize_list('DBParameterGroups.member', params[:db_parameter_groups]))
|
209
212
|
request_hash['DBParameterGroup'] = params[:db_parameter_group] unless params[:db_parameter_group].blank?
|
@@ -817,6 +820,7 @@ module RightAws
|
|
817
820
|
when 'PreferredMaintenanceWindow' then @db_instance[:preferred_maintenance_window] = @text
|
818
821
|
when 'BackupRetentionPeriod' then @db_instance[:backup_retention_period] = @text
|
819
822
|
when 'PreferredBackupWindow' then @db_instance[:preferred_backup_window] = @text
|
823
|
+
when 'MultiAZ' then @db_instance[:multi_az] = @text == 'true'
|
820
824
|
when 'DBInstanceClass'
|
821
825
|
case @xmlpath
|
822
826
|
when /PendingModifiedValues$/ then @db_instance[:pending_modified_values][:instance_class] = @text
|
data/lib/right_aws.rb
CHANGED
@@ -47,6 +47,7 @@ require 'ec2/right_ec2_ebs'
|
|
47
47
|
require 'ec2/right_ec2_reserved_instances'
|
48
48
|
require 'ec2/right_ec2_vpc'
|
49
49
|
require 'ec2/right_ec2_monitoring'
|
50
|
+
require 'ec2/right_ec2_tags'
|
50
51
|
require 'elb/right_elb_interface'
|
51
52
|
require 'acw/right_acw_interface'
|
52
53
|
require 'as/right_as_interface'
|
@@ -67,7 +68,7 @@ module RightAws #:nodoc:
|
|
67
68
|
module VERSION #:nodoc:
|
68
69
|
MAJOR = 2 unless defined?(MAJOR)
|
69
70
|
MINOR = 0 unless defined?(MINOR)
|
70
|
-
TINY =
|
71
|
+
TINY = 2 unless defined?(TINY)
|
71
72
|
|
72
73
|
STRING = [MAJOR, MINOR, TINY].join('.') unless defined?(STRING)
|
73
74
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ktheory-right_aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- RightScale, Inc.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-22 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -58,12 +58,12 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
61
|
+
hash: 19
|
62
62
|
segments:
|
63
63
|
- 2
|
64
64
|
- 6
|
65
|
-
-
|
66
|
-
version: 2.6.
|
65
|
+
- 2
|
66
|
+
version: 2.6.2
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id003
|
69
69
|
description: |-
|
@@ -146,7 +146,7 @@ files:
|
|
146
146
|
- test/rds/test_helper.rb
|
147
147
|
- test/rds/test_right_rds.rb
|
148
148
|
has_rdoc: true
|
149
|
-
homepage:
|
149
|
+
homepage:
|
150
150
|
licenses: []
|
151
151
|
|
152
152
|
post_install_message:
|