right_aws 1.3.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +47 -45
- data/Rakefile +1 -1
- data/lib/awsbase/right_awsbase.rb +104 -19
- data/lib/ec2/right_ec2.rb +226 -74
- data/lib/right_aws.rb +2 -2
- data/lib/s3/right_s3.rb +1 -1
- data/lib/s3/right_s3_interface.rb +8 -3
- data/lib/sqs/right_sqs.rb +1 -1
- data/lib/sqs/right_sqs_interface.rb +12 -3
- data/test/http_connection.rb +3 -1
- data/test/sqs/test_right_sqs.rb +29 -9
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,66 +1,68 @@
|
|
1
|
-
== 1.1.0
|
1
|
+
== 1.1.0 2007-08-10
|
2
2
|
Initial release.
|
3
3
|
|
4
|
-
== 1.2.0
|
5
|
-
------------------------------------------------------------------------
|
6
|
-
r1718 | todd | 2007-09-12 15:34:37 -0700 (Wed, 12 Sep 2007) | 3 lines
|
4
|
+
== 1.2.0 2007-09-12
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
* r1718, todd, 2007-09-12 15:34:37
|
7
|
+
* # 458, Extensive documentation review, rework, and expansion. Also added
|
8
|
+
coverage analysis to the test suite using RCov.
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
* r1690, todd, 2007-09-07 15:23:11
|
11
|
+
* # 447, Add support.rb to manifest
|
13
12
|
|
14
|
-
|
13
|
+
* r1688, todd, 2007-09-07 13:57:39
|
14
|
+
* # 447, Use Active Support if available, but don't require it. Load our own
|
15
|
+
extensions if it's not present. This keeps us from overloading ActiveSupport if
|
16
|
+
a user's already using it.
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
* r1687, todd, 2007-09-07 11:36:43
|
19
|
+
* # 447, Removed dependency on activesupport
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
a user's already using it.
|
21
|
+
* r1676, konstantin, 2007-09-06 01:27:09
|
22
|
+
* paid AMIs, small fix
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
* r1667, konstantin, 2007-09-05 12:58:10
|
25
|
+
* # 427, paid AMI support for ec2_instances
|
25
26
|
|
26
|
-
|
27
|
+
* r1658, konstantin, 2007-09-05 01:02:25
|
28
|
+
* params improvements for ec2.describe_xxx, now ones can use a String as well as an Array.
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
* r1653, konstantin, 2007-09-04 12:31:19
|
31
|
+
* libxml and paid AMI support added
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
r1667 | konstantin | 2007-09-05 12:58:10 -0700 (Wed, 05 Sep 2007) | 1 line
|
33
|
+
* r1581, tve, 2007-08-24 16:21:45
|
34
|
+
* Improved RightAws documentation
|
34
35
|
|
35
|
-
|
36
|
-
------------------------------------------------------------------------
|
37
|
-
r1658 | konstantin | 2007-09-05 01:02:25 -0700 (Wed, 05 Sep 2007) | 1 line
|
36
|
+
== 1.3.0 2007-09-26
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
* r1754, todd, 2007-09-19 13:48:34
|
39
|
+
* # 487, # 488, Consolidate a lot of code that was repeated in three places.
|
40
|
+
Fix error handling path when using streaming GET interfaces with S3.
|
41
|
+
Also add a stub for RightHttpConnection which allows more control over the
|
42
|
+
unit tests. Expand the unit tests and coverage tests.
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
r1581 | tve | 2007-08-24 16:21:45 -0700 (Fri, 24 Aug 2007) | 1 line
|
44
|
+
* r1755, todd, 2007-09-19 14:29:19
|
45
|
+
* # 487, RDoc fixes after code consolidation
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
* r1866, konstantin, 2007-10-05 06:17:36
|
48
|
+
* # 220, close connection on HTTP 5xx/4xx errors
|
49
49
|
|
50
|
-
== 1.
|
51
|
-
------------------------------------------------------------------------
|
52
|
-
r1754 | todd | 2007-09-19 13:48:34 -0700 (Wed, 19 Sep 2007) | 6 lines
|
50
|
+
== 1.4.0 2007-10-10
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
Also add a stub for RightHttpConnection which
|
57
|
-
allows more control over the unit tests. Expand the unit tests and coverage
|
58
|
-
tests.
|
59
|
-
------------------------------------------------------------------------
|
60
|
-
r1755 | todd | 2007-09-19 14:29:19 -0700 (Wed, 19 Sep 2007) | 2 lines
|
52
|
+
* r1868, konstantin, 2007-10-05 06:38:37
|
53
|
+
* # 220, inst_type branch merge into 1.3.0 release
|
61
54
|
|
62
|
-
|
55
|
+
* r1869, konstantin, 2007-10-05 07:32:34
|
56
|
+
* right_http_connection 1.1.1 requirements fixed
|
63
57
|
|
64
|
-
|
58
|
+
* r1879, konstantin, 2007-10-07 02:11:24
|
59
|
+
* # 524, blocks added to ec2_describe_xxx to support aws_cache
|
65
60
|
|
61
|
+
* r1924, konstantin, 2007-10-12 11:35:06
|
62
|
+
* # 536, user_data bug fix
|
66
63
|
|
64
|
+
* r1929, tve, 2007-10-15 00:00:11
|
65
|
+
* Fix libxml/rexml selection bug
|
66
|
+
|
67
|
+
* r1938, konstantin, 2007-10-16 10:53:56
|
68
|
+
* instance type support is set to default
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Hoe.new('right_aws', RightAws::VERSION::STRING) do |p|
|
|
18
18
|
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
19
19
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
20
20
|
p.remote_rdoc_dir = "/right_aws_gem_doc"
|
21
|
-
p.extra_deps = [['right_http_connection','>=
|
21
|
+
p.extra_deps = [['right_http_connection','>= 1.2.0']]
|
22
22
|
p.test_globs = testglobs
|
23
23
|
end
|
24
24
|
|
@@ -89,6 +89,8 @@ module RightAws
|
|
89
89
|
attr_accessor :logger
|
90
90
|
# Initial params hash
|
91
91
|
attr_accessor :params
|
92
|
+
# RightHttpConnection instance
|
93
|
+
attr_reader :connection
|
92
94
|
|
93
95
|
def init(service_info, aws_access_key_id, aws_secret_access_key, params={}) #:nodoc:
|
94
96
|
@params = params
|
@@ -117,6 +119,7 @@ module RightAws
|
|
117
119
|
end
|
118
120
|
|
119
121
|
def request_info_impl(connection, benchblock, request, parser, &block) #:nodoc:
|
122
|
+
@connection = connection
|
120
123
|
@last_request = request[:request]
|
121
124
|
@last_response = nil
|
122
125
|
response=nil
|
@@ -131,7 +134,7 @@ module RightAws
|
|
131
134
|
# Exceptions can originate from code directly in the block, or from user
|
132
135
|
# code called in the other block which is passed to response.read_body.
|
133
136
|
benchblock.service.add! do
|
134
|
-
responsehdr = connection.request(request) do |response|
|
137
|
+
responsehdr = @connection.request(request) do |response|
|
135
138
|
#########
|
136
139
|
begin
|
137
140
|
@last_response = response
|
@@ -139,7 +142,7 @@ module RightAws
|
|
139
142
|
@error_handler = nil
|
140
143
|
response.read_body(&block)
|
141
144
|
else
|
142
|
-
@error_handler = AWSErrorHandler.new(self, parser, self.class.amazon_problems) unless @error_handler
|
145
|
+
@error_handler = AWSErrorHandler.new(self, parser, :errors_list => self.class.amazon_problems) unless @error_handler
|
143
146
|
check_result = @error_handler.check(request)
|
144
147
|
if check_result
|
145
148
|
@error_handler = nil
|
@@ -163,7 +166,7 @@ module RightAws
|
|
163
166
|
return parser.result
|
164
167
|
end
|
165
168
|
else
|
166
|
-
benchblock.service.add!{ response = connection.request(request) }
|
169
|
+
benchblock.service.add!{ response = @connection.request(request) }
|
167
170
|
# check response for errors...
|
168
171
|
@last_response = response
|
169
172
|
if response.is_a?(Net::HTTPSuccess)
|
@@ -171,7 +174,7 @@ module RightAws
|
|
171
174
|
benchblock.xml.add! { parser.parse(response) }
|
172
175
|
return parser.result
|
173
176
|
else
|
174
|
-
@error_handler = AWSErrorHandler.new(self, parser, self.class.amazon_problems) unless @error_handler
|
177
|
+
@error_handler = AWSErrorHandler.new(self, parser, :errors_list => self.class.amazon_problems) unless @error_handler
|
175
178
|
check_result = @error_handler.check(request)
|
176
179
|
if check_result
|
177
180
|
@error_handler = nil
|
@@ -256,6 +259,8 @@ module RightAws
|
|
256
259
|
|
257
260
|
|
258
261
|
class AWSErrorHandler
|
262
|
+
# 0-100 (%)
|
263
|
+
DEFAULT_CLOSE_ON_4XX_PROBABILITY = 10
|
259
264
|
|
260
265
|
@@reiteration_start_delay = 0.2
|
261
266
|
def self.reiteration_start_delay
|
@@ -273,20 +278,45 @@ module RightAws
|
|
273
278
|
@@reiteration_time = reiteration_time
|
274
279
|
end
|
275
280
|
|
276
|
-
|
281
|
+
@@close_on_error = true
|
282
|
+
def self.close_on_error
|
283
|
+
@@close_on_error
|
284
|
+
end
|
285
|
+
def self.close_on_error=(close_on_error)
|
286
|
+
@@close_on_error = close_on_error
|
287
|
+
end
|
288
|
+
|
289
|
+
@@close_on_4xx_probability = DEFAULT_CLOSE_ON_4XX_PROBABILITY
|
290
|
+
def self.close_on_4xx_probability
|
291
|
+
@@close_on_4xx_probability
|
292
|
+
end
|
293
|
+
def self.close_on_4xx_probability=(close_on_4xx_probability)
|
294
|
+
@@close_on_4xx_probability = close_on_4xx_probability
|
295
|
+
end
|
296
|
+
|
297
|
+
# params:
|
298
|
+
# :reiteration_time
|
299
|
+
# :errors_list
|
300
|
+
# :close_on_error = true | false
|
301
|
+
# :close_on_4xx_probability = 1-100
|
302
|
+
def initialize(aws, parser, params={}) #:nodoc:
|
277
303
|
@aws = aws # Link to RightEc2 | RightSqs | RightS3 instance
|
278
304
|
@parser = parser # parser to parse Amazon response
|
279
305
|
@started_at = Time.now
|
280
|
-
@stop_at = @started_at + (reiteration_time || @@reiteration_time)
|
281
|
-
@errors_list = errors_list || []
|
306
|
+
@stop_at = @started_at + (params[:reiteration_time] || @@reiteration_time)
|
307
|
+
@errors_list = params[:errors_list] || []
|
282
308
|
@reiteration_delay = @@reiteration_start_delay
|
283
309
|
@retries = 0
|
310
|
+
# close current HTTP(S) connection on 5xx, errors from list and 4xx errors
|
311
|
+
@close_on_error = params[:close_on_error].nil? ? @@close_on_error : params[:close_on_error]
|
312
|
+
@close_on_4xx_probability = params[:close_on_4xx_probability] || @@close_on_4xx_probability
|
284
313
|
end
|
285
314
|
|
286
315
|
# Returns false if
|
287
316
|
def check(request) #:nodoc:
|
288
317
|
result = false
|
289
318
|
error_found = false
|
319
|
+
error_match = nil
|
290
320
|
last_errors_text = ''
|
291
321
|
response = @aws.last_response
|
292
322
|
# log error
|
@@ -311,12 +341,20 @@ module RightAws
|
|
311
341
|
@errors_list.each do |error_to_find|
|
312
342
|
if last_errors_text[/#{error_to_find}/i]
|
313
343
|
error_found = true
|
344
|
+
error_match = error_to_find
|
314
345
|
@aws.logger.warn("##### Retry is needed, error pattern match: #{error_to_find} #####")
|
315
346
|
break
|
316
347
|
end
|
317
348
|
end
|
318
349
|
# check the time has gone from the first error come
|
319
350
|
if error_found
|
351
|
+
# Close the connection to the server and recreate a new one.
|
352
|
+
# It may have a chance that one server is a semi-down and reconnection
|
353
|
+
# will help us to connect to the other server
|
354
|
+
if @close_on_error
|
355
|
+
@aws.connection.finish "#{self.class.name}: error match to pattern '#{error_match}'"
|
356
|
+
end
|
357
|
+
|
320
358
|
if (Time.now < @stop_at)
|
321
359
|
@retries += 1
|
322
360
|
@aws.logger.warn("##### Retry ##{@retries} is being performed. Sleeping for #{@reiteration_delay} sec. Whole time: #{Time.now-@started_at} sec ####")
|
@@ -326,6 +364,16 @@ module RightAws
|
|
326
364
|
result = @aws.request_info(request, @parser)
|
327
365
|
else
|
328
366
|
@aws.logger.warn("##### Ooops, time is over... ####")
|
367
|
+
end
|
368
|
+
# aha, this is unhandled error:
|
369
|
+
elsif @close_on_error
|
370
|
+
# Is this a 5xx error ?
|
371
|
+
if @aws.last_response.code.to_s[/^5\d\d$/]
|
372
|
+
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}'"
|
373
|
+
# Is this a 4xxx error ?
|
374
|
+
elsif @aws.last_response.code.to_s[/^4\d\d$/] && @close_on_4xx_probability > rand(100)
|
375
|
+
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}', " +
|
376
|
+
"probability: #{@close_on_4xx_probability}%"
|
329
377
|
end
|
330
378
|
end
|
331
379
|
result
|
@@ -336,8 +384,36 @@ module RightAws
|
|
336
384
|
|
337
385
|
#-----------------------------------------------------------------
|
338
386
|
|
387
|
+
class RightSaxParserCallback #:nodoc:
|
388
|
+
def self.include_callback
|
389
|
+
include XML::SaxParser::Callbacks
|
390
|
+
end
|
391
|
+
def initialize(right_aws_parser)
|
392
|
+
@right_aws_parser = right_aws_parser
|
393
|
+
end
|
394
|
+
def on_start_element(name, attr_hash)
|
395
|
+
@right_aws_parser.tag_start(name, attr_hash)
|
396
|
+
end
|
397
|
+
def on_characters(chars)
|
398
|
+
@right_aws_parser.text(chars)
|
399
|
+
end
|
400
|
+
def on_end_element(name)
|
401
|
+
@right_aws_parser.tag_end(name)
|
402
|
+
end
|
403
|
+
def on_start_document; end
|
404
|
+
def on_comment(msg); end
|
405
|
+
def on_processing_instruction(target, data); end
|
406
|
+
def on_cdata_block(cdata); end
|
407
|
+
def on_end_document; end
|
408
|
+
end
|
409
|
+
|
339
410
|
class RightAWSParser #:nodoc:
|
340
|
-
|
411
|
+
# default parsing library
|
412
|
+
DEFAULT_XML_LIBRARY = 'rexml'
|
413
|
+
# a list of supported parsers
|
414
|
+
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
415
|
+
|
416
|
+
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
341
417
|
def self.xml_lib
|
342
418
|
@@xml_lib
|
343
419
|
end
|
@@ -379,32 +455,41 @@ module RightAws
|
|
379
455
|
# Get response body
|
380
456
|
xml_text = xml_text.body unless xml_text.is_a?(String)
|
381
457
|
@xml_lib = params[:xml_lib] || @xml_lib
|
458
|
+
# check that we had no problems with this library otherwise use default
|
459
|
+
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
382
460
|
# load xml library
|
383
461
|
if @xml_lib=='libxml' && !defined?(XML::SaxParser)
|
384
462
|
begin
|
385
|
-
require 'xml/libxml'
|
463
|
+
require 'xml/libxml'
|
464
|
+
# is it new ? - Setup SaxParserCallback
|
465
|
+
if XML::Parser::VERSION >= '0.5.1.0'
|
466
|
+
RightSaxParserCallback.include_callback
|
467
|
+
end
|
386
468
|
rescue LoadError => e
|
387
|
-
@xml_lib
|
469
|
+
@@supported_xml_libs.delete(@xml_lib)
|
470
|
+
@xml_lib = DEFAULT_XML_LIBRARY
|
388
471
|
if @logger
|
389
472
|
@logger.error e.inspect
|
390
473
|
@logger.error e.backtrace
|
391
|
-
@logger.info "Can not load 'libxml' library. '
|
474
|
+
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
392
475
|
end
|
393
476
|
end
|
394
477
|
end
|
395
478
|
# Parse the xml text
|
396
479
|
case @xml_lib
|
397
480
|
when 'libxml'
|
398
|
-
xml
|
399
|
-
xml.string = xml_text
|
400
|
-
|
401
|
-
|
402
|
-
|
481
|
+
xml = XML::SaxParser.new
|
482
|
+
xml.string = xml_text
|
483
|
+
# check libxml-ruby version
|
484
|
+
if XML::Parser::VERSION >= '0.5.1.0'
|
485
|
+
xml.callbacks = RightSaxParserCallback.new(self)
|
486
|
+
else
|
487
|
+
xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)}
|
488
|
+
xml.on_characters{ |text| self.text(text)}
|
489
|
+
xml.on_end_element{ |name| self.tag_end(name)}
|
490
|
+
end
|
403
491
|
xml.parse
|
404
492
|
else
|
405
|
-
if @logger && @xml_lib!='rexml'
|
406
|
-
@logger.info "RightAWSParser#parse: Unknown xml library ('#{@xml_lib}') is selected. The default 'rexml' is used."
|
407
|
-
end
|
408
493
|
REXML::Document.parse_stream(xml_text, self)
|
409
494
|
end
|
410
495
|
end
|
data/lib/ec2/right_ec2.rb
CHANGED
@@ -68,7 +68,7 @@ module RightAws
|
|
68
68
|
|
69
69
|
SIGNATURE_VERSION = "1"
|
70
70
|
# Amazon EC2 API version being used
|
71
|
-
API_VERSION = "2007-
|
71
|
+
API_VERSION = "2007-08-29"
|
72
72
|
DEFAULT_HOST = "ec2.amazonaws.com"
|
73
73
|
DEFAULT_PROTOCOL = 'https'
|
74
74
|
DEFAULT_PORT = 443
|
@@ -76,7 +76,11 @@ module RightAws
|
|
76
76
|
# Default addressing type (public=NAT, direct=no-NAT) used when launching instances.
|
77
77
|
DEFAULT_ADDRESSING_TYPE = 'public'
|
78
78
|
DNS_ADDRESSING_SET = ['public','direct']
|
79
|
-
|
79
|
+
|
80
|
+
# Default EC2 instance type (platform)
|
81
|
+
DEFAULT_INSTANCE_TYPE = 'm1.small'
|
82
|
+
INSTANCE_TYPES = ['m1.small','m1.large','m1.xlarge']
|
83
|
+
|
80
84
|
@@bench = AwsBenchmarkingBlock.new
|
81
85
|
def self.bench_xml
|
82
86
|
@@bench.xml
|
@@ -85,6 +89,12 @@ module RightAws
|
|
85
89
|
@@bench.service
|
86
90
|
end
|
87
91
|
|
92
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
93
|
+
@@api = ENV['EC2_API_VERSION'] || API_VERSION
|
94
|
+
def self.api
|
95
|
+
@@api
|
96
|
+
end
|
97
|
+
|
88
98
|
# Create a new handle to an EC2 account. All handles share the same per process or per thread
|
89
99
|
# HTTP connection to Amazon EC2. Each handle is for a specific account. The params have the
|
90
100
|
# following options:
|
@@ -94,9 +104,14 @@ module RightAws
|
|
94
104
|
# * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
|
95
105
|
# * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
|
96
106
|
#
|
97
|
-
def initialize(aws_access_key_id, aws_secret_access_key, params={})
|
98
|
-
init({:name=>'EC2',
|
99
|
-
|
107
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
108
|
+
init({ :name => 'EC2',
|
109
|
+
:default_host => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).host : DEFAULT_HOST,
|
110
|
+
:default_port => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).port : DEFAULT_PORT,
|
111
|
+
:default_protocol => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).scheme : DEFAULT_PROTOCOL },
|
112
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
|
113
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
114
|
+
params)
|
100
115
|
end
|
101
116
|
|
102
117
|
|
@@ -104,7 +119,7 @@ module RightAws
|
|
104
119
|
timestamp = ( Time::now ).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
105
120
|
request_hash = {"Action" => action,
|
106
121
|
"AWSAccessKeyId" => @aws_access_key_id,
|
107
|
-
"Version" =>
|
122
|
+
"Version" => @@api,
|
108
123
|
"Timestamp" => timestamp,
|
109
124
|
"SignatureVersion" => SIGNATURE_VERSION }
|
110
125
|
request_hash.update(param)
|
@@ -139,18 +154,26 @@ module RightAws
|
|
139
154
|
#-----------------------------------------------------------------
|
140
155
|
#-----------------------------------------------------------------
|
141
156
|
|
142
|
-
def ec2_describe_images(type, list) #:nodoc:
|
157
|
+
def ec2_describe_images(type, list, &block) #:nodoc:
|
143
158
|
link = generate_request("DescribeImages", hash_params(type,list.to_a))
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
159
|
+
# We do not want to break the logic of parsing hence will use a dummy parser to process all the standart
|
160
|
+
# steps (errors checking etc). The dummy parser does nothig - just returns back the params it received.
|
161
|
+
# Then call the block (if it is) with the response. If the block returns +nil+ or +false+ then do not process
|
162
|
+
# real response parsing and exit with +nil+. Otherwise process parsing and return its result.
|
163
|
+
response, params = request_info(link, QEc2DummyParser.new)
|
164
|
+
if block
|
165
|
+
return nil unless block.call(response)
|
166
|
+
end
|
167
|
+
parser = QEc2DescribeImagesParser.new(:logger => @logger)
|
168
|
+
@@bench.xml.add!{ parser.parse(response, params) }
|
169
|
+
parser.result.collect do |image|
|
170
|
+
{ :aws_id => image.imageId,
|
171
|
+
:aws_location => image.imageLocation,
|
172
|
+
:aws_owner => image.imageOwnerId,
|
173
|
+
:aws_state => image.imageState.downcase,
|
174
|
+
:aws_is_public => image.isPublic,
|
175
|
+
:aws_product_codes => image.productCodes }
|
152
176
|
end
|
153
|
-
images
|
154
177
|
rescue Exception
|
155
178
|
on_exception
|
156
179
|
end
|
@@ -175,8 +198,19 @@ module RightAws
|
|
175
198
|
# :aws_location => "marcins_cool_public_images/ubuntu-6.10.manifest.xml",
|
176
199
|
# :aws_is_public => true}]
|
177
200
|
#
|
178
|
-
|
179
|
-
|
201
|
+
# If a block is given then yields a respose before parsing.
|
202
|
+
# If the block returns +false+ or +nil+ the response is not parsed
|
203
|
+
# and describe_images returns +nil+.
|
204
|
+
#
|
205
|
+
# images = ec2.describe_images do |response|
|
206
|
+
# # Compare the response to the previous. If they are the same skip parsing - nothing
|
207
|
+
# # has changed at Amazon. Skpping the parsing will save us a lots of time for the big
|
208
|
+
# # responses.
|
209
|
+
# response.body == previous_response_body ? false : true
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
def describe_images(list=[], &block)
|
213
|
+
ec2_describe_images('ImageId', list, &block)
|
180
214
|
end
|
181
215
|
|
182
216
|
#
|
@@ -185,8 +219,8 @@ module RightAws
|
|
185
219
|
# ec2.describe_images_by_owner('522821470517')
|
186
220
|
# ec2.describe_images_by_owner('self')
|
187
221
|
#
|
188
|
-
def describe_images_by_owner(list)
|
189
|
-
ec2_describe_images('Owner', list)
|
222
|
+
def describe_images_by_owner(list, &block)
|
223
|
+
ec2_describe_images('Owner', list, &block)
|
190
224
|
end
|
191
225
|
|
192
226
|
#
|
@@ -195,8 +229,8 @@ module RightAws
|
|
195
229
|
# ec2.describe_images_by_executable_by('522821470517')
|
196
230
|
# ec2.describe_images_by_executable_by('self')
|
197
231
|
#
|
198
|
-
def describe_images_by_executable_by(list)
|
199
|
-
ec2_describe_images('ExecutableBy', list)
|
232
|
+
def describe_images_by_executable_by(list, &block)
|
233
|
+
ec2_describe_images('ExecutableBy', list, &block)
|
200
234
|
end
|
201
235
|
|
202
236
|
|
@@ -344,7 +378,8 @@ module RightAws
|
|
344
378
|
:ssh_key_name => instance.keyName,
|
345
379
|
:aws_image_id => instance.imageId,
|
346
380
|
:aws_reason => reason,
|
347
|
-
:aws_product_codes => instance.productCodes
|
381
|
+
:aws_product_codes => instance.productCodes,
|
382
|
+
:aws_instance_type => instance.instanceType}
|
348
383
|
end
|
349
384
|
end
|
350
385
|
result
|
@@ -366,13 +401,30 @@ module RightAws
|
|
366
401
|
# :dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
|
367
402
|
# :ssh_key_name => "staging",
|
368
403
|
# :aws_groups => ["default"],
|
369
|
-
# :private_dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com"
|
404
|
+
# :private_dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
|
405
|
+
# :aws_instance_type => "m1.small"},
|
370
406
|
# ..., {...}]
|
371
407
|
#
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
408
|
+
# If a block is given then yields a respose before parsing.
|
409
|
+
# If the block returns +false+ or +nil+ the response is not parsed
|
410
|
+
# and describe_instances returns +nil+.
|
411
|
+
#
|
412
|
+
# instances = ec2.describe_instances do |response|
|
413
|
+
# # Compare the response to the previous. If they are the same skip parsing - nothing
|
414
|
+
# # has changed at Amazon. Skpping the parsing will save us a lots of time for the big
|
415
|
+
# # responses.
|
416
|
+
# response.body == previous_response_body ? false : true
|
417
|
+
# end
|
418
|
+
#
|
419
|
+
def describe_instances(list=[], &block)
|
420
|
+
link = generate_request("DescribeInstances", hash_params('InstanceId',list.to_a))
|
421
|
+
response, params = request_info(link, QEc2DummyParser.new)
|
422
|
+
if block
|
423
|
+
return nil unless block.call(response)
|
424
|
+
end
|
425
|
+
parser = QEc2DescribeInstancesParser.new(:logger => @logger)
|
426
|
+
@@bench.xml.add!{ parser.parse(response, params) }
|
427
|
+
get_desc_instances(parser.result)
|
376
428
|
rescue Exception
|
377
429
|
on_exception
|
378
430
|
end
|
@@ -401,24 +453,77 @@ module RightAws
|
|
401
453
|
# :dns_name => "",
|
402
454
|
# :ssh_key_name => "my_awesome_key",
|
403
455
|
# :aws_groups => ["my_awesome_group"],
|
404
|
-
# :private_dns_name => ""
|
456
|
+
# :private_dns_name => "",
|
457
|
+
# :aws_instance_type => "m1.small"}]
|
405
458
|
#
|
406
|
-
def run_instances(image_id, min_count, max_count, group_ids, key_name, user_data='',
|
407
|
-
|
459
|
+
def run_instances(image_id, min_count, max_count, group_ids, key_name, user_data='',
|
460
|
+
addressing_type = DEFAULT_ADDRESSING_TYPE,
|
461
|
+
instance_type = DEFAULT_INSTANCE_TYPE)
|
462
|
+
launch_instances(image_id, { :min_count => min_count,
|
463
|
+
:max_count => max_count,
|
464
|
+
:user_data => user_data,
|
465
|
+
:group_ids => group_ids,
|
466
|
+
:key_name => key_name,
|
467
|
+
:instance_type => instance_type,
|
468
|
+
:addressing_type => addressing_type })
|
469
|
+
end
|
470
|
+
|
471
|
+
|
472
|
+
# Launch new EC2 instances. Returns a list of launched instances or an exception.
|
473
|
+
#
|
474
|
+
# lparams and their default values:
|
475
|
+
# :min_count - 1
|
476
|
+
# :max_count - 1
|
477
|
+
# :user_data - ''
|
478
|
+
# :group_ids - [] # == 'default'
|
479
|
+
# :key_name - nil
|
480
|
+
# :instance_type - DEFAULT_INSTACE_TYPE
|
481
|
+
# :addressing_type - DEFAULT_ADDRESSING_TYPE
|
482
|
+
#
|
483
|
+
# ec2.launch_instances('ami-e444444d', 'my_awesome_group', :user_data => "Woohoo!!!", \
|
484
|
+
# :addressing_type => "public", :key_name => "my_awesome_key") #=>
|
485
|
+
# [{:aws_image_id => "ami-e444444d",
|
486
|
+
# :aws_reason => "",
|
487
|
+
# :aws_state_code => "0",
|
488
|
+
# :aws_owner => "000000000888",
|
489
|
+
# :aws_instance_id => "i-123f1234",
|
490
|
+
# :aws_reservation_id => "r-aabbccdd",
|
491
|
+
# :aws_state => "pending",
|
492
|
+
# :dns_name => "",
|
493
|
+
# :ssh_key_name => "my_awesome_key",
|
494
|
+
# :aws_groups => ["default"],
|
495
|
+
# :private_dns_name => "",
|
496
|
+
# :aws_instance_type => "m1.small"}]
|
497
|
+
#
|
498
|
+
def launch_instances(image_id, lparams={})
|
499
|
+
defaults = {
|
500
|
+
:min_count => 1,
|
501
|
+
:max_count => 1,
|
502
|
+
:user_data => '',
|
503
|
+
:group_ids => [],
|
504
|
+
:key_name => nil,
|
505
|
+
:instance_type => DEFAULT_INSTANCE_TYPE,
|
506
|
+
:addressing_type => DEFAULT_ADDRESSING_TYPE
|
507
|
+
}
|
508
|
+
lparams = defaults.merge(lparams)
|
509
|
+
|
510
|
+
@logger.info("Launching instance of image #{image_id} for #{@aws_access_key_id}, " +
|
511
|
+
"key: #{lparams[:key_name]}, groups: #{(lparams[:group_ids]||[]).to_a.join(',')}")
|
408
512
|
# careful: keyName and securityGroups may be nil
|
409
|
-
params = hash_params('SecurityGroup', group_ids.to_a)
|
513
|
+
params = hash_params('SecurityGroup', lparams[:group_ids].to_a)
|
410
514
|
params.update( {'ImageId' => image_id,
|
411
|
-
'MinCount' => min_count.to_s,
|
412
|
-
'MaxCount' => max_count.to_s,
|
413
|
-
'AddressingType' => addressing_type })
|
414
|
-
params['
|
415
|
-
unless
|
416
|
-
|
515
|
+
'MinCount' => lparams[:min_count].to_s,
|
516
|
+
'MaxCount' => lparams[:max_count].to_s,
|
517
|
+
'AddressingType' => lparams[:addressing_type] })
|
518
|
+
params['InstanceType'] = lparams[:instance_type]
|
519
|
+
params['KeyName'] = lparams[:key_name] unless lparams[:key_name].blank?
|
520
|
+
unless lparams[:user_data].blank?
|
521
|
+
lparams[:user_data].strip!
|
417
522
|
# Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library.
|
418
523
|
# Amazon 169.254.169.254 does not like escaped symbols!
|
419
524
|
# And it doesn't like "\n" inside of encoded string! Grrr....
|
420
525
|
# Otherwise, some of UserData symbols will be lost...
|
421
|
-
params['UserData'] = Base64.encode64(user_data).delete("\n") unless user_data.blank?
|
526
|
+
params['UserData'] = Base64.encode64(lparams[:user_data]).delete("\n") unless lparams[:user_data].blank?
|
422
527
|
end
|
423
528
|
link = generate_request("RunInstances", params)
|
424
529
|
#debugger
|
@@ -501,12 +606,28 @@ module RightAws
|
|
501
606
|
# {:to_port => "443", :protocol => "tcp", :from_port => "443", :cidr_ips => "0.0.0.0/0"}]},
|
502
607
|
# ..., {...}]
|
503
608
|
#
|
504
|
-
|
609
|
+
# If a block is given then yields a respose before parsing.
|
610
|
+
# If the block returns +false+ or +nil+ the response is not parsed
|
611
|
+
# and describe_security_groups returns +nil+.
|
612
|
+
#
|
613
|
+
# groups = ec2.describe_security_groups do |response|
|
614
|
+
# # Compare the response to the previous. If they are the same skip parsing - nothing
|
615
|
+
# # has changed at Amazon. Skpping the parsing will save us a lots of time for the big
|
616
|
+
# # responses.
|
617
|
+
# response.body == previous_response_body ? false : true
|
618
|
+
# end
|
619
|
+
#
|
620
|
+
def describe_security_groups(list=[], &block)
|
505
621
|
link = generate_request("DescribeSecurityGroups", hash_params('GroupName',list.to_a))
|
506
|
-
|
622
|
+
response, params = request_info(link, QEc2DummyParser.new)
|
623
|
+
if block
|
624
|
+
return nil unless block.call(response)
|
625
|
+
end
|
626
|
+
parser = QEc2DescribeSecurityGroupsParser.new(:logger => @logger)
|
627
|
+
@@bench.xml.add!{ parser.parse(response, params) }
|
507
628
|
|
508
629
|
result = []
|
509
|
-
|
630
|
+
parser.result.each do |item|
|
510
631
|
perms = []
|
511
632
|
item.ipPermissions.each do |perm|
|
512
633
|
perm.groups.each do |ngroup|
|
@@ -636,14 +757,29 @@ module RightAws
|
|
636
757
|
# {:aws_fingerprint=> "1e:29:30:47:58:6d:7b:8c:9f:08:11:20:3c:44:52:69:74:80:97:08", :aws_key_name=>"key-2"},
|
637
758
|
# ..., {...} ]
|
638
759
|
#
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
760
|
+
# If a block is given then yields a respose before parsing.
|
761
|
+
# If the block returns +false+ or +nil+ the response is not parsed
|
762
|
+
# and describe_key_pairs returns +nil+.
|
763
|
+
#
|
764
|
+
# keys = ec2.describe_key_pairs do |response|
|
765
|
+
# # Compare the response to the previous. If they are the same skip parsing - nothing
|
766
|
+
# # has changed at Amazon. Skpping the parsing will save us a lots of time for the big
|
767
|
+
# # responses.
|
768
|
+
# response.body == previous_response_body ? false : true
|
769
|
+
# end
|
770
|
+
#
|
771
|
+
def describe_key_pairs(list=[], &block)
|
772
|
+
link = generate_request("DescribeKeyPairs", hash_params('KeyName',list.to_a))
|
773
|
+
response, params = request_info(link, QEc2DummyParser.new)
|
774
|
+
if block
|
775
|
+
return nil unless block.call(response)
|
776
|
+
end
|
777
|
+
parser = QEc2DescribeKeyPairParser.new(:logger => @logger)
|
778
|
+
@@bench.xml.add!{ parser.parse(response, params) }
|
779
|
+
parser.result.collect do |key|
|
780
|
+
{ :aws_key_name => key.keyName,
|
781
|
+
:aws_fingerprint => key.keyFingerprint }
|
645
782
|
end
|
646
|
-
result
|
647
783
|
rescue Exception
|
648
784
|
on_exception
|
649
785
|
end
|
@@ -685,7 +821,7 @@ module RightAws
|
|
685
821
|
# PARSERS: Boolean Response Parser
|
686
822
|
#-----------------------------------------------------------------
|
687
823
|
|
688
|
-
class RightBoolResponseParser < RightAWSParser
|
824
|
+
class RightBoolResponseParser < RightAWSParser #:nodoc:
|
689
825
|
def tagend(name)
|
690
826
|
@result = @text=='true' ? true : false if name == 'return'
|
691
827
|
end
|
@@ -695,16 +831,16 @@ module RightAws
|
|
695
831
|
# PARSERS: Key Pair
|
696
832
|
#-----------------------------------------------------------------
|
697
833
|
|
698
|
-
class QEc2DescribeKeyPairType
|
834
|
+
class QEc2DescribeKeyPairType #:nodoc:
|
699
835
|
attr_accessor :keyName
|
700
836
|
attr_accessor :keyFingerprint
|
701
837
|
end
|
702
838
|
|
703
|
-
class QEc2CreateKeyPairType < QEc2DescribeKeyPairType
|
839
|
+
class QEc2CreateKeyPairType < QEc2DescribeKeyPairType #:nodoc:
|
704
840
|
attr_accessor :keyMaterial
|
705
841
|
end
|
706
842
|
|
707
|
-
class QEc2DescribeKeyPairParser < RightAWSParser
|
843
|
+
class QEc2DescribeKeyPairParser < RightAWSParser #:nodoc:
|
708
844
|
def tagstart(name, attributes)
|
709
845
|
@item = QEc2DescribeKeyPairType.new if name == 'item'
|
710
846
|
end
|
@@ -720,7 +856,7 @@ module RightAws
|
|
720
856
|
end
|
721
857
|
end
|
722
858
|
|
723
|
-
class QEc2CreateKeyPairParser < RightAWSParser
|
859
|
+
class QEc2CreateKeyPairParser < RightAWSParser #:nodoc:
|
724
860
|
def tagstart(name, attributes)
|
725
861
|
@result = QEc2CreateKeyPairType.new if !@result
|
726
862
|
end
|
@@ -737,12 +873,12 @@ module RightAws
|
|
737
873
|
# PARSERS: Security Groups
|
738
874
|
#-----------------------------------------------------------------
|
739
875
|
|
740
|
-
class QEc2UserIdGroupPairType
|
876
|
+
class QEc2UserIdGroupPairType #:nodoc:
|
741
877
|
attr_accessor :userId
|
742
878
|
attr_accessor :groupName
|
743
879
|
end
|
744
880
|
|
745
|
-
class QEc2IpPermissionType
|
881
|
+
class QEc2IpPermissionType #:nodoc:
|
746
882
|
attr_accessor :ipProtocol
|
747
883
|
attr_accessor :fromPort
|
748
884
|
attr_accessor :toPort
|
@@ -750,7 +886,7 @@ module RightAws
|
|
750
886
|
attr_accessor :ipRanges
|
751
887
|
end
|
752
888
|
|
753
|
-
class QEc2SecurityGroupItemType
|
889
|
+
class QEc2SecurityGroupItemType #:nodoc:
|
754
890
|
attr_accessor :groupName
|
755
891
|
attr_accessor :groupDescription
|
756
892
|
attr_accessor :ownerId
|
@@ -758,7 +894,7 @@ module RightAws
|
|
758
894
|
end
|
759
895
|
|
760
896
|
|
761
|
-
class QEc2DescribeSecurityGroupsParser < RightAWSParser
|
897
|
+
class QEc2DescribeSecurityGroupsParser < RightAWSParser #:nodoc:
|
762
898
|
def tagstart(name, attributes)
|
763
899
|
case name
|
764
900
|
when 'item'
|
@@ -808,7 +944,7 @@ module RightAws
|
|
808
944
|
# PARSERS: Images
|
809
945
|
#-----------------------------------------------------------------
|
810
946
|
|
811
|
-
class QEc2DescribeImagesResponseItemType
|
947
|
+
class QEc2DescribeImagesResponseItemType #:nodoc:
|
812
948
|
attr_accessor :imageId
|
813
949
|
attr_accessor :imageState
|
814
950
|
attr_accessor :imageLocation
|
@@ -817,7 +953,7 @@ module RightAws
|
|
817
953
|
attr_accessor :productCodes
|
818
954
|
end
|
819
955
|
|
820
|
-
class QEc2DescribeImagesParser < RightAWSParser
|
956
|
+
class QEc2DescribeImagesParser < RightAWSParser #:nodoc:
|
821
957
|
def tagstart(name, attributes)
|
822
958
|
if name == 'item' && @xmlpath[%r{.*/imagesSet$}]
|
823
959
|
@image = QEc2DescribeImagesResponseItemType.new
|
@@ -839,7 +975,7 @@ module RightAws
|
|
839
975
|
end
|
840
976
|
end
|
841
977
|
|
842
|
-
class QEc2RegisterImageParser < RightAWSParser
|
978
|
+
class QEc2RegisterImageParser < RightAWSParser #:nodoc:
|
843
979
|
def tagend(name)
|
844
980
|
@result = @text if name == 'imageId'
|
845
981
|
end
|
@@ -849,18 +985,18 @@ module RightAws
|
|
849
985
|
# PARSERS: Image Attribute
|
850
986
|
#-----------------------------------------------------------------
|
851
987
|
|
852
|
-
class QEc2LaunchPermissionItemType
|
988
|
+
class QEc2LaunchPermissionItemType #:nodoc:
|
853
989
|
attr_accessor :groups
|
854
990
|
attr_accessor :userIds
|
855
991
|
end
|
856
992
|
|
857
|
-
class QEc2DescribeImageAttributeType
|
993
|
+
class QEc2DescribeImageAttributeType #:nodoc:
|
858
994
|
attr_accessor :imageId
|
859
995
|
attr_accessor :launchPermission
|
860
996
|
attr_accessor :productCodes
|
861
997
|
end
|
862
998
|
|
863
|
-
class QEc2DescribeImageAttributeParser < RightAWSParser
|
999
|
+
class QEc2DescribeImageAttributeParser < RightAWSParser #:nodoc:
|
864
1000
|
def tagstart(name, attributes)
|
865
1001
|
case name
|
866
1002
|
when 'launchPermission'
|
@@ -892,12 +1028,12 @@ module RightAws
|
|
892
1028
|
# PARSERS: Instances
|
893
1029
|
#-----------------------------------------------------------------
|
894
1030
|
|
895
|
-
class QEc2InstanceStateType
|
1031
|
+
class QEc2InstanceStateType #:nodoc:
|
896
1032
|
attr_accessor :code
|
897
1033
|
attr_accessor :name
|
898
1034
|
end
|
899
1035
|
|
900
|
-
class QEc2RunningInstancesItemType
|
1036
|
+
class QEc2RunningInstancesItemType #:nodoc:
|
901
1037
|
attr_accessor :instanceId
|
902
1038
|
attr_accessor :imageId
|
903
1039
|
attr_accessor :instanceState
|
@@ -907,16 +1043,17 @@ module RightAws
|
|
907
1043
|
attr_accessor :keyName
|
908
1044
|
attr_accessor :amiLaunchIndex
|
909
1045
|
attr_accessor :productCodes
|
1046
|
+
attr_accessor :instanceType
|
910
1047
|
end
|
911
1048
|
|
912
|
-
class QEc2DescribeInstancesType
|
1049
|
+
class QEc2DescribeInstancesType #:nodoc:
|
913
1050
|
attr_accessor :reservationId
|
914
1051
|
attr_accessor :ownerId
|
915
1052
|
attr_accessor :groupSet
|
916
1053
|
attr_accessor :instancesSet
|
917
1054
|
end
|
918
1055
|
|
919
|
-
class QEc2DescribeInstancesParser < RightAWSParser
|
1056
|
+
class QEc2DescribeInstancesParser < RightAWSParser #:nodoc:
|
920
1057
|
def tagstart(name, attributes)
|
921
1058
|
case name
|
922
1059
|
when 'item'
|
@@ -957,6 +1094,7 @@ module RightAws
|
|
957
1094
|
@result << @reservation
|
958
1095
|
end
|
959
1096
|
when 'productCode' ; (@instance.productCodes ||= []) << @text
|
1097
|
+
when 'instanceType' ; @instance.instanceType = @text
|
960
1098
|
end
|
961
1099
|
end
|
962
1100
|
def reset
|
@@ -964,7 +1102,7 @@ module RightAws
|
|
964
1102
|
end
|
965
1103
|
end
|
966
1104
|
|
967
|
-
class QEc2ConfirmProductInstanceParser < RightAWSParser
|
1105
|
+
class QEc2ConfirmProductInstanceParser < RightAWSParser #:nodoc:
|
968
1106
|
def tagend(name)
|
969
1107
|
@result = @text if name == 'ownerId'
|
970
1108
|
end
|
@@ -973,7 +1111,7 @@ module RightAws
|
|
973
1111
|
end
|
974
1112
|
end
|
975
1113
|
|
976
|
-
class QEc2RunInstancesParser < RightAWSParser
|
1114
|
+
class QEc2RunInstancesParser < RightAWSParser #:nodoc:
|
977
1115
|
def tagstart(name, attributes)
|
978
1116
|
case name
|
979
1117
|
when 'RunInstancesResponse'
|
@@ -1011,6 +1149,7 @@ module RightAws
|
|
1011
1149
|
@reservation.instancesSet << @instance if @xmlpath == 'RunInstancesResponse/instancesSet'
|
1012
1150
|
when 'RunInstancesResponse'; @result << @reservation
|
1013
1151
|
when 'productCode' ; (@instance.productCodes ||= []) << @text
|
1152
|
+
when 'instanceType' ; @instance.instanceType = @text
|
1014
1153
|
end
|
1015
1154
|
end
|
1016
1155
|
def reset
|
@@ -1018,13 +1157,13 @@ module RightAws
|
|
1018
1157
|
end
|
1019
1158
|
end
|
1020
1159
|
|
1021
|
-
class QEc2TerminateInstancesResponseInfoType
|
1160
|
+
class QEc2TerminateInstancesResponseInfoType #:nodoc:
|
1022
1161
|
attr_accessor :instanceId
|
1023
1162
|
attr_accessor :shutdownState
|
1024
1163
|
attr_accessor :previousState
|
1025
1164
|
end
|
1026
1165
|
|
1027
|
-
class QEc2TerminateInstancesParser < RightAWSParser
|
1166
|
+
class QEc2TerminateInstancesParser < RightAWSParser #:nodoc:
|
1028
1167
|
def tagstart(name, attributes)
|
1029
1168
|
if name == 'item'
|
1030
1169
|
@instance = QEc2TerminateInstancesResponseInfoType.new
|
@@ -1055,13 +1194,13 @@ module RightAws
|
|
1055
1194
|
# PARSERS: Console
|
1056
1195
|
#-----------------------------------------------------------------
|
1057
1196
|
|
1058
|
-
class QEc2GetConsoleOutputResponseType
|
1197
|
+
class QEc2GetConsoleOutputResponseType #:nodoc:
|
1059
1198
|
attr_accessor :instanceId
|
1060
1199
|
attr_accessor :timestamp
|
1061
1200
|
attr_accessor :output
|
1062
1201
|
end
|
1063
1202
|
|
1064
|
-
class QEc2GetConsoleOutputParser < RightAWSParser
|
1203
|
+
class QEc2GetConsoleOutputParser < RightAWSParser #:nodoc:
|
1065
1204
|
def tagend(name)
|
1066
1205
|
case name
|
1067
1206
|
when 'instanceId' ; @result.instanceId = @text
|
@@ -1076,4 +1215,17 @@ module RightAws
|
|
1076
1215
|
|
1077
1216
|
end
|
1078
1217
|
|
1218
|
+
#-----------------------------------------------------------------
|
1219
|
+
# PARSERS: Fake
|
1220
|
+
#-----------------------------------------------------------------
|
1221
|
+
|
1222
|
+
# Dummy parser - does nothing
|
1223
|
+
# Returns the original params back
|
1224
|
+
class QEc2DummyParser # :nodoc:
|
1225
|
+
attr_accessor :result
|
1226
|
+
def parse(response, params={})
|
1227
|
+
@result = [response, params]
|
1228
|
+
end
|
1229
|
+
end
|
1230
|
+
|
1079
1231
|
end
|
data/lib/right_aws.rb
CHANGED
data/lib/s3/right_s3.rb
CHANGED
@@ -41,7 +41,7 @@ module RightAws
|
|
41
41
|
# Create a new handle to an S3 account. All handles share the same per process or per thread
|
42
42
|
# HTTP connection to Amazon S3. Each handle is for a specific account.
|
43
43
|
# The +params+ are passed through as-is to RightAws::S3Interface.new
|
44
|
-
def initialize(aws_access_key_id, aws_secret_access_key, params={})
|
44
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
45
45
|
@interface = S3Interface.new(aws_access_key_id, aws_secret_access_key, params)
|
46
46
|
end
|
47
47
|
|
@@ -55,9 +55,14 @@ module RightAws
|
|
55
55
|
# :multi_thread => true|false # Multi-threaded (connection per each thread): true or false(default)
|
56
56
|
# :logger => Logger Object} # Logger instance: logs to STDOUT if omitted }
|
57
57
|
#
|
58
|
-
def initialize(aws_access_key_id, aws_secret_access_key, params={})
|
59
|
-
init({:name=>'S3',
|
60
|
-
|
58
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
59
|
+
init({ :name => 'S3',
|
60
|
+
:default_host => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).host : DEFAULT_HOST,
|
61
|
+
:default_port => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).port : DEFAULT_PORT,
|
62
|
+
:default_protocol => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).scheme : DEFAULT_PROTOCOL },
|
63
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
64
|
+
aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
|
65
|
+
params)
|
61
66
|
end
|
62
67
|
|
63
68
|
|
data/lib/sqs/right_sqs.rb
CHANGED
@@ -58,7 +58,7 @@ module RightAws
|
|
58
58
|
class Sqs
|
59
59
|
attr_reader :interface
|
60
60
|
|
61
|
-
def initialize(aws_access_key_id, aws_secret_access_key, params={})
|
61
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
62
62
|
@interface = SqsInterface.new(aws_access_key_id, aws_secret_access_key, params)
|
63
63
|
end
|
64
64
|
|
@@ -43,6 +43,10 @@ module RightAws
|
|
43
43
|
@@bench.service
|
44
44
|
end
|
45
45
|
|
46
|
+
@@api = API_VERSION
|
47
|
+
def self.api
|
48
|
+
@@api
|
49
|
+
end
|
46
50
|
|
47
51
|
# Creates a new SqsInterface instance.
|
48
52
|
#
|
@@ -55,9 +59,14 @@ module RightAws
|
|
55
59
|
# :multi_thread => true|false # Multi-threaded (connection per each thread): true or false(default)
|
56
60
|
# :logger => Logger Object} # Logger instance: logs to STDOUT if omitted }
|
57
61
|
#
|
58
|
-
def initialize(aws_access_key_id, aws_secret_access_key, params={})
|
59
|
-
init({:name=>'SQS',
|
60
|
-
|
62
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
63
|
+
init({ :name => 'SQS',
|
64
|
+
:default_host => ENV['SQS_URL'] ? URI.parse(ENV['SQS_URL']).host : DEFAULT_HOST,
|
65
|
+
:default_port => ENV['SQS_URL'] ? URI.parse(ENV['SQS_URL']).port : DEFAULT_PORT,
|
66
|
+
:default_protocol => ENV['SQS_URL'] ? URI.parse(ENV['SQS_URL']).scheme : DEFAULT_PROTOCOL },
|
67
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
68
|
+
aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
|
69
|
+
params)
|
61
70
|
end
|
62
71
|
|
63
72
|
|
data/test/http_connection.rb
CHANGED
@@ -23,6 +23,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
|
24
24
|
# Stub extension/redefinition of RightHttpConnection for testing purposes.
|
25
25
|
require 'net/http'
|
26
|
+
require 'rubygems'
|
26
27
|
require 'right_http_connection'
|
27
28
|
|
28
29
|
module Net
|
@@ -33,7 +34,8 @@ module Net
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def body
|
36
|
-
|
37
|
+
# defined?() helps us to get rid of a bunch of 'warnings'
|
38
|
+
(defined?(@mymsg) && @mymsg) ? @mymsg : real_body
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/test/sqs/test_right_sqs.rb
CHANGED
@@ -13,6 +13,24 @@ class TestSqs < Test::Unit::TestCase
|
|
13
13
|
@s = Rightscale::Sqs.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
14
14
|
end
|
15
15
|
|
16
|
+
# Wait for the queue to appears in the queues list.
|
17
|
+
# Amazon needs some time to after the queue creation to place
|
18
|
+
# it to the accessible queues list. If we dont want to get
|
19
|
+
# the additional faults then wait a bit...
|
20
|
+
def wait_for_queue_url(queue_name)
|
21
|
+
queue_url = nil
|
22
|
+
until queue_url
|
23
|
+
queue_url = @sqs.queue_url_by_name(queue_name)
|
24
|
+
unless queue_url
|
25
|
+
print '-'
|
26
|
+
STDOUT.flush
|
27
|
+
sleep 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
queue_url
|
31
|
+
end
|
32
|
+
|
33
|
+
|
16
34
|
#---------------------------
|
17
35
|
# Rightscale::SqsInterface
|
18
36
|
#---------------------------
|
@@ -23,6 +41,7 @@ class TestSqs < Test::Unit::TestCase
|
|
23
41
|
end
|
24
42
|
|
25
43
|
def test_02_list_queues
|
44
|
+
wait_for_queue_url(@queue_name)
|
26
45
|
queues = @sqs.list_queues('right_')
|
27
46
|
assert queues.size>0, 'Must more that 0 queues in list'
|
28
47
|
end
|
@@ -31,14 +50,14 @@ class TestSqs < Test::Unit::TestCase
|
|
31
50
|
queue_url = @sqs.queue_url_by_name(@queue_name)
|
32
51
|
assert queue_url[/http.*#{@queue_name}/], "#{@queue_name} must exist!"
|
33
52
|
assert @sqs.set_queue_attributes(queue_url, 'VisibilityTimeout', 111), 'Set_queue_attributes fail'
|
34
|
-
sleep
|
53
|
+
sleep 20 # Amazon needs some time to change attribute
|
35
54
|
assert_equal '111', @sqs.get_queue_attributes(queue_url)['VisibilityTimeout'], 'New VisibilityTimeout must be equal to 111'
|
36
55
|
end
|
37
56
|
|
38
57
|
def test_04_set_and_get_visibility_timeout
|
39
58
|
queue_url = @sqs.queue_url_by_name(@queue_name)
|
40
59
|
assert @sqs.set_visibility_timeout(queue_url, 222), 'Set_visibility_timeout fail'
|
41
|
-
sleep
|
60
|
+
sleep 20 # Amazon needs some time to change attribute
|
42
61
|
assert_equal 222, @sqs.get_visibility_timeout(queue_url), 'Get_visibility_timeout must return to 222'
|
43
62
|
end
|
44
63
|
|
@@ -103,6 +122,7 @@ class TestSqs < Test::Unit::TestCase
|
|
103
122
|
queue = @s.queue("#{@queue_name}_20", true)
|
104
123
|
# check that it is created
|
105
124
|
assert queue.is_a?(Rightscale::Sqs::Queue)
|
125
|
+
wait_for_queue_url(@queue_name)
|
106
126
|
# check that amount of queues has increased
|
107
127
|
assert_equal queues_size + 1, @s.queues.size
|
108
128
|
# delete queue
|
@@ -114,10 +134,10 @@ class TestSqs < Test::Unit::TestCase
|
|
114
134
|
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_21", true)
|
115
135
|
# check that it is created
|
116
136
|
assert queue.is_a?(Rightscale::Sqs::Queue)
|
137
|
+
wait_for_queue_url(@queue_name)
|
117
138
|
end
|
118
139
|
|
119
140
|
def test_22_queue_attributes
|
120
|
-
sleep 10
|
121
141
|
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_21", false)
|
122
142
|
# get a list of attrinutes
|
123
143
|
attributes = queue.get_attribute
|
@@ -127,7 +147,7 @@ class TestSqs < Test::Unit::TestCase
|
|
127
147
|
# set attribute
|
128
148
|
assert queue.set_attribute('VisibilityTimeout', v)
|
129
149
|
# wait a bit
|
130
|
-
sleep
|
150
|
+
sleep 20
|
131
151
|
# check that attribute has changed
|
132
152
|
assert_equal v, queue.get_attribute('VisibilityTimeout')
|
133
153
|
# get queue visibility timeout
|
@@ -219,14 +239,14 @@ class TestSqs < Test::Unit::TestCase
|
|
219
239
|
end
|
220
240
|
|
221
241
|
def test_27_set_amazon_problems
|
222
|
-
original_problems =
|
242
|
+
original_problems = Rightscale::SqsInterface.amazon_problems
|
223
243
|
assert(original_problems.length > 0)
|
224
|
-
|
225
|
-
new_problems =
|
244
|
+
Rightscale::SqsInterface.amazon_problems= original_problems << "A New Problem"
|
245
|
+
new_problems = Rightscale::SqsInterface.amazon_problems
|
226
246
|
assert_equal(new_problems, original_problems)
|
227
247
|
|
228
|
-
|
229
|
-
assert_nil(
|
248
|
+
Rightscale::SqsInterface.amazon_problems= nil
|
249
|
+
assert_nil(Rightscale::SqsInterface.amazon_problems)
|
230
250
|
end
|
231
251
|
|
232
252
|
def test_28_check_threading_model
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: right_aws
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.4.2
|
7
|
+
date: 2007-10-18 00:00:00 +04:00
|
8
8
|
summary: Interface classes for the Amazon EC2, SQS, and S3 Web Services
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 1.2.0
|
79
79
|
version:
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: hoe
|