right_aws 2.1.0 → 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 +38 -14
- data/Manifest.txt +1 -0
- data/Rakefile +34 -8
- data/lib/awsbase/right_awsbase.rb +176 -12
- data/lib/awsbase/version.rb +2 -2
- data/lib/ec2/right_ec2.rb +120 -37
- data/lib/ec2/right_ec2_ebs.rb +57 -41
- data/lib/ec2/right_ec2_images.rb +73 -44
- data/lib/ec2/right_ec2_instances.rb +158 -155
- data/lib/ec2/right_ec2_reserved_instances.rb +36 -26
- data/lib/ec2/right_ec2_security_groups.rb +261 -166
- data/lib/ec2/right_ec2_spot_instances.rb +72 -75
- data/lib/ec2/right_ec2_vpc.rb +15 -8
- data/lib/ec2/right_ec2_vpc2.rb +381 -0
- data/lib/elb/right_elb_interface.rb +3 -1
- data/lib/emr/right_emr_interface.rb +727 -0
- data/lib/rds/right_rds_interface.rb +102 -27
- data/lib/right_aws.rb +4 -1
- data/lib/route_53/right_route_53_interface.rb +24 -14
- data/lib/s3/right_s3.rb +16 -15
- data/lib/s3/right_s3_interface.rb +42 -10
- data/lib/sdb/right_sdb_interface.rb +14 -5
- data/lib/sns/right_sns_interface.rb +286 -0
- data/test/README.mdown +39 -0
- data/test/awsbase/test_right_awsbase.rb +0 -1
- data/test/ec2/test_right_ec2.rb +0 -1
- data/test/elb/test_helper.rb +2 -0
- data/test/elb/test_right_elb.rb +43 -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_right_s3.rb +97 -39
- data/test/sns/test_helper.rb +2 -0
- data/test/sns/test_right_sns.rb +153 -0
- data/test/ts_right_aws.rb +1 -0
- metadata +28 -9
@@ -81,7 +81,7 @@ module RightAws
|
|
81
81
|
request_hash['EndTime'] = AwsUtils::utc_iso8601(options[:end_time]) unless options[:end_time].right_blank?
|
82
82
|
request_hash['ProductDescription'] = options[:product_description] unless options[:product_description].right_blank?
|
83
83
|
request_hash.merge!(amazonize_list('InstanceType', Array(options[:instance_types]))) unless options[:instance_types].right_blank?
|
84
|
-
link = generate_request("DescribeSpotPriceHistory", request_hash)
|
84
|
+
link = generate_request("DescribeSpotPriceHistory", request_hash, :api_version => '2011-05-15')
|
85
85
|
request_info(link, QEc2DescribeSpotPriceHistoryParser.new)
|
86
86
|
rescue Exception
|
87
87
|
on_exception
|
@@ -98,39 +98,32 @@ module RightAws
|
|
98
98
|
# spot-instance-request-id, spot-price, state, tag-key, tag-value, tag:key, type, valid-from, valid-until
|
99
99
|
#
|
100
100
|
# ec2.describe_spot_instance_requests #=>
|
101
|
-
# [{:
|
102
|
-
# :
|
103
|
-
# :
|
104
|
-
# :
|
105
|
-
# :
|
106
|
-
# :product_description=>"Linux/UNIX",
|
107
|
-
# :spot_instance_request_id=>"sir-bfa06804",
|
101
|
+
# [{:product_description=>"Linux/UNIX",
|
102
|
+
# :type=>"one-time",
|
103
|
+
# :availability_zone=>"us-east-1b",
|
104
|
+
# :monitoring_enabled=>false,
|
105
|
+
# :tags=>{},
|
108
106
|
# :image_id=>"ami-08f41161",
|
107
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
109
108
|
# :spot_price=>0.01,
|
110
|
-
# :
|
111
|
-
# {:type=>"one-time",
|
112
|
-
# :create_time=>"2010-03-10T10:33:29.000Z",
|
109
|
+
# :create_time=>"2010-03-24T10:41:28.000Z",
|
113
110
|
# :instance_type=>"c1.medium",
|
114
111
|
# :state=>"open",
|
115
|
-
# :
|
116
|
-
# :
|
117
|
-
#
|
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=>{},
|
118
119
|
# :image_id=>"ami-08f41161",
|
120
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
119
121
|
# :spot_price=>0.01,
|
120
|
-
# :
|
121
|
-
# :key_name=>"tim"},
|
122
|
-
# {:type=>"one-time",
|
123
|
-
# :instance_id=>"i-c516ceae",
|
124
|
-
# :create_time=>"2010-03-10T10:43:48.000Z",
|
122
|
+
# :create_time=>"2010-03-24T11:40:27.000Z",
|
125
123
|
# :instance_type=>"c1.medium",
|
126
|
-
# :state=>"
|
127
|
-
# :
|
128
|
-
# :
|
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"}]
|
124
|
+
# :state=>"open",
|
125
|
+
# :spot_instance_request_id=>"sir-fa912802",
|
126
|
+
# :key_name=>"rightscale_test"}, ... ]
|
134
127
|
#
|
135
128
|
# ec2.describe_spot_instance_requests(:filters => {'type'=>"one-time", 'state'=>"open"})
|
136
129
|
#
|
@@ -153,7 +146,7 @@ module RightAws
|
|
153
146
|
# :spot_price => 0.01,
|
154
147
|
# :key_name => 'tim',
|
155
148
|
# :instance_count => 2,
|
156
|
-
# :
|
149
|
+
# :group_ids => ["sg-a0b85dc9"],
|
157
150
|
# :instance_type => 'c1.medium') #=>
|
158
151
|
#
|
159
152
|
# [{:product_description=>"Linux/UNIX",
|
@@ -163,7 +156,7 @@ module RightAws
|
|
163
156
|
# :image_id=>"ami-08f41161",
|
164
157
|
# :state=>"open",
|
165
158
|
# :spot_price=>0.01,
|
166
|
-
# :groups=>["
|
159
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
167
160
|
# :key_name=>"tim",
|
168
161
|
# :create_time=>"2010-03-10T10:33:09.000Z",
|
169
162
|
# :instance_type=>"c1.medium"},
|
@@ -174,7 +167,7 @@ module RightAws
|
|
174
167
|
# :image_id=>"ami-08f41161",
|
175
168
|
# :state=>"open",
|
176
169
|
# :spot_price=>0.01,
|
177
|
-
# :groups=>["
|
170
|
+
# :groups=>[{:group_id=>"sg-a0b85dc9", :group_name=>"default"}],
|
178
171
|
# :key_name=>"tim",
|
179
172
|
# :create_time=>"2010-03-10T10:33:09.000Z",
|
180
173
|
# :instance_type=>"c1.medium"}]
|
@@ -187,7 +180,7 @@ module RightAws
|
|
187
180
|
# :valid_until => 1.hour.since,
|
188
181
|
# :instance_count => 1,
|
189
182
|
# :key_name => 'tim',
|
190
|
-
# :
|
183
|
+
# :group_names => ['default'],
|
191
184
|
# :availability_zone => 'us-east-1a',
|
192
185
|
# :monitoring_enabled => true,
|
193
186
|
# :launch_group => 'lg1',
|
@@ -198,55 +191,50 @@ module RightAws
|
|
198
191
|
# :ebs_volume_size => 3,
|
199
192
|
# :virtual_name => 'ephemeral2'
|
200
193
|
# } ] ) #=>
|
201
|
-
#
|
202
|
-
# [{:monitoring_enabled=>true,
|
203
|
-
# :type=>"one-time",
|
194
|
+
# [{:type=>"one-time",
|
204
195
|
# :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
196
|
# :availability_zone_group=>"azg1",
|
210
|
-
# :
|
197
|
+
# :key_name=>"default",
|
198
|
+
# :spot_instance_request_id=>"sir-66c79a12",
|
211
199
|
# :block_device_mappings=>
|
212
|
-
# [{:
|
213
|
-
# :ebs_volume_size=>3,
|
200
|
+
# [{:ebs_volume_size=>3,
|
214
201
|
# :virtual_name=>"ephemeral2",
|
215
202
|
# :device_name=>"/dev/sdk",
|
216
|
-
# :ebs_snapshot_id=>"snap-145cbc7d"
|
217
|
-
#
|
218
|
-
# :
|
203
|
+
# :ebs_snapshot_id=>"snap-145cbc7d",
|
204
|
+
# :ebs_delete_on_termination=>true}],
|
205
|
+
# :spot_price=>0.01,
|
219
206
|
# :product_description=>"Linux/UNIX",
|
220
|
-
# :
|
221
|
-
# :
|
207
|
+
# :state=>"open",
|
208
|
+
# :instance_type=>"m1.small",
|
222
209
|
# :availability_zone=>"us-east-1a",
|
223
|
-
# :
|
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"}]
|
224
217
|
#
|
225
218
|
def request_spot_instances(options)
|
226
|
-
options = options.
|
227
|
-
request_hash =
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|
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'})
|
250
238
|
link = generate_request("RequestSpotInstances", request_hash)
|
251
239
|
request_info(link, QEc2DescribeSpotInstanceParser.new(:logger => @logger))
|
252
240
|
end
|
@@ -316,6 +304,7 @@ module RightAws
|
|
316
304
|
when 'productDescription' then @item[:product_description] = @text
|
317
305
|
when 'spotPrice' then @item[:spot_price] = @text.to_f
|
318
306
|
when 'timestamp' then @item[:timestamp] = @text
|
307
|
+
when 'availabilityZone' then @item[:availability_zone] = @text
|
319
308
|
when 'item' then @result << @item
|
320
309
|
end
|
321
310
|
end
|
@@ -329,6 +318,10 @@ module RightAws
|
|
329
318
|
case full_tag_name
|
330
319
|
when %r{spotInstanceRequestSet/item$}
|
331
320
|
@item = { :tags => {} }
|
321
|
+
when %r{groupSet$}
|
322
|
+
@item[:groups] = []
|
323
|
+
when %r{groupSet/item$}
|
324
|
+
@group = {}
|
332
325
|
when %r{/blockDeviceMapping/item$}
|
333
326
|
@item[:block_device_mappings] ||= []
|
334
327
|
@block_device_mapping = {}
|
@@ -361,9 +354,14 @@ module RightAws
|
|
361
354
|
when 'instanceId' then @item[:instance_id] = @text
|
362
355
|
when 'createTime' then @item[:create_time] = @text
|
363
356
|
when 'productDescription' then @item[:product_description] = @text
|
364
|
-
when 'groupId' then (@item[:groups] ||= []) << @text
|
365
357
|
else
|
366
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
|
367
365
|
when %r{monitoring/enabled$}
|
368
366
|
@item[:monitoring_enabled] = @text == 'true'
|
369
367
|
when %r{/blockDeviceMapping/item} # no trailing $
|
@@ -410,9 +408,8 @@ module RightAws
|
|
410
408
|
when 'bucket' then @result[:bucket] = @text
|
411
409
|
when 'prefix' then @result[:prefix] = @text
|
412
410
|
when 'state' then @result[:state] = @text
|
413
|
-
when '
|
414
|
-
when '
|
415
|
-
when 'message' then @result[:message] = @text
|
411
|
+
when 'code' then @result[:fault_code] = @text
|
412
|
+
when 'message' then @result[:fault_message] = @text
|
416
413
|
end
|
417
414
|
end
|
418
415
|
def reset
|
data/lib/ec2/right_ec2_vpc.rb
CHANGED
@@ -38,9 +38,11 @@ module RightAws
|
|
38
38
|
# Filters: cidr, dchp-options-id, state, tag-key, tag-value, tag:key, vpc-id
|
39
39
|
#
|
40
40
|
# ec2.describe_vpcs #=>
|
41
|
-
# [{:
|
41
|
+
# [{:instance_tenancy=>"default",
|
42
|
+
# :vpc_id=>"vpc-e16cf988",
|
43
|
+
# :tags=>{},
|
42
44
|
# :dhcp_options_id=>"default",
|
43
|
-
# :cidr_block=>"
|
45
|
+
# :cidr_block=>"192.168.0.0/24",
|
44
46
|
# :state=>"available"}]
|
45
47
|
#
|
46
48
|
# ec2.describe_vpcs("vpc-890ce2e0")
|
@@ -63,8 +65,10 @@ module RightAws
|
|
63
65
|
# :cidr_block=>"10.0.0.0/23",
|
64
66
|
# :state=>"pending"}
|
65
67
|
#
|
66
|
-
def create_vpc(cidr_block)
|
67
|
-
|
68
|
+
def create_vpc(cidr_block, options = {})
|
69
|
+
request_hash = {'CidrBlock' => cidr_block}
|
70
|
+
request_hash['instanceTenancy'] = options[:instance_tenancy] unless options[:instance_tenancy].right_blank?
|
71
|
+
link = generate_request("CreateVpc", request_hash )
|
68
72
|
request_info(link, QEc2DescribeVpcsParser.new(:logger => @logger)).first
|
69
73
|
rescue Exception
|
70
74
|
on_exception
|
@@ -395,6 +399,7 @@ module RightAws
|
|
395
399
|
on_exception
|
396
400
|
end
|
397
401
|
|
402
|
+
|
398
403
|
#-----------------
|
399
404
|
# Parsers
|
400
405
|
#-----------------
|
@@ -408,10 +413,11 @@ module RightAws
|
|
408
413
|
end
|
409
414
|
def tagend(name)
|
410
415
|
case name
|
411
|
-
when 'vpcId'
|
412
|
-
when 'state'
|
413
|
-
when 'dhcpOptionsId'
|
414
|
-
when 'cidrBlock'
|
416
|
+
when 'vpcId' then @item[:vpc_id] = @text
|
417
|
+
when 'state' then @item[:state] = @text
|
418
|
+
when 'dhcpOptionsId' then @item[:dhcp_options_id] = @text
|
419
|
+
when 'cidrBlock' then @item[:cidr_block] = @text
|
420
|
+
when 'instanceTenancy' then @item[:instance_tenancy] = @text
|
415
421
|
else
|
416
422
|
case full_tag_name
|
417
423
|
when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
|
@@ -579,5 +585,6 @@ module RightAws
|
|
579
585
|
end
|
580
586
|
end
|
581
587
|
|
588
|
+
|
582
589
|
end
|
583
590
|
end
|
@@ -0,0 +1,381 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2011 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
|
+
# VPC v2: Limits
|
29
|
+
#
|
30
|
+
# http://docs.amazonwebservices.com/AmazonVPC/latest/UserGuide/index.html?VPC_Appendix_Limits.html
|
31
|
+
|
32
|
+
#----------------------
|
33
|
+
# InternetGateways
|
34
|
+
#----------------------
|
35
|
+
|
36
|
+
# Create internet gateway
|
37
|
+
#
|
38
|
+
# ec2.create_internet_gateway #=>
|
39
|
+
# { :internet_gateway_id=>"igw-6585c10c", :tags=>{}}
|
40
|
+
#
|
41
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-CreateInternetGateway.html
|
42
|
+
#
|
43
|
+
def create_internet_gateway
|
44
|
+
link = generate_request("CreateInternetGateway")
|
45
|
+
request_info(link, QEc2DescribeInternetGatewaysParser.new(:logger => @logger)).first
|
46
|
+
rescue Exception
|
47
|
+
on_exception
|
48
|
+
end
|
49
|
+
|
50
|
+
# Describe internet gateways.
|
51
|
+
#
|
52
|
+
# ec2.describe_internet_gateways #=>
|
53
|
+
# [{:state=>"available",
|
54
|
+
# :internet_gateway_id=>"igw-6585c10c",
|
55
|
+
# :vpc_id=>"vpc-df80a6b6",
|
56
|
+
# :tags=>{}},
|
57
|
+
# {:internet_gateway_id=>"igw-883503e1",
|
58
|
+
# :tags=>{}}]
|
59
|
+
#
|
60
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-CreateInternetGateway.html
|
61
|
+
#
|
62
|
+
def describe_internet_gateways(*list_and_options)
|
63
|
+
describe_resources_with_list_and_options('DescribeInternetGateways', 'InternetGatewayId', QEc2DescribeInternetGatewaysParser, list_and_options)
|
64
|
+
rescue Exception
|
65
|
+
on_exception
|
66
|
+
end
|
67
|
+
|
68
|
+
# Delete internet gateway.
|
69
|
+
#
|
70
|
+
# ec2.delete_internet_gateway("igw-6585c10c") #=> true
|
71
|
+
#
|
72
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteInternetGateway.html
|
73
|
+
#
|
74
|
+
def delete_internet_gateway(internet_gateway_id)
|
75
|
+
link = generate_request("DeleteInternetGateway", 'InternetGatewayId' => internet_gateway_id )
|
76
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
77
|
+
rescue Exception
|
78
|
+
on_exception
|
79
|
+
end
|
80
|
+
|
81
|
+
# Attaches an Internet gateway to a VPC, enabling connectivity between the Internet and the VPC.
|
82
|
+
#
|
83
|
+
# ec2.attach_internet_gateway("igw-6585c10c", "vpc-df80a6b6") #=> true
|
84
|
+
#
|
85
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AttachInternetGateway.html
|
86
|
+
#
|
87
|
+
def attach_internet_gateway(internet_gateway_id, vpc_id)
|
88
|
+
request_hash = { 'InternetGatewayId' => internet_gateway_id,
|
89
|
+
'VpcId' => vpc_id }
|
90
|
+
link = generate_request("AttachInternetGateway", request_hash)
|
91
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
92
|
+
rescue Exception
|
93
|
+
on_exception
|
94
|
+
end
|
95
|
+
|
96
|
+
# Detaches an Internet gateway from a VPC, disabling connectivity between the Internet and the VPC.
|
97
|
+
# The VPC must not contain any running instances with Elastic IP addresses.
|
98
|
+
#
|
99
|
+
# ec2.detach_internet_gateway("igw-6585c10c", "vpc-df80a6b6") #=> true
|
100
|
+
#
|
101
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DetachInternetGateway.html
|
102
|
+
#
|
103
|
+
def detach_internet_gateway(internet_gateway_id, vpc_id)
|
104
|
+
request_hash = { 'InternetGatewayId' => internet_gateway_id,
|
105
|
+
'VpcId' => vpc_id }
|
106
|
+
link = generate_request("DetachInternetGateway", request_hash)
|
107
|
+
request_info(link, RightHttp2xxParser::new(:logger => @logger))
|
108
|
+
rescue Exception
|
109
|
+
on_exception
|
110
|
+
end
|
111
|
+
|
112
|
+
#----------------------
|
113
|
+
# RouteTables
|
114
|
+
#----------------------
|
115
|
+
|
116
|
+
# Describe route tables.
|
117
|
+
#
|
118
|
+
# # List all tables
|
119
|
+
# ec2.describe_route_tables #=>
|
120
|
+
# [{:route_table_id=>"rtb-be3006d7",
|
121
|
+
# :route_set=>
|
122
|
+
# [{:state=>"active",
|
123
|
+
# :destination_cidr_block=>"10.0.3.0/24",
|
124
|
+
# :gateway_id=>"local"}],
|
125
|
+
# :vpc_id=>"vpc-df80a6b6",
|
126
|
+
# :association_set=>[],
|
127
|
+
# :tags=>{}},
|
128
|
+
# {:route_table_id=>"rtb-e36cf98a",
|
129
|
+
# :route_set=>
|
130
|
+
# [{:state=>"active",
|
131
|
+
# :destination_cidr_block=>"192.168.0.0/24",
|
132
|
+
# :gateway_id=>"local"}],
|
133
|
+
# :vpc_id=>"vpc-e16cf988",
|
134
|
+
# :association_set=>
|
135
|
+
# [{:route_table_id=>"rtb-e36cf98a",
|
136
|
+
# :main=>true,
|
137
|
+
# :route_table_association_id=>"rtbassoc-e26cf98b"}],
|
138
|
+
# :tags=>{}}, ... ]
|
139
|
+
#
|
140
|
+
# # Filter tables by VpcId
|
141
|
+
# ec2.describe_route_tables(:filters => {'vpc-id' => "vpc-df80a6b6"})
|
142
|
+
#
|
143
|
+
# # Custom route table
|
144
|
+
# ec2.describe_route_tables("rtb-be3006d7") #=>
|
145
|
+
# [{:vpc_id=>"vpc-df80a6b6",
|
146
|
+
# :route_set=>
|
147
|
+
# [{:state=>"active",
|
148
|
+
# :destination_cidr_block=>"0.0.0.1/32",
|
149
|
+
# :gateway_id=>"igw-6585c10c"},
|
150
|
+
# {:state=>"active",
|
151
|
+
# :destination_cidr_block=>"10.0.3.0/24",
|
152
|
+
# :gateway_id=>"local"}],
|
153
|
+
# :route_table_id=>"rtb-be3006d7",
|
154
|
+
# :tags=>{},
|
155
|
+
# :association_set=>
|
156
|
+
# [{:route_table_association_id=>"rtbassoc-a02610c9",
|
157
|
+
# :subnet_id=>"subnet-b95f76d0",
|
158
|
+
# :route_table_id=>"rtb-be3006d7"}]}]
|
159
|
+
#
|
160
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeRouteTables.html
|
161
|
+
#
|
162
|
+
def describe_route_tables(*list_and_options)
|
163
|
+
describe_resources_with_list_and_options('DescribeRouteTables', 'RouteTableId', QEc2DescribeRouteTablesParser, list_and_options)
|
164
|
+
rescue Exception
|
165
|
+
on_exception
|
166
|
+
end
|
167
|
+
|
168
|
+
# Creates a new route table within a VPC. After you create a new route table, you can add routes and associate the table with a subne
|
169
|
+
#
|
170
|
+
# ec2.create_route_table("vpc-df80a6b6") #=>
|
171
|
+
# {:route_table_id=>"rtb-4331072a",
|
172
|
+
# :route_set=>
|
173
|
+
# [{:state=>"active",
|
174
|
+
# :destination_cidr_block=>"10.0.3.0/24",
|
175
|
+
# :gateway_id=>"local"}],
|
176
|
+
# :vpc_id=>"vpc-df80a6b6",
|
177
|
+
# :association_set=>[],
|
178
|
+
# :tags=>{}}
|
179
|
+
#
|
180
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-CreateRouteTable.html
|
181
|
+
#
|
182
|
+
def create_route_table(vpc_id)
|
183
|
+
link = generate_request("CreateRouteTable", 'VpcId' => vpc_id )
|
184
|
+
request_info(link, QEc2DescribeRouteTablesParser::new(:logger => @logger)).first
|
185
|
+
rescue Exception
|
186
|
+
on_exception
|
187
|
+
end
|
188
|
+
|
189
|
+
# Deletes a route table from a VPC.
|
190
|
+
# The route table must not be associated with a subnet. You can't delete the main route table.
|
191
|
+
#
|
192
|
+
# ec2.delete_route_table("rtb-4331072a") #=> true
|
193
|
+
#
|
194
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DeleteRouteTable.html
|
195
|
+
def delete_route_table(route_table_id)
|
196
|
+
link = generate_request("DeleteRouteTable", 'RouteTableId' => route_table_id )
|
197
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
198
|
+
rescue Exception
|
199
|
+
on_exception
|
200
|
+
end
|
201
|
+
|
202
|
+
# Associates a subnet with a route table. The subnet and route table must be in the same VPC.
|
203
|
+
# This association causes traffic originating from the subnet to be routed according to the routes in
|
204
|
+
# the route table. The action returns an association ID, which you need if you want to disassociate
|
205
|
+
# the route table from the subnet later. A route table can be associated with multiple subnets.
|
206
|
+
#
|
207
|
+
# ec2.associate_route_table("rtb-be3006d7", "subnet-b95f76d0") #=> true
|
208
|
+
#
|
209
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-AssociateRouteTable.html
|
210
|
+
#
|
211
|
+
def associate_route_table(route_table_id, subnet_id)
|
212
|
+
request_hash = { 'RouteTableId' => route_table_id,
|
213
|
+
'SubnetId' => subnet_id }
|
214
|
+
link = generate_request("AssociateRouteTable", request_hash)
|
215
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
216
|
+
rescue Exception
|
217
|
+
on_exception
|
218
|
+
end
|
219
|
+
|
220
|
+
# Disassociates a subnet from a route table.
|
221
|
+
#
|
222
|
+
# ec2.disassociate_route_table(route_table_association_id) #=> true
|
223
|
+
#
|
224
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DisassociateRouteTable.html
|
225
|
+
#
|
226
|
+
def disassociate_route_table(route_table_association_id)
|
227
|
+
link = generate_request("DisassociateRouteTable", 'AssociationId' => route_table_association_id )
|
228
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
229
|
+
rescue Exception
|
230
|
+
on_exception
|
231
|
+
end
|
232
|
+
|
233
|
+
# Changes the route table associated with a given subnet in a VPC. After you execute this action, the subnet
|
234
|
+
# uses the routes in the new route table it's associated with.
|
235
|
+
# You can also use this action to change which table is the main route table in the VPC. You just specify
|
236
|
+
# the main route table's association ID and the route table that you want to be the new main route table.
|
237
|
+
#
|
238
|
+
# ec2.replace_route_table_association("rtb-be3006d7", "rtbassoc-a02610c9") #=> true
|
239
|
+
#
|
240
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ReplaceRouteTableAssociation.html
|
241
|
+
#
|
242
|
+
def replace_route_table_association(route_table_id, route_table_association_id)
|
243
|
+
request_hash = { 'RouteTableId' => route_table_id,
|
244
|
+
'AssociationId' => route_table_association_id }
|
245
|
+
link = generate_request("ReplaceRouteTableAssociation", request_hash)
|
246
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
247
|
+
rescue Exception
|
248
|
+
on_exception
|
249
|
+
end
|
250
|
+
|
251
|
+
#---------------------
|
252
|
+
# Routes
|
253
|
+
#---------------------
|
254
|
+
|
255
|
+
# Creates a new route in a route table within a VPC. The route's target can be either a gateway attached to
|
256
|
+
# the VPC or a NAT instance in the VPC.
|
257
|
+
# Options: :gateway_id, :instance_id
|
258
|
+
#
|
259
|
+
# ec2.create_route("rtb-be3006d7", "0.0.0.1/32", :gateway_id => 'igw-6585c10c') #=> true
|
260
|
+
#
|
261
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateRoute.html
|
262
|
+
#
|
263
|
+
def create_route(route_table_id, destination_cidr_block, options = {})
|
264
|
+
request_hash = { 'RouteTableId' => route_table_id,
|
265
|
+
'DestinationCidrBlock' => destination_cidr_block }
|
266
|
+
request_hash['GatewayId'] = options[:gateway_id] unless options[:gateway_id].right_blank?
|
267
|
+
request_hash['InstanceId'] = options[:instance_id] unless options[:instance_id].right_blank?
|
268
|
+
link = generate_request("CreateRoute", request_hash)
|
269
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
270
|
+
rescue Exception
|
271
|
+
on_exception
|
272
|
+
end
|
273
|
+
|
274
|
+
# Deletes a route from a route table in a VPC.
|
275
|
+
#
|
276
|
+
# ec2.delete_route("rtb-be3006d7", "0.0.0.1/32") #=> true
|
277
|
+
#
|
278
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteRoute.html
|
279
|
+
#
|
280
|
+
def delete_route(route_table_id, destination_cidr_block)
|
281
|
+
link = generate_request("DeleteRoute", 'RouteTableId' => route_table_id,
|
282
|
+
'DestinationCidrBlock' => destination_cidr_block )
|
283
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
284
|
+
rescue Exception
|
285
|
+
on_exception
|
286
|
+
end
|
287
|
+
|
288
|
+
# Replaces an existing route within a route table in a VPC
|
289
|
+
# Options: :gateway_id, :instance_id
|
290
|
+
#
|
291
|
+
# ec2.replace_route("rtb-be3006d7", "0.0.0.2/32", :gateway_id => 'igw-6585c10c') #=> true
|
292
|
+
#
|
293
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ReplaceRoute.html
|
294
|
+
#
|
295
|
+
def replace_route(route_table_id, destination_cidr_block, options = {})
|
296
|
+
request_hash = { 'RouteTableId' => route_table_id,
|
297
|
+
'DestinationCidrBlock' => destination_cidr_block }
|
298
|
+
request_hash['GatewayId'] = options[:gateway_id] unless options[:gateway_id].right_blank?
|
299
|
+
request_hash['InstanceId'] = options[:instance_id] unless options[:instance_id].right_blank?
|
300
|
+
link = generate_request("ReplaceRoute", request_hash)
|
301
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
302
|
+
rescue Exception
|
303
|
+
on_exception
|
304
|
+
end
|
305
|
+
|
306
|
+
#---------------------
|
307
|
+
# InternetGateways
|
308
|
+
#---------------------
|
309
|
+
|
310
|
+
class QEc2DescribeInternetGatewaysParser < RightAWSParser #:nodoc:
|
311
|
+
def tagstart(name, attributes)
|
312
|
+
case full_tag_name
|
313
|
+
when %r{/(internetGatewaySet/item|internetGateway)$} then @item = { :tags => {} }
|
314
|
+
when %r{/tagSet/item$} then @aws_tag = {}
|
315
|
+
end
|
316
|
+
end
|
317
|
+
def tagend(name)
|
318
|
+
case full_tag_name
|
319
|
+
# item
|
320
|
+
when %r{/(internetGatewaySet/item|internetGateway)$} then @result << @item
|
321
|
+
when %r{/internetGatewayId$} then @item[:internet_gateway_id] = @text
|
322
|
+
when %r{/vpcId$} then @item[:vpc_id] = @text
|
323
|
+
when %r{/state$} then @item[:state] = @text
|
324
|
+
# tags
|
325
|
+
when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
|
326
|
+
when %r{/tagSet/item/value$} then @aws_tag[:value] = @text
|
327
|
+
when %r{/tagSet/item$} then @item[:tags][@aws_tag[:key]] = @aws_tag[:value]
|
328
|
+
end
|
329
|
+
end
|
330
|
+
def reset
|
331
|
+
@result = []
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
#---------------------
|
336
|
+
# Routes
|
337
|
+
#---------------------
|
338
|
+
|
339
|
+
class QEc2DescribeRouteTablesParser < RightAWSParser #:nodoc:
|
340
|
+
def tagstart(name, attributes)
|
341
|
+
case full_tag_name
|
342
|
+
when %r{/(routeTableSet/item|routeTable)$}
|
343
|
+
@item = { :route_set => [],
|
344
|
+
:association_set => [],
|
345
|
+
:tags => {}}
|
346
|
+
when %r{/routeSet/item$} then @route_set = {}
|
347
|
+
when %r{/associationSet/item$} then @association_set = {}
|
348
|
+
end
|
349
|
+
end
|
350
|
+
def tagend(name)
|
351
|
+
case full_tag_name
|
352
|
+
# item
|
353
|
+
when %r{/(routeTableSet/item|routeTable)/routeTableId$} then @item[:route_table_id] = @text
|
354
|
+
when %r{/(routeTableSet/item|routeTable)/vpcId$} then @item[:vpc_id] = @text
|
355
|
+
when %r{/(routeTableSet/item|routeTable)$} then @result << @item
|
356
|
+
# route set
|
357
|
+
when %r{/routeSet/item/destinationCidrBlock$} then @route_set[:destination_cidr_block] = @text
|
358
|
+
when %r{/routeSet/item/gatewayId$} then @route_set[:gateway_id] = @text
|
359
|
+
when %r{/routeSet/item/instanceId$} then @route_set[:instance_id] = @text
|
360
|
+
when %r{/routeSet/item/state$} then @route_set[:state] = @text
|
361
|
+
when %r{/routeSet/item$} then @item[:route_set] << @route_set
|
362
|
+
# association set
|
363
|
+
when %r{/associationSet/item/routeTableId$} then @association_set[:route_table_id] = @text
|
364
|
+
when %r{/associationSet/item/routeTableAssociationId$} then @association_set[:route_table_association_id] = @text
|
365
|
+
when %r{/associationSet/item/subnetId$} then @association_set[:subnet_id] = @text
|
366
|
+
when %r{/associationSet/item/main} then @association_set[:main] = @text == 'true'
|
367
|
+
when %r{/associationSet/item$} then @item[:association_set] << @association_set
|
368
|
+
# tags
|
369
|
+
when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
|
370
|
+
when %r{/tagSet/item/value$} then @aws_tag[:value] = @text
|
371
|
+
when %r{/tagSet/item$} then @item[:tags][@aws_tag[:key]] = @aws_tag[:value]
|
372
|
+
end
|
373
|
+
end
|
374
|
+
def reset
|
375
|
+
@result = []
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|