revans_right_aws 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/History.txt +284 -0
- data/Manifest.txt +50 -0
- data/README.txt +167 -0
- data/Rakefile +110 -0
- data/lib/acf/right_acf_interface.rb +485 -0
- data/lib/acf/right_acf_origin_access_identities.rb +230 -0
- data/lib/acf/right_acf_streaming_interface.rb +236 -0
- data/lib/acw/right_acw_interface.rb +249 -0
- data/lib/as/right_as_interface.rb +699 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/right_awsbase.rb +978 -0
- data/lib/awsbase/support.rb +115 -0
- data/lib/ec2/right_ec2.rb +395 -0
- data/lib/ec2/right_ec2_ebs.rb +452 -0
- data/lib/ec2/right_ec2_images.rb +373 -0
- data/lib/ec2/right_ec2_instances.rb +755 -0
- data/lib/ec2/right_ec2_monitoring.rb +70 -0
- data/lib/ec2/right_ec2_reserved_instances.rb +170 -0
- data/lib/ec2/right_ec2_security_groups.rb +277 -0
- data/lib/ec2/right_ec2_spot_instances.rb +399 -0
- data/lib/ec2/right_ec2_vpc.rb +571 -0
- data/lib/elb/right_elb_interface.rb +496 -0
- data/lib/rds/right_rds_interface.rb +998 -0
- data/lib/right_aws.rb +83 -0
- data/lib/s3/right_s3.rb +1126 -0
- data/lib/s3/right_s3_interface.rb +1199 -0
- data/lib/sdb/active_sdb.rb +1122 -0
- data/lib/sdb/right_sdb_interface.rb +721 -0
- data/lib/sqs/right_sqs.rb +388 -0
- data/lib/sqs/right_sqs_gen2.rb +343 -0
- data/lib/sqs/right_sqs_gen2_interface.rb +524 -0
- data/lib/sqs/right_sqs_interface.rb +594 -0
- data/test/acf/test_helper.rb +2 -0
- data/test/acf/test_right_acf.rb +138 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_right_ec2.rb +108 -0
- data/test/http_connection.rb +87 -0
- data/test/rds/test_helper.rb +2 -0
- data/test/rds/test_right_rds.rb +120 -0
- data/test/s3/test_helper.rb +2 -0
- data/test/s3/test_right_s3.rb +421 -0
- data/test/s3/test_right_s3_stubbed.rb +97 -0
- data/test/sdb/test_active_sdb.rb +357 -0
- data/test/sdb/test_helper.rb +3 -0
- data/test/sdb/test_right_sdb.rb +253 -0
- data/test/sqs/test_helper.rb +2 -0
- data/test/sqs/test_right_sqs.rb +291 -0
- data/test/sqs/test_right_sqs_gen2.rb +264 -0
- data/test/test_credentials.rb +37 -0
- data/test/ts_right_aws.rb +14 -0
- metadata +169 -0
@@ -0,0 +1,115 @@
|
|
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) || defined?(ActiveSupport::Inflector)
|
5
|
+
# These are ActiveSupport-;like extensions to do a few handy things in the gems
|
6
|
+
# Derived from ActiveSupport, so the AS copyright notice applies:
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Copyright (c) 2005 David Heinemeier Hansson
|
11
|
+
#
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
#
|
32
|
+
#
|
33
|
+
class String #:nodoc:
|
34
|
+
|
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
|
67
|
+
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
|
+
|
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
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,395 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2007-2009 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
|
24
|
+
module RightAws
|
25
|
+
|
26
|
+
# = RightAWS::EC2 -- RightScale Amazon EC2 interface
|
27
|
+
# The RightAws::EC2 class provides a complete interface to Amazon's
|
28
|
+
# Elastic Compute Cloud service, as well as the associated EBS (Elastic Block
|
29
|
+
# Store).
|
30
|
+
# For explanations of the semantics
|
31
|
+
# of each call, please refer to Amazon's documentation at
|
32
|
+
# http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=87
|
33
|
+
#
|
34
|
+
# Examples:
|
35
|
+
#
|
36
|
+
# Create an EC2 interface handle:
|
37
|
+
#
|
38
|
+
# @ec2 = RightAws::Ec2.new(aws_access_key_id,
|
39
|
+
# aws_secret_access_key)
|
40
|
+
# Create a new SSH key pair:
|
41
|
+
# @key = 'right_ec2_awesome_test_key'
|
42
|
+
# new_key = @ec2.create_key_pair(@key)
|
43
|
+
# keys = @ec2.describe_key_pairs
|
44
|
+
#
|
45
|
+
# Create a security group:
|
46
|
+
# @group = 'right_ec2_awesome_test_security_group'
|
47
|
+
# @ec2.create_security_group(@group,'My awesome test group')
|
48
|
+
# group = @ec2.describe_security_groups([@group])[0]
|
49
|
+
#
|
50
|
+
# Configure a security group:
|
51
|
+
# @ec2.authorize_security_group_named_ingress(@group, account_number, 'default')
|
52
|
+
# @ec2.authorize_security_group_IP_ingress(@group, 80,80,'udp','192.168.1.0/8')
|
53
|
+
#
|
54
|
+
# Describe the available images:
|
55
|
+
# images = @ec2.describe_images
|
56
|
+
#
|
57
|
+
# Launch an instance:
|
58
|
+
# ec2.run_instances('ami-9a9e7bf3', 1, 1, ['default'], @key, 'SomeImportantUserData', 'public')
|
59
|
+
#
|
60
|
+
#
|
61
|
+
# Describe running instances:
|
62
|
+
# @ec2.describe_instances
|
63
|
+
#
|
64
|
+
# Error handling: all operations raise an RightAws::AwsError in case
|
65
|
+
# of problems. Note that transient errors are automatically retried.
|
66
|
+
|
67
|
+
class Ec2 < RightAwsBase
|
68
|
+
include RightAwsBaseInterface
|
69
|
+
|
70
|
+
# Amazon EC2 API version being used
|
71
|
+
API_VERSION = "2009-11-30"
|
72
|
+
DEFAULT_HOST = "ec2.amazonaws.com"
|
73
|
+
DEFAULT_PATH = '/'
|
74
|
+
DEFAULT_PROTOCOL = 'https'
|
75
|
+
DEFAULT_PORT = 443
|
76
|
+
|
77
|
+
# Default addressing type (public=NAT, direct=no-NAT) used when launching instances.
|
78
|
+
DEFAULT_ADDRESSING_TYPE = 'public'
|
79
|
+
DNS_ADDRESSING_SET = ['public','direct']
|
80
|
+
|
81
|
+
# Amazon EC2 Instance Types : http://www.amazon.com/b?ie=UTF8&node=370375011
|
82
|
+
# Default EC2 instance type (platform)
|
83
|
+
DEFAULT_INSTANCE_TYPE = 'm1.small'
|
84
|
+
INSTANCE_TYPES = ['m1.small','c1.medium','m1.large','m1.xlarge','c1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge']
|
85
|
+
|
86
|
+
@@bench = AwsBenchmarkingBlock.new
|
87
|
+
def self.bench_xml
|
88
|
+
@@bench.xml
|
89
|
+
end
|
90
|
+
def self.bench_ec2
|
91
|
+
@@bench.service
|
92
|
+
end
|
93
|
+
|
94
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
95
|
+
@@api = ENV['EC2_API_VERSION'] || API_VERSION
|
96
|
+
def self.api
|
97
|
+
@@api
|
98
|
+
end
|
99
|
+
|
100
|
+
# Create a new handle to an EC2 account. All handles share the same per process or per thread
|
101
|
+
# HTTP connection to Amazon EC2. Each handle is for a specific account. The params have the
|
102
|
+
# following options:
|
103
|
+
# * <tt>:endpoint_url</tt> a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol and :region). Example: 'https://eu-west-1.ec2.amazonaws.com/'
|
104
|
+
# * <tt>:server</tt>: EC2 service host, default: DEFAULT_HOST
|
105
|
+
# * <tt>:region</tt>: EC2 region (North America by default)
|
106
|
+
# * <tt>:port</tt>: EC2 service port, default: DEFAULT_PORT
|
107
|
+
# * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
|
108
|
+
# * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
|
109
|
+
# * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
|
110
|
+
# * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
|
111
|
+
# * <tt>:cache</tt>: true/false: caching for: ec2_describe_images, describe_instances,
|
112
|
+
# describe_images_by_owner, describe_images_by_executable_by, describe_availability_zones,
|
113
|
+
# describe_security_groups, describe_key_pairs, describe_addresses,
|
114
|
+
# describe_volumes, describe_snapshots methods, default: false.
|
115
|
+
#
|
116
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
117
|
+
init({ :name => 'EC2',
|
118
|
+
:default_host => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).host : DEFAULT_HOST,
|
119
|
+
:default_port => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).port : DEFAULT_PORT,
|
120
|
+
:default_service => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).path : DEFAULT_PATH,
|
121
|
+
:default_protocol => ENV['EC2_URL'] ? URI.parse(ENV['EC2_URL']).scheme : DEFAULT_PROTOCOL,
|
122
|
+
:default_api_version => @@api },
|
123
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
|
124
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
125
|
+
params)
|
126
|
+
# Eucalyptus supports some yummy features but Amazon does not
|
127
|
+
if @params[:eucalyptus]
|
128
|
+
@params[:port_based_group_ingress] = true unless @params.has_key?(:port_based_group_ingress)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def generate_request(action, params={}) #:nodoc:
|
133
|
+
generate_request_impl(:get, action, params )
|
134
|
+
end
|
135
|
+
|
136
|
+
# Sends request to Amazon and parses the response
|
137
|
+
# Raises AwsError if any banana happened
|
138
|
+
def request_info(request, parser) #:nodoc:
|
139
|
+
request_info_impl(:ec2_connection, @@bench, request, parser)
|
140
|
+
end
|
141
|
+
|
142
|
+
#-----------------------------------------------------------------
|
143
|
+
# Keys
|
144
|
+
#-----------------------------------------------------------------
|
145
|
+
|
146
|
+
# Retrieve a list of SSH keys. Returns an array of keys or an exception. Each key is
|
147
|
+
# represented as a two-element hash.
|
148
|
+
#
|
149
|
+
# ec2.describe_key_pairs #=>
|
150
|
+
# [{: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"},
|
151
|
+
# {: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"},
|
152
|
+
# ..., {...} ]
|
153
|
+
#
|
154
|
+
def describe_key_pairs(*key_pairs)
|
155
|
+
key_pairs = key_pairs.flatten
|
156
|
+
link = generate_request("DescribeKeyPairs", amazonize_list('KeyName', key_pairs))
|
157
|
+
request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, @@bench, key_pairs.blank?
|
158
|
+
rescue Exception
|
159
|
+
on_exception
|
160
|
+
end
|
161
|
+
|
162
|
+
# Create new SSH key. Returns a hash of the key's data or an exception.
|
163
|
+
#
|
164
|
+
# ec2.create_key_pair('my_awesome_key') #=>
|
165
|
+
# {:aws_key_name => "my_awesome_key",
|
166
|
+
# :aws_fingerprint => "01:02:03:f4:25:e6:97:e8:9b:02:1a:26:32:4e:58:6b:7a:8c:9f:03",
|
167
|
+
# :aws_material => "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAK...Q8MDrCbuQ=\n-----END RSA PRIVATE KEY-----"}
|
168
|
+
#
|
169
|
+
def create_key_pair(name)
|
170
|
+
link = generate_request("CreateKeyPair",
|
171
|
+
'KeyName' => name.to_s)
|
172
|
+
request_info(link, QEc2CreateKeyPairParser.new(:logger => @logger))
|
173
|
+
rescue Exception
|
174
|
+
on_exception
|
175
|
+
end
|
176
|
+
|
177
|
+
# Delete a key pair. Returns +true+ or an exception.
|
178
|
+
#
|
179
|
+
# ec2.delete_key_pair('my_awesome_key') #=> true
|
180
|
+
#
|
181
|
+
def delete_key_pair(name)
|
182
|
+
link = generate_request("DeleteKeyPair",
|
183
|
+
'KeyName' => name.to_s)
|
184
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
185
|
+
rescue Exception
|
186
|
+
on_exception
|
187
|
+
end
|
188
|
+
|
189
|
+
#-----------------------------------------------------------------
|
190
|
+
# Elastic IPs
|
191
|
+
#-----------------------------------------------------------------
|
192
|
+
|
193
|
+
# Acquire a new elastic IP address for use with your account.
|
194
|
+
# Returns allocated IP address or an exception.
|
195
|
+
#
|
196
|
+
# ec2.allocate_address #=> '75.101.154.140'
|
197
|
+
#
|
198
|
+
def allocate_address
|
199
|
+
link = generate_request("AllocateAddress")
|
200
|
+
request_info(link, QEc2AllocateAddressParser.new(:logger => @logger))
|
201
|
+
rescue Exception
|
202
|
+
on_exception
|
203
|
+
end
|
204
|
+
|
205
|
+
# Associate an elastic IP address with an instance.
|
206
|
+
# Returns +true+ or an exception.
|
207
|
+
#
|
208
|
+
# ec2.associate_address('i-d630cbbf', '75.101.154.140') #=> true
|
209
|
+
#
|
210
|
+
def associate_address(instance_id, public_ip)
|
211
|
+
link = generate_request("AssociateAddress",
|
212
|
+
"InstanceId" => instance_id.to_s,
|
213
|
+
"PublicIp" => public_ip.to_s)
|
214
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
215
|
+
rescue Exception
|
216
|
+
on_exception
|
217
|
+
end
|
218
|
+
|
219
|
+
# List elastic IP addresses assigned to your account.
|
220
|
+
# Returns an array of 2 keys (:instance_id and :public_ip) hashes:
|
221
|
+
#
|
222
|
+
# ec2.describe_addresses #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"},
|
223
|
+
# {:instance_id=>nil, :public_ip=>"75.101.154.141"}]
|
224
|
+
#
|
225
|
+
# ec2.describe_addresses('75.101.154.140') #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"}]
|
226
|
+
#
|
227
|
+
def describe_addresses(*addresses)
|
228
|
+
addresses = addresses.flatten
|
229
|
+
link = generate_request("DescribeAddresses", amazonize_list('PublicIp', addresses))
|
230
|
+
request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, @@bench, addresses.blank?
|
231
|
+
rescue Exception
|
232
|
+
on_exception
|
233
|
+
end
|
234
|
+
|
235
|
+
# Disassociate the specified elastic IP address from the instance to which it is assigned.
|
236
|
+
# Returns +true+ or an exception.
|
237
|
+
#
|
238
|
+
# ec2.disassociate_address('75.101.154.140') #=> true
|
239
|
+
#
|
240
|
+
def disassociate_address(public_ip)
|
241
|
+
link = generate_request("DisassociateAddress",
|
242
|
+
"PublicIp" => public_ip.to_s)
|
243
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
244
|
+
rescue Exception
|
245
|
+
on_exception
|
246
|
+
end
|
247
|
+
|
248
|
+
# Release an elastic IP address associated with your account.
|
249
|
+
# Returns +true+ or an exception.
|
250
|
+
#
|
251
|
+
# ec2.release_address('75.101.154.140') #=> true
|
252
|
+
#
|
253
|
+
def release_address(public_ip)
|
254
|
+
link = generate_request("ReleaseAddress",
|
255
|
+
"PublicIp" => public_ip.to_s)
|
256
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
257
|
+
rescue Exception
|
258
|
+
on_exception
|
259
|
+
end
|
260
|
+
|
261
|
+
#-----------------------------------------------------------------
|
262
|
+
# Availability zones
|
263
|
+
#-----------------------------------------------------------------
|
264
|
+
|
265
|
+
# Describes availability zones that are currently available to the account and their states.
|
266
|
+
# Returns an array of 2 keys (:zone_name and :zone_state) hashes:
|
267
|
+
#
|
268
|
+
# ec2.describe_availability_zones #=> [{:region_name=>"us-east-1",
|
269
|
+
# :zone_name=>"us-east-1a",
|
270
|
+
# :zone_state=>"available"}, ... ]
|
271
|
+
#
|
272
|
+
# ec2.describe_availability_zones('us-east-1c') #=> [{:region_name=>"us-east-1",
|
273
|
+
# :zone_state=>"available",
|
274
|
+
# :zone_name=>"us-east-1c"}]
|
275
|
+
#
|
276
|
+
def describe_availability_zones(*availability_zones)
|
277
|
+
availability_zones = availability_zones.flatten
|
278
|
+
link = generate_request("DescribeAvailabilityZones", amazonize_list('ZoneName', availability_zones))
|
279
|
+
request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, @@bench, availability_zones.blank?
|
280
|
+
rescue Exception
|
281
|
+
on_exception
|
282
|
+
end
|
283
|
+
|
284
|
+
#-----------------------------------------------------------------
|
285
|
+
# Regions
|
286
|
+
#-----------------------------------------------------------------
|
287
|
+
|
288
|
+
# Describe regions.
|
289
|
+
#
|
290
|
+
# ec2.describe_regions #=> ["eu-west-1", "us-east-1"]
|
291
|
+
#
|
292
|
+
def describe_regions(*regions)
|
293
|
+
regions = regions.flatten
|
294
|
+
link = generate_request("DescribeRegions", amazonize_list('RegionName', regions))
|
295
|
+
request_cache_or_info :describe_regions, link, QEc2DescribeRegionsParser, @@bench, regions.blank?
|
296
|
+
rescue Exception
|
297
|
+
on_exception
|
298
|
+
end
|
299
|
+
|
300
|
+
#-----------------------------------------------------------------
|
301
|
+
# PARSERS: Key Pair
|
302
|
+
#-----------------------------------------------------------------
|
303
|
+
|
304
|
+
class QEc2DescribeKeyPairParser < RightAWSParser #:nodoc:
|
305
|
+
def tagstart(name, attributes)
|
306
|
+
@item = {} if name == 'item'
|
307
|
+
end
|
308
|
+
def tagend(name)
|
309
|
+
case name
|
310
|
+
when 'keyName' then @item[:aws_key_name] = @text
|
311
|
+
when 'keyFingerprint' then @item[:aws_fingerprint] = @text
|
312
|
+
when 'item' then @result << @item
|
313
|
+
end
|
314
|
+
end
|
315
|
+
def reset
|
316
|
+
@result = [];
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
class QEc2CreateKeyPairParser < RightAWSParser #:nodoc:
|
321
|
+
def tagstart(name, attributes)
|
322
|
+
@result = {} if name == 'CreateKeyPairResponse'
|
323
|
+
end
|
324
|
+
def tagend(name)
|
325
|
+
case name
|
326
|
+
when 'keyName' then @result[:aws_key_name] = @text
|
327
|
+
when 'keyFingerprint' then @result[:aws_fingerprint] = @text
|
328
|
+
when 'keyMaterial' then @result[:aws_material] = @text
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
#-----------------------------------------------------------------
|
334
|
+
# PARSERS: Elastic IPs
|
335
|
+
#-----------------------------------------------------------------
|
336
|
+
|
337
|
+
class QEc2AllocateAddressParser < RightAWSParser #:nodoc:
|
338
|
+
def tagend(name)
|
339
|
+
@result = @text if name == 'publicIp'
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
class QEc2DescribeAddressesParser < RightAWSParser #:nodoc:
|
344
|
+
def tagstart(name, attributes)
|
345
|
+
@address = {} if name == 'item'
|
346
|
+
end
|
347
|
+
def tagend(name)
|
348
|
+
case name
|
349
|
+
when 'instanceId' then @address[:instance_id] = @text.blank? ? nil : @text
|
350
|
+
when 'publicIp' then @address[:public_ip] = @text
|
351
|
+
when 'item' then @result << @address
|
352
|
+
end
|
353
|
+
end
|
354
|
+
def reset
|
355
|
+
@result = []
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
#-----------------------------------------------------------------
|
360
|
+
# PARSERS: AvailabilityZones
|
361
|
+
#-----------------------------------------------------------------
|
362
|
+
|
363
|
+
class QEc2DescribeAvailabilityZonesParser < RightAWSParser #:nodoc:
|
364
|
+
def tagstart(name, attributes)
|
365
|
+
@zone = {} if name == 'item'
|
366
|
+
end
|
367
|
+
def tagend(name)
|
368
|
+
case name
|
369
|
+
when 'regionName' then @zone[:region_name] = @text
|
370
|
+
when 'zoneName' then @zone[:zone_name] = @text
|
371
|
+
when 'zoneState' then @zone[:zone_state] = @text
|
372
|
+
when 'item' then @result << @zone
|
373
|
+
end
|
374
|
+
end
|
375
|
+
def reset
|
376
|
+
@result = []
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
#-----------------------------------------------------------------
|
381
|
+
# PARSERS: Regions
|
382
|
+
#-----------------------------------------------------------------
|
383
|
+
|
384
|
+
class QEc2DescribeRegionsParser < RightAWSParser #:nodoc:
|
385
|
+
def tagend(name)
|
386
|
+
@result << @text if name == 'regionName'
|
387
|
+
end
|
388
|
+
def reset
|
389
|
+
@result = []
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|