talaris-right_aws 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +305 -0
- data/Manifest.txt +60 -0
- data/README.txt +163 -0
- data/Rakefile +104 -0
- data/lib/acf/right_acf_interface.rb +549 -0
- data/lib/acf/right_acf_invalidations.rb +144 -0
- data/lib/acf/right_acf_origin_access_identities.rb +230 -0
- data/lib/acf/right_acf_streaming_interface.rb +229 -0
- data/lib/acw/right_acw_interface.rb +248 -0
- data/lib/as/right_as_interface.rb +698 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/right_awsbase.rb +1174 -0
- data/lib/awsbase/support.rb +35 -0
- data/lib/awsbase/version.rb +9 -0
- data/lib/ec2/right_ec2.rb +458 -0
- data/lib/ec2/right_ec2_ebs.rb +465 -0
- data/lib/ec2/right_ec2_images.rb +413 -0
- data/lib/ec2/right_ec2_instances.rb +785 -0
- data/lib/ec2/right_ec2_monitoring.rb +70 -0
- data/lib/ec2/right_ec2_placement_groups.rb +108 -0
- data/lib/ec2/right_ec2_reserved_instances.rb +174 -0
- data/lib/ec2/right_ec2_security_groups.rb +396 -0
- data/lib/ec2/right_ec2_spot_instances.rb +425 -0
- data/lib/ec2/right_ec2_tags.rb +139 -0
- data/lib/ec2/right_ec2_vpc.rb +583 -0
- data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
- data/lib/elb/right_elb_interface.rb +571 -0
- data/lib/iam/right_iam_access_keys.rb +71 -0
- data/lib/iam/right_iam_groups.rb +195 -0
- data/lib/iam/right_iam_interface.rb +341 -0
- data/lib/iam/right_iam_mfa_devices.rb +67 -0
- data/lib/iam/right_iam_users.rb +251 -0
- data/lib/rds/right_rds_interface.rb +1309 -0
- data/lib/right_aws.rb +83 -0
- data/lib/route_53/right_route_53_interface.rb +630 -0
- data/lib/s3/right_s3.rb +1123 -0
- data/lib/s3/right_s3_interface.rb +1198 -0
- data/lib/sdb/active_sdb.rb +1107 -0
- data/lib/sdb/right_sdb_interface.rb +753 -0
- data/lib/sqs/right_sqs.rb +387 -0
- data/lib/sqs/right_sqs_gen2.rb +342 -0
- data/lib/sqs/right_sqs_gen2_interface.rb +523 -0
- data/lib/sqs/right_sqs_interface.rb +593 -0
- data/right_aws.gemspec +91 -0
- data/test/acf/test_helper.rb +2 -0
- data/test/acf/test_right_acf.rb +138 -0
- data/test/awsbase/test_helper.rb +2 -0
- data/test/awsbase/test_right_awsbase.rb +12 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_right_ec2.rb +108 -0
- data/test/http_connection.rb +87 -0
- data/test/rds/test_helper.rb +2 -0
- data/test/rds/test_right_rds.rb +120 -0
- data/test/s3/test_helper.rb +2 -0
- data/test/s3/test_right_s3.rb +421 -0
- data/test/s3/test_right_s3_stubbed.rb +97 -0
- data/test/sdb/test_active_sdb.rb +357 -0
- data/test/sdb/test_batch_put_attributes.rb +54 -0
- data/test/sdb/test_helper.rb +3 -0
- data/test/sdb/test_right_sdb.rb +253 -0
- data/test/sqs/test_helper.rb +2 -0
- data/test/sqs/test_right_sqs.rb +285 -0
- data/test/sqs/test_right_sqs_gen2.rb +264 -0
- data/test/test_credentials.rb +37 -0
- data/test/ts_right_aws.rb +14 -0
- metadata +214 -0
@@ -0,0 +1,425 @@
|
|
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
|
+
#
|
34
|
+
# Options: :start_time, :end_time, instance_types, product_description
|
35
|
+
#
|
36
|
+
# Filters: instance-type, product-description, spot-price, timestamp
|
37
|
+
#
|
38
|
+
# ec2.describe_spot_price_history #=>
|
39
|
+
# [{:spot_price=>0.054,
|
40
|
+
# :timestamp=>"2009-12-07T12:12:58.000Z",
|
41
|
+
# :product_description=>"Windows",
|
42
|
+
# :instance_type=>"m1.small"},
|
43
|
+
# {:spot_price=>0.06,
|
44
|
+
# :timestamp=>"2009-12-07T12:18:32.000Z",
|
45
|
+
# :product_description=>"Linux/UNIX",
|
46
|
+
# :instance_type=>"c1.medium"},
|
47
|
+
# {:spot_price=>0.198,
|
48
|
+
# :timestamp=>"2009-12-07T12:58:00.000Z",
|
49
|
+
# :product_description=>"Windows",
|
50
|
+
# :instance_type=>"m1.large"},
|
51
|
+
# {:spot_price=>0.028,
|
52
|
+
# :timestamp=>"2009-12-07T13:48:50.000Z",
|
53
|
+
# :product_description=>"Linux/UNIX",
|
54
|
+
# :instance_type=>"m1.small"}, ... ]
|
55
|
+
#
|
56
|
+
# ec2.describe_spot_price_history(:start_time => 1.day.ago,
|
57
|
+
# :end_time => 10.minutes.ago,
|
58
|
+
# :instance_types => ["c1.medium", "m1.small"],
|
59
|
+
# :product_description => "Linux/UNIX" ) #=>
|
60
|
+
# [{:product_description=>"Linux/UNIX",
|
61
|
+
# :timestamp=>"2010-02-04T05:44:36.000Z",
|
62
|
+
# :spot_price=>0.031,
|
63
|
+
# :instance_type=>"m1.small"},
|
64
|
+
# {:product_description=>"Linux/UNIX",
|
65
|
+
# :timestamp=>"2010-02-04T17:56:25.000Z",
|
66
|
+
# :spot_price=>0.058,
|
67
|
+
# :instance_type=>"c1.medium"}, ... ]
|
68
|
+
#
|
69
|
+
# ec2.describe_spot_price_history(:filters => {'spot-price' => '0.2' })
|
70
|
+
#
|
71
|
+
# ec2.describe_spot_price_history(:instance_types => ["c1.medium"], :filters => {'spot-price' => '0.2' })
|
72
|
+
#
|
73
|
+
#
|
74
|
+
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeSpotPriceHistory.html
|
75
|
+
#
|
76
|
+
def describe_spot_price_history(options={})
|
77
|
+
options = options.dup
|
78
|
+
request_hash = {}
|
79
|
+
request_hash.merge!(amazonize_list(['Filter.?.Name', 'Filter.?.Value.?'], options[:filters])) unless options[:filters].right_blank?
|
80
|
+
request_hash['StartTime'] = AwsUtils::utc_iso8601(options[:start_time]) unless options[:start_time].right_blank?
|
81
|
+
request_hash['EndTime'] = AwsUtils::utc_iso8601(options[:end_time]) unless options[:end_time].right_blank?
|
82
|
+
request_hash['ProductDescription'] = options[:product_description] unless options[:product_description].right_blank?
|
83
|
+
request_hash.merge!(amazonize_list('InstanceType', Array(options[:instance_types]))) unless options[:instance_types].right_blank?
|
84
|
+
link = generate_request("DescribeSpotPriceHistory", request_hash)
|
85
|
+
request_info(link, QEc2DescribeSpotPriceHistoryParser.new)
|
86
|
+
rescue Exception
|
87
|
+
on_exception
|
88
|
+
end
|
89
|
+
|
90
|
+
# Describe Spot Instance requests.
|
91
|
+
#
|
92
|
+
# Accepts a list of requests and/or a set of filters as the last parameter.
|
93
|
+
#
|
94
|
+
# Filters: availability-zone-group, create-time, fault-code, fault-message, instance-id, launch-group,
|
95
|
+
# launch.block-device-mapping.delete-on-termination, launch.block-device-mapping.device-name,
|
96
|
+
# launch.block-device-mapping.snapshot-id, launch.group-id, launch.image-id, launch.instance-type,
|
97
|
+
# launch.kernel-id, launch.key-name, launch.monitoring-enabled, launch.ramdisk-id, product-description,
|
98
|
+
# spot-instance-request-id, spot-price, state, tag-key, tag-value, tag:key, type, valid-from, valid-until
|
99
|
+
#
|
100
|
+
# ec2.describe_spot_instance_requests #=>
|
101
|
+
# [{:type=>"one-time",
|
102
|
+
# :create_time=>"2010-03-10T10:30:32.000Z",
|
103
|
+
# :instance_type=>"c1.medium",
|
104
|
+
# :state=>"cancelled",
|
105
|
+
# :groups=>["default"],
|
106
|
+
# :product_description=>"Linux/UNIX",
|
107
|
+
# :spot_instance_request_id=>"sir-bfa06804",
|
108
|
+
# :image_id=>"ami-08f41161",
|
109
|
+
# :spot_price=>0.01,
|
110
|
+
# :monitoring_enabled=>false},
|
111
|
+
# {:type=>"one-time",
|
112
|
+
# :create_time=>"2010-03-10T10:33:29.000Z",
|
113
|
+
# :instance_type=>"c1.medium",
|
114
|
+
# :state=>"open",
|
115
|
+
# :groups=>["default", "33"],
|
116
|
+
# :product_description=>"Linux/UNIX",
|
117
|
+
# :spot_instance_request_id=>"sir-b1713a03",
|
118
|
+
# :image_id=>"ami-08f41161",
|
119
|
+
# :spot_price=>0.01,
|
120
|
+
# :monitoring_enabled=>false,
|
121
|
+
# :key_name=>"tim"},
|
122
|
+
# {:type=>"one-time",
|
123
|
+
# :instance_id=>"i-c516ceae",
|
124
|
+
# :create_time=>"2010-03-10T10:43:48.000Z",
|
125
|
+
# :instance_type=>"c1.medium",
|
126
|
+
# :state=>"active",
|
127
|
+
# :groups=>["default", "33"],
|
128
|
+
# :product_description=>"Linux/UNIX",
|
129
|
+
# :spot_instance_request_id=>"sir-5eb6c604",
|
130
|
+
# :image_id=>"ami-08f41161",
|
131
|
+
# :spot_price=>0.2,
|
132
|
+
# :monitoring_enabled=>false,
|
133
|
+
# :key_name=>"tim"}]
|
134
|
+
#
|
135
|
+
# ec2.describe_spot_instance_requests(:filters => {'type'=>"one-time", 'state'=>"open"})
|
136
|
+
#
|
137
|
+
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeSpotInstanceRequests.html
|
138
|
+
#
|
139
|
+
def describe_spot_instance_requests(*list_and_options)
|
140
|
+
describe_resources_with_list_and_options('DescribeSpotInstanceRequests', 'SpotInstanceRequestId', QEc2DescribeSpotInstanceParser, list_and_options)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Create a Spot Instance request.
|
144
|
+
#
|
145
|
+
# Mandatory params: :image_id, :spot_price, :instance_type
|
146
|
+
# Optional params: :valid_from, :valid_until, :instance_count, :type, :launch_group,
|
147
|
+
# :availability_zone_group, :key_name, :user_data, :addressing_type, :kernel_id,
|
148
|
+
# :ramdisk_id, :subnet_id, :availability_zone, :monitoring_enabled, :groups,
|
149
|
+
# :block_device_mappings
|
150
|
+
#
|
151
|
+
# ec2.request_spot_instances(
|
152
|
+
# :image_id => 'ami-08f41161',
|
153
|
+
# :spot_price => 0.01,
|
154
|
+
# :key_name => 'tim',
|
155
|
+
# :instance_count => 2,
|
156
|
+
# :groups => ['33','default'],
|
157
|
+
# :instance_type => 'c1.medium') #=>
|
158
|
+
#
|
159
|
+
# [{:product_description=>"Linux/UNIX",
|
160
|
+
# :type=>"one-time",
|
161
|
+
# :spot_instance_requestId=>"sir-7a893003",
|
162
|
+
# :monitoring_enabled=>false,
|
163
|
+
# :image_id=>"ami-08f41161",
|
164
|
+
# :state=>"open",
|
165
|
+
# :spot_price=>0.01,
|
166
|
+
# :groups=>["default", "33"],
|
167
|
+
# :key_name=>"tim",
|
168
|
+
# :create_time=>"2010-03-10T10:33:09.000Z",
|
169
|
+
# :instance_type=>"c1.medium"},
|
170
|
+
# {:product_description=>"Linux/UNIX",
|
171
|
+
# :type=>"one-time",
|
172
|
+
# :spot_instance_requestId=>"sir-13dc9a03",
|
173
|
+
# :monitoring_enabled=>false,
|
174
|
+
# :image_id=>"ami-08f41161",
|
175
|
+
# :state=>"open",
|
176
|
+
# :spot_price=>0.01,
|
177
|
+
# :groups=>["default", "33"],
|
178
|
+
# :key_name=>"tim",
|
179
|
+
# :create_time=>"2010-03-10T10:33:09.000Z",
|
180
|
+
# :instance_type=>"c1.medium"}]
|
181
|
+
#
|
182
|
+
# ec2.request_spot_instances(
|
183
|
+
# :image_id => 'ami-08f41161',
|
184
|
+
# :spot_price => 0.01,
|
185
|
+
# :instance_type => 'm1.small',
|
186
|
+
# :valid_from => 10.minutes.since,
|
187
|
+
# :valid_until => 1.hour.since,
|
188
|
+
# :instance_count => 1,
|
189
|
+
# :key_name => 'tim',
|
190
|
+
# :groups => ['33','default'],
|
191
|
+
# :availability_zone => 'us-east-1a',
|
192
|
+
# :monitoring_enabled => true,
|
193
|
+
# :launch_group => 'lg1',
|
194
|
+
# :availability_zone_group => 'azg1',
|
195
|
+
# :block_device_mappings => [ { :device_name => '/dev/sdk',
|
196
|
+
# :ebs_snapshot_id => 'snap-145cbc7d',
|
197
|
+
# :ebs_delete_on_termination => true,
|
198
|
+
# :ebs_volume_size => 3,
|
199
|
+
# :virtual_name => 'ephemeral2'
|
200
|
+
# } ] ) #=>
|
201
|
+
#
|
202
|
+
# [{:monitoring_enabled=>true,
|
203
|
+
# :type=>"one-time",
|
204
|
+
# :image_id=>"ami-08f41161",
|
205
|
+
# :launch_group=>"lg1",
|
206
|
+
# :state=>"open",
|
207
|
+
# :valid_until=>"2010-02-05T19:13:44.000Z",
|
208
|
+
# :create_time=>"2010-02-05T18:13:46.000Z",
|
209
|
+
# :availability_zone_group=>"azg1",
|
210
|
+
# :spot_price=>0.01,
|
211
|
+
# :block_device_mappings=>
|
212
|
+
# [{:ebs_delete_on_termination=>true,
|
213
|
+
# :ebs_volume_size=>3,
|
214
|
+
# :virtual_name=>"ephemeral2",
|
215
|
+
# :device_name=>"/dev/sdk",
|
216
|
+
# :ebs_snapshot_id=>"snap-145cbc7d"}],
|
217
|
+
# :instance_type=>"m1.small",
|
218
|
+
# :groups=>["default", "33"],
|
219
|
+
# :product_description=>"Linux/UNIX",
|
220
|
+
# :key_name=>"tim",
|
221
|
+
# :valid_from=>"2010-02-05T18:23:44.000Z",
|
222
|
+
# :availability_zone=>"us-east-1a",
|
223
|
+
# :spot_instance_request_id=>"sir-32da8a03"}]
|
224
|
+
#
|
225
|
+
def request_spot_instances(options)
|
226
|
+
options = options.dup
|
227
|
+
request_hash = { 'SpotPrice' => options[:spot_price],
|
228
|
+
'LaunchSpecification.ImageId' => options[:image_id],
|
229
|
+
'LaunchSpecification.InstanceType' => options[:instance_type]}
|
230
|
+
request_hash['ValidFrom'] = AwsUtils::utc_iso8601(options[:valid_from]) unless options[:valid_from].right_blank?
|
231
|
+
request_hash['ValidUntil'] = AwsUtils::utc_iso8601(options[:valid_until]) unless options[:valid_until].right_blank?
|
232
|
+
request_hash['InstanceCount'] = options[:instance_count] unless options[:instance_count].right_blank?
|
233
|
+
request_hash['Type'] = options[:type] unless options[:type].right_blank?
|
234
|
+
request_hash['LaunchGroup'] = options[:launch_group] unless options[:launch_group].right_blank?
|
235
|
+
request_hash['AvailabilityZoneGroup'] = options[:availability_zone_group] unless options[:availability_zone_group].right_blank?
|
236
|
+
request_hash['LaunchSpecification.KeyName'] = options[:key_name] unless options[:key_name].right_blank?
|
237
|
+
request_hash['LaunchSpecification.AddressingType'] = options[:addressing_type] unless options[:addressing_type].right_blank?
|
238
|
+
request_hash['LaunchSpecification.KernelId'] = options[:kernel_id] unless options[:kernel_id].right_blank?
|
239
|
+
request_hash['LaunchSpecification.RamdiskId'] = options[:ramdisk_id] unless options[:ramdisk_id].right_blank?
|
240
|
+
request_hash['LaunchSpecification.SubnetId'] = options[:subnet_id] unless options[:subnet_id].right_blank?
|
241
|
+
request_hash['LaunchSpecification.Placement.AvailabilityZone'] = options[:availability_zone] unless options[:availability_zone].right_blank?
|
242
|
+
request_hash['LaunchSpecification.Monitoring.Enabled'] = options[:monitoring_enabled] unless options[:monitoring_enabled].right_blank?
|
243
|
+
request_hash.merge!(amazonize_list('LaunchSpecification.SecurityGroup', options[:groups])) unless options[:groups].right_blank?
|
244
|
+
request_hash.merge!(amazonize_block_device_mappings(options[:block_device_mappings], 'LaunchSpecification.BlockDeviceMapping'))
|
245
|
+
unless options[:user_data].right_blank?
|
246
|
+
# See RightAws::Ec2#run_instances
|
247
|
+
options[:user_data].strip!
|
248
|
+
request_hash['LaunchSpecification.UserData'] = Base64.encode64(options[:user_data]).delete("\n") unless options[:user_data].right_blank?
|
249
|
+
end
|
250
|
+
link = generate_request("RequestSpotInstances", request_hash)
|
251
|
+
request_info(link, QEc2DescribeSpotInstanceParser.new(:logger => @logger))
|
252
|
+
end
|
253
|
+
|
254
|
+
# Cancel one or more Spot Instance requests.
|
255
|
+
#
|
256
|
+
# ec2.cancel_spot_instance_requests('sir-60662c03',"sir-d3c96e04", "sir-4fa8d804","sir-6992ce04") #=>
|
257
|
+
# [{:state=>"cancelled", :spot_instance_request_id=>"sir-60662c03"},
|
258
|
+
# {:state=>"cancelled", :spot_instance_request_id=>"sir-6992ce04"},
|
259
|
+
# {:state=>"cancelled", :spot_instance_request_id=>"sir-4fa8d804"},
|
260
|
+
# {:state=>"cancelled", :spot_instance_request_id=>"sir-d3c96e04"}]
|
261
|
+
#
|
262
|
+
def cancel_spot_instance_requests(*spot_instance_request_ids)
|
263
|
+
link = generate_request("CancelSpotInstanceRequests", amazonize_list('SpotInstanceRequestId', spot_instance_request_ids.flatten))
|
264
|
+
request_info(link, QEc2CancelSpotInstanceParser.new(:logger => @logger))
|
265
|
+
end
|
266
|
+
|
267
|
+
# Create the data feed for Spot Instances
|
268
|
+
# (Enables to view Spot Instance usage logs)
|
269
|
+
#
|
270
|
+
# ec2.create_spot_datafeed_subscription('bucket-for-konstantin-eu', 'splogs/') #=>
|
271
|
+
# { :owner_id=>"826693181925",
|
272
|
+
# :bucket=>"bucket-for-konstantin-eu",
|
273
|
+
# :prefix=>"splogs/",
|
274
|
+
# :state=>"Active"}
|
275
|
+
#
|
276
|
+
def create_spot_datafeed_subscription(bucket, prefix=nil)
|
277
|
+
request_hash = { 'Bucket' => bucket }
|
278
|
+
request_hash['Prefix'] = prefix unless prefix.right_blank?
|
279
|
+
link = generate_request("CreateSpotDatafeedSubscription", request_hash)
|
280
|
+
request_info(link, QEc2DescribeSpotDatafeedSubscriptionParser.new(:logger => @logger))
|
281
|
+
end
|
282
|
+
|
283
|
+
# Describe the data feed for Spot Instances.
|
284
|
+
#
|
285
|
+
# ec2.describe_spot_datafeed_subscription #=>
|
286
|
+
# { :owner_id=>"826693181925",
|
287
|
+
# :bucket=>"bucket-for-konstantin-eu",
|
288
|
+
# :prefix=>"splogs/",
|
289
|
+
# :state=>"Active"}
|
290
|
+
#
|
291
|
+
def describe_spot_datafeed_subscription
|
292
|
+
link = generate_request("DescribeSpotDatafeedSubscription")
|
293
|
+
request_info(link, QEc2DescribeSpotDatafeedSubscriptionParser.new(:logger => @logger))
|
294
|
+
end
|
295
|
+
|
296
|
+
# Delete the data feed for Spot Instances.
|
297
|
+
#
|
298
|
+
# ec2.delete_spot_datafeed_subscription #=> true
|
299
|
+
#
|
300
|
+
def delete_spot_datafeed_subscription()
|
301
|
+
link = generate_request("DeleteSpotDatafeedSubscription")
|
302
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
303
|
+
end
|
304
|
+
|
305
|
+
#-----------------------------------------------------------------
|
306
|
+
# PARSERS: Spot Instances
|
307
|
+
#-----------------------------------------------------------------
|
308
|
+
|
309
|
+
class QEc2DescribeSpotPriceHistoryParser < RightAWSParser #:nodoc:
|
310
|
+
def tagstart(name, attributes)
|
311
|
+
@item = {} if name == 'item'
|
312
|
+
end
|
313
|
+
def tagend(name)
|
314
|
+
case name
|
315
|
+
when 'instanceType' then @item[:instance_type] = @text
|
316
|
+
when 'productDescription' then @item[:product_description] = @text
|
317
|
+
when 'spotPrice' then @item[:spot_price] = @text.to_f
|
318
|
+
when 'timestamp' then @item[:timestamp] = @text
|
319
|
+
when 'item' then @result << @item
|
320
|
+
end
|
321
|
+
end
|
322
|
+
def reset
|
323
|
+
@result = []
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
class QEc2DescribeSpotInstanceParser < RightAWSParser #:nodoc:
|
328
|
+
def tagstart(name, attributes)
|
329
|
+
case full_tag_name
|
330
|
+
when %r{spotInstanceRequestSet/item$}
|
331
|
+
@item = { :tags => {} }
|
332
|
+
when %r{/blockDeviceMapping/item$}
|
333
|
+
@item[:block_device_mappings] ||= []
|
334
|
+
@block_device_mapping = {}
|
335
|
+
when %r{/tagSet/item$}
|
336
|
+
@aws_tag = {}
|
337
|
+
end
|
338
|
+
end
|
339
|
+
def tagend(name)
|
340
|
+
case name
|
341
|
+
when 'spotInstanceRequestId' then @item[:spot_instance_request_id]= @text
|
342
|
+
when 'spotPrice' then @item[:spot_price] = @text.to_f
|
343
|
+
when 'type' then @item[:type] = @text
|
344
|
+
when 'state' then @item[:state] = @text
|
345
|
+
when 'code' then @item[:fault_code] = @text
|
346
|
+
when 'message' then @item[:fault_message] = @text
|
347
|
+
when 'validFrom' then @item[:valid_from] = @text
|
348
|
+
when 'validUntil' then @item[:valid_until] = @text
|
349
|
+
when 'launchGroup' then @item[:launch_group] = @text
|
350
|
+
when 'availabilityZoneGroup' then @item[:availability_zone_group] = @text
|
351
|
+
when 'imageId' then @item[:image_id] = @text
|
352
|
+
when 'keyName' then @item[:key_name] = @text
|
353
|
+
when 'userData' then @item[:userData] = @text
|
354
|
+
when 'data' then @item[:data] = @text
|
355
|
+
when 'addressingType' then @item[:addressing_type] = @text
|
356
|
+
when 'instanceType' then @item[:instance_type] = @text
|
357
|
+
when 'availabilityZone' then @item[:availability_zone] = @text
|
358
|
+
when 'kernelId' then @item[:kernel_id] = @text
|
359
|
+
when 'ramdiskId' then @item[:ramdisk_id] = @text
|
360
|
+
when 'subnetId' then @item[:subnet_id] = @text
|
361
|
+
when 'instanceId' then @item[:instance_id] = @text
|
362
|
+
when 'createTime' then @item[:create_time] = @text
|
363
|
+
when 'productDescription' then @item[:product_description] = @text
|
364
|
+
when 'groupId' then (@item[:groups] ||= []) << @text
|
365
|
+
else
|
366
|
+
case full_tag_name
|
367
|
+
when %r{monitoring/enabled$}
|
368
|
+
@item[:monitoring_enabled] = @text == 'true'
|
369
|
+
when %r{/blockDeviceMapping/item} # no trailing $
|
370
|
+
case name
|
371
|
+
when 'deviceName' then @block_device_mapping[:device_name] = @text
|
372
|
+
when 'virtualName' then @block_device_mapping[:virtual_name] = @text
|
373
|
+
when 'volumeSize' then @block_device_mapping[:ebs_volume_size] = @text.to_i
|
374
|
+
when 'snapshotId' then @block_device_mapping[:ebs_snapshot_id] = @text
|
375
|
+
when 'deleteOnTermination' then @block_device_mapping[:ebs_delete_on_termination] = @text == 'true' ? true : false
|
376
|
+
when 'item' then @item[:block_device_mappings] << @block_device_mapping
|
377
|
+
end
|
378
|
+
when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
|
379
|
+
when %r{/tagSet/item/value$} then @aws_tag[:value] = @text
|
380
|
+
when %r{/tagSet/item$} then @item[:tags][@aws_tag[:key]] = @aws_tag[:value]
|
381
|
+
when %r{spotInstanceRequestSet/item$} then @result << @item
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
def reset
|
386
|
+
@result = []
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
class QEc2CancelSpotInstanceParser < RightAWSParser #:nodoc:
|
391
|
+
def tagstart(name, attributes)
|
392
|
+
@item = {} if name == 'item'
|
393
|
+
end
|
394
|
+
def tagend(name)
|
395
|
+
case name
|
396
|
+
when 'spotInstanceRequestId' then @item[:spot_instance_request_id] = @text
|
397
|
+
when 'state' then @item[:state] = @text
|
398
|
+
when 'item' then @result << @item
|
399
|
+
end
|
400
|
+
end
|
401
|
+
def reset
|
402
|
+
@result = []
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
class QEc2DescribeSpotDatafeedSubscriptionParser < RightAWSParser #:nodoc:
|
407
|
+
def tagend(name)
|
408
|
+
case name
|
409
|
+
when 'ownerId' then @result[:owner_id] = @text
|
410
|
+
when 'bucket' then @result[:bucket] = @text
|
411
|
+
when 'prefix' then @result[:prefix] = @text
|
412
|
+
when 'state' then @result[:state] = @text
|
413
|
+
when 'fault' then @result[:fault] = @text
|
414
|
+
when 'code' then @result[:code] = @text
|
415
|
+
when 'message' then @result[:message] = @text
|
416
|
+
end
|
417
|
+
end
|
418
|
+
def reset
|
419
|
+
@result = {}
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
end
|
424
|
+
|
425
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2007-2010 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
|
+
class Ec2
|
26
|
+
|
27
|
+
#-----------------------------------------------------------------
|
28
|
+
# Tags
|
29
|
+
#-----------------------------------------------------------------
|
30
|
+
|
31
|
+
# Describe tags.
|
32
|
+
#
|
33
|
+
# Accepts set of filters.
|
34
|
+
#
|
35
|
+
# Filters: key, resource-id, resource-type, value
|
36
|
+
#
|
37
|
+
# ec2.describe_tags #=> [{:resource_id => "i-12345678",
|
38
|
+
# :value => "foo",
|
39
|
+
# :resource_type => "instance",
|
40
|
+
# :key => "myKey"}]
|
41
|
+
#
|
42
|
+
# ec2.describe_tags(:filters => { 'resource-id' => "i-12345678"})
|
43
|
+
#
|
44
|
+
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference_query_DescribeTags.html
|
45
|
+
def describe_tags(options={})
|
46
|
+
request_hash = {}
|
47
|
+
request_hash.merge!(amazonize_list(['Filter.?.Name', 'Filter.?.Value.?'], options[:filters])) unless options[:filters].right_blank?
|
48
|
+
cache_for = (options[:filters].right_blank?) ? :describe_tags : nil
|
49
|
+
link = generate_request("DescribeTags", request_hash)
|
50
|
+
request_cache_or_info cache_for, link, QEc2DescribeTagsParser, @@bench, cache_for
|
51
|
+
rescue Exception
|
52
|
+
on_exception
|
53
|
+
end
|
54
|
+
|
55
|
+
# Create tags.
|
56
|
+
# Options:
|
57
|
+
# :default => 'something' : a default value for keys without (or with nil) values.
|
58
|
+
#
|
59
|
+
# Add a single tag with no value to a resource:
|
60
|
+
# ec2.create_tags("i-12345678", "myKey") => true
|
61
|
+
#
|
62
|
+
# Add multiple tags with no values (actually Amazon sets the values to '')
|
63
|
+
# ec2.create_tags("i-12345678", ["myKey1", "myKey2", "myKey3"]) => true
|
64
|
+
#
|
65
|
+
# Add multiple tags with 'true'
|
66
|
+
# ec2.create_tags("i-12345678", ["myKey1", "myKey2", "myKey3"], :default => true ) => true
|
67
|
+
#
|
68
|
+
# Add multiple keys and values to a resource:
|
69
|
+
# ec2.create_tags("i-12345678", {"myKey1" => "foo", "myKey2" => "bar", "myKeyWithoutVal" => nil }) #=> true
|
70
|
+
#
|
71
|
+
# Add a key and value to multiple resources:
|
72
|
+
# ec2.create_tags(["i-12345678","i-86fb3eec","i-86fb3eed"], {"myKey" => "foo"}) #=> true
|
73
|
+
#
|
74
|
+
def create_tags(resources, tags, options={})
|
75
|
+
default = options[:default].nil? ? '' : options[:default]
|
76
|
+
params = amazonize_list("ResourceId", resources)
|
77
|
+
params.merge! amazonize_list(['Tag.?.Key', 'Tag.?.Value'], tags, :default => default)
|
78
|
+
link = generate_request("CreateTags", params)
|
79
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
80
|
+
rescue Exception
|
81
|
+
on_exception
|
82
|
+
end
|
83
|
+
|
84
|
+
# Delete tags.
|
85
|
+
# Options:
|
86
|
+
# :default => 'something' : a default value for keys without (or with nil) values.
|
87
|
+
#
|
88
|
+
# Delete a tag from a resource regardless of value:
|
89
|
+
# ec2.delete_tags("i-12345678", "myKey") => true
|
90
|
+
#
|
91
|
+
# Delete multiple tags (regardless of their values)
|
92
|
+
# ec2.delete_tags("i-12345678", ["myKey1", "myKey2", "myKey3"]) => true
|
93
|
+
#
|
94
|
+
# Add multiple tags with value 'true'
|
95
|
+
# ec2.delete_tags("i-12345678", ["myKey1", "myKey2", "myKey3"], :default => true) => true
|
96
|
+
#
|
97
|
+
# Delete multiple keys and values to a resource:
|
98
|
+
# ec2.delete_tags("i-12345678", [{"myKey1" => "foo", "myKey2" => "bar","myKeyForAnyVal" => nil }]) #=> true
|
99
|
+
#
|
100
|
+
# Delete a key and value on multiple resources:
|
101
|
+
# ec2.delete_tags(["i-12345678", "i-a1234567", "i-b1234567"], {"myKey" => "foo"}) #=> true
|
102
|
+
#
|
103
|
+
def delete_tags(resources, tags, options={})
|
104
|
+
default = options[:default].nil? ? :skip_nils : options[:default]
|
105
|
+
params = amazonize_list("ResourceId", resources)
|
106
|
+
params.merge! amazonize_list(['Tag.?.Key', 'Tag.?.Value'], tags, :default => default)
|
107
|
+
link = generate_request("DeleteTags", params)
|
108
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
109
|
+
rescue Exception
|
110
|
+
on_exception
|
111
|
+
end
|
112
|
+
|
113
|
+
#-----------------------------------------------------------------
|
114
|
+
# PARSERS: Tags
|
115
|
+
#-----------------------------------------------------------------
|
116
|
+
|
117
|
+
class QEc2DescribeTagsParser < RightAWSParser #:nodoc:
|
118
|
+
def tagstart(name, attributes)
|
119
|
+
@resource_tag = {} if name == 'item'
|
120
|
+
end
|
121
|
+
|
122
|
+
def tagend(name)
|
123
|
+
case name
|
124
|
+
when 'resourceId' then @resource_tag[:resource_id] = @text
|
125
|
+
when 'resourceType' then @resource_tag[:resource_type] = @text
|
126
|
+
when 'key' then @resource_tag[:key] = @text
|
127
|
+
when 'value' then @resource_tag[:value] = @text
|
128
|
+
when 'item' then @result << @resource_tag
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def reset
|
133
|
+
@result = []
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|