icehouse-right_aws 1.11.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/History.txt +93 -15
  2. data/Manifest.txt +15 -1
  3. data/README.txt +0 -4
  4. data/Rakefile +34 -17
  5. data/lib/acf/right_acf_interface.rb +260 -124
  6. data/lib/acf/right_acf_invalidations.rb +144 -0
  7. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  8. data/lib/acf/right_acf_streaming_interface.rb +229 -0
  9. data/lib/acw/right_acw_interface.rb +4 -5
  10. data/lib/as/right_as_interface.rb +59 -51
  11. data/lib/awsbase/benchmark_fix.rb +0 -0
  12. data/lib/awsbase/right_awsbase.rb +351 -104
  13. data/lib/awsbase/support.rb +2 -82
  14. data/lib/awsbase/version.rb +9 -0
  15. data/lib/ec2/right_ec2.rb +97 -246
  16. data/lib/ec2/right_ec2_ebs.rb +88 -68
  17. data/lib/ec2/right_ec2_images.rb +90 -50
  18. data/lib/ec2/right_ec2_instances.rb +118 -89
  19. data/lib/ec2/right_ec2_placement_groups.rb +108 -0
  20. data/lib/ec2/right_ec2_reserved_instances.rb +51 -44
  21. data/lib/ec2/right_ec2_security_groups.rb +396 -0
  22. data/lib/ec2/right_ec2_spot_instances.rb +425 -0
  23. data/lib/ec2/right_ec2_tags.rb +139 -0
  24. data/lib/ec2/right_ec2_vpc.rb +152 -140
  25. data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
  26. data/lib/elb/right_elb_interface.rb +205 -39
  27. data/lib/iam/right_iam_access_keys.rb +71 -0
  28. data/lib/iam/right_iam_groups.rb +195 -0
  29. data/lib/iam/right_iam_interface.rb +341 -0
  30. data/lib/iam/right_iam_mfa_devices.rb +67 -0
  31. data/lib/iam/right_iam_users.rb +251 -0
  32. data/lib/rds/right_rds_interface.rb +591 -205
  33. data/lib/right_aws.rb +16 -12
  34. data/lib/route_53/right_route_53_interface.rb +640 -0
  35. data/lib/s3/right_s3.rb +34 -13
  36. data/lib/s3/right_s3_interface.rb +17 -14
  37. data/lib/sdb/active_sdb.rb +215 -38
  38. data/lib/sdb/right_sdb_interface.rb +93 -12
  39. data/lib/sqs/right_sqs.rb +1 -2
  40. data/lib/sqs/right_sqs_gen2.rb +0 -1
  41. data/lib/sqs/right_sqs_gen2_interface.rb +9 -9
  42. data/lib/sqs/right_sqs_interface.rb +6 -7
  43. data/right_aws.gemspec +91 -0
  44. data/test/README.mdown +39 -0
  45. data/test/acf/test_helper.rb +0 -0
  46. data/test/acf/test_right_acf.rb +10 -18
  47. data/test/awsbase/test_helper.rb +0 -0
  48. data/test/awsbase/test_right_awsbase.rb +0 -1
  49. data/test/ec2/test_helper.rb +0 -0
  50. data/test/ec2/test_right_ec2.rb +0 -1
  51. data/test/elb/test_helper.rb +2 -0
  52. data/test/elb/test_right_elb.rb +43 -0
  53. data/test/http_connection.rb +0 -0
  54. data/test/route_53/fixtures/a_record.xml +18 -0
  55. data/test/route_53/fixtures/alias_record.xml +18 -0
  56. data/test/route_53/test_helper.rb +2 -0
  57. data/test/route_53/test_right_route_53.rb +141 -0
  58. data/test/s3/test_helper.rb +0 -0
  59. data/test/s3/test_right_s3.rb +11 -9
  60. data/test/s3/test_right_s3_stubbed.rb +6 -4
  61. data/test/sdb/test_active_sdb.rb +71 -13
  62. data/test/sdb/test_batch_put_attributes.rb +54 -0
  63. data/test/sdb/test_helper.rb +0 -0
  64. data/test/sdb/test_right_sdb.rb +13 -7
  65. data/test/sqs/test_helper.rb +0 -0
  66. data/test/sqs/test_right_sqs.rb +0 -6
  67. data/test/sqs/test_right_sqs_gen2.rb +22 -34
  68. data/test/test_credentials.rb +0 -0
  69. data/test/ts_right_aws.rb +0 -0
  70. metadata +146 -16
  71. data/VERSION +0 -1
@@ -1,7 +1,3 @@
1
- # If ActiveSupport is loaded, then great - use it. But we don't
2
- # want a dependency on it, so if it's not present, define the few
3
- # extensions that we want to use...
4
- unless defined? ActiveSupport::CoreExtensions
5
1
  # These are ActiveSupport-;like extensions to do a few handy things in the gems
6
2
  # Derived from ActiveSupport, so the AS copyright notice applies:
7
3
  #
@@ -32,84 +28,8 @@ unless defined? ActiveSupport::CoreExtensions
32
28
  #
33
29
  class String #:nodoc:
34
30
 
35
- # Constantize tries to find a declared constant with the name specified
36
- # in the string. It raises a NameError when the name is not in CamelCase
37
- # or is not initialized.
38
- #
39
- # Examples
40
- # "Module".constantize #=> Module
41
- # "Class".constantize #=> Class
42
- def constantize()
43
- unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
44
- raise NameError, "#{self.inspect} is not a valid constant name!"
45
- end
46
-
47
- Object.module_eval("::#{$1}", __FILE__, __LINE__)
48
- end
49
-
50
- def camelize()
51
- self.dup.split(/_/).map{ |word| word.capitalize }.join('')
52
- end
53
-
54
- end
55
-
56
-
57
- class Object #:nodoc:
58
- # "", " ", nil, [], and {} are blank
59
- def blank?
60
- if respond_to?(:empty?) && respond_to?(:strip)
61
- empty? or strip.empty?
62
- elsif respond_to?(:empty?)
63
- empty?
64
- else
65
- !self
66
- end
31
+ def right_underscore
32
+ self.gsub(/[A-Z]/){|match| "#{$`=='' ? '' : '_'}#{match.downcase}" }
67
33
  end
68
- end
69
-
70
- class NilClass #:nodoc:
71
- def blank?
72
- true
73
- end
74
- end
75
-
76
- class FalseClass #:nodoc:
77
- def blank?
78
- true
79
- end
80
- end
81
-
82
- class TrueClass #:nodoc:
83
- def blank?
84
- false
85
- end
86
- end
87
-
88
- class Array #:nodoc:
89
- alias_method :blank?, :empty?
90
- end
91
-
92
- class Hash #:nodoc:
93
- alias_method :blank?, :empty?
94
34
 
95
- # Return a new hash with all keys converted to symbols.
96
- def symbolize_keys
97
- inject({}) do |options, (key, value)|
98
- options[key.to_sym] = value
99
- options
100
- end
101
- end
102
- end
103
-
104
- class String #:nodoc:
105
- def blank?
106
- empty? || strip.empty?
107
- end
108
- end
109
-
110
- class Numeric #:nodoc:
111
- def blank?
112
- false
113
- end
114
35
  end
115
- end
@@ -0,0 +1,9 @@
1
+ module RightAws #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 2 unless defined?(MAJOR)
4
+ MINOR = 2 unless defined?(MINOR)
5
+ TINY = 0 unless defined?(TINY)
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.') unless defined?(STRING)
8
+ end
9
+ end
@@ -68,7 +68,7 @@ module RightAws
68
68
  include RightAwsBaseInterface
69
69
 
70
70
  # Amazon EC2 API version being used
71
- API_VERSION = "2009-10-31"
71
+ API_VERSION = "2010-08-31"
72
72
  DEFAULT_HOST = "ec2.amazonaws.com"
73
73
  DEFAULT_PATH = '/'
74
74
  DEFAULT_PROTOCOL = 'https'
@@ -81,7 +81,9 @@ 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', 'm2.2xlarge', 'm2.4xlarge']
84
+ INSTANCE_TYPES = ['t1.micro','m1.small','c1.medium','m1.large','m1.xlarge',
85
+ 'c1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge',
86
+ 'cc1.4xlarge', 'cg1.4xlarge']
85
87
 
86
88
  @@bench = AwsBenchmarkingBlock.new
87
89
  def self.bench_xml
@@ -105,7 +107,6 @@ module RightAws
105
107
  # * <tt>:region</tt>: EC2 region (North America by default)
106
108
  # * <tt>:port</tt>: EC2 service port, default: DEFAULT_PORT
107
109
  # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
108
- # * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
109
110
  # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
110
111
  # * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
111
112
  # * <tt>:cache</tt>: true/false: caching for: ec2_describe_images, describe_instances,
@@ -123,6 +124,10 @@ module RightAws
123
124
  aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
124
125
  aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
125
126
  params)
127
+ # Eucalyptus supports some yummy features but Amazon does not
128
+ #if @params[:eucalyptus]
129
+ # @params[:port_based_group_ingress] = true unless @params.has_key?(:port_based_group_ingress)
130
+ #end
126
131
  end
127
132
 
128
133
  def generate_request(action, params={}) #:nodoc:
@@ -135,172 +140,70 @@ module RightAws
135
140
  request_info_impl(:ec2_connection, @@bench, request, parser)
136
141
  end
137
142
 
138
- #-----------------------------------------------------------------
139
- # Security groups
140
- #-----------------------------------------------------------------
141
-
142
- # Retrieve Security Group information. If +list+ is omitted the returns the whole list of groups.
143
- #
144
- # ec2.describe_security_groups #=>
145
- # [{:aws_group_name => "default-1",
146
- # :aws_owner => "000000000888",
147
- # :aws_description => "Default allowing SSH, HTTP, and HTTPS ingress",
148
- # :aws_perms =>
149
- # [{:owner => "000000000888", :group => "default"},
150
- # {:owner => "000000000888", :group => "default-1"},
151
- # {:to_port => "-1", :protocol => "icmp", :from_port => "-1", :cidr_ips => "0.0.0.0/0"},
152
- # {:to_port => "22", :protocol => "tcp", :from_port => "22", :cidr_ips => "0.0.0.0/0"},
153
- # {:to_port => "80", :protocol => "tcp", :from_port => "80", :cidr_ips => "0.0.0.0/0"},
154
- # {:to_port => "443", :protocol => "tcp", :from_port => "443", :cidr_ips => "0.0.0.0/0"}]},
155
- # ..., {...}]
156
- #
157
- def describe_security_groups(list=[])
158
- link = generate_request("DescribeSecurityGroups", amazonize_list('GroupName',list.to_a))
159
- request_cache_or_info( :describe_security_groups, link, QEc2DescribeSecurityGroupsParser, @@bench, list.blank?) do |parser|
160
- result = []
161
- parser.result.each do |item|
162
- perms = []
163
- item.ipPermissions.each do |perm|
164
- perm.groups.each do |ngroup|
165
- perms << {:group => ngroup.groupName,
166
- :owner => ngroup.userId}
167
- end
168
- perm.ipRanges.each do |cidr_ip|
169
- perms << {:from_port => perm.fromPort,
170
- :to_port => perm.toPort,
171
- :protocol => perm.ipProtocol,
172
- :cidr_ips => cidr_ip}
173
- end
174
- end
175
-
176
- # delete duplication
177
- perms.each_index do |i|
178
- (0...i).each do |j|
179
- if perms[i] == perms[j] then perms[i] = nil; break; end
180
- end
181
- end
182
- perms.compact!
183
-
184
- result << {:aws_owner => item.ownerId,
185
- :aws_group_name => item.groupName,
186
- :aws_description => item.groupDescription,
187
- :aws_perms => perms}
188
-
143
+ def describe_resources_with_list_and_options(remote_function_name, remote_item_name, parser_class, list_and_options, &block) # :nodoc:
144
+ # 'RemoteFunctionName' -> :remote_funtion_name
145
+ cache_name = remote_function_name.right_underscore.to_sym
146
+ list, options = AwsUtils::split_items_and_params(list_and_options)
147
+ # Resource IDs to fetch
148
+ request_hash = amazonize_list(remote_item_name, list)
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))
189
157
  end
190
- result
191
158
  end
192
- rescue Exception
193
- on_exception
194
- end
195
-
196
- # Create new Security Group. Returns +true+ or an exception.
197
- #
198
- # ec2.create_security_group('default-1',"Default allowing SSH, HTTP, and HTTPS ingress") #=> true
199
- #
200
- def create_security_group(name, description)
201
- # EC2 doesn't like an empty description...
202
- description = " " if description.blank?
203
- link = generate_request("CreateSecurityGroup",
204
- 'GroupName' => name.to_s,
205
- 'GroupDescription' => description.to_s)
206
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
159
+ cache_for = (list.right_blank? && options.right_blank?) ? cache_name : nil
160
+ link = generate_request(remote_function_name, request_hash)
161
+ request_cache_or_info(cache_for, link, parser_class, @@bench, cache_for, &block)
207
162
  rescue Exception
208
163
  on_exception
209
164
  end
210
165
 
211
- # Remove Security Group. Returns +true+ or an exception.
212
- #
213
- # ec2.delete_security_group('default-1') #=> true
166
+ #-----------------------------------------------------------------
167
+ # Keys
168
+ #-----------------------------------------------------------------
169
+
170
+ # Retrieve a list of SSH keys.
214
171
  #
215
- def delete_security_group(name)
216
- link = generate_request("DeleteSecurityGroup",
217
- 'GroupName' => name.to_s)
218
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
219
- rescue Exception
220
- on_exception
221
- end
222
-
223
- # Authorize named ingress for security group. Allows instances that are member of someone
224
- # else's security group to open connections to instances in my group.
172
+ # Accepts a list of ssh keys and/or a set of filters as the last parameter.
225
173
  #
226
- # ec2.authorize_security_group_named_ingress('my_awesome_group', '7011-0219-8268', 'their_group_name') #=> true
174
+ # Filters: fingerprint, key-name
227
175
  #
228
- def authorize_security_group_named_ingress(name, owner, group)
229
- link = generate_request("AuthorizeSecurityGroupIngress",
230
- 'GroupName' => name.to_s,
231
- 'SourceSecurityGroupName' => group.to_s,
232
- 'SourceSecurityGroupOwnerId' => owner.to_s.gsub(/-/,''))
233
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
234
- rescue Exception
235
- on_exception
236
- end
237
-
238
- # Revoke named ingress for security group.
176
+ # Returns an array of keys or an exception. Each key is represented as a two-element hash.
239
177
  #
240
- # ec2.revoke_security_group_named_ingress('my_awesome_group', aws_user_id, 'another_group_name') #=> true
178
+ # ec2.describe_key_pairs #=>
179
+ # [{:aws_fingerprint=> "01:02:03:f4:25:e6:97:e8:9b:02:1a:26:32:4e:58:6b:7a:8c:9f:03", :aws_key_name=>"key-1"},
180
+ # {:aws_fingerprint=> "1e:29:30:47:58:6d:7b:8c:9f:08:11:20:3c:44:52:69:74:80:97:08", :aws_key_name=>"key-2"},
181
+ # ..., {...} ]
241
182
  #
242
- def revoke_security_group_named_ingress(name, owner, group)
243
- link = generate_request("RevokeSecurityGroupIngress",
244
- 'GroupName' => name.to_s,
245
- 'SourceSecurityGroupName' => group.to_s,
246
- 'SourceSecurityGroupOwnerId' => owner.to_s.gsub(/-/,''))
247
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
248
- rescue Exception
249
- on_exception
250
- end
251
-
252
- # Add permission to a security group. Returns +true+ or an exception. +protocol+ is one of :'tcp'|'udp'|'icmp'.
183
+ # ec2.describe_key_pairs(:filters => {'fingerprint' => ["53:0b:73:c9:c8:18:98:6e:bc:98:9e:51:97:04:74:4b:07:f9:00:00",
184
+ # "9f:57:a5:bb:4b:e8:a7:f8:3c:fe:d6:db:41:f5:7e:97:b5:b2:00:00"]})
253
185
  #
254
- # ec2.authorize_security_group_IP_ingress('my_awesome_group', 80, 82, 'udp', '192.168.1.0/8') #=> true
255
- # ec2.authorize_security_group_IP_ingress('my_awesome_group', -1, -1, 'icmp') #=> true
186
+ # P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeKeyPairs.html
256
187
  #
257
- def authorize_security_group_IP_ingress(name, from_port, to_port, protocol='tcp', cidr_ip='0.0.0.0/0')
258
- link = generate_request("AuthorizeSecurityGroupIngress",
259
- 'GroupName' => name.to_s,
260
- 'IpProtocol' => protocol.to_s,
261
- 'FromPort' => from_port.to_s,
262
- 'ToPort' => to_port.to_s,
263
- 'CidrIp' => cidr_ip.to_s)
264
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
265
- rescue Exception
266
- on_exception
188
+ def describe_key_pairs(*list_and_options)
189
+ describe_resources_with_list_and_options('DescribeKeyPairs', 'KeyName', QEc2DescribeKeyPairParser, list_and_options)
267
190
  end
268
-
269
- # Remove permission from a security group. Returns +true+ or an exception. +protocol+ is one of :'tcp'|'udp'|'icmp' ('tcp' is default).
191
+
192
+ # Import new SSH key. Returns a hash of the key's data or an exception.
270
193
  #
271
- # ec2.revoke_security_group_IP_ingress('my_awesome_group', 80, 82, 'udp', '192.168.1.0/8') #=> true
194
+ # ec2.import_key_pair('my_awesome_key', 'C:\keys\myfavoritekeypair_public.ppk') #=>
195
+ # {:aws_key_name => "my_awesome_key",
196
+ # :aws_fingerprint => "01:02:03:f4:25:e6:97:e8:9b:02:1a:26:32:4e:58:6b:7a:8c:9f:03"}
272
197
  #
273
- def revoke_security_group_IP_ingress(name, from_port, to_port, protocol='tcp', cidr_ip='0.0.0.0/0')
274
- link = generate_request("RevokeSecurityGroupIngress",
275
- 'GroupName' => name.to_s,
276
- 'IpProtocol' => protocol.to_s,
277
- 'FromPort' => from_port.to_s,
278
- 'ToPort' => to_port.to_s,
279
- 'CidrIp' => cidr_ip.to_s)
280
- request_info(link, RightBoolResponseParser.new(:logger => @logger))
198
+ def import_key_pair(name, public_key_material)
199
+ link = generate_request("ImportKeyPair",
200
+ 'KeyName' => name.to_s,
201
+ 'PublicKeyMaterial' => Base64.encode64(public_key_material.to_s))
202
+ request_info(link, QEc2ImportKeyPairParser.new(:logger => @logger))
281
203
  rescue Exception
282
204
  on_exception
283
205
  end
284
206
 
285
- #-----------------------------------------------------------------
286
- # Keys
287
- #-----------------------------------------------------------------
288
-
289
- # Retrieve a list of SSH keys. Returns an array of keys or an exception. Each key is
290
- # represented as a two-element hash.
291
- #
292
- # ec2.describe_key_pairs #=>
293
- # [{:aws_fingerprint=> "01:02:03:f4:25:e6:97:e8:9b:02:1a:26:32:4e:58:6b:7a:8c:9f:03", :aws_key_name=>"key-1"},
294
- # {:aws_fingerprint=> "1e:29:30:47:58:6d:7b:8c:9f:08:11:20:3c:44:52:69:74:80:97:08", :aws_key_name=>"key-2"},
295
- # ..., {...} ]
296
- #
297
- def describe_key_pairs(list=[])
298
- link = generate_request("DescribeKeyPairs", amazonize_list('KeyName',list.to_a))
299
- request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, @@bench, list.blank?
300
- rescue Exception
301
- on_exception
302
- end
303
-
304
207
  # Create new SSH key. Returns a hash of the key's data or an exception.
305
208
  #
306
209
  # ec2.create_key_pair('my_awesome_key') #=>
@@ -309,7 +212,7 @@ module RightAws
309
212
  # :aws_material => "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAK...Q8MDrCbuQ=\n-----END RSA PRIVATE KEY-----"}
310
213
  #
311
214
  def create_key_pair(name)
312
- link = generate_request("CreateKeyPair",
215
+ link = generate_request("CreateKeyPair",
313
216
  'KeyName' => name.to_s)
314
217
  request_info(link, QEc2CreateKeyPairParser.new(:logger => @logger))
315
218
  rescue Exception
@@ -359,6 +262,11 @@ module RightAws
359
262
  end
360
263
 
361
264
  # List elastic IP addresses assigned to your account.
265
+ #
266
+ # Accepts a list of addresses and/or a set of filters as the last parameter.
267
+ #
268
+ # Filters: instance-id, public-ip
269
+ #
362
270
  # Returns an array of 2 keys (:instance_id and :public_ip) hashes:
363
271
  #
364
272
  # ec2.describe_addresses #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"},
@@ -366,12 +274,12 @@ module RightAws
366
274
  #
367
275
  # ec2.describe_addresses('75.101.154.140') #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"}]
368
276
  #
369
- def describe_addresses(list=[])
370
- link = generate_request("DescribeAddresses",
371
- amazonize_list('PublicIp',list.to_a))
372
- request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, @@bench, list.blank?
373
- rescue Exception
374
- on_exception
277
+ # ec2.describe_addresses(:filters => { 'public-ip' => "75.101.154.140" })
278
+ #
279
+ # P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeAddresses.html
280
+ #
281
+ def describe_addresses(*list_and_options)
282
+ describe_resources_with_list_and_options('DescribeAddresses', 'PublicIp', QEc2DescribeAddressesParser, list_and_options)
375
283
  end
376
284
 
377
285
  # Disassociate the specified elastic IP address from the instance to which it is assigned.
@@ -405,6 +313,11 @@ module RightAws
405
313
  #-----------------------------------------------------------------
406
314
 
407
315
  # Describes availability zones that are currently available to the account and their states.
316
+ #
317
+ # Accepts a list of availability zones and/or a set of filters as the last parameter.
318
+ #
319
+ # Filters: message, region-name, state, zone-name
320
+ #
408
321
  # Returns an array of 2 keys (:zone_name and :zone_state) hashes:
409
322
  #
410
323
  # ec2.describe_availability_zones #=> [{:region_name=>"us-east-1",
@@ -415,12 +328,10 @@ module RightAws
415
328
  # :zone_state=>"available",
416
329
  # :zone_name=>"us-east-1c"}]
417
330
  #
418
- def describe_availability_zones(list=[])
419
- link = generate_request("DescribeAvailabilityZones",
420
- amazonize_list('ZoneName',list.to_a))
421
- request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, @@bench, list.blank?
422
- rescue Exception
423
- on_exception
331
+ # P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeAvailabilityZones.html
332
+ #
333
+ def describe_availability_zones(*list_and_options)
334
+ describe_resources_with_list_and_options('DescribeAvailabilityZones', 'ZoneName', QEc2DescribeAvailabilityZonesParser, list_and_options)
424
335
  end
425
336
 
426
337
  #-----------------------------------------------------------------
@@ -429,24 +340,16 @@ module RightAws
429
340
 
430
341
  # Describe regions.
431
342
  #
343
+ # Accepts a list of regions and/or a set of filters as the last parameter.
344
+ #
345
+ # Filters: endpoint, region-name
346
+ #
432
347
  # ec2.describe_regions #=> ["eu-west-1", "us-east-1"]
433
348
  #
434
- def describe_regions(list=[])
435
- link = generate_request("DescribeRegions",
436
- amazonize_list('RegionName',list.to_a))
437
- request_cache_or_info :describe_regions, link, QEc2DescribeRegionsParser, @@bench, list.blank?
438
- rescue Exception
439
- on_exception
440
- end
441
-
442
- #-----------------------------------------------------------------
443
- # PARSERS: Boolean Response Parser
444
- #-----------------------------------------------------------------
445
-
446
- class RightBoolResponseParser < RightAWSParser #:nodoc:
447
- def tagend(name)
448
- @result = @text=='true' ? true : false if name == 'return'
449
- end
349
+ # P.S. filters: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeRegions.html
350
+ #
351
+ def describe_regions(*list_and_options)
352
+ describe_resources_with_list_and_options('DescribeRegions', 'RegionName', QEc2DescribeRegionsParser, list_and_options)
450
353
  end
451
354
 
452
355
  #-----------------------------------------------------------------
@@ -482,74 +385,16 @@ module RightAws
482
385
  end
483
386
  end
484
387
 
485
- #-----------------------------------------------------------------
486
- # PARSERS: Security Groups
487
- #-----------------------------------------------------------------
488
-
489
- class QEc2UserIdGroupPairType #:nodoc:
490
- attr_accessor :userId
491
- attr_accessor :groupName
492
- end
493
-
494
- class QEc2IpPermissionType #:nodoc:
495
- attr_accessor :ipProtocol
496
- attr_accessor :fromPort
497
- attr_accessor :toPort
498
- attr_accessor :groups
499
- attr_accessor :ipRanges
500
- end
501
-
502
- class QEc2SecurityGroupItemType #:nodoc:
503
- attr_accessor :groupName
504
- attr_accessor :groupDescription
505
- attr_accessor :ownerId
506
- attr_accessor :ipPermissions
507
- end
508
-
509
- class QEc2DescribeSecurityGroupsParser < RightAWSParser #:nodoc:
388
+ class QEc2ImportKeyPairParser < RightAWSParser #:nodoc:
510
389
  def tagstart(name, attributes)
511
- case name
512
- when 'item'
513
- if @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo'
514
- @group = QEc2SecurityGroupItemType.new
515
- @group.ipPermissions = []
516
- elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions'
517
- @perm = QEc2IpPermissionType.new
518
- @perm.ipRanges = []
519
- @perm.groups = []
520
- elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/groups'
521
- @sgroup = QEc2UserIdGroupPairType.new
522
- end
523
- end
390
+ @result = {} if name == 'ImportKeyPairResponse'
524
391
  end
525
392
  def tagend(name)
526
393
  case name
527
- when 'ownerId' then @group.ownerId = @text
528
- when 'groupDescription' then @group.groupDescription = @text
529
- when 'groupName'
530
- if @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item'
531
- @group.groupName = @text
532
- elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/groups/item'
533
- @sgroup.groupName = @text
534
- end
535
- when 'ipProtocol' then @perm.ipProtocol = @text
536
- when 'fromPort' then @perm.fromPort = @text
537
- when 'toPort' then @perm.toPort = @text
538
- when 'userId' then @sgroup.userId = @text
539
- when 'cidrIp' then @perm.ipRanges << @text
540
- when 'item'
541
- if @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/groups'
542
- @perm.groups << @sgroup
543
- elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions'
544
- @group.ipPermissions << @perm
545
- elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo'
546
- @result << @group
547
- end
394
+ when 'keyName' then @result[:aws_key_name] = @text
395
+ when 'keyFingerprint' then @result[:aws_fingerprint] = @text
548
396
  end
549
397
  end
550
- def reset
551
- @result = []
552
- end
553
398
  end
554
399
 
555
400
  #-----------------------------------------------------------------
@@ -568,7 +413,7 @@ module RightAws
568
413
  end
569
414
  def tagend(name)
570
415
  case name
571
- when 'instanceId' then @address[:instance_id] = @text.blank? ? nil : @text
416
+ when 'instanceId' then @address[:instance_id] = @text.right_blank? ? nil : @text
572
417
  when 'publicIp' then @address[:public_ip] = @text
573
418
  when 'item' then @result << @address
574
419
  end
@@ -584,14 +429,20 @@ module RightAws
584
429
 
585
430
  class QEc2DescribeAvailabilityZonesParser < RightAWSParser #:nodoc:
586
431
  def tagstart(name, attributes)
587
- @zone = {} if name == 'item'
432
+ case full_tag_name
433
+ when %r{/availabilityZoneInfo/item$} then @item = {}
434
+ end
588
435
  end
589
436
  def tagend(name)
590
437
  case name
591
- when 'regionName' then @zone[:region_name] = @text
592
- when 'zoneName' then @zone[:zone_name] = @text
593
- when 'zoneState' then @zone[:zone_state] = @text
594
- when 'item' then @result << @zone
438
+ when 'regionName' then @item[:region_name] = @text
439
+ when 'zoneName' then @item[:zone_name] = @text
440
+ when 'zoneState' then @item[:zone_state] = @text
441
+ else
442
+ case full_tag_name
443
+ when %r{/messageSet/item/message$} then (@item[:messages] ||= []) << @text
444
+ when %r{/availabilityZoneInfo/item$} then @result << @item
445
+ end
595
446
  end
596
447
  end
597
448
  def reset