right_aws 1.6.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +42 -8
- data/Manifest.txt +8 -7
- data/README.txt +3 -3
- data/Rakefile +7 -0
- data/lib/ec2/right_ec2.rb +378 -375
- data/lib/right_aws.rb +2 -2
- data/lib/sdb/active_sdb.rb +695 -0
- data/lib/sdb/right_sdb_interface.rb +5 -5
- data/lib/sqs/right_sqs_gen2.rb +2 -2
- data/test/ec2/test_right_ec2.rb +1 -1
- data/test/sdb/test_active_sdb.rb +249 -0
- metadata +11 -9
data/History.txt
CHANGED
@@ -71,6 +71,7 @@ Initial release.
|
|
71
71
|
|
72
72
|
* r1983, konstantin, 2007-10-25 22:33:00 +0400
|
73
73
|
* Fixed ActiveSupport requirement bug (thanks to Toby)
|
74
|
+
* Fixed HttpConnection logging to stdout bug (thanks to Toby)
|
74
75
|
|
75
76
|
== 1.4.4
|
76
77
|
|
@@ -131,6 +132,7 @@ r2922 | todd | 2008-03-03 15:26:42 -0800 (Mon, 03 Mar 2008) | 2 lines
|
|
131
132
|
couple of documentation tweaks in prep for 1.6.0
|
132
133
|
|
133
134
|
== 1.6.1 2008-03-14
|
135
|
+
|
134
136
|
------------------------------------------------------------------------
|
135
137
|
r2963 | todd | 2008-03-06 19:10:23 -0800 (Thu, 06 Mar 2008) | 3 lines
|
136
138
|
|
@@ -138,21 +140,53 @@ r2963 | todd | 2008-03-06 19:10:23 -0800 (Thu, 06 Mar 2008) | 3 lines
|
|
138
140
|
in
|
139
141
|
certain rare conditions
|
140
142
|
|
141
|
-
== 1.
|
143
|
+
== 1.7.0
|
144
|
+
|
145
|
+
r3051 | konstantin | 2008-03-14 21:26:12 +0300 (Fri, 14 Mar 2008) | 1 line
|
146
|
+
#897, ActiveSdb alpha release
|
147
|
+
|
148
|
+
<<<<<<< .mine
|
149
|
+
#897, ActiveSdb alpha release
|
150
|
+
|
142
151
|
------------------------------------------------------------------------
|
143
|
-
|
152
|
+
r3204 | todd | 2008-03-26 17:50:45 -0700 (Wed, 26 Mar 2008) | 4 lines
|
144
153
|
|
145
|
-
|
154
|
+
Do not autoload right_sdb with the rest of the modules; it requires uuidtools.
|
155
|
+
We want the user to explicly request ActiveSdb, at least as long as it is
|
156
|
+
alpha/beta.
|
146
157
|
|
147
158
|
------------------------------------------------------------------------
|
148
|
-
|
159
|
+
r3220 | konstantin | 2008-03-26 23:03:51 -0700 (Wed, 26 Mar 2008) | 1 line
|
149
160
|
|
150
|
-
|
151
|
-
|
161
|
+
mark ActiveSdb release as alpha,(port to 1.7.0)
|
162
|
+
------------------------------------------------------------------------
|
163
|
+
r3229 | konstantin | 2008-03-27 03:43:17 -0700 (Thu, 27 Mar 2008) | 1 line
|
164
|
+
|
165
|
+
aws pcode fix (release 2.5)
|
166
|
+
------------------------------------------------------------------------
|
167
|
+
r3243 | todd | 2008-03-27 12:10:49 -0700 (Thu, 27 Mar 2008) | 1 line
|
152
168
|
|
169
|
+
(#991) Bring SqsGen2::Queue.pop fix into 1.7.0. Also bring removal of
|
170
|
+
uuidtools dependency.
|
153
171
|
------------------------------------------------------------------------
|
154
|
-
|
172
|
+
r3249 | todd | 2008-03-27 17:59:14 -0700 (Thu, 27 Mar 2008) | 1 line
|
155
173
|
|
156
|
-
|
174
|
+
(#991) Print an informational message if the require of uuidtools fails for
|
175
|
+
ActiveSdb. Update RDoc to show how to include ActiveSdb class. Update README
|
176
|
+
to point to ActiveSdb RDoc.
|
177
|
+
------------------------------------------------------------------------
|
178
|
+
r3250 | todd | 2008-03-27 18:03:09 -0700 (Thu, 27 Mar 2008) | 2 lines
|
179
|
+
|
180
|
+
(#991) Change manifest entry from right_sdb to active_sdb
|
181
|
+
|
182
|
+
------------------------------------------------------------------------
|
183
|
+
r3251 | todd | 2008-03-27 18:03:33 -0700 (Thu, 27 Mar 2008) | 1 line
|
184
|
+
|
185
|
+
(#991) Rename file from right_sdb to active_sdb.
|
186
|
+
------------------------------------------------------------------------
|
187
|
+
r3286 | konstantin | 2008-03-31 06:45:19 -0700 (Mon, 31 Mar 2008) | 4 lines
|
157
188
|
|
189
|
+
right_aws 1.7.0
|
190
|
+
1. remove code duplication on the methods being cached
|
191
|
+
2. add describe_availability_zones to cached methods
|
158
192
|
|
data/Manifest.txt
CHANGED
@@ -2,29 +2,30 @@ History.txt
|
|
2
2
|
Manifest.txt
|
3
3
|
README.txt
|
4
4
|
Rakefile
|
5
|
-
lib/right_aws.rb
|
6
5
|
lib/awsbase/benchmark_fix.rb
|
7
|
-
lib/awsbase/support.rb
|
8
6
|
lib/awsbase/right_awsbase.rb
|
7
|
+
lib/awsbase/support.rb
|
9
8
|
lib/ec2/right_ec2.rb
|
9
|
+
lib/right_aws.rb
|
10
10
|
lib/s3/right_s3.rb
|
11
11
|
lib/s3/right_s3_interface.rb
|
12
|
+
lib/sdb/active_sdb.rb
|
12
13
|
lib/sdb/right_sdb_interface.rb
|
13
14
|
lib/sqs/right_sqs.rb
|
14
|
-
lib/sqs/right_sqs_interface.rb
|
15
15
|
lib/sqs/right_sqs_gen2.rb
|
16
16
|
lib/sqs/right_sqs_gen2_interface.rb
|
17
|
+
lib/sqs/right_sqs_interface.rb
|
17
18
|
test/ec2/test_helper.rb
|
18
19
|
test/ec2/test_right_ec2.rb
|
20
|
+
test/http_connection.rb
|
19
21
|
test/s3/test_helper.rb
|
20
22
|
test/s3/test_right_s3.rb
|
21
23
|
test/s3/test_right_s3_stubbed.rb
|
22
|
-
test/sdb/
|
24
|
+
test/sdb/test_active_sdb.rb
|
23
25
|
test/sdb/test_helper.rb
|
26
|
+
test/sdb/test_right_sdb.rb
|
24
27
|
test/sqs/test_helper.rb
|
25
28
|
test/sqs/test_right_sqs.rb
|
26
29
|
test/sqs/test_right_sqs_gen2.rb
|
27
|
-
test/ts_right_aws.rb
|
28
30
|
test/test_credentials.rb
|
29
|
-
test/
|
30
|
-
|
31
|
+
test/ts_right_aws.rb
|
data/README.txt
CHANGED
@@ -11,7 +11,7 @@ The RightScale AWS gems have been designed to provide a robust, fast, and secure
|
|
11
11
|
- RightAws::S3 and RightAws::S3Interface -- interface to Amazon S3 (Simple Storage Service)
|
12
12
|
- RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service) (API version 2007-05-01)
|
13
13
|
- RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service) (API version 2008-01-01)
|
14
|
-
- RightAws::SdbInterface -- interface to Amazon SDB (SimpleDB)
|
14
|
+
- RightAws::SdbInterface and RightAws::ActiveSdb -- interface to Amazon SDB (SimpleDB)
|
15
15
|
|
16
16
|
== FEATURES:
|
17
17
|
|
@@ -71,13 +71,13 @@ multithreaded mode.
|
|
71
71
|
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=48
|
72
72
|
* For first generation SQS read RightAws::Sqs and consult the Amazon SQS API documentation at
|
73
73
|
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=31
|
74
|
-
* For second generation SQS read RightAws::SqsGen2, RightAws::SqsGen2Interface and consult the Amazon SQS API documentation at
|
74
|
+
* For second generation SQS read RightAws::SqsGen2, RightAws::SqsGen2Interface, and consult the Amazon SQS API documentation at
|
75
75
|
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1214&categoryID=31
|
76
76
|
|
77
77
|
Amazon's Migration Guide for moving from first to second generation SQS is
|
78
78
|
avalable at:
|
79
79
|
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1148
|
80
|
-
* For SDB read RightAws::
|
80
|
+
* For SDB read RightAws::SdbInterface, RightAws::ActiveSdb, and consult the Amazon SDB API documentation at
|
81
81
|
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=141
|
82
82
|
|
83
83
|
== KNOWN ISSUES:
|
data/Rakefile
CHANGED
@@ -86,4 +86,11 @@ task :testsdb do
|
|
86
86
|
require 'test/sdb/test_right_sdb.rb'
|
87
87
|
end
|
88
88
|
|
89
|
+
desc "Test active SDB interface"
|
90
|
+
task :testactivesdb do
|
91
|
+
require 'test/test_credentials'
|
92
|
+
TestCredentials.get_credentials
|
93
|
+
require 'test/sdb/test_active_sdb.rb'
|
94
|
+
end
|
95
|
+
|
89
96
|
# vim: syntax=Ruby
|
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 = "
|
71
|
+
API_VERSION = "2008-02-01"
|
72
72
|
DEFAULT_HOST = "ec2.amazonaws.com"
|
73
73
|
DEFAULT_PROTOCOL = 'https'
|
74
74
|
DEFAULT_PORT = 443
|
@@ -142,52 +142,52 @@ module RightAws
|
|
142
142
|
request_info_impl(thread[:ec2_connection], @@bench, request, parser)
|
143
143
|
end
|
144
144
|
|
145
|
-
|
145
|
+
def request_cache_or_info(method, link, parser_class, use_cache=true) #:nodoc:
|
146
|
+
# We do not want to break the logic of parsing hence will use a dummy parser to process all the standart
|
147
|
+
# steps (errors checking etc). The dummy parser does nothig - just returns back the params it received.
|
148
|
+
# If the caching is enabled and hit then throw AwsNoChange.
|
149
|
+
# P.S. caching works for the whole images list only! (when the list param is blank) response, params = request_info(link, QEc2DummyParser.new)
|
150
|
+
# check cache
|
151
|
+
response, params = request_info(link, QEc2DummyParser.new)
|
152
|
+
cache_hits?(method.to_sym, response.body) if use_cache
|
153
|
+
parser = parser_class.new(:logger => @logger)
|
154
|
+
@@bench.xml.add!{ parser.parse(response, params) }
|
155
|
+
result = block_given? ? yield(parser) : parser.result
|
156
|
+
# update parsed data
|
157
|
+
update_cache(method.to_sym, :parsed => result) if use_cache
|
158
|
+
result
|
159
|
+
end
|
160
|
+
|
146
161
|
def hash_params(prefix, list) #:nodoc:
|
147
162
|
groups = {}
|
148
163
|
list.each_index{|i| groups.update("#{prefix}.#{i+1}"=>list[i])} if list
|
149
164
|
return groups
|
150
165
|
end
|
151
166
|
|
152
|
-
|
153
167
|
#-----------------------------------------------------------------
|
154
168
|
#-----------------------------------------------------------------
|
155
169
|
#-----------------------------------------------------------------
|
156
170
|
|
157
|
-
def ec2_describe_images(
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
# P.S. caching works for the whole images list only! (when the list param is blank)
|
163
|
-
response, params = request_info(link, QEc2DummyParser.new)
|
164
|
-
# if cache is ON and hits then throws AwsNoChange
|
165
|
-
cache_hits?(:describe_images, response.body) if list.blank?
|
166
|
-
parser = QEc2DescribeImagesParser.new(:logger => @logger)
|
167
|
-
@@bench.xml.add!{ parser.parse(response, params) }
|
168
|
-
result = parser.result.collect do |image|
|
169
|
-
{ :aws_id => image.imageId,
|
170
|
-
:aws_location => image.imageLocation,
|
171
|
-
:aws_owner => image.imageOwnerId,
|
172
|
-
:aws_state => image.imageState.downcase,
|
173
|
-
:aws_is_public => image.isPublic,
|
174
|
-
:aws_product_codes => image.productCodes }
|
175
|
-
end
|
176
|
-
# put parsed data into cache if the caching is ON
|
177
|
-
update_cache(:describe_images, :parsed => result) if list.blank?
|
178
|
-
result
|
171
|
+
def ec2_describe_images(list, list_by='ImageId', image_type=nil) #:nodoc:
|
172
|
+
request_hash = hash_params(list_by, list.to_a)
|
173
|
+
request_hash['ImageType'] = image_type if image_type
|
174
|
+
link = generate_request("DescribeImages", request_hash)
|
175
|
+
request_cache_or_info :describe_images, link, QEc2DescribeImagesParser, (list.blank? && list_by == 'ImageId' && image_type.blank?)
|
179
176
|
rescue Exception
|
180
177
|
on_exception
|
181
178
|
end
|
182
179
|
|
183
180
|
# Retrieve a list of images. Returns array of hashes describing the images or an exception:
|
184
|
-
#
|
181
|
+
# +image_type+ = 'machine' || 'kernel' || 'ramdisk'
|
182
|
+
#
|
185
183
|
# ec2.describe_images #=>
|
186
184
|
# [{:aws_owner => "522821470517",
|
187
185
|
# :aws_id => "ami-e4b6538d",
|
188
186
|
# :aws_state => "available",
|
189
187
|
# :aws_location => "marcins_cool_public_images/ubuntu-6.10.manifest.xml",
|
190
|
-
# :aws_is_public => true
|
188
|
+
# :aws_is_public => true,
|
189
|
+
# :aws_architecture => "i386",
|
190
|
+
# :aws_image_type => "machine"},
|
191
191
|
# {...},
|
192
192
|
# {...} ]
|
193
193
|
#
|
@@ -198,30 +198,32 @@ module RightAws
|
|
198
198
|
# :aws_id => "ami-e4b6538d",
|
199
199
|
# :aws_state => "available",
|
200
200
|
# :aws_location => "marcins_cool_public_images/ubuntu-6.10.manifest.xml",
|
201
|
-
# :aws_is_public => true
|
201
|
+
# :aws_is_public => true,
|
202
|
+
# :aws_architecture => "i386",
|
203
|
+
# :aws_image_type => "machine"}]
|
202
204
|
#
|
203
|
-
def describe_images(list=[])
|
204
|
-
ec2_describe_images('ImageId',
|
205
|
+
def describe_images(list=[], image_type=nil)
|
206
|
+
ec2_describe_images(list, 'ImageId', image_type)
|
205
207
|
end
|
206
208
|
|
207
209
|
#
|
208
210
|
# Example:
|
209
211
|
#
|
210
|
-
#
|
211
|
-
#
|
212
|
+
# ec2.describe_images_by_owner('522821470517')
|
213
|
+
# ec2.describe_images_by_owner('self')
|
212
214
|
#
|
213
|
-
def describe_images_by_owner(list)
|
214
|
-
ec2_describe_images('Owner',
|
215
|
+
def describe_images_by_owner(list, image_type=nil)
|
216
|
+
ec2_describe_images(list, 'Owner', image_type)
|
215
217
|
end
|
216
218
|
|
217
219
|
#
|
218
220
|
# Example:
|
219
221
|
#
|
220
|
-
#
|
221
|
-
#
|
222
|
+
# ec2.describe_images_by_executable_by('522821470517')
|
223
|
+
# ec2.describe_images_by_executable_by('self')
|
222
224
|
#
|
223
|
-
def describe_images_by_executable_by(list)
|
224
|
-
ec2_describe_images('ExecutableBy',
|
225
|
+
def describe_images_by_executable_by(list, image_type=nil)
|
226
|
+
ec2_describe_images(list, 'ExecutableBy', image_type)
|
225
227
|
end
|
226
228
|
|
227
229
|
|
@@ -251,7 +253,7 @@ module RightAws
|
|
251
253
|
end
|
252
254
|
|
253
255
|
|
254
|
-
# Describe image attributes. Currently 'launchPermission' and '
|
256
|
+
# Describe image attributes. Currently 'launchPermission', 'productCodes', 'kernel', 'ramdisk' and 'blockDeviceMapping' are supported.
|
255
257
|
#
|
256
258
|
# ec2.describe_image_attribute('ami-e444444d') #=> {:groups=>["all"], :users=>["000000000777"]}
|
257
259
|
#
|
@@ -259,15 +261,7 @@ module RightAws
|
|
259
261
|
link = generate_request("DescribeImageAttribute",
|
260
262
|
'ImageId' => image_id,
|
261
263
|
'Attribute' => attribute)
|
262
|
-
|
263
|
-
result = {}
|
264
|
-
if image_attr.launchPermission
|
265
|
-
result = { :users => image_attr.launchPermission.userIds,
|
266
|
-
:groups => image_attr.launchPermission.groups }
|
267
|
-
elsif image_attr.productCodes
|
268
|
-
result = { :aws_product_codes => image_attr.productCodes}
|
269
|
-
end
|
270
|
-
result
|
264
|
+
request_info(link, QEc2DescribeImageAttributeParser.new(:logger => @logger))
|
271
265
|
rescue Exception
|
272
266
|
on_exception
|
273
267
|
end
|
@@ -331,47 +325,37 @@ module RightAws
|
|
331
325
|
#
|
332
326
|
# ec2.modify_image_launch_perm_add_groups('ami-e444444d') #=> true
|
333
327
|
#
|
334
|
-
def modify_image_launch_perm_add_groups(image_id,
|
335
|
-
modify_image_attribute(image_id, 'launchPermission', 'add', :user_group =>
|
328
|
+
def modify_image_launch_perm_add_groups(image_id, user_group=['all'])
|
329
|
+
modify_image_attribute(image_id, 'launchPermission', 'add', :user_group => user_group.to_a)
|
336
330
|
end
|
337
331
|
|
338
332
|
# Remove image launch permissions for users groups (currently only 'all' is supported, which gives public launch permissions).
|
339
333
|
#
|
340
334
|
# ec2.modify_image_launch_perm_remove_groups('ami-e444444d') #=> true
|
341
335
|
#
|
342
|
-
def modify_image_launch_perm_remove_groups(image_id,
|
343
|
-
modify_image_attribute(image_id, 'launchPermission', 'remove', :user_group =>
|
336
|
+
def modify_image_launch_perm_remove_groups(image_id, user_group=['all'])
|
337
|
+
modify_image_attribute(image_id, 'launchPermission', 'remove', :user_group => user_group.to_a)
|
344
338
|
end
|
345
339
|
|
346
340
|
# Add product code to image
|
347
341
|
#
|
348
342
|
# ec2.modify_image_product_code('ami-e444444d','0ABCDEF') #=> true
|
349
343
|
#
|
350
|
-
def modify_image_product_code(image_id,
|
351
|
-
modify_image_attribute(image_id, 'productCodes', nil, :product_code =>
|
344
|
+
def modify_image_product_code(image_id, product_code=[])
|
345
|
+
modify_image_attribute(image_id, 'productCodes', nil, :product_code => product_code.to_a)
|
352
346
|
end
|
353
347
|
|
354
348
|
def get_desc_instances(instances) # :nodoc:
|
355
349
|
result = []
|
356
|
-
instances.each do |
|
357
|
-
|
350
|
+
instances.each do |reservation|
|
351
|
+
reservation[:instances_set].each do |instance|
|
358
352
|
# Parse and remove timestamp from the reason string. The timestamp is of
|
359
353
|
# the request, not when EC2 took action, thus confusing & useless...
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
:dns_name => instance.dnsName,
|
366
|
-
:private_dns_name => instance.privateDnsName,
|
367
|
-
:aws_instance_id => instance.instanceId,
|
368
|
-
:aws_state => instance.instanceState.name,
|
369
|
-
:ssh_key_name => instance.keyName,
|
370
|
-
:aws_image_id => instance.imageId,
|
371
|
-
:aws_reason => reason,
|
372
|
-
:aws_product_codes => instance.productCodes,
|
373
|
-
:aws_instance_type => instance.instanceType,
|
374
|
-
:aws_launch_time => instance.launchTime}
|
354
|
+
instance[:aws_reason] = instance[:aws_reason].sub(/\(\d[^)]*GMT\) */, '')
|
355
|
+
instance[:aws_owner] = reservation[:aws_owner]
|
356
|
+
instance[:aws_reservation_id] = reservation[:aws_reservation_id]
|
357
|
+
instance[:aws_groups] = reservation[:aws_groups]
|
358
|
+
result << instance
|
375
359
|
end
|
376
360
|
end
|
377
361
|
result
|
@@ -396,19 +380,16 @@ module RightAws
|
|
396
380
|
# :private_dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
|
397
381
|
# :aws_instance_type => "m1.small",
|
398
382
|
# :aws_launch_time => "2008-1-1T00:00:00.000Z"},
|
383
|
+
# :aws_availability_zone => "us-east-1b",
|
384
|
+
# :aws_kernel_id => "aki-ba3adfd3",
|
385
|
+
# :aws_ramdisk_id => "ari-badbad00",
|
399
386
|
# ..., {...}]
|
400
387
|
#
|
401
388
|
def describe_instances(list=[])
|
402
389
|
link = generate_request("DescribeInstances", hash_params('InstanceId',list.to_a))
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
parser = QEc2DescribeInstancesParser.new(:logger => @logger)
|
407
|
-
@@bench.xml.add!{ parser.parse(response, params) }
|
408
|
-
result = get_desc_instances(parser.result)
|
409
|
-
# update parsed data
|
410
|
-
update_cache(:describe_instances, :parsed => result) if list.blank?
|
411
|
-
result
|
390
|
+
request_cache_or_info(:describe_instances, link, QEc2DescribeInstancesParser, list.blank?) do |parser|
|
391
|
+
get_desc_instances(parser.result)
|
392
|
+
end
|
412
393
|
rescue Exception
|
413
394
|
on_exception
|
414
395
|
end
|
@@ -439,34 +420,52 @@ module RightAws
|
|
439
420
|
# :aws_groups => ["my_awesome_group"],
|
440
421
|
# :private_dns_name => "",
|
441
422
|
# :aws_instance_type => "m1.small",
|
442
|
-
# :aws_launch_time => "2008-1-1T00:00:00.000Z"
|
423
|
+
# :aws_launch_time => "2008-1-1T00:00:00.000Z"
|
424
|
+
# :aws_ramdisk_id => "ari-8605e0ef"
|
425
|
+
# :aws_kernel_id => "aki-9905e0f0",
|
426
|
+
# :ami_launch_index => "0",
|
427
|
+
# :aws_availability_zone => "us-east-1b"
|
428
|
+
# }]
|
443
429
|
#
|
444
430
|
def run_instances(image_id, min_count, max_count, group_ids, key_name, user_data='',
|
445
|
-
addressing_type =
|
446
|
-
|
431
|
+
addressing_type = nil, instance_type = nil,
|
432
|
+
kernel_id = nil, ramdisk_id = nil, availability_zone = nil,
|
433
|
+
block_device_mappings = nil)
|
447
434
|
launch_instances(image_id, { :min_count => min_count,
|
448
435
|
:max_count => max_count,
|
449
436
|
:user_data => user_data,
|
450
437
|
:group_ids => group_ids,
|
451
438
|
:key_name => key_name,
|
452
439
|
:instance_type => instance_type,
|
453
|
-
:addressing_type => addressing_type
|
440
|
+
:addressing_type => addressing_type,
|
441
|
+
:kernel_id => kernel_id,
|
442
|
+
:ramdisk_id => ramdisk_id,
|
443
|
+
:availability_zone => availability_zone,
|
444
|
+
:block_device_mappings => block_device_mappings
|
445
|
+
})
|
454
446
|
end
|
455
447
|
|
456
448
|
|
457
449
|
# Launch new EC2 instances. Returns a list of launched instances or an exception.
|
450
|
+
#
|
451
|
+
# +lparams+ keys (default values in parenthesis):
|
452
|
+
# :min_count fixnum, (1)
|
453
|
+
# :max_count fixnum, (1)
|
454
|
+
# :group_ids array or string ([] == 'default')
|
455
|
+
# :instance_type string (DEFAULT_INSTACE_TYPE)
|
456
|
+
# :addressing_type string (DEFAULT_ADDRESSING_TYPE
|
457
|
+
# :key_name string
|
458
|
+
# :kernel_id string
|
459
|
+
# :ramdisk_id string
|
460
|
+
# :availability_zone string
|
461
|
+
# :block_device_mappings string
|
462
|
+
# :user_data string
|
458
463
|
#
|
459
|
-
#
|
460
|
-
#
|
461
|
-
#
|
462
|
-
#
|
463
|
-
#
|
464
|
-
# :key_name - nil
|
465
|
-
# :instance_type - DEFAULT_INSTACE_TYPE
|
466
|
-
# :addressing_type - DEFAULT_ADDRESSING_TYPE
|
467
|
-
#
|
468
|
-
# ec2.launch_instances('ami-e444444d', 'my_awesome_group', :user_data => "Woohoo!!!", \
|
469
|
-
# :addressing_type => "public", :key_name => "my_awesome_key") #=>
|
464
|
+
# ec2.launch_instances('ami-e444444d', :group_ids => 'my_awesome_group',
|
465
|
+
# :user_data => "Woohoo!!!",
|
466
|
+
# :addressing_type => "public",
|
467
|
+
# :key_name => "my_awesome_key",
|
468
|
+
# :availability_zone => "us-east-1c") #=>
|
470
469
|
# [{:aws_image_id => "ami-e444444d",
|
471
470
|
# :aws_reason => "",
|
472
471
|
# :aws_state_code => "0",
|
@@ -476,33 +475,32 @@ module RightAws
|
|
476
475
|
# :aws_state => "pending",
|
477
476
|
# :dns_name => "",
|
478
477
|
# :ssh_key_name => "my_awesome_key",
|
479
|
-
# :aws_groups => ["
|
478
|
+
# :aws_groups => ["my_awesome_group"],
|
480
479
|
# :private_dns_name => "",
|
481
480
|
# :aws_instance_type => "m1.small",
|
482
|
-
# :aws_launch_time => "2008-1-1T00:00:00.000Z"
|
481
|
+
# :aws_launch_time => "2008-1-1T00:00:00.000Z",
|
482
|
+
# :aws_ramdisk_id => "ari-8605e0ef"
|
483
|
+
# :aws_kernel_id => "aki-9905e0f0",
|
484
|
+
# :ami_launch_index => "0",
|
485
|
+
# :aws_availability_zone => "us-east-1c"
|
486
|
+
# }]
|
483
487
|
#
|
484
488
|
def launch_instances(image_id, lparams={})
|
485
|
-
defaults = {
|
486
|
-
:min_count => 1,
|
487
|
-
:max_count => 1,
|
488
|
-
:user_data => '',
|
489
|
-
:group_ids => [],
|
490
|
-
:key_name => nil,
|
491
|
-
:instance_type => DEFAULT_INSTANCE_TYPE,
|
492
|
-
:addressing_type => DEFAULT_ADDRESSING_TYPE
|
493
|
-
}
|
494
|
-
lparams = defaults.merge(lparams)
|
495
|
-
|
496
489
|
@logger.info("Launching instance of image #{image_id} for #{@aws_access_key_id}, " +
|
497
|
-
"key: #{lparams[:key_name]}, groups: #{(lparams[:group_ids]
|
498
|
-
|
490
|
+
"key: #{lparams[:key_name]}, groups: #{(lparams[:group_ids]).to_a.join(',')}")
|
491
|
+
# careful: keyName and securityGroups may be nil
|
499
492
|
params = hash_params('SecurityGroup', lparams[:group_ids].to_a)
|
500
493
|
params.update( {'ImageId' => image_id,
|
501
|
-
'MinCount' => lparams[:min_count].to_s,
|
502
|
-
'MaxCount' => lparams[:max_count].to_s,
|
503
|
-
'AddressingType' => lparams[:addressing_type]
|
504
|
-
|
505
|
-
|
494
|
+
'MinCount' => (lparams[:min_count] || 1).to_s,
|
495
|
+
'MaxCount' => (lparams[:max_count] || 1).to_s,
|
496
|
+
'AddressingType' => lparams[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
|
497
|
+
'InstanceType' => lparams[:instance_type] || DEFAULT_INSTANCE_TYPE })
|
498
|
+
# optional params
|
499
|
+
params['KeyName'] = lparams[:key_name] unless lparams[:key_name].blank?
|
500
|
+
params['KernelId'] = lparams[:kernel_id] unless lparams[:kernel_id].blank?
|
501
|
+
params['RamdiskId'] = lparams[:ramdisk_id] unless lparams[:ramdisk_id].blank?
|
502
|
+
params['Placement.AvailabilityZone'] = lparams[:availability_zone] unless lparams[:availability_zone].blank?
|
503
|
+
params['BlockDeviceMappings'] = lparams[:block_device_mappings] unless lparams[:block_device_mappings].blank?
|
506
504
|
unless lparams[:user_data].blank?
|
507
505
|
lparams[:user_data].strip!
|
508
506
|
# Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library.
|
@@ -513,7 +511,7 @@ module RightAws
|
|
513
511
|
end
|
514
512
|
link = generate_request("RunInstances", params)
|
515
513
|
#debugger
|
516
|
-
instances = request_info(link,
|
514
|
+
instances = request_info(link, QEc2DescribeInstancesParser.new(:logger => @logger))
|
517
515
|
get_desc_instances(instances)
|
518
516
|
rescue Exception
|
519
517
|
on_exception
|
@@ -534,16 +532,8 @@ module RightAws
|
|
534
532
|
# :aws_prev_state_code => 16}]
|
535
533
|
#
|
536
534
|
def terminate_instances(list=[])
|
537
|
-
link
|
538
|
-
|
539
|
-
instances.collect! do |instance|
|
540
|
-
{ :aws_instance_id => instance.instanceId,
|
541
|
-
:aws_shutdown_state => instance.shutdownState.name,
|
542
|
-
:aws_shutdown_state_code => instance.shutdownState.code.to_i,
|
543
|
-
:aws_prev_state => instance.previousState.name,
|
544
|
-
:aws_prev_state_code => instance.previousState.code.to_i }
|
545
|
-
end
|
546
|
-
instances
|
535
|
+
link = generate_request("TerminateInstances", hash_params('InstanceId',list.to_a))
|
536
|
+
request_info(link, QEc2TerminateInstancesParser.new(:logger => @logger))
|
547
537
|
rescue Exception
|
548
538
|
on_exception
|
549
539
|
end
|
@@ -556,12 +546,8 @@ module RightAws
|
|
556
546
|
# :timestamp => Wed May 23 21:36:07 UTC 2007, # Time instance
|
557
547
|
# :aws_output => "Linux version 2.6.16-xenU (builder@patchbat.amazonsa) (gcc version 4.0.1 20050727 ..."
|
558
548
|
def get_console_output(instance_id)
|
559
|
-
link
|
560
|
-
|
561
|
-
{ :aws_instance_id => result.instanceId,
|
562
|
-
:aws_timestamp => result.timestamp,
|
563
|
-
:timestamp => (Time.parse(result.timestamp)).utc,
|
564
|
-
:aws_output => result.output }
|
549
|
+
link = generate_request("GetConsoleOutput", { 'InstanceId.1' => instance_id })
|
550
|
+
request_info(link, QEc2GetConsoleOutputParser.new(:logger => @logger))
|
565
551
|
rescue Exception
|
566
552
|
on_exception
|
567
553
|
end
|
@@ -593,45 +579,40 @@ module RightAws
|
|
593
579
|
# ..., {...}]
|
594
580
|
#
|
595
581
|
def describe_security_groups(list=[])
|
596
|
-
link
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
582
|
+
link = generate_request("DescribeSecurityGroups", hash_params('GroupName',list.to_a))
|
583
|
+
request_cache_or_info( :describe_security_groups, link, QEc2DescribeSecurityGroupsParser, list.blank?) do |parser|
|
584
|
+
result = []
|
585
|
+
parser.result.each do |item|
|
586
|
+
perms = []
|
587
|
+
item.ipPermissions.each do |perm|
|
588
|
+
perm.groups.each do |ngroup|
|
589
|
+
perms << {:group => ngroup.groupName,
|
590
|
+
:owner => ngroup.userId}
|
591
|
+
end
|
592
|
+
perm.ipRanges.each do |cidr_ip|
|
593
|
+
perms << {:from_port => perm.fromPort,
|
594
|
+
:to_port => perm.toPort,
|
595
|
+
:protocol => perm.ipProtocol,
|
596
|
+
:cidr_ips => cidr_ip}
|
597
|
+
end
|
610
598
|
end
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
599
|
+
|
600
|
+
# delete duplication
|
601
|
+
perms.each_index do |i|
|
602
|
+
(0...i).each do |j|
|
603
|
+
if perms[i] == perms[j] then perms[i] = nil; break; end
|
604
|
+
end
|
616
605
|
end
|
617
|
-
|
606
|
+
perms.compact!
|
607
|
+
|
608
|
+
result << {:aws_owner => item.ownerId,
|
609
|
+
:aws_group_name => item.groupName,
|
610
|
+
:aws_description => item.groupDescription,
|
611
|
+
:aws_perms => perms}
|
618
612
|
|
619
|
-
# delete duplication
|
620
|
-
perms.each_index do |i|
|
621
|
-
(0...i).each do |j|
|
622
|
-
if perms[i] == perms[j] then perms[i] = nil; break; end
|
623
|
-
end
|
624
613
|
end
|
625
|
-
|
626
|
-
|
627
|
-
result << {:aws_owner => item.ownerId,
|
628
|
-
:aws_group_name => item.groupName,
|
629
|
-
:aws_description => item.groupDescription,
|
630
|
-
:aws_perms => perms}
|
614
|
+
result
|
631
615
|
end
|
632
|
-
# update parsed data
|
633
|
-
update_cache(:describe_security_groups, :parsed => result) if list.blank?
|
634
|
-
result
|
635
616
|
rescue Exception
|
636
617
|
on_exception
|
637
618
|
end
|
@@ -735,18 +716,7 @@ module RightAws
|
|
735
716
|
#
|
736
717
|
def describe_key_pairs(list=[])
|
737
718
|
link = generate_request("DescribeKeyPairs", hash_params('KeyName',list.to_a))
|
738
|
-
|
739
|
-
# check cache
|
740
|
-
cache_hits?(:describe_key_pairs, response.body) if list.blank?
|
741
|
-
parser = QEc2DescribeKeyPairParser.new(:logger => @logger)
|
742
|
-
@@bench.xml.add!{ parser.parse(response, params) }
|
743
|
-
result = parser.result.collect do |key|
|
744
|
-
{ :aws_key_name => key.keyName,
|
745
|
-
:aws_fingerprint => key.keyFingerprint }
|
746
|
-
end
|
747
|
-
# update parsed data
|
748
|
-
update_cache(:describe_key_pairs, :parsed => result) if list.blank?
|
749
|
-
result
|
719
|
+
request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, list.blank?
|
750
720
|
rescue Exception
|
751
721
|
on_exception
|
752
722
|
end
|
@@ -761,10 +731,7 @@ module RightAws
|
|
761
731
|
def create_key_pair(name)
|
762
732
|
link = generate_request("CreateKeyPair",
|
763
733
|
'KeyName' => name.to_s)
|
764
|
-
|
765
|
-
{ :aws_key_name => key.keyName,
|
766
|
-
:aws_fingerprint => key.keyFingerprint,
|
767
|
-
:aws_material => key.keyMaterial}
|
734
|
+
request_info(link, QEc2CreateKeyPairParser.new(:logger => @logger))
|
768
735
|
rescue Exception
|
769
736
|
on_exception
|
770
737
|
end
|
@@ -781,6 +748,99 @@ module RightAws
|
|
781
748
|
on_exception
|
782
749
|
end
|
783
750
|
|
751
|
+
#-----------------------------------------------------------------
|
752
|
+
# Elastic IPs
|
753
|
+
#-----------------------------------------------------------------
|
754
|
+
|
755
|
+
# Acquire a new elastic IP address for use with your account.
|
756
|
+
# Returns allocated IP address or an exception.
|
757
|
+
#
|
758
|
+
# ec2.allocate_address #=> '75.101.154.140'
|
759
|
+
#
|
760
|
+
def allocate_address
|
761
|
+
link = generate_request("AllocateAddress")
|
762
|
+
request_info(link, QEc2AllocateAddressParser.new(:logger => @logger))
|
763
|
+
rescue Exception
|
764
|
+
on_exception
|
765
|
+
end
|
766
|
+
|
767
|
+
# Associate an elastic IP address with an instance.
|
768
|
+
# Returns +true+ or an exception.
|
769
|
+
#
|
770
|
+
# ec2.associate_address('i-d630cbbf', '75.101.154.140') #=> true
|
771
|
+
#
|
772
|
+
def associate_address(instance_id, public_ip)
|
773
|
+
link = generate_request("AssociateAddress",
|
774
|
+
"InstanceId" => instance_id.to_s,
|
775
|
+
"PublicIp" => public_ip.to_s)
|
776
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
777
|
+
rescue Exception
|
778
|
+
on_exception
|
779
|
+
end
|
780
|
+
|
781
|
+
# List elastic IP addresses assigned to your account.
|
782
|
+
# Returns an array of 2 keys (:instance_id and :public_ip) hashes:
|
783
|
+
#
|
784
|
+
# ec2.describe_addresses #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"},
|
785
|
+
# {:instance_id=>nil, :public_ip=>"75.101.154.141"}]
|
786
|
+
#
|
787
|
+
# ec2.describe_addresses('75.101.154.140') #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"}]
|
788
|
+
#
|
789
|
+
def describe_addresses(list=[])
|
790
|
+
link = generate_request("DescribeAddresses",
|
791
|
+
hash_params('PublicIp',list.to_a))
|
792
|
+
request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, list.blank?
|
793
|
+
rescue Exception
|
794
|
+
on_exception
|
795
|
+
end
|
796
|
+
|
797
|
+
# Disassociate the specified elastic IP address from the instance to which it is assigned.
|
798
|
+
# Returns +true+ or an exception.
|
799
|
+
#
|
800
|
+
# ec2.disassociate_address('75.101.154.140') #=> true
|
801
|
+
#
|
802
|
+
def disassociate_address(public_ip)
|
803
|
+
link = generate_request("DisassociateAddress",
|
804
|
+
"PublicIp" => public_ip.to_s)
|
805
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
806
|
+
rescue Exception
|
807
|
+
on_exception
|
808
|
+
end
|
809
|
+
|
810
|
+
# Release an elastic IP address associated with your account.
|
811
|
+
# Returns +true+ or an exception.
|
812
|
+
#
|
813
|
+
# ec2.release_address('75.101.154.140') #=> true
|
814
|
+
#
|
815
|
+
def release_address(public_ip)
|
816
|
+
link = generate_request("ReleaseAddress",
|
817
|
+
"PublicIp" => public_ip.to_s)
|
818
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
819
|
+
rescue Exception
|
820
|
+
on_exception
|
821
|
+
end
|
822
|
+
|
823
|
+
#-----------------------------------------------------------------
|
824
|
+
# Availability zones
|
825
|
+
#-----------------------------------------------------------------
|
826
|
+
|
827
|
+
# Describes availability zones that are currently available to the account and their states.
|
828
|
+
# Returns an array of 2 keys (:zone_name and :zone_state) hashes:
|
829
|
+
#
|
830
|
+
# ec2.describe_availability_zones #=> [{:zone_state=>"available", :zone_name=>"us-east-1a"},
|
831
|
+
# {:zone_state=>"available", :zone_name=>"us-east-1b"},
|
832
|
+
# {:zone_state=>"available", :zone_name=>"us-east-1c"}]
|
833
|
+
#
|
834
|
+
# ec2.describe_availability_zones('us-east-1c') #=> [{:zone_state=>"available", :zone_name=>"us-east-1c"}]
|
835
|
+
#
|
836
|
+
def describe_availability_zones(list=[])
|
837
|
+
link = generate_request("DescribeAvailabilityZones",
|
838
|
+
hash_params('ZoneName',list.to_a))
|
839
|
+
request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, list.blank?
|
840
|
+
rescue Exception
|
841
|
+
on_exception
|
842
|
+
end
|
843
|
+
|
784
844
|
#- Internal stuff from here on down...
|
785
845
|
|
786
846
|
|
@@ -798,24 +858,15 @@ module RightAws
|
|
798
858
|
# PARSERS: Key Pair
|
799
859
|
#-----------------------------------------------------------------
|
800
860
|
|
801
|
-
class QEc2DescribeKeyPairType #:nodoc:
|
802
|
-
attr_accessor :keyName
|
803
|
-
attr_accessor :keyFingerprint
|
804
|
-
end
|
805
|
-
|
806
|
-
class QEc2CreateKeyPairType < QEc2DescribeKeyPairType #:nodoc:
|
807
|
-
attr_accessor :keyMaterial
|
808
|
-
end
|
809
|
-
|
810
861
|
class QEc2DescribeKeyPairParser < RightAWSParser #:nodoc:
|
811
862
|
def tagstart(name, attributes)
|
812
|
-
@item =
|
863
|
+
@item = {} if name == 'item'
|
813
864
|
end
|
814
865
|
def tagend(name)
|
815
866
|
case name
|
816
|
-
when 'keyName'
|
817
|
-
when 'keyFingerprint'
|
818
|
-
when 'item'
|
867
|
+
when 'keyName' : @item[:aws_key_name] = @text
|
868
|
+
when 'keyFingerprint': @item[:aws_fingerprint] = @text
|
869
|
+
when 'item' : @result << @item
|
819
870
|
end
|
820
871
|
end
|
821
872
|
def reset
|
@@ -825,13 +876,13 @@ module RightAws
|
|
825
876
|
|
826
877
|
class QEc2CreateKeyPairParser < RightAWSParser #:nodoc:
|
827
878
|
def tagstart(name, attributes)
|
828
|
-
@result =
|
879
|
+
@result = {} if name == 'CreateKeyPairResponse'
|
829
880
|
end
|
830
881
|
def tagend(name)
|
831
882
|
case name
|
832
|
-
when 'keyName'
|
833
|
-
when 'keyFingerprint'
|
834
|
-
when 'keyMaterial'
|
883
|
+
when 'keyName' : @result[:aws_key_name] = @text
|
884
|
+
when 'keyFingerprint': @result[:aws_fingerprint] = @text
|
885
|
+
when 'keyMaterial' : @result[:aws_material] = @text
|
835
886
|
end
|
836
887
|
end
|
837
888
|
end
|
@@ -910,30 +961,25 @@ module RightAws
|
|
910
961
|
#-----------------------------------------------------------------
|
911
962
|
# PARSERS: Images
|
912
963
|
#-----------------------------------------------------------------
|
913
|
-
|
914
|
-
class QEc2DescribeImagesResponseItemType #:nodoc:
|
915
|
-
attr_accessor :imageId
|
916
|
-
attr_accessor :imageState
|
917
|
-
attr_accessor :imageLocation
|
918
|
-
attr_accessor :imageOwnerId
|
919
|
-
attr_accessor :isPublic
|
920
|
-
attr_accessor :productCodes
|
921
|
-
end
|
922
|
-
|
964
|
+
|
923
965
|
class QEc2DescribeImagesParser < RightAWSParser #:nodoc:
|
924
966
|
def tagstart(name, attributes)
|
925
967
|
if name == 'item' && @xmlpath[%r{.*/imagesSet$}]
|
926
|
-
@image =
|
968
|
+
@image = {}
|
927
969
|
end
|
928
970
|
end
|
929
971
|
def tagend(name)
|
930
972
|
case name
|
931
|
-
when 'imageId' ; @image
|
932
|
-
when 'imageLocation' ; @image
|
933
|
-
when 'imageState' ; @image
|
934
|
-
when 'imageOwnerId' ; @image
|
935
|
-
when 'isPublic' ; @image
|
936
|
-
when 'productCode' ;
|
973
|
+
when 'imageId' ; @image[:aws_id] = @text
|
974
|
+
when 'imageLocation' ; @image[:aws_location] = @text
|
975
|
+
when 'imageState' ; @image[:aws_state] = @text
|
976
|
+
when 'imageOwnerId' ; @image[:aws_owner] = @text
|
977
|
+
when 'isPublic' ; @image[:aws_is_public]= @text == 'true' ? true : false
|
978
|
+
when 'productCode' ;(@image[:aws_product_codes] ||= []) << @text
|
979
|
+
when 'architecture' ; @image[:aws_architecture] = @text
|
980
|
+
when 'imageType' ; @image[:aws_image_type] = @text
|
981
|
+
when 'kernelId' ; @image[:aws_kernel_id] = @text
|
982
|
+
when 'ramdiskId' ; @image[:aws_ramdisk_id] = @text
|
937
983
|
when 'item' ; @result << @image if @xmlpath[%r{.*/imagesSet$}]
|
938
984
|
end
|
939
985
|
end
|
@@ -952,24 +998,14 @@ module RightAws
|
|
952
998
|
# PARSERS: Image Attribute
|
953
999
|
#-----------------------------------------------------------------
|
954
1000
|
|
955
|
-
class QEc2LaunchPermissionItemType #:nodoc:
|
956
|
-
attr_accessor :groups
|
957
|
-
attr_accessor :userIds
|
958
|
-
end
|
959
|
-
|
960
|
-
class QEc2DescribeImageAttributeType #:nodoc:
|
961
|
-
attr_accessor :imageId
|
962
|
-
attr_accessor :launchPermission
|
963
|
-
attr_accessor :productCodes
|
964
|
-
end
|
965
|
-
|
966
1001
|
class QEc2DescribeImageAttributeParser < RightAWSParser #:nodoc:
|
967
1002
|
def tagstart(name, attributes)
|
968
1003
|
case name
|
969
1004
|
when 'launchPermission'
|
970
|
-
@result
|
971
|
-
@result
|
972
|
-
|
1005
|
+
@result[:groups] = []
|
1006
|
+
@result[:users] = []
|
1007
|
+
when 'productCodes'
|
1008
|
+
@result[:aws_product_codes] = []
|
973
1009
|
end
|
974
1010
|
end
|
975
1011
|
def tagend(name)
|
@@ -977,17 +1013,17 @@ module RightAws
|
|
977
1013
|
# But nobody know what will they xml later as attribute. That is why we
|
978
1014
|
# check for 'group' and 'userId' inside of 'launchPermission/item'
|
979
1015
|
case name
|
980
|
-
when 'imageId'
|
981
|
-
when 'group'
|
982
|
-
|
983
|
-
when '
|
984
|
-
|
985
|
-
when '
|
986
|
-
|
1016
|
+
when 'imageId' : @result[:aws_id] = @text
|
1017
|
+
when 'group' : @result[:groups] << @text if @xmlpath == 'DescribeImageAttributeResponse/launchPermission/item'
|
1018
|
+
when 'userId' : @result[:users] << @text if @xmlpath == 'DescribeImageAttributeResponse/launchPermission/item'
|
1019
|
+
when 'productCode' : @result[:aws_product_codes] << @text
|
1020
|
+
when 'kernel' : @result[:aws_kernel] = @text
|
1021
|
+
when 'ramdisk' : @result[:aws_ramdisk] = @text
|
1022
|
+
when 'blockDeviceMapping' : @result[:block_device_mapping] = @text
|
987
1023
|
end
|
988
1024
|
end
|
989
1025
|
def reset
|
990
|
-
@result =
|
1026
|
+
@result = {}
|
991
1027
|
end
|
992
1028
|
end
|
993
1029
|
|
@@ -995,75 +1031,60 @@ module RightAws
|
|
995
1031
|
# PARSERS: Instances
|
996
1032
|
#-----------------------------------------------------------------
|
997
1033
|
|
998
|
-
class QEc2InstanceStateType #:nodoc:
|
999
|
-
attr_accessor :code
|
1000
|
-
attr_accessor :name
|
1001
|
-
end
|
1002
|
-
|
1003
|
-
class QEc2RunningInstancesItemType #:nodoc:
|
1004
|
-
attr_accessor :instanceId
|
1005
|
-
attr_accessor :imageId
|
1006
|
-
attr_accessor :instanceState
|
1007
|
-
attr_accessor :dnsName
|
1008
|
-
attr_accessor :privateDnsName
|
1009
|
-
attr_accessor :reason
|
1010
|
-
attr_accessor :keyName
|
1011
|
-
attr_accessor :amiLaunchIndex
|
1012
|
-
attr_accessor :productCodes
|
1013
|
-
attr_accessor :instanceType
|
1014
|
-
attr_accessor :launchTime
|
1015
|
-
end
|
1016
|
-
|
1017
|
-
class QEc2DescribeInstancesType #:nodoc:
|
1018
|
-
attr_accessor :reservationId
|
1019
|
-
attr_accessor :ownerId
|
1020
|
-
attr_accessor :groupSet
|
1021
|
-
attr_accessor :instancesSet
|
1022
|
-
end
|
1023
|
-
|
1024
1034
|
class QEc2DescribeInstancesParser < RightAWSParser #:nodoc:
|
1025
1035
|
def tagstart(name, attributes)
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
#
|
1035
|
-
@
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1036
|
+
# DescribeInstances property
|
1037
|
+
if (name == 'item' && @xmlpath == 'DescribeInstancesResponse/reservationSet') ||
|
1038
|
+
# RunInstances property
|
1039
|
+
(name == 'RunInstancesResponse')
|
1040
|
+
@reservation = { :aws_groups => [],
|
1041
|
+
:instances_set => [] }
|
1042
|
+
|
1043
|
+
elsif (name == 'item') &&
|
1044
|
+
# DescribeInstances property
|
1045
|
+
( @xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet' ||
|
1046
|
+
# RunInstances property
|
1047
|
+
@xmlpath=='RunInstancesResponse/instancesSet' )
|
1048
|
+
# the optional params (sometimes are missing and we dont want them to be nil)
|
1049
|
+
@instance = { :aws_reason => '',
|
1050
|
+
:dns_name => '',
|
1051
|
+
:private_dns_name => '',
|
1052
|
+
:ami_launch_index => '',
|
1053
|
+
:ssh_key_name => '',
|
1054
|
+
:aws_state => '',
|
1055
|
+
:aws_product_codes => [] }
|
1056
|
+
end
|
1043
1057
|
end
|
1044
1058
|
def tagend(name)
|
1045
1059
|
case name
|
1046
|
-
|
1047
|
-
when '
|
1048
|
-
when '
|
1049
|
-
when '
|
1050
|
-
|
1051
|
-
when '
|
1052
|
-
when '
|
1053
|
-
when '
|
1054
|
-
when '
|
1055
|
-
when '
|
1056
|
-
when '
|
1057
|
-
when '
|
1060
|
+
# reservation
|
1061
|
+
when 'reservationId' : @reservation[:aws_reservation_id] = @text
|
1062
|
+
when 'ownerId' : @reservation[:aws_owner] = @text
|
1063
|
+
when 'groupId' : @reservation[:aws_groups] << @text
|
1064
|
+
# instance
|
1065
|
+
when 'instanceId' : @instance[:aws_instance_id] = @text
|
1066
|
+
when 'imageId' : @instance[:aws_image_id] = @text
|
1067
|
+
when 'dnsName' : @instance[:dns_name] = @text
|
1068
|
+
when 'privateDnsName' : @instance[:private_dns_name] = @text
|
1069
|
+
when 'reason' : @instance[:aws_reason] = @text
|
1070
|
+
when 'keyName' : @instance[:ssh_key_name] = @text
|
1071
|
+
when 'amiLaunchIndex' : @instance[:ami_launch_index] = @text
|
1072
|
+
when 'code' : @instance[:aws_state_code] = @text
|
1073
|
+
when 'name' : @instance[:aws_state] = @text
|
1074
|
+
when 'productCode' : @instance[:aws_product_codes] << @text
|
1075
|
+
when 'instanceType' : @instance[:aws_instance_type] = @text
|
1076
|
+
when 'launchTime' : @instance[:aws_launch_time] = @text
|
1077
|
+
when 'kernelId' : @instance[:aws_kernel_id] = @text
|
1078
|
+
when 'ramdiskId' : @instance[:aws_ramdisk_id] = @text
|
1079
|
+
when 'availabilityZone': @instance[:aws_availability_zone] = @text
|
1058
1080
|
when 'item'
|
1059
|
-
if @xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet'
|
1060
|
-
|
1061
|
-
|
1081
|
+
if @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet' || # DescribeInstances property
|
1082
|
+
@xmlpath == 'RunInstancesResponse/instancesSet' # RunInstances property
|
1083
|
+
@reservation[:instances_set] << @instance
|
1084
|
+
elsif @xmlpath=='DescribeInstancesResponse/reservationSet' # DescribeInstances property
|
1062
1085
|
@result << @reservation
|
1063
1086
|
end
|
1064
|
-
when '
|
1065
|
-
when 'instanceType' ; @instance.instanceType = @text
|
1066
|
-
when 'launchTime' ; @instance.launchTime = @text
|
1087
|
+
when 'RunInstancesResponse': @result << @reservation # RunInstances property
|
1067
1088
|
end
|
1068
1089
|
end
|
1069
1090
|
def reset
|
@@ -1075,84 +1096,24 @@ module RightAws
|
|
1075
1096
|
def tagend(name)
|
1076
1097
|
@result = @text if name == 'ownerId'
|
1077
1098
|
end
|
1078
|
-
def reset
|
1079
|
-
@result = nil
|
1080
|
-
end
|
1081
|
-
end
|
1082
|
-
|
1083
|
-
class QEc2RunInstancesParser < RightAWSParser #:nodoc:
|
1084
|
-
def tagstart(name, attributes)
|
1085
|
-
case name
|
1086
|
-
when 'RunInstancesResponse'
|
1087
|
-
@reservation = QEc2DescribeInstancesType.new
|
1088
|
-
@reservation.groupSet = []
|
1089
|
-
@reservation.instancesSet = []
|
1090
|
-
when 'item'
|
1091
|
-
if @xmlpath == 'RunInstancesResponse/instancesSet'
|
1092
|
-
@instance = QEc2RunningInstancesItemType.new
|
1093
|
-
# the optional params (sometimes are missing and we dont want them to be nil)
|
1094
|
-
@instance.reason = ''
|
1095
|
-
@instance.dnsName = ''
|
1096
|
-
@instance.privateDnsName = ''
|
1097
|
-
@instance.amiLaunchIndex = ''
|
1098
|
-
@instance.keyName = ''
|
1099
|
-
@instance.instanceState = QEc2InstanceStateType.new
|
1100
|
-
end
|
1101
|
-
end
|
1102
|
-
end
|
1103
|
-
def tagend(name)
|
1104
|
-
case name
|
1105
|
-
when 'reservationId' ; @reservation.reservationId = @text
|
1106
|
-
when 'ownerId' ; @reservation.ownerId = @text
|
1107
|
-
when 'groupId' ; @reservation.groupSet << @text
|
1108
|
-
when 'instanceId' ; @instance.instanceId = @text
|
1109
|
-
when 'imageId' ; @instance.imageId = @text
|
1110
|
-
when 'dnsName' ; @instance.dnsName = @text
|
1111
|
-
when 'privateDnsName'; @instance.privateDnsName = @text
|
1112
|
-
when 'reason' ; @instance.reason = @text
|
1113
|
-
when 'keyName' ; @instance.keyName = @text
|
1114
|
-
when 'amiLaunchIndex'; @instance.amiLaunchIndex = @text
|
1115
|
-
when 'code' ; @instance.instanceState.code = @text
|
1116
|
-
when 'name' ; @instance.instanceState.name = @text
|
1117
|
-
when 'item'
|
1118
|
-
@reservation.instancesSet << @instance if @xmlpath == 'RunInstancesResponse/instancesSet'
|
1119
|
-
when 'RunInstancesResponse'; @result << @reservation
|
1120
|
-
when 'productCode' ; (@instance.productCodes ||= []) << @text
|
1121
|
-
when 'instanceType' ; @instance.instanceType = @text
|
1122
|
-
when 'launchTime' ; @instance.launchTime = @text
|
1123
|
-
end
|
1124
|
-
end
|
1125
|
-
def reset
|
1126
|
-
@result = []
|
1127
|
-
end
|
1128
|
-
end
|
1129
|
-
|
1130
|
-
class QEc2TerminateInstancesResponseInfoType #:nodoc:
|
1131
|
-
attr_accessor :instanceId
|
1132
|
-
attr_accessor :shutdownState
|
1133
|
-
attr_accessor :previousState
|
1134
1099
|
end
|
1135
1100
|
|
1136
1101
|
class QEc2TerminateInstancesParser < RightAWSParser #:nodoc:
|
1137
1102
|
def tagstart(name, attributes)
|
1138
|
-
if name == 'item'
|
1139
|
-
@instance = QEc2TerminateInstancesResponseInfoType.new
|
1140
|
-
@instance.shutdownState = QEc2InstanceStateType.new
|
1141
|
-
@instance.previousState = QEc2InstanceStateType.new
|
1142
|
-
end
|
1103
|
+
@instance = {} if name == 'item'
|
1143
1104
|
end
|
1144
1105
|
def tagend(name)
|
1145
1106
|
case name
|
1146
|
-
when 'instanceId'
|
1147
|
-
when 'item' ; @result << @instance
|
1107
|
+
when 'instanceId' : @instance[:aws_instance_id] = @text
|
1148
1108
|
when 'code'
|
1149
1109
|
if @xmlpath == 'TerminateInstancesResponse/instancesSet/item/shutdownState'
|
1150
|
-
@instance
|
1151
|
-
else @instance
|
1110
|
+
@instance[:aws_shutdown_state_code] = @text.to_i
|
1111
|
+
else @instance[:aws_prev_state_code] = @text.to_i end
|
1152
1112
|
when 'name'
|
1153
1113
|
if @xmlpath == 'TerminateInstancesResponse/instancesSet/item/shutdownState'
|
1154
|
-
@instance
|
1155
|
-
else @instance
|
1114
|
+
@instance[:aws_shutdown_state] = @text
|
1115
|
+
else @instance[:aws_prev_state] = @text end
|
1116
|
+
when 'item' : @result << @instance
|
1156
1117
|
end
|
1157
1118
|
end
|
1158
1119
|
def reset
|
@@ -1164,22 +1125,18 @@ module RightAws
|
|
1164
1125
|
# PARSERS: Console
|
1165
1126
|
#-----------------------------------------------------------------
|
1166
1127
|
|
1167
|
-
class QEc2GetConsoleOutputResponseType #:nodoc:
|
1168
|
-
attr_accessor :instanceId
|
1169
|
-
attr_accessor :timestamp
|
1170
|
-
attr_accessor :output
|
1171
|
-
end
|
1172
1128
|
|
1173
1129
|
class QEc2GetConsoleOutputParser < RightAWSParser #:nodoc:
|
1174
1130
|
def tagend(name)
|
1175
1131
|
case name
|
1176
|
-
when 'instanceId'
|
1177
|
-
when 'timestamp'
|
1178
|
-
|
1132
|
+
when 'instanceId' : @result[:aws_instance_id] = @text
|
1133
|
+
when 'timestamp' : @result[:aws_timestamp] = @text
|
1134
|
+
@result[:timestamp] = (Time.parse(@text)).utc
|
1135
|
+
when 'output' : @result[:aws_output] = Base64.decode64(@text)
|
1179
1136
|
end
|
1180
1137
|
end
|
1181
1138
|
def reset
|
1182
|
-
@result =
|
1139
|
+
@result = {}
|
1183
1140
|
end
|
1184
1141
|
end
|
1185
1142
|
|
@@ -1197,5 +1154,51 @@ module RightAws
|
|
1197
1154
|
@result = [response, params]
|
1198
1155
|
end
|
1199
1156
|
end
|
1157
|
+
|
1158
|
+
#-----------------------------------------------------------------
|
1159
|
+
# PARSERS: Elastic IPs
|
1160
|
+
#-----------------------------------------------------------------
|
1200
1161
|
|
1162
|
+
class QEc2AllocateAddressParser < RightAWSParser #:nodoc:
|
1163
|
+
def tagend(name)
|
1164
|
+
@result = @text if name == 'publicIp'
|
1165
|
+
end
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
class QEc2DescribeAddressesParser < RightAWSParser #:nodoc:
|
1169
|
+
def tagstart(name, attributes)
|
1170
|
+
@address = {} if name == 'item'
|
1171
|
+
end
|
1172
|
+
def tagend(name)
|
1173
|
+
case name
|
1174
|
+
when 'instanceId' ; @address[:instance_id] = @text.blank? ? nil : @text
|
1175
|
+
when 'publicIp' ; @address[:public_ip] = @text
|
1176
|
+
when 'item' ; @result << @address
|
1177
|
+
end
|
1178
|
+
end
|
1179
|
+
def reset
|
1180
|
+
@result = []
|
1181
|
+
end
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
#-----------------------------------------------------------------
|
1185
|
+
# PARSERS: AvailabilityZones
|
1186
|
+
#-----------------------------------------------------------------
|
1187
|
+
|
1188
|
+
class QEc2DescribeAvailabilityZonesParser < RightAWSParser #:nodoc:
|
1189
|
+
def tagstart(name, attributes)
|
1190
|
+
@zone = {} if name == 'item'
|
1191
|
+
end
|
1192
|
+
def tagend(name)
|
1193
|
+
case name
|
1194
|
+
when 'zoneName' ; @zone[:zone_name] = @text
|
1195
|
+
when 'zoneState' ; @zone[:zone_state] = @text
|
1196
|
+
when 'item' ; @result << @zone
|
1197
|
+
end
|
1198
|
+
end
|
1199
|
+
def reset
|
1200
|
+
@result = []
|
1201
|
+
end
|
1202
|
+
end
|
1203
|
+
|
1201
1204
|
end
|