aboisvert_aws 3.0.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.
- data/History.txt +329 -0
- data/Manifest.txt +61 -0
- data/README.txt +163 -0
- data/Rakefile +130 -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 +1343 -0
- data/lib/awsbase/support.rb +35 -0
- data/lib/awsbase/version.rb +9 -0
- data/lib/ec2/right_ec2.rb +541 -0
- data/lib/ec2/right_ec2_ebs.rb +481 -0
- data/lib/ec2/right_ec2_images.rb +444 -0
- data/lib/ec2/right_ec2_instances.rb +788 -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 +184 -0
- data/lib/ec2/right_ec2_security_groups.rb +491 -0
- data/lib/ec2/right_ec2_spot_instances.rb +422 -0
- data/lib/ec2/right_ec2_tags.rb +139 -0
- data/lib/ec2/right_ec2_vpc.rb +590 -0
- data/lib/ec2/right_ec2_vpc2.rb +381 -0
- data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
- data/lib/elb/right_elb_interface.rb +573 -0
- data/lib/emr/right_emr_interface.rb +727 -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 +1384 -0
- data/lib/right_aws.rb +86 -0
- data/lib/route_53/right_route_53_interface.rb +640 -0
- data/lib/s3/right_s3.rb +1138 -0
- data/lib/s3/right_s3_interface.rb +1278 -0
- data/lib/sdb/active_sdb.rb +1107 -0
- data/lib/sdb/right_sdb_interface.rb +762 -0
- data/lib/sns/right_sns_interface.rb +286 -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 +90 -0
- data/test/README.mdown +39 -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 +11 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_right_ec2.rb +107 -0
- data/test/elb/test_helper.rb +2 -0
- data/test/elb/test_right_elb.rb +43 -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/route_53/fixtures/a_record.xml +18 -0
- data/test/route_53/fixtures/alias_record.xml +18 -0
- data/test/route_53/test_helper.rb +2 -0
- data/test/route_53/test_right_route_53.rb +141 -0
- data/test/s3/test_helper.rb +2 -0
- data/test/s3/test_right_s3.rb +528 -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/sns/test_helper.rb +2 -0
- data/test/sns/test_right_sns.rb +153 -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 +15 -0
- metadata +257 -0
@@ -0,0 +1,422 @@
|
|
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, :api_version => '2011-05-15')
|
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
|
+
# [{:product_description=>"Linux/UNIX",
|
102
|
+
# :type=>"one-time",
|
103
|
+
# :availability_zone=>"us-east-1b",
|
104
|
+
# :monitoring_enabled=>false,
|
105
|
+
# :tags=>{},
|
106
|
+
# :image_id=>"ami-08f41161",
|
107
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
108
|
+
# :spot_price=>0.01,
|
109
|
+
# :create_time=>"2010-03-24T10:41:28.000Z",
|
110
|
+
# :instance_type=>"c1.medium",
|
111
|
+
# :state=>"open",
|
112
|
+
# :spot_instance_request_id=>"sir-9652a604",
|
113
|
+
# :key_name=>"rightscale_test"},
|
114
|
+
# {:product_description=>"Linux/UNIX",
|
115
|
+
# :type=>"one-time",
|
116
|
+
# :availability_zone=>"us-east-1b",
|
117
|
+
# :monitoring_enabled=>false,
|
118
|
+
# :tags=>{},
|
119
|
+
# :image_id=>"ami-08f41161",
|
120
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
121
|
+
# :spot_price=>0.01,
|
122
|
+
# :create_time=>"2010-03-24T11:40:27.000Z",
|
123
|
+
# :instance_type=>"c1.medium",
|
124
|
+
# :state=>"open",
|
125
|
+
# :spot_instance_request_id=>"sir-fa912802",
|
126
|
+
# :key_name=>"rightscale_test"}, ... ]
|
127
|
+
#
|
128
|
+
# ec2.describe_spot_instance_requests(:filters => {'type'=>"one-time", 'state'=>"open"})
|
129
|
+
#
|
130
|
+
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeSpotInstanceRequests.html
|
131
|
+
#
|
132
|
+
def describe_spot_instance_requests(*list_and_options)
|
133
|
+
describe_resources_with_list_and_options('DescribeSpotInstanceRequests', 'SpotInstanceRequestId', QEc2DescribeSpotInstanceParser, list_and_options)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Create a Spot Instance request.
|
137
|
+
#
|
138
|
+
# Mandatory params: :image_id, :spot_price, :instance_type
|
139
|
+
# Optional params: :valid_from, :valid_until, :instance_count, :type, :launch_group,
|
140
|
+
# :availability_zone_group, :key_name, :user_data, :addressing_type, :kernel_id,
|
141
|
+
# :ramdisk_id, :subnet_id, :availability_zone, :monitoring_enabled, :groups,
|
142
|
+
# :block_device_mappings
|
143
|
+
#
|
144
|
+
# ec2.request_spot_instances(
|
145
|
+
# :image_id => 'ami-08f41161',
|
146
|
+
# :spot_price => 0.01,
|
147
|
+
# :key_name => 'tim',
|
148
|
+
# :instance_count => 2,
|
149
|
+
# :group_ids => ["sg-a0b85dc9"],
|
150
|
+
# :instance_type => 'c1.medium') #=>
|
151
|
+
#
|
152
|
+
# [{:product_description=>"Linux/UNIX",
|
153
|
+
# :type=>"one-time",
|
154
|
+
# :spot_instance_requestId=>"sir-7a893003",
|
155
|
+
# :monitoring_enabled=>false,
|
156
|
+
# :image_id=>"ami-08f41161",
|
157
|
+
# :state=>"open",
|
158
|
+
# :spot_price=>0.01,
|
159
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
160
|
+
# :key_name=>"tim",
|
161
|
+
# :create_time=>"2010-03-10T10:33:09.000Z",
|
162
|
+
# :instance_type=>"c1.medium"},
|
163
|
+
# {:product_description=>"Linux/UNIX",
|
164
|
+
# :type=>"one-time",
|
165
|
+
# :spot_instance_requestId=>"sir-13dc9a03",
|
166
|
+
# :monitoring_enabled=>false,
|
167
|
+
# :image_id=>"ami-08f41161",
|
168
|
+
# :state=>"open",
|
169
|
+
# :spot_price=>0.01,
|
170
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
171
|
+
# :key_name=>"tim",
|
172
|
+
# :create_time=>"2010-03-10T10:33:09.000Z",
|
173
|
+
# :instance_type=>"c1.medium"}]
|
174
|
+
#
|
175
|
+
# ec2.request_spot_instances(
|
176
|
+
# :image_id => 'ami-08f41161',
|
177
|
+
# :spot_price => 0.01,
|
178
|
+
# :instance_type => 'm1.small',
|
179
|
+
# :valid_from => 10.minutes.since,
|
180
|
+
# :valid_until => 1.hour.since,
|
181
|
+
# :instance_count => 1,
|
182
|
+
# :key_name => 'tim',
|
183
|
+
# :group_names => ['default'],
|
184
|
+
# :availability_zone => 'us-east-1a',
|
185
|
+
# :monitoring_enabled => true,
|
186
|
+
# :launch_group => 'lg1',
|
187
|
+
# :availability_zone_group => 'azg1',
|
188
|
+
# :block_device_mappings => [ { :device_name => '/dev/sdk',
|
189
|
+
# :ebs_snapshot_id => 'snap-145cbc7d',
|
190
|
+
# :ebs_delete_on_termination => true,
|
191
|
+
# :ebs_volume_size => 3,
|
192
|
+
# :virtual_name => 'ephemeral2'
|
193
|
+
# } ] ) #=>
|
194
|
+
# [{:type=>"one-time",
|
195
|
+
# :image_id=>"ami-08f41161",
|
196
|
+
# :availability_zone_group=>"azg1",
|
197
|
+
# :key_name=>"default",
|
198
|
+
# :spot_instance_request_id=>"sir-66c79a12",
|
199
|
+
# :block_device_mappings=>
|
200
|
+
# [{:ebs_volume_size=>3,
|
201
|
+
# :virtual_name=>"ephemeral2",
|
202
|
+
# :device_name=>"/dev/sdk",
|
203
|
+
# :ebs_snapshot_id=>"snap-145cbc7d",
|
204
|
+
# :ebs_delete_on_termination=>true}],
|
205
|
+
# :spot_price=>0.01,
|
206
|
+
# :product_description=>"Linux/UNIX",
|
207
|
+
# :state=>"open",
|
208
|
+
# :instance_type=>"m1.small",
|
209
|
+
# :availability_zone=>"us-east-1a",
|
210
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
211
|
+
# :valid_from=>"2011-07-01T14:26:33.000Z",
|
212
|
+
# :tags=>{},
|
213
|
+
# :monitoring_enabled=>true,
|
214
|
+
# :valid_until=>"2011-07-01T14:28:03.000Z",
|
215
|
+
# :create_time=>"2011-07-01T14:26:24.000Z",
|
216
|
+
# :launch_group=>"lg1"}]
|
217
|
+
#
|
218
|
+
def request_spot_instances(options)
|
219
|
+
options[:user_data] = options[:user_data].to_s
|
220
|
+
request_hash = map_api_keys_and_values( options,
|
221
|
+
:spot_price, :availability_zone_group, :launch_group, :type, :instance_count,
|
222
|
+
:image_id => 'LaunchSpecification.ImageId',
|
223
|
+
:instance_type => 'LaunchSpecification.InstanceType',
|
224
|
+
:key_name => 'LaunchSpecification.KeyName',
|
225
|
+
:addressing_type => 'LaunchSpecification.AddressingType',
|
226
|
+
:kernel_id => 'LaunchSpecification.KernelId',
|
227
|
+
:ramdisk_id => 'LaunchSpecification.RamdiskId',
|
228
|
+
:subnet_id => 'LaunchSpecification.SubnetId',
|
229
|
+
:availability_zone => 'LaunchSpecification.Placement.AvailabilityZone',
|
230
|
+
:monitoring_enabled => 'LaunchSpecification.Monitoring.Enabled',
|
231
|
+
:valid_from => { :value => Proc.new { !options[:valid_from].right_blank? && AwsUtils::utc_iso8601(options[:valid_from]) }},
|
232
|
+
:valid_until => { :value => Proc.new { !options[:valid_until].right_blank? && AwsUtils::utc_iso8601(options[:valid_until]) }},
|
233
|
+
:user_data => { :name => 'LaunchSpecification.UserData',
|
234
|
+
:value => Proc.new { !options[:user_data].empty? && Base64.encode64(options[:user_data]).delete("\n") }},
|
235
|
+
:group_names => { :amazonize_list => 'LaunchSpecification.SecurityGroup'},
|
236
|
+
:group_ids => { :amazonize_list => 'LaunchSpecification.SecurityGroupId'},
|
237
|
+
:block_device_mappings => { :amazonize_bdm => 'LaunchSpecification.BlockDeviceMapping'})
|
238
|
+
link = generate_request("RequestSpotInstances", request_hash)
|
239
|
+
request_info(link, QEc2DescribeSpotInstanceParser.new(:logger => @logger))
|
240
|
+
end
|
241
|
+
|
242
|
+
# Cancel one or more Spot Instance requests.
|
243
|
+
#
|
244
|
+
# ec2.cancel_spot_instance_requests('sir-60662c03',"sir-d3c96e04", "sir-4fa8d804","sir-6992ce04") #=>
|
245
|
+
# [{:state=>"cancelled", :spot_instance_request_id=>"sir-60662c03"},
|
246
|
+
# {:state=>"cancelled", :spot_instance_request_id=>"sir-6992ce04"},
|
247
|
+
# {:state=>"cancelled", :spot_instance_request_id=>"sir-4fa8d804"},
|
248
|
+
# {:state=>"cancelled", :spot_instance_request_id=>"sir-d3c96e04"}]
|
249
|
+
#
|
250
|
+
def cancel_spot_instance_requests(*spot_instance_request_ids)
|
251
|
+
link = generate_request("CancelSpotInstanceRequests", amazonize_list('SpotInstanceRequestId', spot_instance_request_ids.flatten))
|
252
|
+
request_info(link, QEc2CancelSpotInstanceParser.new(:logger => @logger))
|
253
|
+
end
|
254
|
+
|
255
|
+
# Create the data feed for Spot Instances
|
256
|
+
# (Enables to view Spot Instance usage logs)
|
257
|
+
#
|
258
|
+
# ec2.create_spot_datafeed_subscription('bucket-for-konstantin-eu', 'splogs/') #=>
|
259
|
+
# { :owner_id=>"826693181925",
|
260
|
+
# :bucket=>"bucket-for-konstantin-eu",
|
261
|
+
# :prefix=>"splogs/",
|
262
|
+
# :state=>"Active"}
|
263
|
+
#
|
264
|
+
def create_spot_datafeed_subscription(bucket, prefix=nil)
|
265
|
+
request_hash = { 'Bucket' => bucket }
|
266
|
+
request_hash['Prefix'] = prefix unless prefix.right_blank?
|
267
|
+
link = generate_request("CreateSpotDatafeedSubscription", request_hash)
|
268
|
+
request_info(link, QEc2DescribeSpotDatafeedSubscriptionParser.new(:logger => @logger))
|
269
|
+
end
|
270
|
+
|
271
|
+
# Describe the data feed for Spot Instances.
|
272
|
+
#
|
273
|
+
# ec2.describe_spot_datafeed_subscription #=>
|
274
|
+
# { :owner_id=>"826693181925",
|
275
|
+
# :bucket=>"bucket-for-konstantin-eu",
|
276
|
+
# :prefix=>"splogs/",
|
277
|
+
# :state=>"Active"}
|
278
|
+
#
|
279
|
+
def describe_spot_datafeed_subscription
|
280
|
+
link = generate_request("DescribeSpotDatafeedSubscription")
|
281
|
+
request_info(link, QEc2DescribeSpotDatafeedSubscriptionParser.new(:logger => @logger))
|
282
|
+
end
|
283
|
+
|
284
|
+
# Delete the data feed for Spot Instances.
|
285
|
+
#
|
286
|
+
# ec2.delete_spot_datafeed_subscription #=> true
|
287
|
+
#
|
288
|
+
def delete_spot_datafeed_subscription()
|
289
|
+
link = generate_request("DeleteSpotDatafeedSubscription")
|
290
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
291
|
+
end
|
292
|
+
|
293
|
+
#-----------------------------------------------------------------
|
294
|
+
# PARSERS: Spot Instances
|
295
|
+
#-----------------------------------------------------------------
|
296
|
+
|
297
|
+
class QEc2DescribeSpotPriceHistoryParser < RightAWSParser #:nodoc:
|
298
|
+
def tagstart(name, attributes)
|
299
|
+
@item = {} if name == 'item'
|
300
|
+
end
|
301
|
+
def tagend(name)
|
302
|
+
case name
|
303
|
+
when 'instanceType' then @item[:instance_type] = @text
|
304
|
+
when 'productDescription' then @item[:product_description] = @text
|
305
|
+
when 'spotPrice' then @item[:spot_price] = @text.to_f
|
306
|
+
when 'timestamp' then @item[:timestamp] = @text
|
307
|
+
when 'availabilityZone' then @item[:availability_zone] = @text
|
308
|
+
when 'item' then @result << @item
|
309
|
+
end
|
310
|
+
end
|
311
|
+
def reset
|
312
|
+
@result = []
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
class QEc2DescribeSpotInstanceParser < RightAWSParser #:nodoc:
|
317
|
+
def tagstart(name, attributes)
|
318
|
+
case full_tag_name
|
319
|
+
when %r{spotInstanceRequestSet/item$}
|
320
|
+
@item = { :tags => {} }
|
321
|
+
when %r{groupSet$}
|
322
|
+
@item[:groups] = []
|
323
|
+
when %r{groupSet/item$}
|
324
|
+
@group = {}
|
325
|
+
when %r{/blockDeviceMapping/item$}
|
326
|
+
@item[:block_device_mappings] ||= []
|
327
|
+
@block_device_mapping = {}
|
328
|
+
when %r{/tagSet/item$}
|
329
|
+
@aws_tag = {}
|
330
|
+
end
|
331
|
+
end
|
332
|
+
def tagend(name)
|
333
|
+
case name
|
334
|
+
when 'spotInstanceRequestId' then @item[:spot_instance_request_id]= @text
|
335
|
+
when 'spotPrice' then @item[:spot_price] = @text.to_f
|
336
|
+
when 'type' then @item[:type] = @text
|
337
|
+
when 'state' then @item[:state] = @text
|
338
|
+
when 'code' then @item[:fault_code] = @text
|
339
|
+
when 'message' then @item[:fault_message] = @text
|
340
|
+
when 'validFrom' then @item[:valid_from] = @text
|
341
|
+
when 'validUntil' then @item[:valid_until] = @text
|
342
|
+
when 'launchGroup' then @item[:launch_group] = @text
|
343
|
+
when 'availabilityZoneGroup' then @item[:availability_zone_group] = @text
|
344
|
+
when 'imageId' then @item[:image_id] = @text
|
345
|
+
when 'keyName' then @item[:key_name] = @text
|
346
|
+
when 'userData' then @item[:userData] = @text
|
347
|
+
when 'data' then @item[:data] = @text
|
348
|
+
when 'addressingType' then @item[:addressing_type] = @text
|
349
|
+
when 'instanceType' then @item[:instance_type] = @text
|
350
|
+
when 'availabilityZone' then @item[:availability_zone] = @text
|
351
|
+
when 'kernelId' then @item[:kernel_id] = @text
|
352
|
+
when 'ramdiskId' then @item[:ramdisk_id] = @text
|
353
|
+
when 'subnetId' then @item[:subnet_id] = @text
|
354
|
+
when 'instanceId' then @item[:instance_id] = @text
|
355
|
+
when 'createTime' then @item[:create_time] = @text
|
356
|
+
when 'productDescription' then @item[:product_description] = @text
|
357
|
+
else
|
358
|
+
case full_tag_name
|
359
|
+
when %r{/groupSet/item} # no trailing $
|
360
|
+
case name
|
361
|
+
when 'groupId' then @group[:group_id] = @text
|
362
|
+
when 'groupName' then @group[:group_name] = @text
|
363
|
+
when 'item' then @item[:groups] << @group
|
364
|
+
end
|
365
|
+
when %r{monitoring/enabled$}
|
366
|
+
@item[:monitoring_enabled] = @text == 'true'
|
367
|
+
when %r{/blockDeviceMapping/item} # no trailing $
|
368
|
+
case name
|
369
|
+
when 'deviceName' then @block_device_mapping[:device_name] = @text
|
370
|
+
when 'virtualName' then @block_device_mapping[:virtual_name] = @text
|
371
|
+
when 'volumeSize' then @block_device_mapping[:ebs_volume_size] = @text.to_i
|
372
|
+
when 'snapshotId' then @block_device_mapping[:ebs_snapshot_id] = @text
|
373
|
+
when 'deleteOnTermination' then @block_device_mapping[:ebs_delete_on_termination] = @text == 'true' ? true : false
|
374
|
+
when 'item' then @item[:block_device_mappings] << @block_device_mapping
|
375
|
+
end
|
376
|
+
when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
|
377
|
+
when %r{/tagSet/item/value$} then @aws_tag[:value] = @text
|
378
|
+
when %r{/tagSet/item$} then @item[:tags][@aws_tag[:key]] = @aws_tag[:value]
|
379
|
+
when %r{spotInstanceRequestSet/item$} then @result << @item
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
def reset
|
384
|
+
@result = []
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
class QEc2CancelSpotInstanceParser < RightAWSParser #:nodoc:
|
389
|
+
def tagstart(name, attributes)
|
390
|
+
@item = {} if name == 'item'
|
391
|
+
end
|
392
|
+
def tagend(name)
|
393
|
+
case name
|
394
|
+
when 'spotInstanceRequestId' then @item[:spot_instance_request_id] = @text
|
395
|
+
when 'state' then @item[:state] = @text
|
396
|
+
when 'item' then @result << @item
|
397
|
+
end
|
398
|
+
end
|
399
|
+
def reset
|
400
|
+
@result = []
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
class QEc2DescribeSpotDatafeedSubscriptionParser < RightAWSParser #:nodoc:
|
405
|
+
def tagend(name)
|
406
|
+
case name
|
407
|
+
when 'ownerId' then @result[:owner_id] = @text
|
408
|
+
when 'bucket' then @result[:bucket] = @text
|
409
|
+
when 'prefix' then @result[:prefix] = @text
|
410
|
+
when 'state' then @result[:state] = @text
|
411
|
+
when 'code' then @result[:fault_code] = @text
|
412
|
+
when 'message' then @result[:fault_message] = @text
|
413
|
+
end
|
414
|
+
end
|
415
|
+
def reset
|
416
|
+
@result = {}
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
end
|
421
|
+
|
422
|
+
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
|