ktheory-right_aws 2.0.1

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 (51) hide show
  1. data/History.txt +284 -0
  2. data/Manifest.txt +50 -0
  3. data/README.txt +167 -0
  4. data/Rakefile +110 -0
  5. data/lib/acf/right_acf_interface.rb +485 -0
  6. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  7. data/lib/acf/right_acf_streaming_interface.rb +236 -0
  8. data/lib/acw/right_acw_interface.rb +249 -0
  9. data/lib/as/right_as_interface.rb +699 -0
  10. data/lib/awsbase/benchmark_fix.rb +39 -0
  11. data/lib/awsbase/right_awsbase.rb +978 -0
  12. data/lib/awsbase/support.rb +115 -0
  13. data/lib/ec2/right_ec2.rb +395 -0
  14. data/lib/ec2/right_ec2_ebs.rb +452 -0
  15. data/lib/ec2/right_ec2_images.rb +373 -0
  16. data/lib/ec2/right_ec2_instances.rb +755 -0
  17. data/lib/ec2/right_ec2_monitoring.rb +70 -0
  18. data/lib/ec2/right_ec2_reserved_instances.rb +170 -0
  19. data/lib/ec2/right_ec2_security_groups.rb +277 -0
  20. data/lib/ec2/right_ec2_spot_instances.rb +399 -0
  21. data/lib/ec2/right_ec2_vpc.rb +571 -0
  22. data/lib/elb/right_elb_interface.rb +496 -0
  23. data/lib/rds/right_rds_interface.rb +998 -0
  24. data/lib/right_aws.rb +83 -0
  25. data/lib/s3/right_s3.rb +1126 -0
  26. data/lib/s3/right_s3_interface.rb +1199 -0
  27. data/lib/sdb/active_sdb.rb +1122 -0
  28. data/lib/sdb/right_sdb_interface.rb +721 -0
  29. data/lib/sqs/right_sqs.rb +388 -0
  30. data/lib/sqs/right_sqs_gen2.rb +343 -0
  31. data/lib/sqs/right_sqs_gen2_interface.rb +524 -0
  32. data/lib/sqs/right_sqs_interface.rb +594 -0
  33. data/test/acf/test_helper.rb +2 -0
  34. data/test/acf/test_right_acf.rb +138 -0
  35. data/test/ec2/test_helper.rb +2 -0
  36. data/test/ec2/test_right_ec2.rb +108 -0
  37. data/test/http_connection.rb +87 -0
  38. data/test/rds/test_helper.rb +2 -0
  39. data/test/rds/test_right_rds.rb +120 -0
  40. data/test/s3/test_helper.rb +2 -0
  41. data/test/s3/test_right_s3.rb +421 -0
  42. data/test/s3/test_right_s3_stubbed.rb +97 -0
  43. data/test/sdb/test_active_sdb.rb +357 -0
  44. data/test/sdb/test_helper.rb +3 -0
  45. data/test/sdb/test_right_sdb.rb +253 -0
  46. data/test/sqs/test_helper.rb +2 -0
  47. data/test/sqs/test_right_sqs.rb +291 -0
  48. data/test/sqs/test_right_sqs_gen2.rb +264 -0
  49. data/test/test_credentials.rb +37 -0
  50. data/test/ts_right_aws.rb +14 -0
  51. metadata +184 -0
@@ -0,0 +1,399 @@
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
+ # Spot Instances
30
+ #-----------------------------------------------------------------
31
+
32
+ # Describe Spot Price history.
33
+ # Options: :start_time, :end_time, instance_types, product_description
34
+ #
35
+ # ec2.describe_spot_price_history #=>
36
+ # [{:spot_price=>0.054,
37
+ # :timestamp=>"2009-12-07T12:12:58.000Z",
38
+ # :product_description=>"Windows",
39
+ # :instance_type=>"m1.small"},
40
+ # {:spot_price=>0.06,
41
+ # :timestamp=>"2009-12-07T12:18:32.000Z",
42
+ # :product_description=>"Linux/UNIX",
43
+ # :instance_type=>"c1.medium"},
44
+ # {:spot_price=>0.198,
45
+ # :timestamp=>"2009-12-07T12:58:00.000Z",
46
+ # :product_description=>"Windows",
47
+ # :instance_type=>"m1.large"},
48
+ # {:spot_price=>0.028,
49
+ # :timestamp=>"2009-12-07T13:48:50.000Z",
50
+ # :product_description=>"Linux/UNIX",
51
+ # :instance_type=>"m1.small"}, ... ]
52
+ #
53
+ # ec2.describe_spot_price_history(:start_time => 1.day.ago,
54
+ # :end_time => 10.minutes.ago,
55
+ # :instance_types => ["c1.medium", "m1.small"],
56
+ # :product_description => "Linux/UNIX" ) #=>
57
+ # [{:product_description=>"Linux/UNIX",
58
+ # :timestamp=>"2010-02-04T05:44:36.000Z",
59
+ # :spot_price=>0.031,
60
+ # :instance_type=>"m1.small"},
61
+ # {:product_description=>"Linux/UNIX",
62
+ # :timestamp=>"2010-02-04T17:56:25.000Z",
63
+ # :spot_price=>0.058,
64
+ # :instance_type=>"c1.medium"}, ... ]
65
+ #
66
+ def describe_spot_price_history(options={})
67
+ options = options.dup
68
+ request_hash = {}
69
+ request_hash['StartTime'] = AwsUtils::utc_iso8601(options[:start_time]) unless options[:start_time].blank?
70
+ request_hash['EndTime'] = AwsUtils::utc_iso8601(options[:end_time]) unless options[:end_time].blank?
71
+ request_hash['ProductDescription'] = options[:product_description] unless options[:product_description].blank?
72
+ request_hash.merge!(amazonize_list('InstanceType', Array(options[:instance_types]))) unless options[:instance_types].blank?
73
+ link = generate_request("DescribeSpotPriceHistory", request_hash)
74
+ request_info(link, QEc2DescribeSpotPriceHistoryParser.new)
75
+ rescue Exception
76
+ on_exception
77
+ end
78
+
79
+ # Describe Spot Instance requests.
80
+ #
81
+ # ec2.describe_spot_instance_requests #=>
82
+ # [{:type=>"one-time",
83
+ # :create_time=>"2010-03-10T10:30:32.000Z",
84
+ # :instance_type=>"c1.medium",
85
+ # :state=>"cancelled",
86
+ # :groups=>["default"],
87
+ # :product_description=>"Linux/UNIX",
88
+ # :spot_instance_request_id=>"sir-bfa06804",
89
+ # :image_id=>"ami-08f41161",
90
+ # :spot_price=>0.01,
91
+ # :monitoring_enabled=>false},
92
+ # {:type=>"one-time",
93
+ # :create_time=>"2010-03-10T10:33:29.000Z",
94
+ # :instance_type=>"c1.medium",
95
+ # :state=>"open",
96
+ # :groups=>["default", "33"],
97
+ # :product_description=>"Linux/UNIX",
98
+ # :spot_instance_request_id=>"sir-b1713a03",
99
+ # :image_id=>"ami-08f41161",
100
+ # :spot_price=>0.01,
101
+ # :monitoring_enabled=>false,
102
+ # :key_name=>"tim"},
103
+ # {:type=>"one-time",
104
+ # :instance_id=>"i-c516ceae",
105
+ # :create_time=>"2010-03-10T10:43:48.000Z",
106
+ # :instance_type=>"c1.medium",
107
+ # :state=>"active",
108
+ # :groups=>["default", "33"],
109
+ # :product_description=>"Linux/UNIX",
110
+ # :spot_instance_request_id=>"sir-5eb6c604",
111
+ # :image_id=>"ami-08f41161",
112
+ # :spot_price=>0.2,
113
+ # :monitoring_enabled=>false,
114
+ # :key_name=>"tim"}]
115
+ #
116
+ def describe_spot_instance_requests(*spot_instance_request_ids)
117
+ link = generate_request("DescribeSpotInstanceRequests", amazonize_list('SpotInstanceRequestId', spot_instance_request_ids.flatten))
118
+ request_info(link, QEc2DescribeSpotInstanceParser.new(:logger => @logger))
119
+ end
120
+
121
+ # Create a Spot Instance request.
122
+ #
123
+ # Mandatory params: :image_id, :spot_price, :instance_type
124
+ # Optional params: :valid_from, :valid_until, :instance_count, :type, :launch_group,
125
+ # :availability_zone_group, :key_name, :user_data, :addressing_type, :kernel_id,
126
+ # :ramdisk_id, :subnet_id, :availability_zone, :monitoring_enabled, :groups,
127
+ # :block_device_mappings
128
+ #
129
+ # ec2.request_spot_instances(
130
+ # :image_id => 'ami-08f41161',
131
+ # :spot_price => 0.01,
132
+ # :key_name => 'tim',
133
+ # :instance_count => 2,
134
+ # :groups => ['33','default'],
135
+ # :instance_type => 'c1.medium') #=>
136
+ #
137
+ # [{:product_description=>"Linux/UNIX",
138
+ # :type=>"one-time",
139
+ # :spot_instance_requestId=>"sir-7a893003",
140
+ # :monitoring_enabled=>false,
141
+ # :image_id=>"ami-08f41161",
142
+ # :state=>"open",
143
+ # :spot_price=>0.01,
144
+ # :groups=>["default", "33"],
145
+ # :key_name=>"tim",
146
+ # :create_time=>"2010-03-10T10:33:09.000Z",
147
+ # :instance_type=>"c1.medium"},
148
+ # {:product_description=>"Linux/UNIX",
149
+ # :type=>"one-time",
150
+ # :spot_instance_requestId=>"sir-13dc9a03",
151
+ # :monitoring_enabled=>false,
152
+ # :image_id=>"ami-08f41161",
153
+ # :state=>"open",
154
+ # :spot_price=>0.01,
155
+ # :groups=>["default", "33"],
156
+ # :key_name=>"tim",
157
+ # :create_time=>"2010-03-10T10:33:09.000Z",
158
+ # :instance_type=>"c1.medium"}]
159
+ #
160
+ # ec2.request_spot_instances(
161
+ # :image_id => 'ami-08f41161',
162
+ # :spot_price => 0.01,
163
+ # :instance_type => 'm1.small',
164
+ # :valid_from => 10.minutes.since,
165
+ # :valid_until => 1.hour.since,
166
+ # :instance_count => 1,
167
+ # :key_name => 'tim',
168
+ # :groups => ['33','default'],
169
+ # :availability_zone => 'us-east-1a',
170
+ # :monitoring_enabled => true,
171
+ # :launch_group => 'lg1',
172
+ # :availability_zone_group => 'azg1',
173
+ # :block_device_mappings => [ { :device_name => '/dev/sdk',
174
+ # :ebs_snapshot_id => 'snap-145cbc7d',
175
+ # :ebs_delete_on_termination => true,
176
+ # :ebs_volume_size => 3,
177
+ # :virtual_name => 'ephemeral2'
178
+ # } ] ) #=>
179
+ #
180
+ # [{:monitoring_enabled=>true,
181
+ # :type=>"one-time",
182
+ # :image_id=>"ami-08f41161",
183
+ # :launch_group=>"lg1",
184
+ # :state=>"open",
185
+ # :valid_until=>"2010-02-05T19:13:44.000Z",
186
+ # :create_time=>"2010-02-05T18:13:46.000Z",
187
+ # :availability_zone_group=>"azg1",
188
+ # :spot_price=>0.01,
189
+ # :block_device_mappings=>
190
+ # [{:ebs_delete_on_termination=>true,
191
+ # :ebs_volume_size=>3,
192
+ # :virtual_name=>"ephemeral2",
193
+ # :device_name=>"/dev/sdk",
194
+ # :ebs_snapshot_id=>"snap-145cbc7d"}],
195
+ # :instance_type=>"m1.small",
196
+ # :groups=>["default", "33"],
197
+ # :product_description=>"Linux/UNIX",
198
+ # :key_name=>"tim",
199
+ # :valid_from=>"2010-02-05T18:23:44.000Z",
200
+ # :availability_zone=>"us-east-1a",
201
+ # :spot_instance_request_id=>"sir-32da8a03"}]
202
+ #
203
+ def request_spot_instances(options)
204
+ options = options.dup
205
+ request_hash = { 'SpotPrice' => options[:spot_price],
206
+ 'LaunchSpecification.ImageId' => options[:image_id],
207
+ 'LaunchSpecification.InstanceType' => options[:instance_type]}
208
+ request_hash['ValidFrom'] = AwsUtils::utc_iso8601(options[:valid_from]) unless options[:valid_from].blank?
209
+ request_hash['ValidUntil'] = AwsUtils::utc_iso8601(options[:valid_until]) unless options[:valid_until].blank?
210
+ request_hash['InstanceCount'] = options[:instance_count] unless options[:instance_count].blank?
211
+ request_hash['Type'] = options[:type] unless options[:type].blank?
212
+ request_hash['LaunchGroup'] = options[:launch_group] unless options[:launch_group].blank?
213
+ request_hash['AvailabilityZoneGroup'] = options[:availability_zone_group] unless options[:availability_zone_group].blank?
214
+ request_hash['LaunchSpecification.KeyName'] = options[:key_name] unless options[:key_name].blank?
215
+ request_hash['LaunchSpecification.AddressingType'] = options[:addressing_type] unless options[:addressing_type].blank?
216
+ request_hash['LaunchSpecification.KernelId'] = options[:kernel_id] unless options[:kernel_id].blank?
217
+ request_hash['LaunchSpecification.RamdiskId'] = options[:ramdisk_id] unless options[:ramdisk_id].blank?
218
+ request_hash['LaunchSpecification.SubnetId'] = options[:subnet_id] unless options[:subnet_id].blank?
219
+ request_hash['LaunchSpecification.Placement.AvailabilityZone'] = options[:availability_zone] unless options[:availability_zone].blank?
220
+ request_hash['LaunchSpecification.Monitoring.Enabled'] = options[:monitoring_enabled] unless options[:monitoring_enabled].blank?
221
+ request_hash.merge!(amazonize_list('LaunchSpecification.SecurityGroup', options[:groups])) unless options[:groups].blank?
222
+ request_hash.merge!(amazonize_block_device_mappings(options[:block_device_mappings], 'LaunchSpecification.BlockDeviceMapping'))
223
+ unless options[:user_data].blank?
224
+ # See RightAws::Ec2#run_instances
225
+ options[:user_data].strip!
226
+ request_hash['LaunchSpecification.UserData'] = Base64.encode64(options[:user_data]).delete("\n") unless options[:user_data].blank?
227
+ end
228
+ link = generate_request("RequestSpotInstances", request_hash)
229
+ request_info(link, QEc2DescribeSpotInstanceParser.new(:logger => @logger))
230
+ end
231
+
232
+ # Cancel one or more Spot Instance requests.
233
+ #
234
+ # ec2.cancel_spot_instance_requests('sir-60662c03',"sir-d3c96e04", "sir-4fa8d804","sir-6992ce04") #=>
235
+ # [{:state=>"cancelled", :spot_instance_request_id=>"sir-60662c03"},
236
+ # {:state=>"cancelled", :spot_instance_request_id=>"sir-6992ce04"},
237
+ # {:state=>"cancelled", :spot_instance_request_id=>"sir-4fa8d804"},
238
+ # {:state=>"cancelled", :spot_instance_request_id=>"sir-d3c96e04"}]
239
+ #
240
+ def cancel_spot_instance_requests(*spot_instance_request_ids)
241
+ link = generate_request("CancelSpotInstanceRequests", amazonize_list('SpotInstanceRequestId', spot_instance_request_ids.flatten))
242
+ request_info(link, QEc2CancelSpotInstanceParser.new(:logger => @logger))
243
+ end
244
+
245
+ # Create the data feed for Spot Instances
246
+ # (Enables to view Spot Instance usage logs)
247
+ #
248
+ # ec2.create_spot_datafeed_subscription('bucket-for-konstantin-eu', 'splogs/') #=>
249
+ # { :owner_id=>"826693181925",
250
+ # :bucket=>"bucket-for-konstantin-eu",
251
+ # :prefix=>"splogs/",
252
+ # :state=>"Active"}
253
+ #
254
+ def create_spot_datafeed_subscription(bucket, prefix=nil)
255
+ request_hash = { 'Bucket' => bucket }
256
+ request_hash['Prefix'] = prefix unless prefix.blank?
257
+ link = generate_request("CreateSpotDatafeedSubscription", request_hash)
258
+ request_info(link, QEc2DescribeSpotDatafeedSubscriptionParser.new(:logger => @logger))
259
+ end
260
+
261
+ # Describe the data feed for Spot Instances.
262
+ #
263
+ # ec2.describe_spot_datafeed_subscription #=>
264
+ # { :owner_id=>"826693181925",
265
+ # :bucket=>"bucket-for-konstantin-eu",
266
+ # :prefix=>"splogs/",
267
+ # :state=>"Active"}
268
+ #
269
+ def describe_spot_datafeed_subscription
270
+ link = generate_request("DescribeSpotDatafeedSubscription")
271
+ request_info(link, QEc2DescribeSpotDatafeedSubscriptionParser.new(:logger => @logger))
272
+ end
273
+
274
+ # Delete the data feed for Spot Instances.
275
+ #
276
+ # ec2.delete_spot_datafeed_subscription #=> true
277
+ #
278
+ def delete_spot_datafeed_subscription()
279
+ link = generate_request("DeleteSpotDatafeedSubscription")
280
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
281
+ end
282
+
283
+ #-----------------------------------------------------------------
284
+ # PARSERS: Spot Instances
285
+ #-----------------------------------------------------------------
286
+
287
+ class QEc2DescribeSpotPriceHistoryParser < RightAWSParser #:nodoc:
288
+ def tagstart(name, attributes)
289
+ @item = {} if name == 'item'
290
+ end
291
+ def tagend(name)
292
+ case name
293
+ when 'instanceType' then @item[:instance_type] = @text
294
+ when 'productDescription' then @item[:product_description] = @text
295
+ when 'spotPrice' then @item[:spot_price] = @text.to_f
296
+ when 'timestamp' then @item[:timestamp] = @text
297
+ when 'item' then @result << @item
298
+ end
299
+ end
300
+ def reset
301
+ @result = []
302
+ end
303
+ end
304
+
305
+ class QEc2DescribeSpotInstanceParser < RightAWSParser #:nodoc:
306
+ def tagstart(name, attributes)
307
+ case full_tag_name
308
+ when %r{spotInstanceRequestSet/item$}
309
+ @item = {}
310
+ when %r{/blockDeviceMapping/item$}
311
+ @item[:block_device_mappings] ||= []
312
+ @block_device_mapping = {}
313
+ end
314
+ end
315
+ def tagend(name)
316
+ case name
317
+ when 'spotInstanceRequestId' then @item[:spot_instance_request_id]= @text
318
+ when 'spotPrice' then @item[:spot_price] = @text.to_f
319
+ when 'type' then @item[:type] = @text
320
+ when 'state' then @item[:state] = @text
321
+ when 'code' then @item[:fault_code] = @text
322
+ when 'message' then @item[:fault_message] = @text
323
+ when 'validFrom' then @item[:valid_from] = @text
324
+ when 'validUntil' then @item[:valid_until] = @text
325
+ when 'launchGroup' then @item[:launch_group] = @text
326
+ when 'availabilityZoneGroup' then @item[:availability_zone_group] = @text
327
+ when 'imageId' then @item[:image_id] = @text
328
+ when 'keyName' then @item[:key_name] = @text
329
+ when 'userData' then @item[:userData] = @text
330
+ when 'data' then @item[:data] = @text
331
+ when 'addressingType' then @item[:addressing_type] = @text
332
+ when 'instanceType' then @item[:instance_type] = @text
333
+ when 'availabilityZone' then @item[:availability_zone] = @text
334
+ when 'kernelId' then @item[:kernel_id] = @text
335
+ when 'ramdiskId' then @item[:ramdisk_id] = @text
336
+ when 'subnetId' then @item[:subnet_id] = @text
337
+ when 'instanceId' then @item[:instance_id] = @text
338
+ when 'createTime' then @item[:create_time] = @text
339
+ when 'productDescription' then @item[:product_description] = @text
340
+ when 'groupId' then (@item[:groups] ||= []) << @text
341
+ else
342
+ case full_tag_name
343
+ when %r{monitoring/enabled$}
344
+ @item[:monitoring_enabled] = @text == 'true'
345
+ when %r{/blockDeviceMapping/item} # no trailing $
346
+ case name
347
+ when 'deviceName' then @block_device_mapping[:device_name] = @text
348
+ when 'virtualName' then @block_device_mapping[:virtual_name] = @text
349
+ when 'volumeSize' then @block_device_mapping[:ebs_volume_size] = @text.to_i
350
+ when 'snapshotId' then @block_device_mapping[:ebs_snapshot_id] = @text
351
+ when 'deleteOnTermination' then @block_device_mapping[:ebs_delete_on_termination] = @text == 'true' ? true : false
352
+ when 'item' then @item[:block_device_mappings] << @block_device_mapping
353
+ end
354
+ when %r{spotInstanceRequestSet/item$}
355
+ @result << @item
356
+ end
357
+ end
358
+ end
359
+ def reset
360
+ @result = []
361
+ end
362
+ end
363
+
364
+ class QEc2CancelSpotInstanceParser < RightAWSParser #:nodoc:
365
+ def tagstart(name, attributes)
366
+ @item = {} if name == 'item'
367
+ end
368
+ def tagend(name)
369
+ case name
370
+ when 'spotInstanceRequestId' then @item[:spot_instance_request_id] = @text
371
+ when 'state' then @item[:state] = @text
372
+ when 'item' then @result << @item
373
+ end
374
+ end
375
+ def reset
376
+ @result = []
377
+ end
378
+ end
379
+
380
+ class QEc2DescribeSpotDatafeedSubscriptionParser < RightAWSParser #:nodoc:
381
+ def tagend(name)
382
+ case name
383
+ when 'ownerId' then @result[:owner_id] = @text
384
+ when 'bucket' then @result[:bucket] = @text
385
+ when 'prefix' then @result[:prefix] = @text
386
+ when 'state' then @result[:state] = @text
387
+ when 'fault' then @result[:fault] = @text
388
+ when 'code' then @result[:code] = @text
389
+ when 'message' then @result[:message] = @text
390
+ end
391
+ end
392
+ def reset
393
+ @result = {}
394
+ end
395
+ end
396
+
397
+ end
398
+
399
+ end