redaranj-right_aws 1.10.5 → 1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -229,3 +229,11 @@ the source key.
229
229
  - SDB: added: SQL-like query, select and query_with_attributes support
230
230
  - SDB: fixed no method error when searching for id that doesn't exist
231
231
 
232
+ === 1.11.0
233
+
234
+ Release Notes:
235
+ - Full Amazon RDS instances support added with RightAws::RdsInterface
236
+ - Boot from EBS support added
237
+ - VPC support added
238
+ - Latest EC2 API 2009-10-31 support added
239
+ - Some of bugs fixed
@@ -6,6 +6,12 @@ lib/awsbase/benchmark_fix.rb
6
6
  lib/awsbase/right_awsbase.rb
7
7
  lib/awsbase/support.rb
8
8
  lib/ec2/right_ec2.rb
9
+ lib/ec2/right_ec2_images.rb
10
+ lib/ec2/right_ec2_instances.rb
11
+ lib/ec2/right_ec2_ebs.rb
12
+ lib/ec2/right_ec2_reserved_instances.rb
13
+ lib/ec2/right_ec2_vpc.rb
14
+ lib/ec2/right_ec2_monitoring.rb
9
15
  lib/right_aws.rb
10
16
  lib/s3/right_s3.rb
11
17
  lib/acw/right_acw_interface.rb
@@ -19,6 +25,7 @@ lib/sqs/right_sqs_gen2.rb
19
25
  lib/sqs/right_sqs_gen2_interface.rb
20
26
  lib/sqs/right_sqs_interface.rb
21
27
  lib/acf/right_acf_interface.rb
28
+ lib/rds/right_rds_interface.rb
22
29
  test/ec2/test_helper.rb
23
30
  test/ec2/test_right_ec2.rb
24
31
  test/http_connection.rb
@@ -35,3 +42,6 @@ test/test_credentials.rb
35
42
  test/ts_right_aws.rb
36
43
  test/acf/test_helper.rb
37
44
  test/acf/test_right_acf.rb
45
+ test/rds/test_helper.rb
46
+ test/rds/test_right_rds.rb
47
+
data/README.txt CHANGED
@@ -9,17 +9,20 @@ The RightScale AWS gems have been designed to provide a robust, fast, and secure
9
9
  These gems have been used in production by RightScale since late 2006 and are being maintained to track enhancements made by Amazon.
10
10
  The RightScale AWS gems comprise:
11
11
 
12
- - RightAws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud) and the
13
- associated EBS (Elastic Block Store)
12
+ - RightAws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud), VPC (Virtual Private Cloud) and the associated EBS (Elastic Block Store)
14
13
  - RightAws::S3 and RightAws::S3Interface -- interface to Amazon S3 (Simple Storage Service)
15
- - RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service) (API version 2007-05-01)
16
- - RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service) (API version 2008-01-01)
14
+ - RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service)
15
+ - RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service)
17
16
  - RightAws::SdbInterface and RightAws::ActiveSdb -- interface to Amazon SDB (SimpleDB)
18
17
  - RightAws::AcfInterface -- interface to Amazon CloudFront, a content distribution service
18
+ - RightAws::AsInterface -- interface to Amazon Auto Scaling
19
+ - RightAws::AcwInterface -- interface to Amazon Cloud Watch
20
+ - RightAws::ElbInterface -- interface to Amazon Elastic Load Balancer
21
+ - RightAws::RdsInterface -- interface to Amazon RDS instances
19
22
 
20
23
  == FEATURES:
21
24
 
22
- - Full programmmatic access to EC2, EBS, S3, SQS, SDB, and CloudFront.
25
+ - Full programmmatic access to EC2, EBS, S3, SQS, SDB, CloudFront, AS, ACW, ELB and RDS.
23
26
  - Complete error handling: all operations check for errors and report complete
24
27
  error information by raising an AwsError.
25
28
  - Persistent HTTP connections with robust network-level retry layer using
@@ -142,7 +145,7 @@ sudo gem install right_aws
142
145
 
143
146
  == LICENSE:
144
147
 
145
- Copyright (c) 2007-2008 RightScale, Inc.
148
+ Copyright (c) 2007-2009 RightScale, Inc.
146
149
 
147
150
  Permission is hereby granted, free of charge, to any person obtaining
148
151
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -100,4 +100,11 @@ task :testacf do
100
100
  require 'test/acf/test_right_acf.rb'
101
101
  end
102
102
 
103
+ desc "Test RDS interface"
104
+ task :testrds do
105
+ require 'test/test_credentials'
106
+ TestCredentials.get_credentials
107
+ require 'test/rds/test_right_rds.rb'
108
+ end
109
+
103
110
  # vim: syntax=Ruby
@@ -123,6 +123,11 @@ module RightAws
123
123
  $1
124
124
  end
125
125
 
126
+ def self.split_items_and_params(array)
127
+ items = array.to_a.flatten.compact
128
+ params = items.last.kind_of?(Hash) ? items.pop : {}
129
+ [items, params]
130
+ end
126
131
  end
127
132
 
128
133
  class AwsBenchmarkingBlock #:nodoc:
@@ -481,13 +486,26 @@ module RightAws
481
486
  # { 'Item.1.Name' => 'A', 'Item.1.Value' => 'a',
482
487
  # 'Item.2.Name' => 'B', 'Item.2.Value' => 'b' }
483
488
  #
489
+ # amazonize_list(['Filter.?.Key', 'Filter.?.Value.?'], {'A' => ['aa','ab'], 'B' => ['ba','bb']}) #=>
490
+ # amazonize_list(['Filter.?.Key', 'Filter.?.Value.?'], [['A',['aa','ab']], ['B',['ba','bb']]]) #=>
491
+ # {"Filter.1.Key"=>"A",
492
+ # "Filter.1.Value.1"=>"aa",
493
+ # "Filter.1.Value.2"=>"ab",
494
+ # "Filter.2.Key"=>"B",
495
+ # "Filter.2.Value.1"=>"ba",
496
+ # "Filter.2.Value.2"=>"bb"}
484
497
  def amazonize_list(masks, list) #:nodoc:
485
498
  groups = {}
486
499
  list.to_a.each_with_index do |list_item, i|
487
500
  masks.to_a.each_with_index do |mask, mask_idx|
488
501
  key = mask[/\?/] ? mask.dup : mask.dup + '.?'
489
- key.gsub!('?', (i+1).to_s)
490
- groups[key] = list_item.to_a[mask_idx]
502
+ key.sub!('?', (i+1).to_s)
503
+ value = list_item.to_a[mask_idx]
504
+ if value.is_a?(Array)
505
+ groups.merge!(amazonize_list(key, value))
506
+ else
507
+ groups[key] = value
508
+ end
491
509
  end
492
510
  end
493
511
  groups
@@ -625,7 +643,7 @@ module RightAws
625
643
  last_errors_text = ''
626
644
  response = @aws.last_response
627
645
  # log error
628
- request_text_data = "#{request[:server]}:#{request[:port]}#{request[:request].path}"
646
+ request_text_data = "#{request[:protocol]}://#{request[:server]}:#{request[:port]}#{request[:request].path}"
629
647
  # is this a redirect?
630
648
  # yes!
631
649
  if response.is_a?(Net::HTTPRedirection)
@@ -635,33 +653,36 @@ module RightAws
635
653
  @aws.logger.warn("##### #{@aws.class.name} returned an error: #{response.code} #{response.message}\n#{response.body} #####")
636
654
  @aws.logger.warn("##### #{@aws.class.name} request: #{request_text_data} ####")
637
655
  end
638
- # Check response body: if it is an Amazon XML document or not:
639
- if redirect_detected || (response.body && response.body[/^(<\?xml|<ErrorResponse)/]) # ... it is a xml document
656
+
657
+ # Extract error/redirection message from the response body
658
+ # Amazon claims that a redirection must have a body but somethimes it is nil....
659
+ if response.body && response.body[/^(<\?xml|<ErrorResponse)/]
660
+ error_parser = RightErrorResponseParser.new
640
661
  @aws.class.bench_xml.add! do
641
- error_parser = RightErrorResponseParser.new
642
- error_parser.parse(response)
643
- @aws.last_errors = error_parser.errors
644
- @aws.last_request_id = error_parser.requestID
645
- last_errors_text = @aws.last_errors.flatten.join("\n")
646
- # on redirect :
647
- if redirect_detected
648
- location = response['location']
649
- # ... log information and ...
650
- @aws.logger.info("##### #{@aws.class.name} redirect requested: #{response.code} #{response.message} #####")
651
- @aws.logger.info("##### New location: #{location} #####")
652
- # ... fix the connection data
653
- request[:server] = URI.parse(location).host
654
- request[:protocol] = URI.parse(location).scheme
655
- request[:port] = URI.parse(location).port
656
- end
662
+ error_parser.parse(response.body)
657
663
  end
658
- else # ... it is not a xml document(probably just a html page?)
664
+ @aws.last_errors = error_parser.errors
665
+ @aws.last_request_id = error_parser.requestID
666
+ last_errors_text = @aws.last_errors.flatten.join("\n")
667
+ else
659
668
  @aws.last_errors = [[response.code, "#{response.message} (#{request_text_data})"]]
660
669
  @aws.last_request_id = '-undefined-'
661
670
  last_errors_text = response.message
662
671
  end
663
- # now - check the error
664
- unless redirect_detected
672
+
673
+ # Ok, it is a redirect, find the new destination location
674
+ if redirect_detected
675
+ location = response['location']
676
+ # ... log information and ...
677
+ @aws.logger.info("##### #{@aws.class.name} redirect requested: #{response.code} #{response.message} #####")
678
+ @aws.logger.info(" Old location: #{request_text_data}")
679
+ @aws.logger.info(" New location: #{location}")
680
+ # ... fix the connection data
681
+ request[:server] = URI.parse(location).host
682
+ request[:protocol] = URI.parse(location).scheme
683
+ request[:port] = URI.parse(location).port
684
+ else
685
+ # Not a redirect but an error: try to find the error in our list
665
686
  @errors_list.each do |error_to_find|
666
687
  if last_errors_text[/#{error_to_find}/i]
667
688
  error_found = true
@@ -671,6 +692,7 @@ module RightAws
671
692
  end
672
693
  end
673
694
  end
695
+
674
696
  # check the time has gone from the first error come
675
697
  if redirect_detected || error_found
676
698
  # Close the connection to the server and recreate a new one.
@@ -734,7 +756,7 @@ module RightAws
734
756
  @right_aws_parser.tag_start(name, attr_hash)
735
757
  end
736
758
  def on_characters(chars)
737
- @right_aws_parser.text(chars)
759
+ @right_aws_parser.text(chars)
738
760
  end
739
761
  def on_end_element(name)
740
762
  @right_aws_parser.tag_end(name)
@@ -763,24 +785,30 @@ module RightAws
763
785
  attr_accessor :result
764
786
  attr_reader :xmlpath
765
787
  attr_accessor :xml_lib
788
+ attr_reader :full_tag_name
789
+ attr_reader :tag
766
790
 
767
791
  def initialize(params={})
768
792
  @xmlpath = ''
793
+ @full_tag_name = ''
769
794
  @result = false
770
795
  @text = ''
796
+ @tag = ''
771
797
  @xml_lib = params[:xml_lib] || @@xml_lib
772
798
  @logger = params[:logger]
773
799
  reset
774
800
  end
775
801
  def tag_start(name, attributes)
776
802
  @text = ''
803
+ @tag = name
804
+ @full_tag_name += @full_tag_name.empty? ? name : "/#{name}"
777
805
  tagstart(name, attributes)
778
- @xmlpath += @xmlpath.empty? ? name : "/#{name}"
806
+ @xmlpath = @full_tag_name
779
807
  end
780
808
  def tag_end(name)
781
- @xmlpath[/^(.*?)\/?#{name}$/]
782
- @xmlpath = $1
809
+ @xmlpath = @full_tag_name[/^(.*?)\/?#{name}$/] && $1
783
810
  tagend(name)
811
+ @full_tag_name = @xmlpath
784
812
  end
785
813
  def text(text)
786
814
  @text += text
@@ -824,7 +852,7 @@ module RightAws
824
852
  xml.callbacks = RightSaxParserCallback.new(self)
825
853
  else
826
854
  xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)}
827
- xml.on_characters{ |text| self.text(text)}
855
+ xml.on_characters{ |text| self.text(text)}
828
856
  xml.on_end_element{ |name| self.tag_end(name)}
829
857
  end
830
858
  xml.parse
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2007-2008 RightScale Inc
2
+ # Copyright (c) 2007-2009 RightScale Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -68,7 +68,7 @@ module RightAws
68
68
  include RightAwsBaseInterface
69
69
 
70
70
  # Amazon EC2 API version being used
71
- API_VERSION = "2009-03-01"
71
+ API_VERSION = "2009-10-31"
72
72
  DEFAULT_HOST = "ec2.amazonaws.com"
73
73
  DEFAULT_PATH = '/'
74
74
  DEFAULT_PROTOCOL = 'https'
@@ -81,7 +81,7 @@ module RightAws
81
81
  # Amazon EC2 Instance Types : http://www.amazon.com/b?ie=UTF8&node=370375011
82
82
  # Default EC2 instance type (platform)
83
83
  DEFAULT_INSTANCE_TYPE = 'm1.small'
84
- INSTANCE_TYPES = ['m1.small','c1.medium','m1.large','m1.xlarge','c1.xlarge']
84
+ INSTANCE_TYPES = ['m1.small','c1.medium','m1.large','m1.xlarge','c1.xlarge', 'm2.2xlarge', 'm2.4xlarge']
85
85
 
86
86
  @@bench = AwsBenchmarkingBlock.new
87
87
  def self.bench_xml
@@ -135,620 +135,6 @@ module RightAws
135
135
  request_info_impl(:ec2_connection, @@bench, request, parser)
136
136
  end
137
137
 
138
- #-----------------------------------------------------------------
139
- # Images
140
- #-----------------------------------------------------------------
141
-
142
- # params:
143
- # { 'ImageId' => ['id1', ..., 'idN'],
144
- # 'Owner' => ['self', ..., 'userN'],
145
- # 'ExecutableBy' => ['self', 'all', ..., 'userN']
146
- # }
147
- def ec2_describe_images(params={}, image_type=nil, cache_for=nil) #:nodoc:
148
- request_hash = {}
149
- params.each do |list_by, list|
150
- request_hash.merge! amazonize_list(list_by, list.to_a)
151
- end
152
- request_hash['ImageType'] = image_type if image_type
153
- link = generate_request("DescribeImages", request_hash)
154
- request_cache_or_info cache_for, link, QEc2DescribeImagesParser, @@bench, cache_for
155
- rescue Exception
156
- on_exception
157
- end
158
-
159
- # Retrieve a list of images. Returns array of hashes describing the images or an exception:
160
- # +image_type+ = 'machine' || 'kernel' || 'ramdisk'
161
- #
162
- # ec2.describe_images #=>
163
- # [{:aws_owner => "522821470517",
164
- # :aws_id => "ami-e4b6538d",
165
- # :aws_state => "available",
166
- # :aws_location => "marcins_cool_public_images/ubuntu-6.10.manifest.xml",
167
- # :aws_is_public => true,
168
- # :aws_architecture => "i386",
169
- # :aws_image_type => "machine"},
170
- # {...},
171
- # {...} ]
172
- #
173
- # If +list+ param is set, then retrieve information about the listed images only:
174
- #
175
- # ec2.describe_images(['ami-e4b6538d']) #=>
176
- # [{:aws_owner => "522821470517",
177
- # :aws_id => "ami-e4b6538d",
178
- # :aws_state => "available",
179
- # :aws_location => "marcins_cool_public_images/ubuntu-6.10.manifest.xml",
180
- # :aws_is_public => true,
181
- # :aws_architecture => "i386",
182
- # :aws_image_type => "machine"}]
183
- #
184
- def describe_images(list=[], image_type=nil)
185
- list = list.to_a
186
- cache_for = list.empty? && !image_type ? :describe_images : nil
187
- ec2_describe_images({ 'ImageId' => list }, image_type, cache_for)
188
- end
189
-
190
- #
191
- # Example:
192
- #
193
- # ec2.describe_images_by_owner('522821470517')
194
- # ec2.describe_images_by_owner('self')
195
- #
196
- def describe_images_by_owner(list=['self'], image_type=nil)
197
- list = list.to_a
198
- cache_for = list==['self'] && !image_type ? :describe_images_by_owner : nil
199
- ec2_describe_images({ 'Owner' => list }, image_type, cache_for)
200
- end
201
-
202
- #
203
- # Example:
204
- #
205
- # ec2.describe_images_by_executable_by('522821470517')
206
- # ec2.describe_images_by_executable_by('self')
207
- # ec2.describe_images_by_executable_by('all')
208
- #
209
- def describe_images_by_executable_by(list=['self'], image_type=nil)
210
- list = list.to_a
211
- cache_for = list==['self'] && !image_type ? :describe_images_by_executable_by : nil
212
- ec2_describe_images({ 'ExecutableBy' => list }, image_type, cache_for)
213
- end
214
-
215
-
216
- # Register new image at Amazon.
217
- # Returns new image id or an exception.
218
- #
219
- # ec2.register_image('bucket/key/manifest') #=> 'ami-e444444d'
220
- #
221
- def register_image(image_location)
222
- link = generate_request("RegisterImage",
223
- 'ImageLocation' => image_location.to_s)
224
- request_info(link, QEc2RegisterImageParser.new(:logger => @logger))
225
- rescue Exception
226
- on_exception
227
- end
228
-
229
- # Deregister image at Amazon. Returns +true+ or an exception.
230
- #
231
- # ec2.deregister_image('ami-e444444d') #=> true
232
- #
233
- def deregister_image(image_id)
234
- link = generate_request("DeregisterImage",
235
- 'ImageId' => image_id.to_s)
236
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
237
- rescue Exception
238
- on_exception
239
- end
240
-
241
-
242
- # Describe image attributes. Currently 'launchPermission', 'productCodes', 'kernel', 'ramdisk' and 'blockDeviceMapping' are supported.
243
- #
244
- # ec2.describe_image_attribute('ami-e444444d') #=> {:groups=>["all"], :users=>["000000000777"]}
245
- #
246
- def describe_image_attribute(image_id, attribute='launchPermission')
247
- link = generate_request("DescribeImageAttribute",
248
- 'ImageId' => image_id,
249
- 'Attribute' => attribute)
250
- request_info(link, QEc2DescribeImageAttributeParser.new(:logger => @logger))
251
- rescue Exception
252
- on_exception
253
- end
254
-
255
- # Reset image attribute. Currently, only 'launchPermission' is supported. Returns +true+ or an exception.
256
- #
257
- # ec2.reset_image_attribute('ami-e444444d') #=> true
258
- #
259
- def reset_image_attribute(image_id, attribute='launchPermission')
260
- link = generate_request("ResetImageAttribute",
261
- 'ImageId' => image_id,
262
- 'Attribute' => attribute)
263
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
264
- rescue Exception
265
- on_exception
266
- end
267
-
268
- # Modify an image's attributes. It is recommended that you use
269
- # modify_image_launch_perm_add_users, modify_image_launch_perm_remove_users, etc.
270
- # instead of modify_image_attribute because the signature of
271
- # modify_image_attribute may change with EC2 service changes.
272
- #
273
- # attribute : currently, only 'launchPermission' is supported.
274
- # operation_type : currently, only 'add' & 'remove' are supported.
275
- # vars:
276
- # :user_group : currently, only 'all' is supported.
277
- # :user_id
278
- # :product_code
279
- def modify_image_attribute(image_id, attribute, operation_type = nil, vars = {})
280
- params = {'ImageId' => image_id,
281
- 'Attribute' => attribute}
282
- params['OperationType'] = operation_type if operation_type
283
- params.update(amazonize_list('UserId', vars[:user_id].to_a)) if vars[:user_id]
284
- params.update(amazonize_list('UserGroup', vars[:user_group].to_a)) if vars[:user_group]
285
- params.update(amazonize_list('ProductCode', vars[:product_code])) if vars[:product_code]
286
- link = generate_request("ModifyImageAttribute", params)
287
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
288
- rescue Exception
289
- on_exception
290
- end
291
-
292
- # Grant image launch permissions to users.
293
- # Parameter +userId+ is a list of user AWS account ids.
294
- # Returns +true+ or an exception.
295
- #
296
- # ec2.modify_image_launch_perm_add_users('ami-e444444d',['000000000777','000000000778']) #=> true
297
- def modify_image_launch_perm_add_users(image_id, user_id=[])
298
- modify_image_attribute(image_id, 'launchPermission', 'add', :user_id => user_id.to_a)
299
- end
300
-
301
- # Revokes image launch permissions for users. +userId+ is a list of users AWS accounts ids. Returns +true+ or an exception.
302
- #
303
- # ec2.modify_image_launch_perm_remove_users('ami-e444444d',['000000000777','000000000778']) #=> true
304
- #
305
- def modify_image_launch_perm_remove_users(image_id, user_id=[])
306
- modify_image_attribute(image_id, 'launchPermission', 'remove', :user_id => user_id.to_a)
307
- end
308
-
309
- # Add image launch permissions for users groups (currently only 'all' is supported, which gives public launch permissions).
310
- # Returns +true+ or an exception.
311
- #
312
- # ec2.modify_image_launch_perm_add_groups('ami-e444444d') #=> true
313
- #
314
- def modify_image_launch_perm_add_groups(image_id, user_group=['all'])
315
- modify_image_attribute(image_id, 'launchPermission', 'add', :user_group => user_group.to_a)
316
- end
317
-
318
- # Remove image launch permissions for users groups (currently only 'all' is supported, which gives public launch permissions).
319
- #
320
- # ec2.modify_image_launch_perm_remove_groups('ami-e444444d') #=> true
321
- #
322
- def modify_image_launch_perm_remove_groups(image_id, user_group=['all'])
323
- modify_image_attribute(image_id, 'launchPermission', 'remove', :user_group => user_group.to_a)
324
- end
325
-
326
- # Add product code to image
327
- #
328
- # ec2.modify_image_product_code('ami-e444444d','0ABCDEF') #=> true
329
- #
330
- def modify_image_product_code(image_id, product_code=[])
331
- modify_image_attribute(image_id, 'productCodes', nil, :product_code => product_code.to_a)
332
- end
333
-
334
- #-----------------------------------------------------------------
335
- # Instances
336
- #-----------------------------------------------------------------
337
-
338
- def get_desc_instances(instances) # :nodoc:
339
- result = []
340
- instances.each do |reservation|
341
- reservation[:instances_set].each do |instance|
342
- # Parse and remove timestamp from the reason string. The timestamp is of
343
- # the request, not when EC2 took action, thus confusing & useless...
344
- instance[:aws_reason] = instance[:aws_reason].sub(/\(\d[^)]*GMT\) */, '')
345
- instance[:aws_owner] = reservation[:aws_owner]
346
- instance[:aws_reservation_id] = reservation[:aws_reservation_id]
347
- instance[:aws_groups] = reservation[:aws_groups]
348
- result << instance
349
- end
350
- end
351
- result
352
- rescue Exception
353
- on_exception
354
- end
355
-
356
- # Retrieve information about EC2 instances. If +list+ is omitted then returns the
357
- # list of all instances.
358
- #
359
- # ec2.describe_instances #=>
360
- # [{:aws_image_id => "ami-e444444d",
361
- # :aws_reason => "",
362
- # :aws_state_code => "16",
363
- # :aws_owner => "000000000888",
364
- # :aws_instance_id => "i-123f1234",
365
- # :aws_reservation_id => "r-aabbccdd",
366
- # :aws_state => "running",
367
- # :dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
368
- # :ssh_key_name => "staging",
369
- # :aws_groups => ["default"],
370
- # :private_dns_name => "domU-12-34-67-89-01-C9.usma2.compute.amazonaws.com",
371
- # :aws_instance_type => "m1.small",
372
- # :aws_launch_time => "2008-1-1T00:00:00.000Z"},
373
- # :aws_availability_zone => "us-east-1b",
374
- # :aws_kernel_id => "aki-ba3adfd3",
375
- # :aws_ramdisk_id => "ari-badbad00",
376
- # ..., {...}]
377
- #
378
- def describe_instances(list=[])
379
- link = generate_request("DescribeInstances", amazonize_list('InstanceId',list.to_a))
380
- request_cache_or_info(:describe_instances, link, QEc2DescribeInstancesParser, @@bench, list.blank?) do |parser|
381
- get_desc_instances(parser.result)
382
- end
383
- rescue Exception
384
- on_exception
385
- end
386
-
387
- # Return the product code attached to instance or +nil+ otherwise.
388
- #
389
- # ec2.confirm_product_instance('ami-e444444d','12345678') #=> nil
390
- # ec2.confirm_product_instance('ami-e444444d','00001111') #=> "000000000888"
391
- #
392
- def confirm_product_instance(instance, product_code)
393
- link = generate_request("ConfirmProductInstance", { 'ProductCode' => product_code,
394
- 'InstanceId' => instance })
395
- request_info(link, QEc2ConfirmProductInstanceParser.new(:logger => @logger))
396
- end
397
-
398
- # Launch new EC2 instances. Returns a list of launched instances or an exception.
399
- #
400
- # ec2.run_instances('ami-e444444d',1,1,['my_awesome_group'],'my_awesome_key', 'Woohoo!!!', 'public') #=>
401
- # [{:aws_image_id => "ami-e444444d",
402
- # :aws_reason => "",
403
- # :aws_state_code => "0",
404
- # :aws_owner => "000000000888",
405
- # :aws_instance_id => "i-123f1234",
406
- # :aws_reservation_id => "r-aabbccdd",
407
- # :aws_state => "pending",
408
- # :dns_name => "",
409
- # :ssh_key_name => "my_awesome_key",
410
- # :aws_groups => ["my_awesome_group"],
411
- # :private_dns_name => "",
412
- # :aws_instance_type => "m1.small",
413
- # :aws_launch_time => "2008-1-1T00:00:00.000Z"
414
- # :aws_ramdisk_id => "ari-8605e0ef"
415
- # :aws_kernel_id => "aki-9905e0f0",
416
- # :ami_launch_index => "0",
417
- # :aws_availability_zone => "us-east-1b"
418
- # }]
419
- #
420
- def run_instances(image_id, min_count, max_count, group_ids, key_name, user_data='',
421
- addressing_type = nil, instance_type = nil,
422
- kernel_id = nil, ramdisk_id = nil, availability_zone = nil,
423
- block_device_mappings = nil)
424
- launch_instances(image_id, { :min_count => min_count,
425
- :max_count => max_count,
426
- :user_data => user_data,
427
- :group_ids => group_ids,
428
- :key_name => key_name,
429
- :instance_type => instance_type,
430
- :addressing_type => addressing_type,
431
- :kernel_id => kernel_id,
432
- :ramdisk_id => ramdisk_id,
433
- :availability_zone => availability_zone,
434
- :block_device_mappings => block_device_mappings
435
- })
436
- end
437
-
438
-
439
- # Launch new EC2 instances. Returns a list of launched instances or an exception.
440
- #
441
- # +lparams+ keys (default values in parenthesis):
442
- # :min_count fixnum, (1)
443
- # :max_count fixnum, (1)
444
- # :group_ids array or string ([] == 'default')
445
- # :instance_type string (DEFAULT_INSTACE_TYPE)
446
- # :addressing_type string (DEFAULT_ADDRESSING_TYPE
447
- # :key_name string
448
- # :kernel_id string
449
- # :ramdisk_id string
450
- # :availability_zone string
451
- # :block_device_mappings string
452
- # :user_data string
453
- #
454
- # ec2.launch_instances('ami-e444444d', :group_ids => 'my_awesome_group',
455
- # :user_data => "Woohoo!!!",
456
- # :addressing_type => "public",
457
- # :key_name => "my_awesome_key",
458
- # :availability_zone => "us-east-1c") #=>
459
- # [{:aws_image_id => "ami-e444444d",
460
- # :aws_reason => "",
461
- # :aws_state_code => "0",
462
- # :aws_owner => "000000000888",
463
- # :aws_instance_id => "i-123f1234",
464
- # :aws_reservation_id => "r-aabbccdd",
465
- # :aws_state => "pending",
466
- # :dns_name => "",
467
- # :ssh_key_name => "my_awesome_key",
468
- # :aws_groups => ["my_awesome_group"],
469
- # :private_dns_name => "",
470
- # :aws_instance_type => "m1.small",
471
- # :aws_launch_time => "2008-1-1T00:00:00.000Z",
472
- # :aws_ramdisk_id => "ari-8605e0ef"
473
- # :aws_kernel_id => "aki-9905e0f0",
474
- # :ami_launch_index => "0",
475
- # :aws_availability_zone => "us-east-1c"
476
- # }]
477
- #
478
- def launch_instances(image_id, lparams={})
479
- @logger.info("Launching instance of image #{image_id} for #{@aws_access_key_id}, " +
480
- "key: #{lparams[:key_name]}, groups: #{(lparams[:group_ids]).to_a.join(',')}")
481
- # careful: keyName and securityGroups may be nil
482
- params = amazonize_list('SecurityGroup', lparams[:group_ids].to_a)
483
- params.update( {'ImageId' => image_id,
484
- 'MinCount' => (lparams[:min_count] || 1).to_s,
485
- 'MaxCount' => (lparams[:max_count] || 1).to_s,
486
- 'AddressingType' => lparams[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
487
- 'InstanceType' => lparams[:instance_type] || DEFAULT_INSTANCE_TYPE })
488
- # optional params
489
- params['KeyName'] = lparams[:key_name] unless lparams[:key_name].blank?
490
- params['KernelId'] = lparams[:kernel_id] unless lparams[:kernel_id].blank?
491
- params['RamdiskId'] = lparams[:ramdisk_id] unless lparams[:ramdisk_id].blank?
492
- params['Placement.AvailabilityZone'] = lparams[:availability_zone] unless lparams[:availability_zone].blank?
493
- params['BlockDeviceMappings'] = lparams[:block_device_mappings] unless lparams[:block_device_mappings].blank?
494
- unless lparams[:user_data].blank?
495
- lparams[:user_data].strip!
496
- # Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library.
497
- # Amazon 169.254.169.254 does not like escaped symbols!
498
- # And it doesn't like "\n" inside of encoded string! Grrr....
499
- # Otherwise, some of UserData symbols will be lost...
500
- params['UserData'] = Base64.encode64(lparams[:user_data]).delete("\n") unless lparams[:user_data].blank?
501
- end
502
- link = generate_request("RunInstances", params)
503
- #debugger
504
- instances = request_info(link, QEc2DescribeInstancesParser.new(:logger => @logger))
505
- get_desc_instances(instances)
506
- rescue Exception
507
- on_exception
508
- end
509
-
510
- # Terminates EC2 instances. Returns a list of termination params or an exception.
511
- #
512
- # ec2.terminate_instances(['i-f222222d','i-f222222e']) #=>
513
- # [{:aws_shutdown_state => "shutting-down",
514
- # :aws_instance_id => "i-f222222d",
515
- # :aws_shutdown_state_code => 32,
516
- # :aws_prev_state => "running",
517
- # :aws_prev_state_code => 16},
518
- # {:aws_shutdown_state => "shutting-down",
519
- # :aws_instance_id => "i-f222222e",
520
- # :aws_shutdown_state_code => 32,
521
- # :aws_prev_state => "running",
522
- # :aws_prev_state_code => 16}]
523
- #
524
- def terminate_instances(list=[])
525
- link = generate_request("TerminateInstances", amazonize_list('InstanceId',list.to_a))
526
- request_info(link, QEc2TerminateInstancesParser.new(:logger => @logger))
527
- rescue Exception
528
- on_exception
529
- end
530
-
531
- # Retreive EC2 instance OS logs. Returns a hash of data or an exception.
532
- #
533
- # ec2.get_console_output('i-f222222d') =>
534
- # {:aws_instance_id => 'i-f222222d',
535
- # :aws_timestamp => "2007-05-23T14:36:07.000-07:00",
536
- # :timestamp => Wed May 23 21:36:07 UTC 2007, # Time instance
537
- # :aws_output => "Linux version 2.6.16-xenU (builder@patchbat.amazonsa) (gcc version 4.0.1 20050727 ..."
538
- def get_console_output(instance_id)
539
- link = generate_request("GetConsoleOutput", { 'InstanceId.1' => instance_id })
540
- request_info(link, QEc2GetConsoleOutputParser.new(:logger => @logger))
541
- rescue Exception
542
- on_exception
543
- end
544
-
545
- # Reboot an EC2 instance. Returns +true+ or an exception.
546
- #
547
- # ec2.reboot_instances(['i-f222222d','i-f222222e']) #=> true
548
- #
549
- def reboot_instances(list)
550
- link = generate_request("RebootInstances", amazonize_list('InstanceId', list.to_a))
551
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
552
- rescue Exception
553
- on_exception
554
- end
555
-
556
- #-----------------------------------------------------------------
557
- # Instances: Windows addons
558
- #-----------------------------------------------------------------
559
-
560
- # Get initial Windows Server setup password from an instance console output.
561
- #
562
- # my_awesome_key = ec2.create_key_pair('my_awesome_key') #=>
563
- # {:aws_key_name => "my_awesome_key",
564
- # :aws_fingerprint => "01:02:03:f4:25:e6:97:e8:9b:02:1a:26:32:4e:58:6b:7a:8c:9f:03",
565
- # :aws_material => "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAK...Q8MDrCbuQ=\n-----END RSA PRIVATE KEY-----"}
566
- #
567
- # my_awesome_instance = ec2.run_instances('ami-a000000a',1,1,['my_awesome_group'],'my_awesome_key', 'WindowsInstance!!!') #=>
568
- # [{:aws_image_id => "ami-a000000a",
569
- # :aws_instance_id => "i-12345678",
570
- # ...
571
- # :aws_availability_zone => "us-east-1b"
572
- # }]
573
- #
574
- # # wait until instance enters 'operational' state and get it's initial password
575
- #
576
- # puts ec2.get_initial_password(my_awesome_instance[:aws_instance_id], my_awesome_key[:aws_material]) #=> "MhjWcgZuY6"
577
- #
578
- def get_initial_password(instance_id, private_key)
579
- console_output = get_console_output(instance_id)
580
- crypted_password = console_output[:aws_output][%r{<Password>(.+)</Password>}m] && $1
581
- unless crypted_password
582
- raise AwsError.new("Initial password was not found in console output for #{instance_id}")
583
- else
584
- OpenSSL::PKey::RSA.new(private_key).private_decrypt(Base64.decode64(crypted_password))
585
- end
586
- rescue Exception
587
- on_exception
588
- end
589
-
590
- # Bundle a Windows image.
591
- # Internally, it queues the bundling task and shuts down the instance.
592
- # It then takes a snapshot of the Windows volume bundles it, and uploads it to
593
- # S3. After bundling completes, Rightaws::Ec2#register_image may be used to
594
- # register the new Windows AMI for subsequent launches.
595
- #
596
- # ec2.bundle_instance('i-e3e24e8a', 'my-awesome-bucket', 'my-win-image-1') #=>
597
- # [{:aws_update_time => "2008-10-16T13:58:25.000Z",
598
- # :s3_bucket => "kd-win-1",
599
- # :s3_prefix => "win2pr",
600
- # :aws_state => "pending",
601
- # :aws_id => "bun-26a7424f",
602
- # :aws_instance_id => "i-878a25ee",
603
- # :aws_start_time => "2008-10-16T13:58:02.000Z"}]
604
- #
605
- def bundle_instance(instance_id, s3_bucket, s3_prefix,
606
- s3_owner_aws_access_key_id=nil, s3_owner_aws_secret_access_key=nil,
607
- s3_expires = S3Interface::DEFAULT_EXPIRES_AFTER,
608
- s3_upload_policy='ec2-bundle-read')
609
- # S3 access and signatures
610
- s3_owner_aws_access_key_id ||= @aws_access_key_id
611
- s3_owner_aws_secret_access_key ||= @aws_secret_access_key
612
- s3_expires = Time.now.utc + s3_expires if s3_expires.is_a?(Fixnum) && (s3_expires < S3Interface::ONE_YEAR_IN_SECONDS)
613
- # policy
614
- policy = { 'expiration' => s3_expires.strftime('%Y-%m-%dT%H:%M:%SZ'),
615
- 'conditions' => [ { 'bucket' => s3_bucket },
616
- { 'acl' => s3_upload_policy },
617
- [ 'starts-with', '$key', s3_prefix ] ] }.to_json
618
- policy64 = Base64.encode64(policy).gsub("\n","")
619
- signed_policy64 = AwsUtils.sign(s3_owner_aws_secret_access_key, policy64)
620
- # fill request params
621
- params = { 'InstanceId' => instance_id,
622
- 'Storage.S3.AWSAccessKeyId' => s3_owner_aws_access_key_id,
623
- 'Storage.S3.UploadPolicy' => policy64,
624
- 'Storage.S3.UploadPolicySignature' => signed_policy64,
625
- 'Storage.S3.Bucket' => s3_bucket,
626
- 'Storage.S3.Prefix' => s3_prefix,
627
- }
628
- link = generate_request("BundleInstance", params)
629
- request_info(link, QEc2BundleInstanceParser.new)
630
- rescue Exception
631
- on_exception
632
- end
633
-
634
- # Describe the status of the Windows AMI bundlings.
635
- # If +list+ is omitted the returns the whole list of tasks.
636
- #
637
- # ec2.describe_bundle_tasks(['bun-4fa74226']) #=>
638
- # [{:s3_bucket => "my-awesome-bucket"
639
- # :aws_id => "bun-0fa70206",
640
- # :s3_prefix => "win1pr",
641
- # :aws_start_time => "2008-10-14T16:27:57.000Z",
642
- # :aws_update_time => "2008-10-14T16:37:10.000Z",
643
- # :aws_error_code => "Client.S3Error",
644
- # :aws_error_message =>
645
- # "AccessDenied(403)- Invalid according to Policy: Policy Condition failed: [\"eq\", \"$acl\", \"aws-exec-read\"]",
646
- # :aws_state => "failed",
647
- # :aws_instance_id => "i-e3e24e8a"}]
648
- #
649
- def describe_bundle_tasks(list=[])
650
- link = generate_request("DescribeBundleTasks", amazonize_list('BundleId', list.to_a))
651
- request_info(link, QEc2DescribeBundleTasksParser.new)
652
- rescue Exception
653
- on_exception
654
- end
655
-
656
- # Cancel an in‐progress or pending bundle task by id.
657
- #
658
- # ec2.cancel_bundle_task('bun-73a7421a') #=>
659
- # [{:s3_bucket => "my-awesome-bucket"
660
- # :aws_id => "bun-0fa70206",
661
- # :s3_prefix => "win02",
662
- # :aws_start_time => "2008-10-14T13:00:29.000Z",
663
- # :aws_error_message => "User has requested bundling operation cancellation",
664
- # :aws_state => "failed",
665
- # :aws_update_time => "2008-10-14T13:01:31.000Z",
666
- # :aws_error_code => "Client.Cancelled",
667
- # :aws_instance_id => "i-e3e24e8a"}
668
- #
669
- def cancel_bundle_task(bundle_id)
670
- link = generate_request("CancelBundleTask", { 'BundleId' => bundle_id })
671
- request_info(link, QEc2BundleInstanceParser.new)
672
- rescue Exception
673
- on_exception
674
- end
675
-
676
- #-----------------------------------------------------------------
677
- # Reserved instances
678
- #-----------------------------------------------------------------
679
-
680
- # Retrieve reserved instances list.
681
- # Returns a list of Reserved Instances.
682
- #
683
- # ec2.describe_reserved_instances #=>
684
- # [{:aws_id=>"1ba8e2e3-1c40-434c-a741-5ff16a4c542e",
685
- # :aws_duration=>31536000,
686
- # :aws_instance_type=>"m1.small",
687
- # :aws_usage_price=>0.03,
688
- # :aws_availability_zone=>"us-east-1b",
689
- # :aws_state=>"payment-pending",
690
- # :aws_product_description=>"Test",
691
- # :aws_fixed_price=>325.0,
692
- # :aws_instance_count=>1}]
693
- #
694
- def describe_reserved_instances(list=[])
695
- link = generate_request("DescribeReservedInstances", amazonize_list('ReservedInstancesId',list.to_a))
696
- request_cache_or_info(:describe_reserved_instances, link, QEc2DescribeReservedInstancesParser, @@bench, list.blank?)
697
- rescue Exception
698
- on_exception
699
- end
700
-
701
- # Retrieve reserved instances offerings.
702
- # Returns a set of available offerings.
703
- #
704
- # Optional params:
705
- # :aws_ids => String || Array
706
- # :aws_instance_type => String
707
- # :aws_availability_zone => String
708
- # :aws_product_description => String
709
- #
710
- # ec2.describe_reserved_instances_offerings #=>
711
- # [{:aws_instance_type=>"c1.medium",
712
- # :aws_availability_zone=>"us-east-1c",
713
- # :aws_duration=>94608000,
714
- # :aws_product_description=>"Linux/UNIX",
715
- # :aws_id=>"e5a2ff3b-f6eb-4b4e-83f8-b879d7060257",
716
- # :aws_usage_price=>0.06,
717
- # :aws_fixed_price=>1000.0},
718
- # ...
719
- # {:aws_instance_type=>"m1.xlarge",
720
- # :aws_availability_zone=>"us-east-1a",
721
- # :aws_duration=>31536000,
722
- # :aws_product_description=>"Linux/UNIX",
723
- # :aws_id=>"c48ab04c-63ab-4cd6-b8f5-978a29eb9bcc",
724
- # :aws_usage_price=>0.24,
725
- # :aws_fixed_price=>2600.0}]
726
- #
727
- def describe_reserved_instances_offerings(params={})
728
- rparams = {}
729
- rparams.update(amazonize_list('ReservedInstancesOfferingId', params[:aws_ids].to_a)) if params[:aws_ids]
730
- rparams['InstanceType'] = params[:aws_instance_type] if params[:aws_instance_type]
731
- rparams['AvailabilityZone'] = params[:aws_availability_zone] if params[:aws_availability_zone]
732
- rparams['ProductDescription'] = params[:aws_product_description] if params[:aws_product_description]
733
- link = generate_request("DescribeReservedInstancesOfferings", rparams)
734
- request_cache_or_info(:describe_reserved_instances_offerings, link, QEc2DescribeReservedInstancesOfferingsParser, @@bench, params.blank?)
735
- rescue Exception
736
- on_exception
737
- end
738
-
739
- # Purchase a Reserved Instance.
740
- # Returns ReservedInstancesId value.
741
- #
742
- # ec2.purchase_reserved_instances_offering('e5a2ff3b-f6eb-4b4e-83f8-b879d7060257', 3) # => '4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8'
743
- #
744
- def purchase_reserved_instances_offering(reserved_instances_offering_id, instance_count=1)
745
- link = generate_request("PurchaseReservedInstancesOffering", { 'ReservedInstancesOfferingId' => reserved_instances_offering_id,
746
- 'InstanceCount' => instance_count })
747
- request_info(link, QEc2PurchaseReservedInstancesOfferingParser.new)
748
- rescue Exception
749
- on_exception
750
- end
751
-
752
138
  #-----------------------------------------------------------------
753
139
  # Security groups
754
140
  #-----------------------------------------------------------------
@@ -1053,210 +439,6 @@ module RightAws
1053
439
  on_exception
1054
440
  end
1055
441
 
1056
-
1057
- #-----------------------------------------------------------------
1058
- # EBS: Volumes
1059
- #-----------------------------------------------------------------
1060
-
1061
- # Describe all EBS volumes.
1062
- #
1063
- # ec2.describe_volumes #=>
1064
- # [{:aws_size => 94,
1065
- # :aws_device => "/dev/sdc",
1066
- # :aws_attachment_status => "attached",
1067
- # :zone => "merlot",
1068
- # :snapshot_id => nil,
1069
- # :aws_attached_at => Wed Jun 18 08:19:28 UTC 2008,
1070
- # :aws_status => "in-use",
1071
- # :aws_id => "vol-60957009",
1072
- # :aws_created_at => Wed Jun 18 08:19:20s UTC 2008,
1073
- # :aws_instance_id => "i-c014c0a9"},
1074
- # {:aws_size => 1,
1075
- # :zone => "merlot",
1076
- # :snapshot_id => nil,
1077
- # :aws_status => "available",
1078
- # :aws_id => "vol-58957031",
1079
- # :aws_created_at => Wed Jun 18 08:19:21 UTC 2008,}, ... ]
1080
- #
1081
- def describe_volumes(list=[])
1082
- link = generate_request("DescribeVolumes",
1083
- amazonize_list('VolumeId',list.to_a))
1084
- request_cache_or_info :describe_volumes, link, QEc2DescribeVolumesParser, @@bench, list.blank?
1085
- rescue Exception
1086
- on_exception
1087
- end
1088
-
1089
- # Create new EBS volume based on previously created snapshot.
1090
- # +Size+ in Gigabytes.
1091
- #
1092
- # ec2.create_volume('snap-000000', 10, zone) #=>
1093
- # {:snapshot_id => "snap-e21df98b",
1094
- # :aws_status => "creating",
1095
- # :aws_id => "vol-fc9f7a95",
1096
- # :zone => "merlot",
1097
- # :aws_created_at => Tue Jun 24 18:13:32 UTC 2008,
1098
- # :aws_size => 94}
1099
- #
1100
- def create_volume(snapshot_id, size, zone)
1101
- hash = { "Size" => size.to_s,
1102
- "AvailabilityZone" => zone.to_s }
1103
- # Get rig of empty snapshot: e8s guys do not like it
1104
- hash["SnapshotId"] = snapshot_id.to_s unless snapshot_id.blank?
1105
- link = generate_request("CreateVolume", hash )
1106
- request_info(link, QEc2CreateVolumeParser.new(:logger => @logger))
1107
- rescue Exception
1108
- on_exception
1109
- end
1110
-
1111
- # Delete the specified EBS volume.
1112
- # This does not deletes any snapshots created from this volume.
1113
- #
1114
- # ec2.delete_volume('vol-b48a6fdd') #=> true
1115
- #
1116
- def delete_volume(volume_id)
1117
- link = generate_request("DeleteVolume",
1118
- "VolumeId" => volume_id.to_s)
1119
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
1120
- rescue Exception
1121
- on_exception
1122
- end
1123
-
1124
- # Attach the specified EBS volume to a specified instance, exposing the
1125
- # volume using the specified device name.
1126
- #
1127
- # ec2.attach_volume('vol-898a6fe0', 'i-7c905415', '/dev/sdh') #=>
1128
- # { :aws_instance_id => "i-7c905415",
1129
- # :aws_device => "/dev/sdh",
1130
- # :aws_status => "attaching",
1131
- # :aws_attached_at => "2008-03-28T14:14:39.000Z",
1132
- # :aws_id => "vol-898a6fe0" }
1133
- #
1134
- def attach_volume(volume_id, instance_id, device)
1135
- link = generate_request("AttachVolume",
1136
- "VolumeId" => volume_id.to_s,
1137
- "InstanceId" => instance_id.to_s,
1138
- "Device" => device.to_s)
1139
- request_info(link, QEc2AttachAndDetachVolumeParser.new(:logger => @logger))
1140
- rescue Exception
1141
- on_exception
1142
- end
1143
-
1144
- # Detach the specified EBS volume from the instance to which it is attached.
1145
- #
1146
- # ec2.detach_volume('vol-898a6fe0') #=>
1147
- # { :aws_instance_id => "i-7c905415",
1148
- # :aws_device => "/dev/sdh",
1149
- # :aws_status => "detaching",
1150
- # :aws_attached_at => "2008-03-28T14:38:34.000Z",
1151
- # :aws_id => "vol-898a6fe0"}
1152
- #
1153
- def detach_volume(volume_id, instance_id=nil, device=nil, force=nil)
1154
- hash = { "VolumeId" => volume_id.to_s }
1155
- hash["InstanceId"] = instance_id.to_s unless instance_id.blank?
1156
- hash["Device"] = device.to_s unless device.blank?
1157
- hash["Force"] = 'true' if force
1158
- #
1159
- link = generate_request("DetachVolume", hash)
1160
- request_info(link, QEc2AttachAndDetachVolumeParser.new(:logger => @logger))
1161
- rescue Exception
1162
- on_exception
1163
- end
1164
-
1165
-
1166
- #-----------------------------------------------------------------
1167
- # EBS: Snapshots
1168
- #-----------------------------------------------------------------
1169
-
1170
- # Describe all EBS snapshots.
1171
- #
1172
- # ec2.describe_snapshots #=>
1173
- # [ { :aws_progress => "100%",
1174
- # :aws_status => "completed",
1175
- # :aws_id => "snap-72a5401b",
1176
- # :aws_volume_id => "vol-5582673c",
1177
- # :aws_started_at => "2008-02-23T02:50:48.000Z"},
1178
- # { :aws_progress => "100%",
1179
- # :aws_status => "completed",
1180
- # :aws_id => "snap-75a5401c",
1181
- # :aws_volume_id => "vol-5582673c",
1182
- # :aws_started_at => "2008-02-23T16:23:19.000Z" },...]
1183
- #
1184
- def describe_snapshots(list=[])
1185
- link = generate_request("DescribeSnapshots",
1186
- amazonize_list('SnapshotId',list.to_a))
1187
- request_cache_or_info :describe_snapshots, link, QEc2DescribeSnapshotsParser, @@bench, list.blank?
1188
- rescue Exception
1189
- on_exception
1190
- end
1191
-
1192
- # Create a snapshot of specified volume.
1193
- #
1194
- # ec2.create_snapshot('vol-898a6fe0') #=>
1195
- # {:aws_volume_id => "vol-fd9f7a94",
1196
- # :aws_started_at => Tue Jun 24 18:40:40 UTC 2008,
1197
- # :aws_progress => "",
1198
- # :aws_status => "pending",
1199
- # :aws_id => "snap-d56783bc"}
1200
- #
1201
- def create_snapshot(volume_id)
1202
- link = generate_request("CreateSnapshot",
1203
- "VolumeId" => volume_id.to_s)
1204
- request_info(link, QEc2CreateSnapshotParser.new(:logger => @logger))
1205
- rescue Exception
1206
- on_exception
1207
- end
1208
-
1209
- # Create a snapshot of specified volume, but with the normal retry algorithms disabled.
1210
- # This method will return immediately upon error. The user can specify connect and read timeouts (in s)
1211
- # for the connection to AWS. If the user does not specify timeouts, try_create_snapshot uses the default values
1212
- # in Rightscale::HttpConnection.
1213
- #
1214
- # ec2.try_create_snapshot('vol-898a6fe0') #=>
1215
- # {:aws_volume_id => "vol-fd9f7a94",
1216
- # :aws_started_at => Tue Jun 24 18:40:40 UTC 2008,
1217
- # :aws_progress => "",
1218
- # :aws_status => "pending",
1219
- # :aws_id => "snap-d56783bc"}
1220
- #
1221
- def try_create_snapshot(volume_id, connect_timeout = nil, read_timeout = nil)
1222
- # For safety in the ensure block...we don't want to restore values
1223
- # if we never read them in the first place
1224
- orig_reiteration_time = nil
1225
- orig_http_params = nil
1226
-
1227
- orig_reiteration_time = RightAws::AWSErrorHandler::reiteration_time
1228
- RightAws::AWSErrorHandler::reiteration_time = 0
1229
-
1230
- orig_http_params = Rightscale::HttpConnection::params()
1231
- new_http_params = orig_http_params.dup
1232
- new_http_params[:http_connection_retry_count] = 0
1233
- new_http_params[:http_connection_open_timeout] = connect_timeout if !connect_timeout.nil?
1234
- new_http_params[:http_connection_read_timeout] = read_timeout if !read_timeout.nil?
1235
- Rightscale::HttpConnection::params = new_http_params
1236
-
1237
- link = generate_request("CreateSnapshot",
1238
- "VolumeId" => volume_id.to_s)
1239
- request_info(link, QEc2CreateSnapshotParser.new(:logger => @logger))
1240
-
1241
- rescue Exception
1242
- on_exception
1243
- ensure
1244
- RightAws::AWSErrorHandler::reiteration_time = orig_reiteration_time if orig_reiteration_time
1245
- Rightscale::HttpConnection::params = orig_http_params if orig_http_params
1246
- end
1247
-
1248
- # Delete the specified snapshot.
1249
- #
1250
- # ec2.delete_snapshot('snap-55a5403c') #=> true
1251
- #
1252
- def delete_snapshot(snapshot_id)
1253
- link = generate_request("DeleteSnapshot",
1254
- "SnapshotId" => snapshot_id.to_s)
1255
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
1256
- rescue Exception
1257
- on_exception
1258
- end
1259
-
1260
442
  #-----------------------------------------------------------------
1261
443
  # PARSERS: Boolean Response Parser
1262
444
  #-----------------------------------------------------------------
@@ -1324,7 +506,6 @@ module RightAws
1324
506
  attr_accessor :ipPermissions
1325
507
  end
1326
508
 
1327
-
1328
509
  class QEc2DescribeSecurityGroupsParser < RightAWSParser #:nodoc:
1329
510
  def tagstart(name, attributes)
1330
511
  case name
@@ -1371,296 +552,6 @@ module RightAws
1371
552
  end
1372
553
  end
1373
554
 
1374
- #-----------------------------------------------------------------
1375
- # PARSERS: Images
1376
- #-----------------------------------------------------------------
1377
-
1378
- class QEc2DescribeImagesParser < RightAWSParser #:nodoc:
1379
- def tagstart(name, attributes)
1380
- if name == 'item' && @xmlpath[%r{.*/imagesSet$}]
1381
- @image = {}
1382
- end
1383
- end
1384
- def tagend(name)
1385
- case name
1386
- when 'imageId' then @image[:aws_id] = @text
1387
- when 'imageLocation' then @image[:aws_location] = @text
1388
- when 'imageState' then @image[:aws_state] = @text
1389
- when 'imageOwnerId' then @image[:aws_owner] = @text
1390
- when 'isPublic' then @image[:aws_is_public]= @text == 'true' ? true : false
1391
- when 'productCode' then (@image[:aws_product_codes] ||= []) << @text
1392
- when 'architecture' then @image[:aws_architecture] = @text
1393
- when 'imageType' then @image[:aws_image_type] = @text
1394
- when 'kernelId' then @image[:aws_kernel_id] = @text
1395
- when 'ramdiskId' then @image[:aws_ramdisk_id] = @text
1396
- when 'item' then @result << @image if @xmlpath[%r{.*/imagesSet$}]
1397
- end
1398
- end
1399
- def reset
1400
- @result = []
1401
- end
1402
- end
1403
-
1404
- class QEc2RegisterImageParser < RightAWSParser #:nodoc:
1405
- def tagend(name)
1406
- @result = @text if name == 'imageId'
1407
- end
1408
- end
1409
-
1410
- #-----------------------------------------------------------------
1411
- # PARSERS: Image Attribute
1412
- #-----------------------------------------------------------------
1413
-
1414
- class QEc2DescribeImageAttributeParser < RightAWSParser #:nodoc:
1415
- def tagstart(name, attributes)
1416
- case name
1417
- when 'launchPermission'
1418
- @result[:groups] = []
1419
- @result[:users] = []
1420
- when 'productCodes'
1421
- @result[:aws_product_codes] = []
1422
- end
1423
- end
1424
- def tagend(name)
1425
- # right now only 'launchPermission' is supported by Amazon.
1426
- # But nobody know what will they xml later as attribute. That is why we
1427
- # check for 'group' and 'userId' inside of 'launchPermission/item'
1428
- case name
1429
- when 'imageId' then @result[:aws_id] = @text
1430
- when 'group' then @result[:groups] << @text if @xmlpath == 'DescribeImageAttributeResponse/launchPermission/item'
1431
- when 'userId' then @result[:users] << @text if @xmlpath == 'DescribeImageAttributeResponse/launchPermission/item'
1432
- when 'productCode' then @result[:aws_product_codes] << @text
1433
- when 'kernel' then @result[:aws_kernel] = @text
1434
- when 'ramdisk' then @result[:aws_ramdisk] = @text
1435
- when 'blockDeviceMapping' then @result[:block_device_mapping] = @text
1436
- end
1437
- end
1438
- def reset
1439
- @result = {}
1440
- end
1441
- end
1442
-
1443
- #-----------------------------------------------------------------
1444
- # PARSERS: Instances
1445
- #-----------------------------------------------------------------
1446
-
1447
- class QEc2DescribeInstancesParser < RightAWSParser #:nodoc:
1448
- def tagstart(name, attributes)
1449
- # DescribeInstances property
1450
- if (name == 'item' && @xmlpath == 'DescribeInstancesResponse/reservationSet') ||
1451
- # RunInstances property
1452
- (name == 'RunInstancesResponse')
1453
- @reservation = { :aws_groups => [],
1454
- :instances_set => [] }
1455
-
1456
- elsif (name == 'item') &&
1457
- # DescribeInstances property
1458
- ( @xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet' ||
1459
- # RunInstances property
1460
- @xmlpath=='RunInstancesResponse/instancesSet' )
1461
- # the optional params (sometimes are missing and we dont want them to be nil)
1462
- @instance = { :aws_reason => '',
1463
- :dns_name => '',
1464
- :private_dns_name => '',
1465
- :ami_launch_index => '',
1466
- :ssh_key_name => '',
1467
- :aws_state => '',
1468
- :aws_product_codes => [] }
1469
- end
1470
- end
1471
- def tagend(name)
1472
- case name
1473
- # reservation
1474
- when 'reservationId' then @reservation[:aws_reservation_id] = @text
1475
- when 'ownerId' then @reservation[:aws_owner] = @text
1476
- when 'groupId' then @reservation[:aws_groups] << @text
1477
- # instance
1478
- when 'instanceId' then @instance[:aws_instance_id] = @text
1479
- when 'imageId' then @instance[:aws_image_id] = @text
1480
- when 'dnsName' then @instance[:dns_name] = @text
1481
- when 'privateDnsName' then @instance[:private_dns_name] = @text
1482
- when 'reason' then @instance[:aws_reason] = @text
1483
- when 'keyName' then @instance[:ssh_key_name] = @text
1484
- when 'amiLaunchIndex' then @instance[:ami_launch_index] = @text
1485
- when 'code' then @instance[:aws_state_code] = @text
1486
- when 'name' then @instance[:aws_state] = @text
1487
- when 'productCode' then @instance[:aws_product_codes] << @text
1488
- when 'instanceType' then @instance[:aws_instance_type] = @text
1489
- when 'launchTime' then @instance[:aws_launch_time] = @text
1490
- when 'kernelId' then @instance[:aws_kernel_id] = @text
1491
- when 'ramdiskId' then @instance[:aws_ramdisk_id] = @text
1492
- when 'platform' then @instance[:aws_platform] = @text
1493
- when 'availabilityZone' then @instance[:aws_availability_zone] = @text
1494
- when 'item'
1495
- if @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet' || # DescribeInstances property
1496
- @xmlpath == 'RunInstancesResponse/instancesSet' # RunInstances property
1497
- @reservation[:instances_set] << @instance
1498
- elsif @xmlpath=='DescribeInstancesResponse/reservationSet' # DescribeInstances property
1499
- @result << @reservation
1500
- end
1501
- when 'RunInstancesResponse' then @result << @reservation # RunInstances property
1502
- end
1503
- end
1504
- def reset
1505
- @result = []
1506
- end
1507
- end
1508
-
1509
- class QEc2ConfirmProductInstanceParser < RightAWSParser #:nodoc:
1510
- def tagend(name)
1511
- @result = @text if name == 'ownerId'
1512
- end
1513
- end
1514
-
1515
- class QEc2TerminateInstancesParser < RightAWSParser #:nodoc:
1516
- def tagstart(name, attributes)
1517
- @instance = {} if name == 'item'
1518
- end
1519
- def tagend(name)
1520
- case name
1521
- when 'instanceId' then @instance[:aws_instance_id] = @text
1522
- when 'code'
1523
- if @xmlpath == 'TerminateInstancesResponse/instancesSet/item/shutdownState'
1524
- @instance[:aws_shutdown_state_code] = @text.to_i
1525
- else @instance[:aws_prev_state_code] = @text.to_i end
1526
- when 'name'
1527
- if @xmlpath == 'TerminateInstancesResponse/instancesSet/item/shutdownState'
1528
- @instance[:aws_shutdown_state] = @text
1529
- else @instance[:aws_prev_state] = @text end
1530
- when 'item' then @result << @instance
1531
- end
1532
- end
1533
- def reset
1534
- @result = []
1535
- end
1536
- end
1537
-
1538
- #-----------------------------------------------------------------
1539
- # PARSERS: ReservedInstances
1540
- #-----------------------------------------------------------------
1541
-
1542
- class QEc2DescribeReservedInstancesParser < RightAWSParser #:nodoc:
1543
- def tagstart(name, attributes)
1544
- @item = {} if name == 'item'
1545
- end
1546
- def tagend(name)
1547
- case name
1548
- when 'reservedInstancesId' then @item[:aws_id] = @text
1549
- when 'instanceType' then @item[:aws_instance_type] = @text
1550
- when 'availabilityZone' then @item[:aws_availability_zone] = @text
1551
- when 'duration' then @item[:aws_duration] = @text.to_i
1552
- when 'usagePrice' then @item[:aws_usage_price] = @text.to_f
1553
- when 'fixedPrice' then @item[:aws_fixed_price] = @text.to_f
1554
- when 'instanceCount' then @item[:aws_instance_count] = @text.to_i
1555
- when 'productDescription' then @item[:aws_product_description] = @text
1556
- when 'state' then @item[:aws_state] = @text
1557
- when 'item' then @result << @item
1558
- end
1559
- end
1560
- def reset
1561
- @result = []
1562
- end
1563
- end
1564
-
1565
- class QEc2DescribeReservedInstancesOfferingsParser < RightAWSParser #:nodoc:
1566
- def tagstart(name, attributes)
1567
- @item = {} if name == 'item'
1568
- end
1569
- def tagend(name)
1570
- case name
1571
- when 'reservedInstancesOfferingId' then @item[:aws_id] = @text
1572
- when 'instanceType' then @item[:aws_instance_type] = @text
1573
- when 'availabilityZone' then @item[:aws_availability_zone] = @text
1574
- when 'duration' then @item[:aws_duration] = @text.to_i
1575
- when 'usagePrice' then @item[:aws_usage_price] = @text.to_f
1576
- when 'fixedPrice' then @item[:aws_fixed_price] = @text.to_f
1577
- when 'productDescription' then @item[:aws_product_description] = @text
1578
- when 'item' then @result << @item
1579
- end
1580
- end
1581
- def reset
1582
- @result = []
1583
- end
1584
- end
1585
-
1586
- class QEc2PurchaseReservedInstancesOfferingParser < RightAWSParser #:nodoc:
1587
- def tagend(name)
1588
- if name == 'reservedInstancesId'
1589
- @result = @text
1590
- end
1591
- end
1592
- def reset
1593
- @result = ''
1594
- end
1595
- end
1596
-
1597
- #-----------------------------------------------------------------
1598
- # PARSERS: Console
1599
- #-----------------------------------------------------------------
1600
-
1601
- class QEc2GetConsoleOutputParser < RightAWSParser #:nodoc:
1602
- def tagend(name)
1603
- case name
1604
- when 'instanceId' then @result[:aws_instance_id] = @text
1605
- when 'timestamp' then @result[:aws_timestamp] = @text
1606
- @result[:timestamp] = (Time.parse(@text)).utc
1607
- when 'output' then @result[:aws_output] = Base64.decode64(@text)
1608
- end
1609
- end
1610
- def reset
1611
- @result = {}
1612
- end
1613
- end
1614
-
1615
- #-----------------------------------------------------------------
1616
- # Instances: Wondows related part
1617
- #-----------------------------------------------------------------
1618
- class QEc2DescribeBundleTasksParser < RightAWSParser #:nodoc:
1619
- def tagstart(name, attributes)
1620
- @bundle = {} if name == 'item'
1621
- end
1622
- def tagend(name)
1623
- case name
1624
- # when 'requestId' then @bundle[:request_id] = @text
1625
- when 'instanceId' then @bundle[:aws_instance_id] = @text
1626
- when 'bundleId' then @bundle[:aws_id] = @text
1627
- when 'bucket' then @bundle[:s3_bucket] = @text
1628
- when 'prefix' then @bundle[:s3_prefix] = @text
1629
- when 'startTime' then @bundle[:aws_start_time] = @text
1630
- when 'updateTime' then @bundle[:aws_update_time] = @text
1631
- when 'state' then @bundle[:aws_state] = @text
1632
- when 'progress' then @bundle[:aws_progress] = @text
1633
- when 'code' then @bundle[:aws_error_code] = @text
1634
- when 'message' then @bundle[:aws_error_message] = @text
1635
- when 'item' then @result << @bundle
1636
- end
1637
- end
1638
- def reset
1639
- @result = []
1640
- end
1641
- end
1642
-
1643
- class QEc2BundleInstanceParser < RightAWSParser #:nodoc:
1644
- def tagend(name)
1645
- case name
1646
- # when 'requestId' then @result[:request_id] = @text
1647
- when 'instanceId' then @result[:aws_instance_id] = @text
1648
- when 'bundleId' then @result[:aws_id] = @text
1649
- when 'bucket' then @result[:s3_bucket] = @text
1650
- when 'prefix' then @result[:s3_prefix] = @text
1651
- when 'startTime' then @result[:aws_start_time] = @text
1652
- when 'updateTime' then @result[:aws_update_time] = @text
1653
- when 'state' then @result[:aws_state] = @text
1654
- when 'progress' then @result[:aws_progress] = @text
1655
- when 'code' then @result[:aws_error_code] = @text
1656
- when 'message' then @result[:aws_error_message] = @text
1657
- end
1658
- end
1659
- def reset
1660
- @result = {}
1661
- end
1662
- end
1663
-
1664
555
  #-----------------------------------------------------------------
1665
556
  # PARSERS: Elastic IPs
1666
557
  #-----------------------------------------------------------------
@@ -1700,7 +591,7 @@ module RightAws
1700
591
  when 'regionName' then @zone[:region_name] = @text
1701
592
  when 'zoneName' then @zone[:zone_name] = @text
1702
593
  when 'zoneState' then @zone[:zone_state] = @text
1703
- when 'item' then @result << @zone
594
+ when 'item' then @result << @zone
1704
595
  end
1705
596
  end
1706
597
  def reset
@@ -1720,117 +611,6 @@ module RightAws
1720
611
  @result = []
1721
612
  end
1722
613
  end
1723
-
1724
- #-----------------------------------------------------------------
1725
- # PARSERS: EBS - Volumes
1726
- #-----------------------------------------------------------------
1727
-
1728
- class QEc2CreateVolumeParser < RightAWSParser #:nodoc:
1729
- def tagend(name)
1730
- case name
1731
- when 'volumeId' then @result[:aws_id] = @text
1732
- when 'status' then @result[:aws_status] = @text
1733
- when 'createTime' then @result[:aws_created_at] = Time.parse(@text)
1734
- when 'size' then @result[:aws_size] = @text.to_i ###
1735
- when 'snapshotId' then @result[:snapshot_id] = @text.blank? ? nil : @text ###
1736
- when 'availabilityZone' then @result[:zone] = @text ###
1737
- end
1738
- end
1739
- def reset
1740
- @result = {}
1741
- end
1742
- end
1743
-
1744
- class QEc2AttachAndDetachVolumeParser < RightAWSParser #:nodoc:
1745
- def tagend(name)
1746
- case name
1747
- when 'volumeId' then @result[:aws_id] = @text
1748
- when 'instanceId' then @result[:aws_instance_id] = @text
1749
- when 'device' then @result[:aws_device] = @text
1750
- when 'status' then @result[:aws_attachment_status] = @text
1751
- when 'attachTime' then @result[:aws_attached_at] = Time.parse(@text)
1752
- end
1753
- end
1754
- def reset
1755
- @result = {}
1756
- end
1757
- end
1758
-
1759
- class QEc2DescribeVolumesParser < RightAWSParser #:nodoc:
1760
- def tagstart(name, attributes)
1761
- case name
1762
- when 'item'
1763
- case @xmlpath
1764
- when 'DescribeVolumesResponse/volumeSet' then @volume = {}
1765
- end
1766
- end
1767
- end
1768
- def tagend(name)
1769
- case name
1770
- when 'volumeId'
1771
- case @xmlpath
1772
- when 'DescribeVolumesResponse/volumeSet/item' then @volume[:aws_id] = @text
1773
- end
1774
- when 'status'
1775
- case @xmlpath
1776
- when 'DescribeVolumesResponse/volumeSet/item' then @volume[:aws_status] = @text
1777
- when 'DescribeVolumesResponse/volumeSet/item/attachmentSet/item' then @volume[:aws_attachment_status] = @text
1778
- end
1779
- when 'size' then @volume[:aws_size] = @text.to_i
1780
- when 'createTime' then @volume[:aws_created_at] = Time.parse(@text)
1781
- when 'instanceId' then @volume[:aws_instance_id] = @text
1782
- when 'device' then @volume[:aws_device] = @text
1783
- when 'attachTime' then @volume[:aws_attached_at] = Time.parse(@text)
1784
- when 'snapshotId' then @volume[:snapshot_id] = @text.blank? ? nil : @text
1785
- when 'availabilityZone' then @volume[:zone] = @text
1786
- when 'item'
1787
- case @xmlpath
1788
- when 'DescribeVolumesResponse/volumeSet' then @result << @volume
1789
- end
1790
- end
1791
- end
1792
- def reset
1793
- @result = []
1794
- end
1795
- end
1796
-
1797
- #-----------------------------------------------------------------
1798
- # PARSERS: EBS - Snapshots
1799
- #-----------------------------------------------------------------
1800
-
1801
- class QEc2DescribeSnapshotsParser < RightAWSParser #:nodoc:
1802
- def tagstart(name, attributes)
1803
- @snapshot = {} if name == 'item'
1804
- end
1805
- def tagend(name)
1806
- case name
1807
- when 'volumeId' then @snapshot[:aws_volume_id] = @text
1808
- when 'snapshotId' then @snapshot[:aws_id] = @text
1809
- when 'status' then @snapshot[:aws_status] = @text
1810
- when 'startTime' then @snapshot[:aws_started_at] = Time.parse(@text)
1811
- when 'progress' then @snapshot[:aws_progress] = @text
1812
- when 'item' then @result << @snapshot
1813
- end
1814
- end
1815
- def reset
1816
- @result = []
1817
- end
1818
- end
1819
-
1820
- class QEc2CreateSnapshotParser < RightAWSParser #:nodoc:
1821
- def tagend(name)
1822
- case name
1823
- when 'volumeId' then @result[:aws_volume_id] = @text
1824
- when 'snapshotId' then @result[:aws_id] = @text
1825
- when 'status' then @result[:aws_status] = @text
1826
- when 'startTime' then @result[:aws_started_at] = Time.parse(@text)
1827
- when 'progress' then @result[:aws_progress] = @text
1828
- end
1829
- end
1830
- def reset
1831
- @result = {}
1832
- end
1833
- end
1834
614
 
1835
615
  end
1836
616