2011-08-31 16:52:53 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'aws'))
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class RDS < Fog::Service
|
|
|
|
|
|
|
|
class IdentifierTaken < Fog::Errors::Error; end
|
2011-12-27 17:37:04 -05:00
|
|
|
|
|
|
|
class AuthorizationAlreadyExists < Fog::Errors::Error; end
|
2011-03-10 15:06:03 -05:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
requires :aws_access_key_id, :aws_secret_access_key
|
|
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent
|
|
|
|
|
|
|
|
request_path 'fog/aws/requests/rds'
|
|
|
|
|
|
|
|
request :create_db_instance
|
|
|
|
request :modify_db_instance
|
|
|
|
request :describe_db_instances
|
|
|
|
request :delete_db_instance
|
|
|
|
request :reboot_db_instance
|
|
|
|
request :create_db_instance_read_replica
|
2011-07-12 16:03:04 -04:00
|
|
|
request :describe_db_engine_versions
|
|
|
|
request :describe_db_reserved_instances
|
2011-03-10 15:06:03 -05:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
request :describe_db_snapshots
|
|
|
|
request :create_db_snapshot
|
|
|
|
request :delete_db_snapshot
|
|
|
|
|
|
|
|
|
|
|
|
request :create_db_parameter_group
|
|
|
|
request :delete_db_parameter_group
|
|
|
|
request :modify_db_parameter_group
|
|
|
|
request :describe_db_parameter_groups
|
|
|
|
|
2011-03-08 11:11:38 -05:00
|
|
|
request :describe_db_security_groups
|
|
|
|
request :create_db_security_group
|
|
|
|
request :delete_db_security_group
|
|
|
|
request :authorize_db_security_group_ingress
|
|
|
|
request :revoke_db_security_group_ingress
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
request :describe_db_parameters
|
2011-03-10 15:06:03 -05:00
|
|
|
|
|
|
|
request :restore_db_instance_from_db_snapshot
|
|
|
|
request :restore_db_instance_to_point_in_time
|
|
|
|
|
2011-05-11 15:27:27 -04:00
|
|
|
model_path 'fog/aws/models/rds'
|
2011-02-27 16:09:12 -05:00
|
|
|
model :server
|
|
|
|
collection :servers
|
|
|
|
model :snapshot
|
|
|
|
collection :snapshots
|
|
|
|
model :parameter_group
|
|
|
|
collection :parameter_groups
|
|
|
|
|
|
|
|
model :parameter
|
|
|
|
collection :parameters
|
|
|
|
|
2011-03-08 11:11:38 -05:00
|
|
|
model :security_group
|
|
|
|
collection :security_groups
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
class Mock
|
|
|
|
|
2011-11-29 13:40:36 -05:00
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, region|
|
|
|
|
owner_id = Fog::AWS::Mock.owner_id
|
|
|
|
hash[region] = Hash.new do |region_hash, key|
|
|
|
|
region_hash[key] = {
|
2011-12-27 17:37:04 -05:00
|
|
|
:servers => {},
|
|
|
|
:security_groups => {}
|
2011-11-29 13:40:36 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def initialize(options={})
|
2011-11-29 13:40:36 -05:00
|
|
|
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
|
|
|
|
@region = options[:region] || 'us-east-1'
|
|
|
|
|
|
|
|
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
|
|
|
|
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@region][@aws_access_key_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data[@region].delete(@aws_access_key_id)
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
2011-11-29 13:40:36 -05:00
|
|
|
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
# Initialize connection to ELB
|
|
|
|
#
|
|
|
|
# ==== Notes
|
|
|
|
# options parameter must include values for :aws_access_key_id and
|
|
|
|
# :aws_secret_access_key in order to create a connection
|
|
|
|
#
|
|
|
|
# ==== Examples
|
|
|
|
# elb = ELB.new(
|
|
|
|
# :aws_access_key_id => your_aws_access_key_id,
|
|
|
|
# :aws_secret_access_key => your_aws_secret_access_key
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
2012-02-02 17:02:51 -05:00
|
|
|
# * region<~String> - optional region to use. For instance, 'eu-west-1', 'us-east-1' and etc.
|
2011-02-27 16:09:12 -05:00
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * ELB object with connection to AWS.
|
|
|
|
def initialize(options={})
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
2011-02-27 16:09:12 -05:00
|
|
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
2011-03-02 13:57:52 -05:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
options[:region] ||= 'us-east-1'
|
2012-02-02 17:02:51 -05:00
|
|
|
@host = options[:host] || "rds.#{options[:region]}.amazonaws.com"
|
2011-09-12 11:01:48 -04:00
|
|
|
@path = options[:path] || '/'
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
idempotent = params.delete(:idempotent)
|
|
|
|
parser = params.delete(:parser)
|
|
|
|
|
2011-06-20 16:49:37 -04:00
|
|
|
body = Fog::AWS.signed_params(
|
2011-02-27 16:09:12 -05:00
|
|
|
params,
|
|
|
|
{
|
|
|
|
:aws_access_key_id => @aws_access_key_id,
|
|
|
|
:hmac => @hmac,
|
|
|
|
:host => @host,
|
|
|
|
:path => @path,
|
|
|
|
:port => @port,
|
2011-07-12 16:03:04 -04:00
|
|
|
:version => '2011-04-01' #'2010-07-28'
|
2011-02-27 16:09:12 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request({
|
|
|
|
:body => body,
|
|
|
|
:expects => 200,
|
|
|
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
|
|
|
:idempotent => idempotent,
|
|
|
|
:host => @host,
|
|
|
|
:method => 'POST',
|
|
|
|
:parser => parser
|
|
|
|
})
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
if match = error.message.match(/<Code>(.*)<\/Code>[\s\\\w]+<Message>(.*)<\/Message>/m)
|
|
|
|
case match[1].split('.').last
|
2011-04-11 16:02:59 -04:00
|
|
|
when 'DBInstanceNotFound', 'DBParameterGroupNotFound', 'DBSnapshotNotFound', 'DBSecurityGroupNotFound'
|
2011-02-27 16:09:12 -05:00
|
|
|
raise Fog::AWS::RDS::NotFound.slurp(error, match[2])
|
|
|
|
when 'DBParameterGroupAlreadyExists'
|
|
|
|
raise Fog::AWS::RDS::IdentifierTaken.slurp(error, match[2])
|
2011-12-27 17:37:04 -05:00
|
|
|
when 'AuthorizationAlreadyExists'
|
|
|
|
raise Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[2])
|
2011-02-27 16:09:12 -05:00
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|