right_aws 1.9.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/History.txt +164 -13
  2. data/Manifest.txt +28 -1
  3. data/README.txt +12 -10
  4. data/Rakefile +56 -29
  5. data/lib/acf/right_acf_interface.rb +343 -172
  6. data/lib/acf/right_acf_invalidations.rb +144 -0
  7. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  8. data/lib/acf/right_acf_streaming_interface.rb +229 -0
  9. data/lib/acw/right_acw_interface.rb +248 -0
  10. data/lib/as/right_as_interface.rb +698 -0
  11. data/lib/awsbase/right_awsbase.rb +755 -115
  12. data/lib/awsbase/support.rb +2 -78
  13. data/lib/awsbase/version.rb +9 -0
  14. data/lib/ec2/right_ec2.rb +274 -1294
  15. data/lib/ec2/right_ec2_ebs.rb +514 -0
  16. data/lib/ec2/right_ec2_images.rb +444 -0
  17. data/lib/ec2/right_ec2_instances.rb +797 -0
  18. data/lib/ec2/right_ec2_monitoring.rb +70 -0
  19. data/lib/ec2/right_ec2_placement_groups.rb +108 -0
  20. data/lib/ec2/right_ec2_reserved_instances.rb +243 -0
  21. data/lib/ec2/right_ec2_security_groups.rb +496 -0
  22. data/lib/ec2/right_ec2_spot_instances.rb +422 -0
  23. data/lib/ec2/right_ec2_tags.rb +139 -0
  24. data/lib/ec2/right_ec2_vpc.rb +598 -0
  25. data/lib/ec2/right_ec2_vpc2.rb +382 -0
  26. data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
  27. data/lib/elb/right_elb_interface.rb +573 -0
  28. data/lib/emr/right_emr_interface.rb +728 -0
  29. data/lib/iam/right_iam_access_keys.rb +71 -0
  30. data/lib/iam/right_iam_groups.rb +195 -0
  31. data/lib/iam/right_iam_interface.rb +341 -0
  32. data/lib/iam/right_iam_mfa_devices.rb +67 -0
  33. data/lib/iam/right_iam_users.rb +251 -0
  34. data/lib/rds/right_rds_interface.rb +1657 -0
  35. data/lib/right_aws.rb +30 -13
  36. data/lib/route_53/right_route_53_interface.rb +641 -0
  37. data/lib/s3/right_s3.rb +108 -41
  38. data/lib/s3/right_s3_interface.rb +349 -118
  39. data/lib/sdb/active_sdb.rb +388 -54
  40. data/lib/sdb/right_sdb_interface.rb +323 -64
  41. data/lib/sns/right_sns_interface.rb +286 -0
  42. data/lib/sqs/right_sqs.rb +1 -2
  43. data/lib/sqs/right_sqs_gen2.rb +73 -17
  44. data/lib/sqs/right_sqs_gen2_interface.rb +146 -73
  45. data/lib/sqs/right_sqs_interface.rb +12 -22
  46. data/right_aws.gemspec +91 -0
  47. data/test/README.mdown +39 -0
  48. data/test/acf/test_right_acf.rb +11 -19
  49. data/test/awsbase/test_helper.rb +2 -0
  50. data/test/awsbase/test_right_awsbase.rb +11 -0
  51. data/test/ec2/test_right_ec2.rb +32 -1
  52. data/test/elb/test_helper.rb +2 -0
  53. data/test/elb/test_right_elb.rb +43 -0
  54. data/test/rds/test_helper.rb +2 -0
  55. data/test/rds/test_right_rds.rb +120 -0
  56. data/test/route_53/fixtures/a_record.xml +18 -0
  57. data/test/route_53/fixtures/alias_record.xml +18 -0
  58. data/test/route_53/test_helper.rb +2 -0
  59. data/test/route_53/test_right_route_53.rb +141 -0
  60. data/test/s3/test_right_s3.rb +176 -42
  61. data/test/s3/test_right_s3_stubbed.rb +6 -4
  62. data/test/sdb/test_active_sdb.rb +120 -19
  63. data/test/sdb/test_batch_put_attributes.rb +54 -0
  64. data/test/sdb/test_right_sdb.rb +71 -16
  65. data/test/sns/test_helper.rb +2 -0
  66. data/test/sns/test_right_sns.rb +153 -0
  67. data/test/sqs/test_right_sqs.rb +0 -6
  68. data/test/sqs/test_right_sqs_gen2.rb +104 -49
  69. data/test/ts_right_aws.rb +1 -0
  70. metadata +181 -22
@@ -0,0 +1,514 @@
1
+ #
2
+ # Copyright (c) 2009 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+
24
+ module RightAws
25
+
26
+ class Ec2
27
+
28
+ #-----------------------------------------------------------------
29
+ # EBS: Volumes
30
+ #-----------------------------------------------------------------
31
+
32
+ VOLUME_API_VERSION = (API_VERSION > '2012-06-15') ? API_VERSION : '2012-06-15'
33
+ VOLUME_TYPES = ['standard', 'io1']
34
+
35
+ # Describe EBS volumes.
36
+ #
37
+ # Accepts a list of volumes and/or a set of filters as the last parameter.
38
+ #
39
+ # Filters: attachement.attach-time, attachment.delete-on-termination, attachement.device, attachment.instance-id,
40
+ # attachment.status, availability-zone, create-time, size, snapshot-id, status, tag-key, tag-value, tag:key, volume-id
41
+ #
42
+ # ec2.describe_volumes #=>
43
+ # [{:aws_size => 94,
44
+ # :aws_device => "/dev/sdc",
45
+ # :aws_attachment_status => "attached",
46
+ # :zone => "merlot",
47
+ # :snapshot_id => nil,
48
+ # :aws_attached_at => "2008-06-18T08:19:28.000Z",
49
+ # :aws_status => "in-use",
50
+ # :aws_id => "vol-60957009",
51
+ # :aws_created_at => "2008-06-18T08:19:20.000Z",
52
+ # :aws_instance_id => "i-c014c0a9"},
53
+ # {:aws_id => "vol-71de8b1f",
54
+ # :aws_size => 5,
55
+ # :snapshot_id => nil,
56
+ # :zone => "us-east-1a",
57
+ # :aws_status => "available",
58
+ # :aws_created_at => "2012-06-21T18:47:34.000Z",
59
+ # :volume_type => "io1",
60
+ # :iop => "5"},#
61
+ # {:aws_size => 1,
62
+ # :zone => "merlot",
63
+ # :snapshot_id => nil,
64
+ # :aws_status => "available",
65
+ # :aws_id => "vol-58957031",
66
+ # :aws_created_at => Wed Jun 18 08:19:21 UTC 2008,}, ... ]
67
+ #
68
+ # ec2.describe_volumes(:filters => { 'availability-zone' => 'us-east-1a', 'size' => '10' })
69
+ #
70
+ # P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeVolumes.html
71
+ #
72
+ def describe_volumes(*list_and_options)
73
+ list_and_options = merge_new_options_into_list_and_options(list_and_options, :options => {:api_version => VOLUME_API_VERSION})
74
+ describe_resources_with_list_and_options('DescribeVolumes', 'VolumeId', QEc2DescribeVolumesParser, list_and_options)
75
+ end
76
+
77
+ # Create new EBS volume based on previously created snapshot.
78
+ # +Size+ in Gigabytes.
79
+ #
80
+ # ec2.create_volume('snap-000000', 10, zone) #=>
81
+ # {:snapshot_id => "snap-e21df98b",
82
+ # :aws_status => "creating",
83
+ # :aws_id => "vol-fc9f7a95",
84
+ # :zone => "merlot",
85
+ # :aws_created_at => "2008-06-24T18:13:32.000Z",
86
+ # :aws_size => 94}
87
+ #
88
+ # ec2.create_volume(nil, 5, 'us-east-1a', :iops => '5', :volume_type => 'io1') #=>
89
+ # {:aws_id=>"vol-71de8b1f",
90
+ # :aws_size=>5,
91
+ # :snapshot_id=>nil,
92
+ # :zone=>"us-east-1a",
93
+ # :aws_status=>"creating",
94
+ # :aws_created_at=>"2012-06-21T18:47:34.000Z",
95
+ # :volume_type=>"io1",
96
+ # :iops=>"5"}
97
+ #
98
+ def create_volume(snapshot_id, size, zone, options={})
99
+ hash = { "Size" => size.to_s,
100
+ "AvailabilityZone" => zone.to_s }
101
+ # Get rig of empty snapshot: e8s guys do not like it
102
+ hash["SnapshotId"] = snapshot_id.to_s unless snapshot_id.right_blank?
103
+ # Add IOPS support (default behavior) but skip it when an old API version call is requested
104
+ options[:options] ||= {}
105
+ options[:options][:api_version] ||= VOLUME_API_VERSION
106
+ if options[:options][:api_version] >= VOLUME_API_VERSION
107
+ hash["VolumeType"] = options[:volume_type] unless options[:volume_type].right_blank?
108
+ hash["Iops"] = options[:iops] unless options[:iops].right_blank?
109
+ end
110
+ link = generate_request("CreateVolume", hash, options[:options])
111
+ request_info(link, QEc2CreateVolumeParser.new(:logger => @logger))
112
+ rescue Exception
113
+ on_exception
114
+ end
115
+
116
+ # Delete the specified EBS volume.
117
+ # This does not deletes any snapshots created from this volume.
118
+ #
119
+ # ec2.delete_volume('vol-b48a6fdd') #=> true
120
+ #
121
+ def delete_volume(volume_id)
122
+ link = generate_request("DeleteVolume",
123
+ "VolumeId" => volume_id.to_s)
124
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
125
+ rescue Exception
126
+ on_exception
127
+ end
128
+
129
+ # Attach the specified EBS volume to a specified instance, exposing the
130
+ # volume using the specified device name.
131
+ #
132
+ # ec2.attach_volume('vol-898a6fe0', 'i-7c905415', '/dev/sdh') #=>
133
+ # { :aws_instance_id => "i-7c905415",
134
+ # :aws_device => "/dev/sdh",
135
+ # :aws_status => "attaching",
136
+ # :aws_attached_at => "2008-03-28T14:14:39.000Z",
137
+ # :aws_id => "vol-898a6fe0" }
138
+ #
139
+ def attach_volume(volume_id, instance_id, device)
140
+ link = generate_request("AttachVolume",
141
+ "VolumeId" => volume_id.to_s,
142
+ "InstanceId" => instance_id.to_s,
143
+ "Device" => device.to_s)
144
+ request_info(link, QEc2AttachAndDetachVolumeParser.new(:logger => @logger))
145
+ rescue Exception
146
+ on_exception
147
+ end
148
+
149
+ # Detach the specified EBS volume from the instance to which it is attached.
150
+ #
151
+ # ec2.detach_volume('vol-898a6fe0') #=>
152
+ # { :aws_instance_id => "i-7c905415",
153
+ # :aws_device => "/dev/sdh",
154
+ # :aws_status => "detaching",
155
+ # :aws_attached_at => "2008-03-28T14:38:34.000Z",
156
+ # :aws_id => "vol-898a6fe0"}
157
+ #
158
+ def detach_volume(volume_id, instance_id=nil, device=nil, force=nil)
159
+ hash = { "VolumeId" => volume_id.to_s }
160
+ hash["InstanceId"] = instance_id.to_s unless instance_id.right_blank?
161
+ hash["Device"] = device.to_s unless device.right_blank?
162
+ hash["Force"] = 'true' if force
163
+ #
164
+ link = generate_request("DetachVolume", hash)
165
+ request_info(link, QEc2AttachAndDetachVolumeParser.new(:logger => @logger))
166
+ rescue Exception
167
+ on_exception
168
+ end
169
+
170
+
171
+ #-----------------------------------------------------------------
172
+ # EBS: Snapshots
173
+ #-----------------------------------------------------------------
174
+
175
+ # Describe EBS snapshots.
176
+ #
177
+ # Accepts a list of snapshots and/or options: :restorable_by, :owner and :filters
178
+ #
179
+ # Options: :restorable_by => Array or String, :owner => Array or String, :filters => Hash
180
+ #
181
+ # Filters: description, owner-alias, owner-id, progress, snapshot-id, start-time, status, tag-key,
182
+ # tag-value, tag:key, volume-id, volume-size
183
+ #
184
+ # ec2.describe_snapshots #=>
185
+ # [{:aws_volume_size=>2,
186
+ # :tags=>{},
187
+ # :aws_id=>"snap-d010f6b9",
188
+ # :owner_alias=>"amazon",
189
+ # :aws_progress=>"100%",
190
+ # :aws_status=>"completed",
191
+ # :aws_description=>
192
+ # "Windows 2003 R2 Installation Media [Deprecated] - Enterprise Edition 64-bit",
193
+ # :aws_owner=>"711940113766",
194
+ # :aws_volume_id=>"vol-351efb5c",
195
+ # :aws_started_at=>"2008-10-20T18:23:59.000Z"},
196
+ # {:aws_volume_size=>2,
197
+ # :tags=>{},
198
+ # :aws_id=>"snap-a310f6ca",
199
+ # :owner_alias=>"amazon",
200
+ # :aws_progress=>"100%",
201
+ # :aws_status=>"completed",
202
+ # :aws_description=>"Windows 2003 R2 Installation Media 64-bit",
203
+ # :aws_owner=>"711940113766",
204
+ # :aws_volume_id=>"vol-001efb69",
205
+ # :aws_started_at=>"2008-10-20T18:25:53.000Z"}, ... ]
206
+ #
207
+ # ec2.describe_snapshots("snap-e676e28a", "snap-e176e281")
208
+ #
209
+ # ec2.describe_snapshots(:restorable_by => ['123456781234'],
210
+ # :owner => ['self', 'amazon'],
211
+ # :filters => {'tag:MyTag' => 'MyValue'})
212
+ #
213
+ # P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeSnapshots.html
214
+ #
215
+ def describe_snapshots(*list_and_options)
216
+ describe_resources_with_list_and_options('DescribeSnapshots', 'SnapshotId', QEc2DescribeSnapshotsParser, list_and_options)
217
+ end
218
+
219
+ def describe_snapshots_by_restorable_by(*list_and_options)
220
+ describe_resources_with_list_and_options('DescribeSnapshots', 'RestorableBy', QEc2DescribeSnapshotsParser, list_and_options)
221
+ end
222
+
223
+ # Create a snapshot of specified volume.
224
+ #
225
+ # ec2.create_snapshot('vol-898a6fe0', 'KD: WooHoo!!') #=>
226
+ # {:aws_volume_id=>"vol-e429db8d",
227
+ # :aws_started_at=>"2009-10-01T09:23:38.000Z",
228
+ # :aws_description=>"KD: WooHoo!!",
229
+ # :aws_owner=>"648770000000",
230
+ # :aws_progress=>"",
231
+ # :aws_status=>"pending",
232
+ # :aws_volume_size=>1,
233
+ # :aws_id=>"snap-3df54854"}
234
+ #
235
+ def create_snapshot(volume_id, description='')
236
+ link = generate_request("CreateSnapshot",
237
+ "VolumeId" => volume_id.to_s,
238
+ "Description" => description)
239
+ request_info(link, QEc2DescribeSnapshotsParser.new(:logger => @logger)).first
240
+ rescue Exception
241
+ on_exception
242
+ end
243
+
244
+ # Create a snapshot of specified volume, but with the normal retry algorithms disabled.
245
+ # This method will return immediately upon error. The user can specify connect and read timeouts (in s)
246
+ # for the connection to AWS. If the user does not specify timeouts, try_create_snapshot uses the default values
247
+ # in Rightscale::HttpConnection.
248
+ #
249
+ # ec2.try_create_snapshot('vol-898a6fe0', 'KD: WooHoo!!') #=>
250
+ # {:aws_volume_id=>"vol-e429db8d",
251
+ # :aws_started_at=>"2009-10-01T09:23:38.000Z",
252
+ # :aws_description=>"KD: WooHoo!!",
253
+ # :aws_owner=>"648770000000",
254
+ # :aws_progress=>"",
255
+ # :aws_status=>"pending",
256
+ # :aws_volume_size=>1,
257
+ # :aws_id=>"snap-3df54854"}
258
+ #
259
+ def try_create_snapshot(volume_id, connect_timeout = nil, read_timeout = nil, description='')
260
+ # For safety in the ensure block...we don't want to restore values
261
+ # if we never read them in the first place
262
+ orig_reiteration_time = nil
263
+ orig_http_params = nil
264
+
265
+ orig_reiteration_time = RightAws::AWSErrorHandler::reiteration_time
266
+ RightAws::AWSErrorHandler::reiteration_time = 0
267
+
268
+ orig_http_params = Rightscale::HttpConnection::params()
269
+ new_http_params = orig_http_params.dup
270
+ new_http_params[:http_connection_retry_count] = 0
271
+ new_http_params[:http_connection_open_timeout] = connect_timeout if !connect_timeout.nil?
272
+ new_http_params[:http_connection_read_timeout] = read_timeout if !read_timeout.nil?
273
+ Rightscale::HttpConnection::params = new_http_params
274
+
275
+ link = generate_request("CreateSnapshot",
276
+ "VolumeId" => volume_id.to_s,
277
+ "Description" => description)
278
+ request_info(link, QEc2DescribeSnapshotsParser.new(:logger => @logger)).first
279
+
280
+ rescue Exception
281
+ on_exception
282
+ ensure
283
+ RightAws::AWSErrorHandler::reiteration_time = orig_reiteration_time if orig_reiteration_time
284
+ Rightscale::HttpConnection::params = orig_http_params if orig_http_params
285
+ end
286
+
287
+ # Describe snapshot attribute.
288
+ #
289
+ # ec2.describe_snapshot_attribute('snap-36fe435f') #=>
290
+ # {:create_volume_permission=>
291
+ # {:users=>["826690000000", "826690000001"], :groups=>['all']}}
292
+ #
293
+ def describe_snapshot_attribute(snapshot_id, attribute='createVolumePermission')
294
+ link = generate_request("DescribeSnapshotAttribute",
295
+ 'SnapshotId'=> snapshot_id,
296
+ 'Attribute' => attribute)
297
+ request_info(link, QEc2DescribeSnapshotAttributeParser.new(:logger => @logger))
298
+ rescue Exception
299
+ on_exception
300
+ end
301
+
302
+ # Reset permission settings for the specified snapshot.
303
+ #
304
+ # ec2.reset_snapshot_attribute('snap-cecd29a7') #=> true
305
+ #
306
+ def reset_snapshot_attribute(snapshot_id, attribute='createVolumePermission')
307
+ link = generate_request("ResetSnapshotAttribute",
308
+ 'SnapshotId' => snapshot_id,
309
+ 'Attribute' => attribute)
310
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
311
+ rescue Exception
312
+ on_exception
313
+ end
314
+
315
+ # Modify snapshot attribute.
316
+ #
317
+ # Attribute can take only 'createVolumePermission' value.
318
+ # Value is a Hash {:add_user_ids, :add_groups, :remove_user_ids, :remove_groups }.
319
+ #
320
+ def modify_snapshot_attribute(snapshot_id, attribute, value)
321
+ params = { 'SnapshotId' => snapshot_id }
322
+ case attribute.to_s
323
+ when 'createVolumePermission'
324
+ params.update(amazonize_list('CreateVolumePermission.Add.?.UserId', value[:add_user_ids]))
325
+ params.update(amazonize_list('CreateVolumePermission.Add.?.Group', value[:add_groups]))
326
+ params.update(amazonize_list('CreateVolumePermission.Remove.?.UserId', value[:remove_user_ids]))
327
+ params.update(amazonize_list('CreateVolumePermission.Remove.?.Group', value[:remove_groups]))
328
+ end
329
+ link = generate_request("ModifySnapshotAttribute", params)
330
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
331
+ rescue Exception
332
+ on_exception
333
+ end
334
+
335
+ # Grant create volume permission for a list of users.
336
+ #
337
+ # ec2.modify_snapshot_attribute_create_volume_permission_add_users('snap-36fe435f', '000000000000', '000000000001') #=> true
338
+ #
339
+ def modify_snapshot_attribute_create_volume_permission_add_users(snapshot_id, *user_ids)
340
+ modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :add_user_ids => user_ids.flatten )
341
+ end
342
+
343
+ # Revoke create volume permission for a list of users.
344
+ #
345
+ # ec2.modify_snapshot_attribute_create_volume_permission_remove_users('snap-36fe435f', '000000000000', '000000000001') #=> true
346
+ #
347
+ def modify_snapshot_attribute_create_volume_permission_remove_users(snapshot_id, *user_ids)
348
+ modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :remove_user_ids => user_ids.flatten )
349
+ end
350
+
351
+ # Grant create volume permission for user groups (currently only 'all' is supported).
352
+ #
353
+ # ec2.modify_snapshot_attribute_create_volume_permission_add_groups('snap-36fe435f') #=> true
354
+ #
355
+ def modify_snapshot_attribute_create_volume_permission_add_groups(snapshot_id, *groups)
356
+ groups.flatten!
357
+ groups = ['all'] if groups.right_blank?
358
+ modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :add_groups => groups )
359
+ end
360
+
361
+ # Remove create volume permission for user groups (currently only 'all' is supported).
362
+ #
363
+ # ec2.modify_snapshot_attribute_create_volume_permission_remove_groups('snap-36fe435f') #=> true
364
+ #
365
+ def modify_snapshot_attribute_create_volume_permission_remove_groups(snapshot_id, *groups)
366
+ groups.flatten!
367
+ groups = ['all'] if groups.right_blank?
368
+ modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :remove_groups => groups )
369
+ end
370
+
371
+ # Delete the specified snapshot.
372
+ #
373
+ # ec2.delete_snapshot('snap-55a5403c') #=> true
374
+ #
375
+ def delete_snapshot(snapshot_id)
376
+ link = generate_request("DeleteSnapshot",
377
+ "SnapshotId" => snapshot_id.to_s)
378
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
379
+ rescue Exception
380
+ on_exception
381
+ end
382
+
383
+ #-----------------------------------------------------------------
384
+ # PARSERS: EBS - Volumes
385
+ #-----------------------------------------------------------------
386
+
387
+ class QEc2CreateVolumeParser < RightAWSParser #:nodoc:
388
+ def tagend(name)
389
+ case name
390
+ when 'volumeId' then @result[:aws_id] = @text
391
+ when 'status' then @result[:aws_status] = @text
392
+ when 'createTime' then @result[:aws_created_at] = @text
393
+ when 'size' then @result[:aws_size] = @text.to_i ###
394
+ when 'snapshotId' then @result[:snapshot_id] = @text.right_blank? ? nil : @text ###
395
+ when 'availabilityZone' then @result[:zone] = @text ###
396
+ when 'volumeType' then @result[:volume_type] = @text
397
+ when 'iops' then @result[:iops] = @text
398
+ end
399
+ end
400
+ def reset
401
+ @result = {}
402
+ end
403
+ end
404
+
405
+ class QEc2AttachAndDetachVolumeParser < RightAWSParser #:nodoc:
406
+ def tagend(name)
407
+ case name
408
+ when 'volumeId' then @result[:aws_id] = @text
409
+ when 'instanceId' then @result[:aws_instance_id] = @text
410
+ when 'device' then @result[:aws_device] = @text
411
+ when 'status' then @result[:aws_attachment_status] = @text
412
+ when 'attachTime' then @result[:aws_attached_at] = @text
413
+ end
414
+ end
415
+ def reset
416
+ @result = {}
417
+ end
418
+ end
419
+
420
+ class QEc2DescribeVolumesParser < RightAWSParser #:nodoc:
421
+ def tagstart(name, attributes)
422
+ case full_tag_name
423
+ when %r{volumeSet/item$} then @item = { :tags => {} }
424
+ when %r{/tagSet/item$} then @aws_tag = {}
425
+ end
426
+ end
427
+ def tagend(name)
428
+ case name
429
+ when 'size' then @item[:aws_size] = @text.to_i
430
+ when 'createTime' then @item[:aws_created_at] = @text
431
+ when 'instanceId' then @item[:aws_instance_id] = @text
432
+ when 'device' then @item[:aws_device] = @text
433
+ when 'attachTime' then @item[:aws_attached_at] = @text
434
+ when 'snapshotId' then @item[:snapshot_id] = @text.right_blank? ? nil : @text
435
+ when 'availabilityZone' then @item[:zone] = @text
436
+ when 'deleteOnTermination' then @item[:delete_on_termination] = (@text == 'true')
437
+ when 'volumeType' then @item[:volume_type] = @text
438
+ when 'iops' then @item[:iops] = @text
439
+ else
440
+ case full_tag_name
441
+ when %r{/volumeSet/item/volumeId$} then @item[:aws_id] = @text
442
+ when %r{/volumeSet/item/status$} then @item[:aws_status] = @text
443
+ when %r{/attachmentSet/item/status$} then @item[:aws_attachment_status] = @text
444
+ when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
445
+ when %r{/tagSet/item/value$} then @aws_tag[:value] = @text
446
+ when %r{/tagSet/item$} then @item[:tags][@aws_tag[:key]] = @aws_tag[:value]
447
+ when %r{/volumeSet/item$} then @result << @item
448
+ end
449
+ end
450
+ end
451
+ def reset
452
+ @result = []
453
+ end
454
+ end
455
+
456
+ #-----------------------------------------------------------------
457
+ # PARSERS: EBS - Snapshots
458
+ #-----------------------------------------------------------------
459
+
460
+ class QEc2DescribeSnapshotsParser < RightAWSParser #:nodoc:
461
+ def tagstart(name, attributes)
462
+ case full_tag_name
463
+ when %r{CreateSnapshotResponse$},
464
+ %r{/snapshotSet/item$} then @item = { :tags => {} }
465
+ when %r{/tagSet/item$} then @aws_tag = {}
466
+ end
467
+ end
468
+ def tagend(name)
469
+ case name
470
+ when 'volumeId' then @item[:aws_volume_id] = @text
471
+ when 'snapshotId' then @item[:aws_id] = @text
472
+ when 'status' then @item[:aws_status] = @text
473
+ when 'startTime' then @item[:aws_started_at] = @text
474
+ when 'progress' then @item[:aws_progress] = @text
475
+ when 'description' then @item[:aws_description] = @text
476
+ when 'ownerId' then @item[:aws_owner] = @text
477
+ when 'volumeSize' then @item[:aws_volume_size] = @text.to_i
478
+ when 'ownerAlias' then @item[:owner_alias] = @text
479
+ else
480
+ case full_tag_name
481
+ when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
482
+ when %r{/tagSet/item/value$} then @aws_tag[:value] = @text
483
+ when %r{/tagSet/item$} then @item[:tags][@aws_tag[:key]] = @aws_tag[:value]
484
+ when %r{CreateSnapshotResponse$},
485
+ %r{/snapshotSet/item$} then @result << @item
486
+ end
487
+ end
488
+ end
489
+ def reset
490
+ @result = []
491
+ end
492
+ end
493
+
494
+ class QEc2DescribeSnapshotAttributeParser < RightAWSParser #:nodoc:
495
+ def tagstart(name, attributes)
496
+ case name
497
+ when 'createVolumePermission' then @result[:create_volume_permission] = { :groups => [], :users => [] }
498
+ end
499
+ end
500
+ def tagend(name)
501
+ case full_tag_name
502
+ when "#{@create_volume_permission}/group" then @result[:create_volume_permission][:groups] << @text
503
+ when "#{@create_volume_permission}/userId" then @result[:create_volume_permission][:users] << @text
504
+ end
505
+ end
506
+ def reset
507
+ @create_volume_permission = "DescribeSnapshotAttributeResponse/createVolumePermission/item"
508
+ @result = {}
509
+ end
510
+ end
511
+
512
+ end
513
+
514
+ end