aws 2.1.13 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -6
- data/lib/aws.rb +2 -0
- data/lib/awsbase/right_awsbase.rb +156 -1
- data/lib/ec2/right_ec2.rb +1 -1
- data/lib/elb/elb_interface.rb +4 -32
- data/lib/rds/rds.rb +127 -0
- data/lib/sdb/right_sdb_interface.rb +1 -32
- data/test/rds/test_rds.rb +70 -0
- data/test/test_credentials.rb +0 -2
- metadata +14 -2
data/README.markdown
CHANGED
@@ -8,7 +8,7 @@ The Appoxy AWS gem is a forked version of RightScale's AWS library.
|
|
8
8
|
1. It didn't work with Ruby 1.9 - this version does
|
9
9
|
1. RightScale doesn't have the source hosted for the community
|
10
10
|
1. We needed fixes and changes for [http://code.google.com/p/simple-record/ SimpleRecord] and didn't want to wait for RightScale to do it.
|
11
|
-
1. We needed
|
11
|
+
1. We needed support for new AWS services.
|
12
12
|
|
13
13
|
## Discussion Group
|
14
14
|
|
@@ -28,11 +28,6 @@ Published by Appoxy LLC, under the MIT License. Special thanks to RightScale fro
|
|
28
28
|
|
29
29
|
## INSTALL:
|
30
30
|
|
31
|
-
ONE TIME: Be sure to add the new gemcutter source:
|
32
|
-
|
33
|
-
gem install gemcutter
|
34
|
-
gem tumble
|
35
|
-
|
36
31
|
THEN (you should have http://gemcutter.org in your sources and it MUST be above rubyforge.org):
|
37
32
|
|
38
33
|
gem install aws
|
data/lib/aws.rb
CHANGED
@@ -27,6 +27,7 @@ module Aws
|
|
27
27
|
require 'pp'
|
28
28
|
require 'cgi'
|
29
29
|
require 'uri'
|
30
|
+
require 'xmlsimple'
|
30
31
|
|
31
32
|
class AwsUtils #:nodoc:
|
32
33
|
@@digest1 = OpenSSL::Digest::Digest.new("sha1")
|
@@ -269,6 +270,120 @@ module Aws
|
|
269
270
|
end
|
270
271
|
end
|
271
272
|
|
273
|
+
# FROM SDB
|
274
|
+
def generate_request2(aws_access_key, aws_secret_key, action, api_version, lib_params, user_params={}) #:nodoc:
|
275
|
+
# remove empty params from request
|
276
|
+
user_params.delete_if {|key, value| value.nil? }
|
277
|
+
#params_string = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
|
278
|
+
# prepare service data
|
279
|
+
service = lib_params[:service]
|
280
|
+
# puts 'service=' + service.to_s
|
281
|
+
service_hash = {"Action" => action,
|
282
|
+
"AWSAccessKeyId" => aws_access_key }
|
283
|
+
service_hash.update("Version" => api_version) if api_version
|
284
|
+
service_hash.update(user_params)
|
285
|
+
service_params = signed_service_params(aws_secret_key, service_hash, :get, lib_params[:server], lib_params[:service])
|
286
|
+
#
|
287
|
+
# use POST method if the length of the query string is too large
|
288
|
+
# see http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/MakingRESTRequests.html
|
289
|
+
if service_params.size > 2000
|
290
|
+
if signature_version == '2'
|
291
|
+
# resign the request because HTTP verb is included into signature
|
292
|
+
service_params = signed_service_params(aws_secret_key, service_hash, :post, lib_params[:server], service)
|
293
|
+
end
|
294
|
+
request = Net::HTTP::Post.new(service)
|
295
|
+
request.body = service_params
|
296
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
297
|
+
else
|
298
|
+
request = Net::HTTP::Get.new("#{service}?#{service_params}")
|
299
|
+
end
|
300
|
+
|
301
|
+
#puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
|
302
|
+
#puts "#{@params[:service]}?#{service_params}\n\n"
|
303
|
+
|
304
|
+
# prepare output hash
|
305
|
+
{ :request => request,
|
306
|
+
:server => lib_params[:server],
|
307
|
+
:port => lib_params[:port],
|
308
|
+
:protocol => lib_params[:protocol] }
|
309
|
+
end
|
310
|
+
|
311
|
+
def get_conn(connection_name, lib_params, logger)
|
312
|
+
thread = lib_params[:multi_thread] ? Thread.current : Thread.main
|
313
|
+
thread[connection_name] ||= Rightscale::HttpConnection.new(:exception => Aws::AwsError, :logger => logger)
|
314
|
+
conn = thread[connection_name]
|
315
|
+
return conn
|
316
|
+
end
|
317
|
+
|
318
|
+
def request_info2(request, parser, lib_params, connection_name, logger, bench)
|
319
|
+
t = get_conn(connection_name, lib_params, logger)
|
320
|
+
request_info_impl(t, bench, request, parser)
|
321
|
+
end
|
322
|
+
|
323
|
+
# This is the direction we should head instead of writing our own parsers for everything, much simpler
|
324
|
+
def request_info_xml_simple(connection_name, lib_params, request, logger)
|
325
|
+
|
326
|
+
@connection = get_conn(connection_name, lib_params, logger)
|
327
|
+
@last_request = request[:request]
|
328
|
+
@last_response = nil
|
329
|
+
response=nil
|
330
|
+
blockexception = nil
|
331
|
+
|
332
|
+
response = @connection.request(request)
|
333
|
+
# benchblock.service.add!{ response = @connection.request(request) }
|
334
|
+
# check response for errors...
|
335
|
+
@last_response = response
|
336
|
+
if response.is_a?(Net::HTTPSuccess)
|
337
|
+
@error_handler = nil
|
338
|
+
# benchblock.xml.add! { parser.parse(response) }
|
339
|
+
# return parser.result
|
340
|
+
return XmlSimple.xml_in(response.body, {"KeyToSymbol"=>false, 'ForceArray' => false})
|
341
|
+
else
|
342
|
+
@error_handler = AWSErrorHandler.new(self, nil, :errors_list => self.class.amazon_problems) unless @error_handler
|
343
|
+
check_result = @error_handler.check(request)
|
344
|
+
if check_result
|
345
|
+
@error_handler = nil
|
346
|
+
return check_result
|
347
|
+
end
|
348
|
+
request_text_data = "#{request[:server]}:#{request[:port]}#{request[:request].path}"
|
349
|
+
raise AwsError2.new(@last_response.code, @last_request_id, request_text_data, @last_response.body)
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
# FROM ELB
|
355
|
+
=begin
|
356
|
+
def generate_request2(action, params={})
|
357
|
+
service_hash = {"Action" => action,
|
358
|
+
"AWSAccessKeyId" => @aws_access_key_id,
|
359
|
+
"Version" => @@api }
|
360
|
+
service_hash.update(params)
|
361
|
+
service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
|
362
|
+
|
363
|
+
# use POST method if the length of the query string is too large
|
364
|
+
if service_params.size > 2000
|
365
|
+
if signature_version == '2'
|
366
|
+
# resign the request because HTTP verb is included into signature
|
367
|
+
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
|
368
|
+
end
|
369
|
+
request = Net::HTTP::Post.new(service)
|
370
|
+
request.body = service_params
|
371
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
372
|
+
else
|
373
|
+
request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
|
374
|
+
end
|
375
|
+
|
376
|
+
#puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
|
377
|
+
#puts "#{@params[:service]}?#{service_params}\n\n"
|
378
|
+
|
379
|
+
# prepare output hash
|
380
|
+
{ :request => request,
|
381
|
+
:server => @params[:server],
|
382
|
+
:port => @params[:port],
|
383
|
+
:protocol => @params[:protocol] }
|
384
|
+
end
|
385
|
+
=end
|
386
|
+
|
272
387
|
# Returns +true+ if the describe_xxx responses are being cached
|
273
388
|
def caching?
|
274
389
|
@params.key?(:cache) ? @params[:cache] : @@caching
|
@@ -443,11 +558,14 @@ module Aws
|
|
443
558
|
# Raw request text data to AWS
|
444
559
|
attr_reader :request_data
|
445
560
|
|
446
|
-
|
561
|
+
attr_reader :response
|
562
|
+
|
563
|
+
def initialize(errors=nil, http_code=nil, request_id=nil, request_data=nil, response=nil)
|
447
564
|
@errors = errors
|
448
565
|
@request_id = request_id
|
449
566
|
@http_code = http_code
|
450
567
|
@request_data = request_data
|
568
|
+
@response = response
|
451
569
|
msg = @errors.is_a?(Array) ? @errors.map{|code, msg| "#{code}: #{msg}"}.join("; ") : @errors.to_s
|
452
570
|
msg += "\nREQUEST(#{@request_data})" unless @request_data.nil?
|
453
571
|
super(msg)
|
@@ -479,6 +597,7 @@ module Aws
|
|
479
597
|
if options[:log]
|
480
598
|
request = aws.last_request ? aws.last_request.path : '-none-'
|
481
599
|
response = aws.last_response ? "#{aws.last_response.code} -- #{aws.last_response.message} -- #{aws.last_response.body}" : '-none-'
|
600
|
+
@response = response
|
482
601
|
aws.logger.error error_text
|
483
602
|
aws.logger.error "Request was: #{request}"
|
484
603
|
aws.logger.error "Response was: #{response}"
|
@@ -496,6 +615,42 @@ module Aws
|
|
496
615
|
|
497
616
|
end
|
498
617
|
|
618
|
+
# Simplified version
|
619
|
+
class AwsError2 < RuntimeError
|
620
|
+
# Request id (if exists)
|
621
|
+
attr_reader :request_id
|
622
|
+
|
623
|
+
# Response HTTP error code
|
624
|
+
attr_reader :http_code
|
625
|
+
|
626
|
+
# Raw request text data to AWS
|
627
|
+
attr_reader :request_data
|
628
|
+
|
629
|
+
attr_reader :response
|
630
|
+
|
631
|
+
attr_reader :errors
|
632
|
+
|
633
|
+
def initialize(http_code=nil, request_id=nil, request_data=nil, response=nil)
|
634
|
+
|
635
|
+
@request_id = request_id
|
636
|
+
@http_code = http_code
|
637
|
+
@request_data = request_data
|
638
|
+
@response = response
|
639
|
+
# puts '@response=' + @response.inspect
|
640
|
+
|
641
|
+
if @response
|
642
|
+
ref = XmlSimple.xml_in(@response, { "ForceArray"=>false })
|
643
|
+
# puts "refxml=" + ref.inspect
|
644
|
+
msg = "#{ref['Error']['Code']}: #{ref['Error']['Message']}"
|
645
|
+
else
|
646
|
+
msg = "#{@http_code}: REQUEST(#{@request_data})"
|
647
|
+
end
|
648
|
+
super(msg)
|
649
|
+
end
|
650
|
+
|
651
|
+
|
652
|
+
end
|
653
|
+
|
499
654
|
|
500
655
|
class AWSErrorHandler
|
501
656
|
# 0-100 (%)
|
data/lib/ec2/right_ec2.rb
CHANGED
@@ -144,7 +144,7 @@ module Aws
|
|
144
144
|
# resign the request because HTTP verb is included into signature
|
145
145
|
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
|
146
146
|
end
|
147
|
-
request
|
147
|
+
request = Net::HTTP::Post.new(@params[:service])
|
148
148
|
request.body = service_params
|
149
149
|
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
150
150
|
else
|
data/lib/elb/elb_interface.rb
CHANGED
@@ -24,7 +24,7 @@ module Aws
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# Current API version (sometimes we have to check it outside the GEM).
|
27
|
-
@@api = ENV['
|
27
|
+
@@api = ENV['ELB_API_VERSION'] || API_VERSION
|
28
28
|
|
29
29
|
def self.api
|
30
30
|
@@api
|
@@ -44,42 +44,14 @@ module Aws
|
|
44
44
|
|
45
45
|
|
46
46
|
def generate_request(action, params={})
|
47
|
-
|
48
|
-
"AWSAccessKeyId" => @aws_access_key_id,
|
49
|
-
"Version" => @@api }
|
50
|
-
service_hash.update(params)
|
51
|
-
service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
|
52
|
-
|
53
|
-
# use POST method if the length of the query string is too large
|
54
|
-
if service_params.size > 2000
|
55
|
-
if signature_version == '2'
|
56
|
-
# resign the request because HTTP verb is included into signature
|
57
|
-
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
|
58
|
-
end
|
59
|
-
request = Net::HTTP::Post.new(service)
|
60
|
-
request.body = service_params
|
61
|
-
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
62
|
-
else
|
63
|
-
request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
|
64
|
-
end
|
65
|
-
|
66
|
-
#puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
|
67
|
-
#puts "#{@params[:service]}?#{service_params}\n\n"
|
68
|
-
|
69
|
-
# prepare output hash
|
70
|
-
{ :request => request,
|
71
|
-
:server => @params[:server],
|
72
|
-
:port => @params[:port],
|
73
|
-
:protocol => @params[:protocol] }
|
47
|
+
generate_request2(@aws_access_key_id, @aws_secret_access_key, action, @@api, @params, params)
|
74
48
|
end
|
75
49
|
|
76
50
|
|
77
51
|
# Sends request to Amazon and parses the response
|
78
52
|
# Raises AwsError if any banana happened
|
79
53
|
def request_info(request, parser)
|
80
|
-
|
81
|
-
thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => Aws::AwsError, :logger => @logger)
|
82
|
-
request_info_impl(thread[:elb_connection], @@bench, request, parser)
|
54
|
+
request_info2(request, parser, @params, :elb_connection, @logger, @@bench)
|
83
55
|
end
|
84
56
|
|
85
57
|
|
@@ -309,7 +281,7 @@ module Aws
|
|
309
281
|
# puts 'tagstart ' + name + ' -- ' + @xmlpath
|
310
282
|
if (name == 'member' &&
|
311
283
|
(@xmlpath == 'RegisterInstancesWithLoadBalancerResponse/RegisterInstancesWithLoadBalancerResult/Instances' ||
|
312
|
-
|
284
|
+
@xmlpath == 'DeregisterInstancesFromLoadBalancerResponse/DeregisterInstancesFromLoadBalancerResult/Instances')
|
313
285
|
)
|
314
286
|
@member = { }
|
315
287
|
end
|
data/lib/rds/rds.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
|
4
|
+
require 'xmlsimple'
|
5
|
+
|
6
|
+
# API Reference: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
|
7
|
+
class Rds < AwsBase
|
8
|
+
include AwsBaseInterface
|
9
|
+
|
10
|
+
|
11
|
+
# Amazon API version being used
|
12
|
+
API_VERSION = nil
|
13
|
+
DEFAULT_HOST = "rds.amazonaws.com"
|
14
|
+
DEFAULT_PATH = '/'
|
15
|
+
DEFAULT_PROTOCOL = 'https'
|
16
|
+
DEFAULT_PORT = 443
|
17
|
+
|
18
|
+
@@api = ENV['RDS_API_VERSION'] || API_VERSION
|
19
|
+
|
20
|
+
def self.api
|
21
|
+
@@api
|
22
|
+
end
|
23
|
+
|
24
|
+
@@bench = AwsBenchmarkingBlock.new
|
25
|
+
|
26
|
+
def self.bench_xml
|
27
|
+
@@bench.xml
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bench_ec2
|
31
|
+
@@bench.service
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
35
|
+
uri = ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']) : nil
|
36
|
+
init({ :name => 'RDS',
|
37
|
+
:default_host => uri ? uri.host : DEFAULT_HOST,
|
38
|
+
:default_port => uri ? uri.port : DEFAULT_PORT,
|
39
|
+
:default_service => uri ? uri.path : DEFAULT_PATH,
|
40
|
+
:default_protocol => uri ? uri.scheme : DEFAULT_PROTOCOL },
|
41
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
42
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
43
|
+
params)
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_request(action, params={})
|
47
|
+
generate_request2(@aws_access_key_id, @aws_secret_access_key, action, @@api, @params, params)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
#-----------------------------------------------------------------
|
52
|
+
# REQUESTS
|
53
|
+
#-----------------------------------------------------------------
|
54
|
+
|
55
|
+
#
|
56
|
+
# identifier: db instance identifier. Must be unique per account per zone.
|
57
|
+
# instance_class: db.m1.small | db.m1.large | db.m1.xlarge | db.m2.2xlarge | db.m2.4xlarge
|
58
|
+
# See this for other values: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
|
59
|
+
#
|
60
|
+
# options:
|
61
|
+
# db_name: if you want a database created at the same time as the instance, specify :db_name option.
|
62
|
+
# availability_zone: default is random zone.
|
63
|
+
def create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options={})
|
64
|
+
params = {}
|
65
|
+
params['DBInstanceIdentifier'] = identifier
|
66
|
+
params['DBInstanceClass'] = instance_class
|
67
|
+
params['AllocatedStorage'] = allocated_storage
|
68
|
+
params['MasterUsername'] = master_username
|
69
|
+
params['MasterUserPassword'] = master_password
|
70
|
+
|
71
|
+
params['Engine'] = options[:engine] || "MySQL5.1"
|
72
|
+
params['DBName'] = options[:db_name] if options[:db_name]
|
73
|
+
params['AvailabilityZone'] = options[:availability_zone] if options[:availability_zone]
|
74
|
+
params['PreferredMaintenanceWindow'] = options[:preferred_maintenance_window] if options[:preferred_maintenance_window]
|
75
|
+
params['BackupRetentionPeriod'] = options[:preferred_retention_period] if options[:preferred_retention_period]
|
76
|
+
params['PreferredBackupWindow'] = options[:preferred_backup_window] if options[:preferred_backup_window]
|
77
|
+
|
78
|
+
@logger.info("Creating DB Instance called #{identifier}")
|
79
|
+
|
80
|
+
link = generate_request("CreateDBInstance", params)
|
81
|
+
resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
|
82
|
+
|
83
|
+
rescue Exception
|
84
|
+
on_exception
|
85
|
+
end
|
86
|
+
|
87
|
+
# options:
|
88
|
+
# DBInstanceIdentifier
|
89
|
+
# MaxRecords
|
90
|
+
# Marker
|
91
|
+
def describe_db_instances(options={})
|
92
|
+
params = {}
|
93
|
+
params['DBInstanceIdentifier'] = options[:DBInstanceIdentifier] if options[:DBInstanceIdentifier]
|
94
|
+
params['MaxRecords'] = options[:MaxRecords] if options[:MaxRecords]
|
95
|
+
params['Marker'] = options[:Marker] if options[:Marker]
|
96
|
+
|
97
|
+
link = generate_request("DescribeDBInstances", params)
|
98
|
+
resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
|
99
|
+
|
100
|
+
rescue Exception
|
101
|
+
on_exception
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# identifier: identifier of db instance to delete.
|
106
|
+
# final_snapshot_identifier: if specified, RDS will crate a final snapshot before deleting so you can restore it later.
|
107
|
+
def delete_db_instance(identifier, final_snapshot_identifier=nil)
|
108
|
+
@logger.info("Deleting DB Instance - " + identifier.to_s)
|
109
|
+
|
110
|
+
params = {}
|
111
|
+
params['DBInstanceIdentifier'] = identifier
|
112
|
+
if final_snapshot_identifier
|
113
|
+
params['FinalDBSnapshotIdentifier'] = final_snapshot_identifier
|
114
|
+
else
|
115
|
+
params['SkipFinalSnapshot'] = true
|
116
|
+
end
|
117
|
+
|
118
|
+
link = generate_request("DeleteDBInstance", params)
|
119
|
+
resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
|
120
|
+
|
121
|
+
rescue Exception
|
122
|
+
on_exception
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -82,38 +82,7 @@ module Aws
|
|
82
82
|
#-----------------------------------------------------------------
|
83
83
|
# Requests
|
84
84
|
#-----------------------------------------------------------------
|
85
|
-
|
86
|
-
# remove empty params from request
|
87
|
-
params.delete_if {|key,value| value.nil? }
|
88
|
-
#params_string = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
|
89
|
-
# prepare service data
|
90
|
-
service = @params[:service]
|
91
|
-
# puts 'service=' + service.to_s
|
92
|
-
service_hash = {"Action" => action,
|
93
|
-
"AWSAccessKeyId" => @aws_access_key_id,
|
94
|
-
"Version" => API_VERSION }
|
95
|
-
service_hash.update(params)
|
96
|
-
service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
|
97
|
-
#
|
98
|
-
# use POST method if the length of the query string is too large
|
99
|
-
# see http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/MakingRESTRequests.html
|
100
|
-
if service_params.size > 2000
|
101
|
-
if signature_version == '2'
|
102
|
-
# resign the request because HTTP verb is included into signature
|
103
|
-
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], service)
|
104
|
-
end
|
105
|
-
request = Net::HTTP::Post.new(service)
|
106
|
-
request.body = service_params
|
107
|
-
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
108
|
-
else
|
109
|
-
request = Net::HTTP::Get.new("#{service}?#{service_params}")
|
110
|
-
end
|
111
|
-
# prepare output hash
|
112
|
-
{ :request => request,
|
113
|
-
:server => @params[:server],
|
114
|
-
:port => @params[:port],
|
115
|
-
:protocol => @params[:protocol] }
|
116
|
-
end
|
85
|
+
|
117
86
|
|
118
87
|
# Sends request to Amazon and parses the response
|
119
88
|
# Raises AwsError if any banana happened
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../../lib/aws'
|
3
|
+
require 'rds/rds'
|
4
|
+
require 'pp'
|
5
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
6
|
+
|
7
|
+
class TestElb < Test::Unit::TestCase
|
8
|
+
|
9
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
10
|
+
# are not tested here due to their potentially risk.
|
11
|
+
|
12
|
+
def setup
|
13
|
+
TestCredentials.get_credentials
|
14
|
+
|
15
|
+
@rds = Aws::Rds.new(TestCredentials.aws_access_key_id,
|
16
|
+
TestCredentials.aws_secret_access_key)
|
17
|
+
|
18
|
+
@identifier = 'my-db-instance'
|
19
|
+
@identifier2 = 'my-db-instance2'
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_01_create_db_instance
|
24
|
+
|
25
|
+
|
26
|
+
begin
|
27
|
+
db_instance2 = @rds.create_db_instance('right_ec2_awesome_test_key', "db.m1.small", 5, "master", "masterpass")
|
28
|
+
rescue => ex
|
29
|
+
puts "msg=" + ex.message
|
30
|
+
puts "response=" + ex.response
|
31
|
+
assert ex.message[0,"InvalidParameterValue".size] == "InvalidParameterValue"
|
32
|
+
end
|
33
|
+
|
34
|
+
db_instance = @rds.create_db_instance(@identifier, "db.m1.small", 5, "master", "masterpass")
|
35
|
+
puts 'db_instance=' + db_instance.inspect
|
36
|
+
|
37
|
+
db_instance2 = @rds.create_db_instance(@identifier2, "db.m1.small", 5, "master", "masterpass")
|
38
|
+
puts 'db_instance2=' + db_instance2.inspect
|
39
|
+
|
40
|
+
sleep 10
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_02_describe_db_instances
|
46
|
+
instances_result = @rds.describe_db_instances
|
47
|
+
puts "instances_result=" + instances_result.inspect
|
48
|
+
instances = instances_result["DescribeDBInstancesResult"]["DBInstances"]["DBInstance"]
|
49
|
+
puts 'instances=' + instances.inspect
|
50
|
+
assert instances.size == 2
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_06_delete_db_instance
|
54
|
+
|
55
|
+
@rds.delete_db_instance(@identifier)
|
56
|
+
@rds.delete_db_instance(@identifier2)
|
57
|
+
|
58
|
+
sleep 2
|
59
|
+
|
60
|
+
instances_result = @rds.describe_db_instances
|
61
|
+
puts "instances_result=" + instances_result.inspect
|
62
|
+
instances_result["DescribeDBInstancesResult"]["DBInstances"]["DBInstance"].each do |i|
|
63
|
+
assert i["DBInstanceStatus"] == "deleting"
|
64
|
+
end
|
65
|
+
# assert instances_result["DescribeDBInstancesResult"]["DBInstances"]["DBInstance"].size == 0
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
data/test/test_credentials.rb
CHANGED
@@ -42,10 +42,8 @@ class TestCredentials
|
|
42
42
|
Dir.chdir(File.expand_path("~/.test-configs")) do
|
43
43
|
credentials = YAML::load(File.open("aws.yml"))
|
44
44
|
@@config = credentials
|
45
|
-
puts 'creds=' + credentials.inspect
|
46
45
|
self.aws_access_key_id = credentials["amazon"]["access_key"]
|
47
46
|
self.aws_secret_access_key = credentials["amazon"]["secret_key"]
|
48
|
-
puts 'akey=' + self.aws_access_key_id
|
49
47
|
end
|
50
48
|
rescue Exception => e
|
51
49
|
puts "#{e.message}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2010-02-
|
14
|
+
date: 2010-02-02 00:00:00 -08:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,16 @@ dependencies:
|
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: "0"
|
36
36
|
version:
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: xml-simple
|
39
|
+
type: :runtime
|
40
|
+
version_requirement:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
37
47
|
description: AWS Ruby Library for interfacing with Amazon Web Services.
|
38
48
|
email: travis@appoxy.com
|
39
49
|
executables: []
|
@@ -51,6 +61,7 @@ files:
|
|
51
61
|
- lib/ec2/right_ec2.rb
|
52
62
|
- lib/ec2/right_mon_interface.rb
|
53
63
|
- lib/elb/elb_interface.rb
|
64
|
+
- lib/rds/rds.rb
|
54
65
|
- lib/right_aws.rb
|
55
66
|
- lib/s3/right_s3.rb
|
56
67
|
- lib/s3/right_s3_interface.rb
|
@@ -95,6 +106,7 @@ test_files:
|
|
95
106
|
- test/ec2/test_right_ec2.rb
|
96
107
|
- test/elb/test_elb.rb
|
97
108
|
- test/http_connection.rb
|
109
|
+
- test/rds/test_rds.rb
|
98
110
|
- test/s3/test_helper.rb
|
99
111
|
- test/s3/test_right_s3.rb
|
100
112
|
- test/s3/test_right_s3_stubbed.rb
|