2014-02-01 21:13:17 -05:00
|
|
|
require 'fog/aws/core'
|
2011-08-31 16:52:53 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class RDS < Fog::Service
|
2012-06-18 04:44:51 -04:00
|
|
|
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
2011-02-27 16:09:12 -05:00
|
|
|
|
|
|
|
class IdentifierTaken < Fog::Errors::Error; end
|
2012-10-11 17:02:26 -04:00
|
|
|
|
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
|
2013-07-02 13:34:48 -04:00
|
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :version
|
2011-02-27 16:09:12 -05:00
|
|
|
|
|
|
|
request_path 'fog/aws/requests/rds'
|
2012-10-02 13:35:12 -04:00
|
|
|
request :describe_events
|
2011-02-27 16:09:12 -05:00
|
|
|
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
|
|
|
|
2012-10-28 22:19:30 -04:00
|
|
|
request :add_tags_to_resource
|
|
|
|
request :list_tags_for_resource
|
|
|
|
request :remove_tags_from_resource
|
|
|
|
|
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
|
|
|
|
|
2012-10-11 17:02:26 -04:00
|
|
|
request :create_db_subnet_group
|
|
|
|
request :describe_db_subnet_groups
|
2013-12-02 01:08:21 -05:00
|
|
|
request :delete_db_subnet_group
|
|
|
|
# TODO: :modify_db_subnet_group
|
2012-10-11 17:02:26 -04:00
|
|
|
|
2013-07-08 18:36:58 -04:00
|
|
|
request :describe_orderable_db_instance_options
|
|
|
|
|
2013-07-06 15:48:41 -04:00
|
|
|
request :describe_db_log_files
|
2013-07-08 17:02:02 -04:00
|
|
|
request :download_db_logfile_portion
|
2014-05-26 09:44:18 -04:00
|
|
|
|
2014-04-15 17:33:16 -04:00
|
|
|
request :promote_read_replica
|
2013-07-06 15:48:41 -04:00
|
|
|
|
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
|
2013-07-08 20:19:20 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
model :snapshot
|
|
|
|
collection :snapshots
|
2013-07-08 20:19:20 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
model :parameter_group
|
|
|
|
collection :parameter_groups
|
|
|
|
|
|
|
|
model :parameter
|
|
|
|
collection :parameters
|
|
|
|
|
2011-03-08 11:11:38 -05:00
|
|
|
model :security_group
|
|
|
|
collection :security_groups
|
|
|
|
|
2012-10-11 17:02:26 -04:00
|
|
|
model :subnet_group
|
|
|
|
collection :subnet_groups
|
|
|
|
|
2013-07-08 20:19:20 -04:00
|
|
|
model :instance_option
|
|
|
|
collection :instance_options
|
|
|
|
|
2013-07-06 15:48:41 -04:00
|
|
|
model :log_file
|
|
|
|
collection :log_files
|
|
|
|
|
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|
|
|
|
|
hash[region] = Hash.new do |region_hash, key|
|
|
|
|
region_hash[key] = {
|
2011-12-27 17:37:04 -05:00
|
|
|
:servers => {},
|
2012-02-26 15:00:35 -05:00
|
|
|
:security_groups => {},
|
2012-10-11 17:02:26 -04:00
|
|
|
:subnet_groups => {},
|
2012-03-05 16:31:18 -05:00
|
|
|
:snapshots => {},
|
|
|
|
:parameter_groups => {"default.mysql5.1" => { "DBParameterGroupFamily"=>"mysql5.1",
|
|
|
|
"Description"=>"Default parameter group for mysql5.1",
|
|
|
|
"DBParameterGroupName"=>"default.mysql5.1"
|
|
|
|
},
|
|
|
|
"default.mysql5.5" => {"DBParameterGroupFamily"=>"mysql5.5",
|
|
|
|
"Description"=>"Default parameter group for mysql5.5",
|
|
|
|
"DBParameterGroupName"=>"default.mysql5.5"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-29 13:40:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-03 14:18:52 -04:00
|
|
|
|
2011-11-29 13:40:36 -05:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
2012-08-03 14:18:52 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def initialize(options={})
|
2012-06-18 04:44:51 -04:00
|
|
|
@use_iam_profile = options[:use_iam_profile]
|
2011-11-29 13:40:36 -05:00
|
|
|
@region = options[:region] || 'us-east-1'
|
2012-08-03 14:18:52 -04:00
|
|
|
|
2012-11-13 21:32:07 -05:00
|
|
|
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
|
2011-11-29 13:40:36 -05:00
|
|
|
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
|
|
|
end
|
|
|
|
end
|
2012-08-03 14:18:52 -04:00
|
|
|
|
2011-11-29 13:40:36 -05:00
|
|
|
def data
|
|
|
|
self.class.data[@region][@aws_access_key_id]
|
|
|
|
end
|
2012-08-03 14:18:52 -04:00
|
|
|
|
2011-11-29 13:40:36 -05:00
|
|
|
def reset_data
|
|
|
|
self.class.data[@region].delete(@aws_access_key_id)
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
2012-08-03 14:18:52 -04:00
|
|
|
|
2012-06-18 04:44:51 -04:00
|
|
|
def setup_credentials(options)
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
end
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
2012-10-28 22:17:01 -04:00
|
|
|
attr_reader :region
|
|
|
|
|
2012-06-18 04:44:51 -04:00
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
2011-02-27 16:09:12 -05:00
|
|
|
# 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={})
|
2012-06-18 04:44:51 -04:00
|
|
|
@use_iam_profile = options[:use_iam_profile]
|
|
|
|
setup_credentials(options)
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
2011-03-02 13:57:52 -05:00
|
|
|
|
2012-10-28 22:17:01 -04:00
|
|
|
@region = options[:region] || 'us-east-1'
|
|
|
|
@host = options[:host] || "rds.#{@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'
|
2014-02-26 19:50:35 -05:00
|
|
|
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
2013-11-14 11:11:29 -05:00
|
|
|
@version = options[:version] || '2013-05-15'
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
|
|
|
|
2012-10-28 22:17:01 -04:00
|
|
|
def owner_id
|
2012-11-16 16:07:01 -05:00
|
|
|
@owner_id ||= security_groups.get('default').owner_id
|
2012-10-28 22:17:01 -04:00
|
|
|
end
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2012-06-18 04:44:51 -04:00
|
|
|
def setup_credentials(options)
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
|
|
@aws_session_token = options[:aws_session_token]
|
|
|
|
@aws_credentials_expire_at = options[:aws_credentials_expire_at]
|
|
|
|
|
2012-10-11 17:02:26 -04:00
|
|
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
2012-06-18 04:44:51 -04:00
|
|
|
end
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def request(params)
|
2012-06-18 04:44:51 -04:00
|
|
|
refresh_credentials_if_expired
|
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
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,
|
[AWS] make beanstalk, cdn, cloudformation, cloudwatch, elasticache, elb, storage, rds, ses, sns, route53 temporary credential friendly
2012-06-20 18:16:34 -04:00
|
|
|
:aws_session_token => @aws_session_token,
|
2011-02-27 16:09:12 -05:00
|
|
|
:hmac => @hmac,
|
|
|
|
:host => @host,
|
|
|
|
:path => @path,
|
|
|
|
:port => @port,
|
2013-07-02 13:34:48 -04:00
|
|
|
:version => @version
|
2011-02-27 16:09:12 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
begin
|
2013-07-02 22:39:23 -04:00
|
|
|
@connection.request({
|
2011-02-27 16:09:12 -05:00
|
|
|
:body => body,
|
|
|
|
:expects => 200,
|
|
|
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
|
|
|
:idempotent => idempotent,
|
|
|
|
:method => 'POST',
|
|
|
|
:parser => parser
|
|
|
|
})
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2013-07-02 22:39:23 -04:00
|
|
|
match = Fog::AWS::Errors.match_error(error)
|
|
|
|
if match.empty?
|
2013-07-01 19:47:29 -04:00
|
|
|
case error.message
|
|
|
|
when 'Not Found'
|
|
|
|
raise Fog::AWS::RDS::NotFound.slurp(error, 'RDS Instance not found')
|
2011-02-27 16:09:12 -05:00
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
else
|
2013-07-02 22:39:23 -04:00
|
|
|
raise case match[:code]
|
|
|
|
when 'DBInstanceNotFound', 'DBParameterGroupNotFound', 'DBSnapshotNotFound', 'DBSecurityGroupNotFound'
|
|
|
|
Fog::AWS::RDS::NotFound.slurp(error, match[:message])
|
|
|
|
when 'DBParameterGroupAlreadyExists'
|
|
|
|
Fog::AWS::RDS::IdentifierTaken.slurp(error, match[:message])
|
|
|
|
when 'AuthorizationAlreadyExists'
|
|
|
|
Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[:message])
|
|
|
|
else
|
2013-07-03 13:00:07 -04:00
|
|
|
Fog::AWS::RDS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
2013-07-02 22:39:23 -04:00
|
|
|
end
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|