right_aws 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/awsbase/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module RightAws #:nodoc:
|
2
2
|
module VERSION #:nodoc:
|
3
|
-
MAJOR =
|
4
|
-
MINOR =
|
3
|
+
MAJOR = 3 unless defined?(MAJOR)
|
4
|
+
MINOR = 0 unless defined?(MINOR)
|
5
5
|
TINY = 0 unless defined?(TINY)
|
6
6
|
|
7
7
|
STRING = [MAJOR, MINOR, TINY].join('.') unless defined?(STRING)
|
data/lib/ec2/right_ec2.rb
CHANGED
@@ -68,7 +68,7 @@ module RightAws
|
|
68
68
|
include RightAwsBaseInterface
|
69
69
|
|
70
70
|
# Amazon EC2 API version being used
|
71
|
-
API_VERSION = "
|
71
|
+
API_VERSION = "2011-02-28"
|
72
72
|
DEFAULT_HOST = "ec2.amazonaws.com"
|
73
73
|
DEFAULT_PATH = '/'
|
74
74
|
DEFAULT_PROTOCOL = 'https'
|
@@ -130,8 +130,8 @@ module RightAws
|
|
130
130
|
#end
|
131
131
|
end
|
132
132
|
|
133
|
-
def generate_request(action, params={}) #:nodoc:
|
134
|
-
generate_request_impl(:get, action, params )
|
133
|
+
def generate_request(action, params={}, custom_options={}) #:nodoc:
|
134
|
+
generate_request_impl(:get, action, params, custom_options)
|
135
135
|
end
|
136
136
|
|
137
137
|
# Sends request to Amazon and parses the response
|
@@ -144,9 +144,19 @@ module RightAws
|
|
144
144
|
# 'RemoteFunctionName' -> :remote_funtion_name
|
145
145
|
cache_name = remote_function_name.right_underscore.to_sym
|
146
146
|
list, options = AwsUtils::split_items_and_params(list_and_options)
|
147
|
+
# Resource IDs to fetch
|
147
148
|
request_hash = amazonize_list(remote_item_name, list)
|
148
|
-
|
149
|
-
|
149
|
+
# Other custom options
|
150
|
+
options.each do |key, values|
|
151
|
+
next if values.right_blank?
|
152
|
+
case key
|
153
|
+
when :filters then
|
154
|
+
request_hash.merge!(amazonize_list(['Filter.?.Name', 'Filter.?.Value.?'], values))
|
155
|
+
else
|
156
|
+
request_hash.merge!(amazonize_list(key.to_s.right_camelize, values))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
cache_for = (list.right_blank? && options.right_blank?) ? cache_name : nil
|
150
160
|
link = generate_request(remote_function_name, request_hash)
|
151
161
|
request_cache_or_info(cache_for, link, parser_class, @@bench, cache_for, &block)
|
152
162
|
rescue Exception
|
@@ -226,32 +236,49 @@ module RightAws
|
|
226
236
|
#-----------------------------------------------------------------
|
227
237
|
|
228
238
|
# Acquire a new elastic IP address for use with your account.
|
229
|
-
#
|
239
|
+
# Options: :domain.
|
240
|
+
# Returns allocated IP address or or an exception.
|
230
241
|
#
|
231
|
-
# ec2.allocate_address #=>
|
242
|
+
# ec2.allocate_address #=>
|
243
|
+
# { :public_ip => "50.19.214.224",
|
244
|
+
# :domain => "standard"}
|
232
245
|
#
|
233
|
-
|
234
|
-
|
246
|
+
# ec2.allocate_address(:domain => 'vpc') #=>
|
247
|
+
# { :allocation_id => "eipalloc-c6abfeaf",
|
248
|
+
# :domain => "vpc",
|
249
|
+
# :public_ip => "184.72.112.39"}
|
250
|
+
#
|
251
|
+
def allocate_address(options={})
|
252
|
+
request_hash = {}
|
253
|
+
request_hash['Domain'] = options[:domain] unless options[:domain].right_blank?
|
254
|
+
link = generate_request("AllocateAddress", request_hash)
|
235
255
|
request_info(link, QEc2AllocateAddressParser.new(:logger => @logger))
|
236
256
|
rescue Exception
|
237
257
|
on_exception
|
238
258
|
end
|
239
259
|
|
240
260
|
# Associate an elastic IP address with an instance.
|
241
|
-
#
|
261
|
+
# Options: :public_ip, :allocation_id.
|
262
|
+
# Returns a hash of data or an exception.
|
242
263
|
#
|
243
|
-
# ec2.associate_address('i-d630cbbf', '75.101.154.140') #=>
|
264
|
+
# ec2.associate_address('i-d630cbbf', :public_ip => '75.101.154.140') #=>
|
265
|
+
# { :return => true }
|
244
266
|
#
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
267
|
+
# ec2.associate_address(inst, :allocation_id => "eipalloc-c6abfeaf") #=>
|
268
|
+
# { :return => true,
|
269
|
+
# :association_id => 'eipassoc-fc5ca095'}
|
270
|
+
#
|
271
|
+
def associate_address(instance_id, options={})
|
272
|
+
request_hash = { "InstanceId" => instance_id.to_s }
|
273
|
+
request_hash['PublicIp'] = options[:public_ip] unless options[:public_ip].right_blank?
|
274
|
+
request_hash['AllocationId'] = options[:allocation_id] unless options[:allocation_id].right_blank?
|
275
|
+
link = generate_request("AssociateAddress", request_hash)
|
276
|
+
request_info(link, QEc2AssociateAddressParser.new(:logger => @logger))
|
250
277
|
rescue Exception
|
251
278
|
on_exception
|
252
279
|
end
|
253
280
|
|
254
|
-
# List elastic
|
281
|
+
# List elastic IPs by public addresses.
|
255
282
|
#
|
256
283
|
# Accepts a list of addresses and/or a set of filters as the last parameter.
|
257
284
|
#
|
@@ -259,40 +286,62 @@ module RightAws
|
|
259
286
|
#
|
260
287
|
# Returns an array of 2 keys (:instance_id and :public_ip) hashes:
|
261
288
|
#
|
262
|
-
# ec2.describe_addresses #=> [{:instance_id=>"i-
|
263
|
-
#
|
289
|
+
# ec2.describe_addresses #=> [{:instance_id=>"i-75ebd41b", :domain=>"standard", :public_ip=>"50.17.211.96"},
|
290
|
+
# :domain=>"vpc", :public_ip=>"184.72.112.39", :allocation_id=>"eipalloc-c6abfeaf"}]
|
264
291
|
#
|
265
|
-
# ec2.describe_addresses('75.101.154.140') #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"}]
|
292
|
+
# ec2.describe_addresses('75.101.154.140') #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140", :domain=>"standard"}]
|
266
293
|
#
|
267
294
|
# ec2.describe_addresses(:filters => { 'public-ip' => "75.101.154.140" })
|
268
295
|
#
|
269
|
-
# P.S.
|
296
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeAddresses.html
|
270
297
|
#
|
271
298
|
def describe_addresses(*list_and_options)
|
272
299
|
describe_resources_with_list_and_options('DescribeAddresses', 'PublicIp', QEc2DescribeAddressesParser, list_and_options)
|
273
300
|
end
|
274
301
|
|
302
|
+
|
303
|
+
# List elastic IPs by allocation ids.
|
304
|
+
#
|
305
|
+
# Accepts a list of allocations and/or a set of filters as the last parameter.
|
306
|
+
#
|
307
|
+
# describe_addresses_by_allocation_ids("eipalloc-c6abfeaf") #=>
|
308
|
+
# [{:domain=>"vpc",
|
309
|
+
# :public_ip=>"184.72.112.39",
|
310
|
+
# :allocation_id=>"eipalloc-c6abfeaf"}]
|
311
|
+
#
|
312
|
+
# P.S. http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeAddresses.html
|
313
|
+
#
|
314
|
+
def describe_addresses_by_allocation_ids(*list_and_options)
|
315
|
+
describe_resources_with_list_and_options('DescribeAddresses', 'AllocationId', QEc2DescribeAddressesParser, list_and_options)
|
316
|
+
end
|
317
|
+
|
275
318
|
# Disassociate the specified elastic IP address from the instance to which it is assigned.
|
319
|
+
# Options: :public_ip, :association_id.
|
276
320
|
# Returns +true+ or an exception.
|
277
321
|
#
|
278
|
-
# ec2.disassociate_address('75.101.154.140') #=> true
|
322
|
+
# ec2.disassociate_address(:public_ip => '75.101.154.140') #=> true
|
279
323
|
#
|
280
|
-
def disassociate_address(
|
281
|
-
|
282
|
-
|
324
|
+
def disassociate_address(options = {})
|
325
|
+
request_hash = {}
|
326
|
+
request_hash['PublicIp'] = options[:public_ip] unless options[:public_ip].right_blank?
|
327
|
+
request_hash['AssociationId'] = options[:association_id] unless options[:association_id].right_blank?
|
328
|
+
link = generate_request("DisassociateAddress", request_hash)
|
283
329
|
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
284
330
|
rescue Exception
|
285
331
|
on_exception
|
286
332
|
end
|
287
333
|
|
288
334
|
# Release an elastic IP address associated with your account.
|
335
|
+
# Options: :public_ip, :allocation_id.
|
289
336
|
# Returns +true+ or an exception.
|
290
337
|
#
|
291
|
-
# ec2.release_address('75.101.154.140') #=> true
|
338
|
+
# ec2.release_address(:public_ip => '75.101.154.140') #=> true
|
292
339
|
#
|
293
|
-
def release_address(
|
294
|
-
|
295
|
-
|
340
|
+
def release_address(options = {})
|
341
|
+
request_hash = {}
|
342
|
+
request_hash['PublicIp'] = options[:public_ip] unless options[:public_ip].right_blank?
|
343
|
+
request_hash['AllocationId'] = options[:allocation_id] unless options[:allocation_id].right_blank?
|
344
|
+
link = generate_request("ReleaseAddress", request_hash)
|
296
345
|
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
297
346
|
rescue Exception
|
298
347
|
on_exception
|
@@ -334,7 +383,12 @@ module RightAws
|
|
334
383
|
#
|
335
384
|
# Filters: endpoint, region-name
|
336
385
|
#
|
337
|
-
# ec2.describe_regions #=>
|
386
|
+
# ec2.describe_regions #=>
|
387
|
+
# [{:region_endpoint=>"ec2.eu-west-1.amazonaws.com", :region_name=>"eu-west-1"},
|
388
|
+
# {:region_endpoint=>"ec2.us-east-1.amazonaws.com", :region_name=>"us-east-1"},
|
389
|
+
# {:region_endpoint=>"ec2.ap-northeast-1.amazonaws.com", :region_name=>"ap-northeast-1"},
|
390
|
+
# {:region_endpoint=>"ec2.us-west-1.amazonaws.com", :region_name=>"us-west-1"},
|
391
|
+
# {:region_endpoint=>"ec2.ap-southeast-1.amazonaws.com", :region_name=>"ap-southeast-1"}]
|
338
392
|
#
|
339
393
|
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeRegions.html
|
340
394
|
#
|
@@ -393,19 +447,41 @@ module RightAws
|
|
393
447
|
|
394
448
|
class QEc2AllocateAddressParser < RightAWSParser #:nodoc:
|
395
449
|
def tagend(name)
|
396
|
-
|
450
|
+
case name
|
451
|
+
when 'publicIp' then @result[:public_ip] = @text
|
452
|
+
when 'allocationId' then @result[:allocation_id] = @text
|
453
|
+
when 'domain' then @result[:domain] = @text
|
454
|
+
end
|
455
|
+
end
|
456
|
+
def reset
|
457
|
+
@result = {}
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
class QEc2AssociateAddressParser < RightAWSParser #:nodoc:
|
462
|
+
def tagend(name)
|
463
|
+
case name
|
464
|
+
when 'return' then @result[:return] = @text == 'true'
|
465
|
+
when 'associationId' then @result[:association_id] = @text
|
466
|
+
end
|
467
|
+
end
|
468
|
+
def reset
|
469
|
+
@result = {}
|
397
470
|
end
|
398
471
|
end
|
399
|
-
|
472
|
+
|
400
473
|
class QEc2DescribeAddressesParser < RightAWSParser #:nodoc:
|
401
474
|
def tagstart(name, attributes)
|
402
|
-
@
|
475
|
+
@item = {} if name == 'item'
|
403
476
|
end
|
404
477
|
def tagend(name)
|
405
478
|
case name
|
406
|
-
when 'instanceId'
|
407
|
-
when 'publicIp'
|
408
|
-
when '
|
479
|
+
when 'instanceId' then (@item[:instance_id] = @text unless @text.right_blank?)
|
480
|
+
when 'publicIp' then @item[:public_ip] = @text
|
481
|
+
when 'allocationId' then @item[:allocation_id] = @text
|
482
|
+
when 'associationId' then @item[:association_id] = @text
|
483
|
+
when 'domain' then @item[:domain] = @text
|
484
|
+
when 'item' then @result << @item
|
409
485
|
end
|
410
486
|
end
|
411
487
|
def reset
|
@@ -445,8 +521,15 @@ module RightAws
|
|
445
521
|
#-----------------------------------------------------------------
|
446
522
|
|
447
523
|
class QEc2DescribeRegionsParser < RightAWSParser #:nodoc:
|
524
|
+
def tagstart(name, attributes)
|
525
|
+
@item = {} if name == 'item'
|
526
|
+
end
|
448
527
|
def tagend(name)
|
449
|
-
|
528
|
+
case name
|
529
|
+
when 'regionName' then @item[:region_name] = @text
|
530
|
+
when 'regionEndpoint' then @item[:region_endpoint] = @text
|
531
|
+
when 'item' then @result << @item
|
532
|
+
end
|
450
533
|
end
|
451
534
|
def reset
|
452
535
|
@result = []
|
data/lib/ec2/right_ec2_ebs.rb
CHANGED
@@ -145,30 +145,41 @@ module RightAws
|
|
145
145
|
|
146
146
|
# Describe EBS snapshots.
|
147
147
|
#
|
148
|
-
# Accepts a list of snapshots and/or
|
148
|
+
# Accepts a list of snapshots and/or options: :restorable_by, :owner and :filters
|
149
|
+
#
|
150
|
+
# Options: :restorable_by => Array or String, :owner => Array or String, :filters => Hash
|
149
151
|
#
|
150
152
|
# Filters: description, owner-alias, owner-id, progress, snapshot-id, start-time, status, tag-key,
|
151
153
|
# tag-value, tag:key, volume-id, volume-size
|
152
154
|
#
|
153
155
|
# ec2.describe_snapshots #=>
|
154
|
-
#
|
155
|
-
# :
|
156
|
+
# [{:aws_volume_size=>2,
|
157
|
+
# :tags=>{},
|
158
|
+
# :aws_id=>"snap-d010f6b9",
|
159
|
+
# :owner_alias=>"amazon",
|
156
160
|
# :aws_progress=>"100%",
|
157
|
-
# :
|
158
|
-
# :
|
159
|
-
#
|
160
|
-
# :
|
161
|
-
# :
|
162
|
-
#
|
163
|
-
#
|
161
|
+
# :aws_status=>"completed",
|
162
|
+
# :aws_description=>
|
163
|
+
# "Windows 2003 R2 Installation Media [Deprecated] - Enterprise Edition 64-bit",
|
164
|
+
# :aws_owner=>"711940113766",
|
165
|
+
# :aws_volume_id=>"vol-351efb5c",
|
166
|
+
# :aws_started_at=>"2008-10-20T18:23:59.000Z"},
|
167
|
+
# {:aws_volume_size=>2,
|
168
|
+
# :tags=>{},
|
169
|
+
# :aws_id=>"snap-a310f6ca",
|
170
|
+
# :owner_alias=>"amazon",
|
164
171
|
# :aws_progress=>"100%",
|
165
|
-
# :
|
166
|
-
# :
|
167
|
-
# :
|
168
|
-
# :
|
169
|
-
# :
|
170
|
-
#
|
171
|
-
# ec2.describe_snapshots(
|
172
|
+
# :aws_status=>"completed",
|
173
|
+
# :aws_description=>"Windows 2003 R2 Installation Media 64-bit",
|
174
|
+
# :aws_owner=>"711940113766",
|
175
|
+
# :aws_volume_id=>"vol-001efb69",
|
176
|
+
# :aws_started_at=>"2008-10-20T18:25:53.000Z"}, ... ]
|
177
|
+
#
|
178
|
+
# ec2.describe_snapshots("snap-e676e28a", "snap-e176e281")
|
179
|
+
#
|
180
|
+
# ec2.describe_snapshots(:restorable_by => ['123456781234'],
|
181
|
+
# :owner => ['self', 'amazon'],
|
182
|
+
# :filters => {'tag:MyTag' => 'MyValue'})
|
172
183
|
#
|
173
184
|
# P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeSnapshots.html
|
174
185
|
#
|
@@ -176,6 +187,10 @@ module RightAws
|
|
176
187
|
describe_resources_with_list_and_options('DescribeSnapshots', 'SnapshotId', QEc2DescribeSnapshotsParser, list_and_options)
|
177
188
|
end
|
178
189
|
|
190
|
+
def describe_snapshots_by_restorable_by(*list_and_options)
|
191
|
+
describe_resources_with_list_and_options('DescribeSnapshots', 'RestorableBy', QEc2DescribeSnapshotsParser, list_and_options)
|
192
|
+
end
|
193
|
+
|
179
194
|
# Create a snapshot of specified volume.
|
180
195
|
#
|
181
196
|
# ec2.create_snapshot('vol-898a6fe0', 'KD: WooHoo!!') #=>
|
@@ -270,18 +285,18 @@ module RightAws
|
|
270
285
|
|
271
286
|
# Modify snapshot attribute.
|
272
287
|
#
|
273
|
-
#
|
274
|
-
#
|
275
|
-
#
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
288
|
+
# Attribute can take only 'createVolumePermission' value.
|
289
|
+
# Value is a Hash {:add_user_ids, :add_groups, :remove_user_ids, :remove_groups }.
|
290
|
+
#
|
291
|
+
def modify_snapshot_attribute(snapshot_id, attribute, value)
|
292
|
+
params = { 'SnapshotId' => snapshot_id }
|
293
|
+
case attribute.to_s
|
294
|
+
when 'createVolumePermission'
|
295
|
+
params.update(amazonize_list('CreateVolumePermission.Add.?.UserId', value[:add_user_ids]))
|
296
|
+
params.update(amazonize_list('CreateVolumePermission.Add.?.Group', value[:add_groups]))
|
297
|
+
params.update(amazonize_list('CreateVolumePermission.Remove.?.UserId', value[:remove_user_ids]))
|
298
|
+
params.update(amazonize_list('CreateVolumePermission.Remove.?.Group', value[:remove_groups]))
|
299
|
+
end
|
285
300
|
link = generate_request("ModifySnapshotAttribute", params)
|
286
301
|
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
287
302
|
rescue Exception
|
@@ -292,36 +307,36 @@ module RightAws
|
|
292
307
|
#
|
293
308
|
# ec2.modify_snapshot_attribute_create_volume_permission_add_users('snap-36fe435f', '000000000000', '000000000001') #=> true
|
294
309
|
#
|
295
|
-
def modify_snapshot_attribute_create_volume_permission_add_users(snapshot_id, *
|
296
|
-
modify_snapshot_attribute(snapshot_id, 'createVolumePermission',
|
310
|
+
def modify_snapshot_attribute_create_volume_permission_add_users(snapshot_id, *user_ids)
|
311
|
+
modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :add_user_ids => user_ids.flatten )
|
297
312
|
end
|
298
313
|
|
299
314
|
# Revoke create volume permission for a list of users.
|
300
315
|
#
|
301
316
|
# ec2.modify_snapshot_attribute_create_volume_permission_remove_users('snap-36fe435f', '000000000000', '000000000001') #=> true
|
302
317
|
#
|
303
|
-
def modify_snapshot_attribute_create_volume_permission_remove_users(snapshot_id, *
|
304
|
-
modify_snapshot_attribute(snapshot_id, 'createVolumePermission',
|
318
|
+
def modify_snapshot_attribute_create_volume_permission_remove_users(snapshot_id, *user_ids)
|
319
|
+
modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :remove_user_ids => user_ids.flatten )
|
305
320
|
end
|
306
321
|
|
307
322
|
# Grant create volume permission for user groups (currently only 'all' is supported).
|
308
323
|
#
|
309
324
|
# ec2.modify_snapshot_attribute_create_volume_permission_add_groups('snap-36fe435f') #=> true
|
310
325
|
#
|
311
|
-
def modify_snapshot_attribute_create_volume_permission_add_groups(snapshot_id, *
|
312
|
-
|
313
|
-
|
314
|
-
modify_snapshot_attribute(snapshot_id, 'createVolumePermission',
|
326
|
+
def modify_snapshot_attribute_create_volume_permission_add_groups(snapshot_id, *groups)
|
327
|
+
groups.flatten!
|
328
|
+
groups = ['all'] if groups.right_blank?
|
329
|
+
modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :add_groups => groups )
|
315
330
|
end
|
316
331
|
|
317
332
|
# Remove create volume permission for user groups (currently only 'all' is supported).
|
318
333
|
#
|
319
334
|
# ec2.modify_snapshot_attribute_create_volume_permission_remove_groups('snap-36fe435f') #=> true
|
320
335
|
#
|
321
|
-
def modify_snapshot_attribute_create_volume_permission_remove_groups(snapshot_id, *
|
322
|
-
|
323
|
-
|
324
|
-
modify_snapshot_attribute(snapshot_id, 'createVolumePermission',
|
336
|
+
def modify_snapshot_attribute_create_volume_permission_remove_groups(snapshot_id, *groups)
|
337
|
+
groups.flatten!
|
338
|
+
groups = ['all'] if groups.right_blank?
|
339
|
+
modify_snapshot_attribute(snapshot_id, 'createVolumePermission', :remove_groups => groups )
|
325
340
|
end
|
326
341
|
|
327
342
|
# Delete the specified snapshot.
|
@@ -427,6 +442,7 @@ module RightAws
|
|
427
442
|
when 'description' then @item[:aws_description] = @text
|
428
443
|
when 'ownerId' then @item[:aws_owner] = @text
|
429
444
|
when 'volumeSize' then @item[:aws_volume_size] = @text.to_i
|
445
|
+
when 'ownerAlias' then @item[:owner_alias] = @text
|
430
446
|
else
|
431
447
|
case full_tag_name
|
432
448
|
when %r{/tagSet/item/key$} then @aws_tag[:key] = @text
|
data/lib/ec2/right_ec2_images.rb
CHANGED
@@ -180,7 +180,7 @@ module RightAws
|
|
180
180
|
params['KernelId'] = options[:kernel_id] if options[:kernel_id]
|
181
181
|
params['RamdiskId'] = options[:ramdisk_id] if options[:ramdisk_id]
|
182
182
|
params['RootDeviceName'] = options[:root_device_name] if options[:root_device_name]
|
183
|
-
params['VirtualizationType'] = options[:virtualization_type] if options[:virtualization_type]
|
183
|
+
params['VirtualizationType'] = options[:virtualization_type] if options[:virtualization_type]
|
184
184
|
# params['SnapshotId'] = options[:snapshot_id] if options[:snapshot_id]
|
185
185
|
params.merge!(amazonize_block_device_mappings(options[:block_device_mappings]))
|
186
186
|
link = generate_request("RegisterImage", params)
|
@@ -201,9 +201,19 @@ module RightAws
|
|
201
201
|
on_exception
|
202
202
|
end
|
203
203
|
|
204
|
-
# Describe image attributes.
|
205
|
-
#
|
206
|
-
#
|
204
|
+
# Describe image attributes.
|
205
|
+
#
|
206
|
+
# Returns: String (or nil) for 'description', 'kernel', 'ramdisk'; Hash for 'launchPermission'; Array for 'productCodes', 'blockDeviceMapping'
|
207
|
+
#
|
208
|
+
# ec2.describe_image_attribute('ami-00000000', 'description') #=> 'My cool Image'
|
209
|
+
# ec2.describe_image_attribute('ami-00000000', 'launchPermission') #=> {:user_ids=>["443739700000", "115864000000", "309179000000", "857501300000"]}
|
210
|
+
# ec2.describe_image_attribute('ami-00000000', 'productCodes') #=> ["8ED10000"]
|
211
|
+
# ec2.describe_image_attribute('ami-00000000', 'kernel') #=> "aki-9b00e5f2"
|
212
|
+
# ec2.describe_image_attribute('ami-00000000', 'ramdisk') #=> nil
|
213
|
+
# ec2.describe_image_attribute('ami-00000000', 'blockDeviceMapping') #=> [{:device_name=>"sda2", :virtual_name=>"ephemeral0"},
|
214
|
+
# {:device_name=>"sda1", :virtual_name=>"ami"},
|
215
|
+
# {:device_name=>"/dev/sda1", :virtual_name=>"root"},
|
216
|
+
# {:device_name=>"sda3", :virtual_name=>"swap"}]
|
207
217
|
#
|
208
218
|
def describe_image_attribute(image_id, attribute='launchPermission')
|
209
219
|
link = generate_request("DescribeImageAttribute",
|
@@ -232,19 +242,23 @@ module RightAws
|
|
232
242
|
# instead of modify_image_attribute because the signature of
|
233
243
|
# modify_image_attribute may change with EC2 service changes.
|
234
244
|
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
245
|
+
# Attribute can take next values: 'launchPermission', 'productCode', 'description'.
|
246
|
+
# Value is a String for'description'. is a String or an Array for 'productCode' and
|
247
|
+
# is a Hash {:add_user_ids, :add_groups, :remove_user_ids, :remove_groups } for 'launchPermission'.
|
248
|
+
#
|
249
|
+
def modify_image_attribute(image_id, attribute, value)
|
250
|
+
params = { 'ImageId' => image_id }
|
251
|
+
case attribute.to_s
|
252
|
+
when 'launchPermission'
|
253
|
+
params.update(amazonize_list('LaunchPermission.Add.?.UserId', value[:add_user_ids]))
|
254
|
+
params.update(amazonize_list('LaunchPermission.Add.?.Group', value[:add_groups]))
|
255
|
+
params.update(amazonize_list('LaunchPermission.Remove.?.UserId', value[:remove_user_ids]))
|
256
|
+
params.update(amazonize_list('LaunchPermission.Remove.?.Group', value[:remove_groups]))
|
257
|
+
when 'productCode'
|
258
|
+
params.update(amazonize_list('ProductCode', value))
|
259
|
+
when 'description'
|
260
|
+
params['Description.Value'] = value
|
261
|
+
end
|
248
262
|
link = generate_request("ModifyImageAttribute", params)
|
249
263
|
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
250
264
|
rescue Exception
|
@@ -256,16 +270,16 @@ module RightAws
|
|
256
270
|
# Returns +true+ or an exception.
|
257
271
|
#
|
258
272
|
# ec2.modify_image_launch_perm_add_users('ami-e444444d',['000000000777','000000000778']) #=> true
|
259
|
-
def modify_image_launch_perm_add_users(image_id,
|
260
|
-
modify_image_attribute(image_id, 'launchPermission',
|
273
|
+
def modify_image_launch_perm_add_users(image_id, *user_ids)
|
274
|
+
modify_image_attribute(image_id, 'launchPermission', :add_user_ids => user_ids.flatten)
|
261
275
|
end
|
262
276
|
|
263
277
|
# Revokes image launch permissions for users. +user_id+ is a list of users AWS accounts ids. Returns +true+ or an exception.
|
264
278
|
#
|
265
279
|
# ec2.modify_image_launch_perm_remove_users('ami-e444444d',['000000000777','000000000778']) #=> true
|
266
280
|
#
|
267
|
-
def modify_image_launch_perm_remove_users(image_id,
|
268
|
-
modify_image_attribute(image_id, 'launchPermission',
|
281
|
+
def modify_image_launch_perm_remove_users(image_id, *user_ids)
|
282
|
+
modify_image_attribute(image_id, 'launchPermission', :remove_user_ids => user_ids.flatten)
|
269
283
|
end
|
270
284
|
|
271
285
|
# Add image launch permissions for users groups (currently only 'all' is supported, which gives public launch permissions).
|
@@ -273,24 +287,32 @@ module RightAws
|
|
273
287
|
#
|
274
288
|
# ec2.modify_image_launch_perm_add_groups('ami-e444444d') #=> true
|
275
289
|
#
|
276
|
-
def modify_image_launch_perm_add_groups(image_id,
|
277
|
-
modify_image_attribute(image_id, 'launchPermission',
|
290
|
+
def modify_image_launch_perm_add_groups(image_id, *groups)
|
291
|
+
modify_image_attribute(image_id, 'launchPermission', :add_groups => groups.flatten)
|
278
292
|
end
|
279
293
|
|
280
294
|
# Remove image launch permissions for users groups (currently only 'all' is supported, which gives public launch permissions).
|
281
295
|
#
|
282
296
|
# ec2.modify_image_launch_perm_remove_groups('ami-e444444d') #=> true
|
283
297
|
#
|
284
|
-
def modify_image_launch_perm_remove_groups(image_id,
|
285
|
-
modify_image_attribute(image_id, 'launchPermission',
|
298
|
+
def modify_image_launch_perm_remove_groups(image_id, *groups)
|
299
|
+
modify_image_attribute(image_id, 'launchPermission', :remove_groups => groups.flatten)
|
286
300
|
end
|
287
301
|
|
288
302
|
# Add product code to image
|
289
303
|
#
|
290
304
|
# ec2.modify_image_product_code('ami-e444444d','0ABCDEF') #=> true
|
291
305
|
#
|
292
|
-
def modify_image_product_code(image_id,
|
293
|
-
modify_image_attribute(image_id, 'productCodes',
|
306
|
+
def modify_image_product_code(image_id, product_codes=[])
|
307
|
+
modify_image_attribute(image_id, 'productCodes',product_codes)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Modify image description
|
311
|
+
#
|
312
|
+
# ec2.modify_image_product_code('ami-e444444d','My cool image') #=> true
|
313
|
+
#
|
314
|
+
def modify_image_description(image_id, description)
|
315
|
+
modify_image_attribute(image_id, 'description', description)
|
294
316
|
end
|
295
317
|
|
296
318
|
# Create a new image.
|
@@ -345,6 +367,7 @@ module RightAws
|
|
345
367
|
when 'rootDeviceName' then @item[:root_device_name] = @text
|
346
368
|
when 'imageClass' then @item[:image_class] = @text
|
347
369
|
when 'virtualizationType' then @item[:virtualization_type] = @text
|
370
|
+
when 'hypervisor' then @item [:hypervisor] = @text
|
348
371
|
else
|
349
372
|
case full_tag_name
|
350
373
|
when %r{/stateReason/code$} then @item[:state_reason_code] = @text.to_i
|
@@ -382,29 +405,35 @@ module RightAws
|
|
382
405
|
|
383
406
|
class QEc2DescribeImageAttributeParser < RightAWSParser #:nodoc:
|
384
407
|
def tagstart(name, attributes)
|
385
|
-
case
|
386
|
-
|
387
|
-
@result
|
388
|
-
|
389
|
-
|
390
|
-
@result[:aws_product_codes] = []
|
408
|
+
case full_tag_name
|
409
|
+
when %r{launchPermission$} then @result = {}
|
410
|
+
when %r{productCodes$} then @result = []
|
411
|
+
when %r{blockDeviceMapping$} then @result = []
|
412
|
+
when %r{blockDeviceMapping/item$} then @block_device_mapping = {}
|
391
413
|
end
|
392
414
|
end
|
393
415
|
def tagend(name)
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
when '
|
416
|
+
case full_tag_name
|
417
|
+
when %r{/kernel/value$} then @result = @text
|
418
|
+
when %r{/ramdisk/value$} then @result = @text
|
419
|
+
when %r{/description/value$} then @result = @text
|
420
|
+
when %r{/productCode$} then @result << @text
|
421
|
+
when %r{launchPermission/item/group$} then (@result[:groups] ||=[]) << @text
|
422
|
+
when %r{launchPermission/item/userId$} then (@result[:user_ids]||=[]) << @text
|
423
|
+
when %r{/blockDeviceMapping/item} # no trailing $
|
424
|
+
case name
|
425
|
+
when 'deviceName' then @block_device_mapping[:device_name] = @text
|
426
|
+
when 'virtualName' then @block_device_mapping[:virtual_name] = @text
|
427
|
+
when 'noDevice' then @block_device_mapping[:no_device] = @text
|
428
|
+
when 'snapshotId' then @block_device_mapping[:ebs_snapshot_id] = @text
|
429
|
+
when 'volumeSize' then @block_device_mapping[:ebs_volume_size] = @text
|
430
|
+
when 'deleteOnTermination' then @block_device_mapping[:ebs_delete_on_termination] = @text == 'true' ? true : false
|
431
|
+
when 'item' then @result << @block_device_mapping
|
432
|
+
end
|
404
433
|
end
|
405
434
|
end
|
406
435
|
def reset
|
407
|
-
@result =
|
436
|
+
@result = nil
|
408
437
|
end
|
409
438
|
end
|
410
439
|
|