2011-09-27 10:48:38 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2011-09-02 12:49:21 -04:00
|
|
|
class Elasticache < Fog::Service
|
2012-06-18 04:44:51 -04:00
|
|
|
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-07-14 10:45:52 -04:00
|
|
|
class IdentifierTaken < Fog::Errors::Error; end
|
2011-09-15 12:06:04 -04:00
|
|
|
class InvalidInstance < Fog::Errors::Error; end
|
2013-08-20 05:18:58 -04:00
|
|
|
class AuthorizationAlreadyExists < Fog::Errors::Error; end
|
2011-07-14 10:45:52 -04:00
|
|
|
|
2011-09-27 10:48:38 -04:00
|
|
|
requires :aws_access_key_id, :aws_secret_access_key
|
2012-06-18 04:44:51 -04:00
|
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-09-27 11:03:11 -04:00
|
|
|
request_path 'fog/aws/requests/elasticache'
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-09-06 15:51:30 -04:00
|
|
|
request :create_cache_cluster
|
2011-09-06 16:46:12 -04:00
|
|
|
request :delete_cache_cluster
|
2011-09-06 15:51:30 -04:00
|
|
|
request :describe_cache_clusters
|
2011-09-09 15:33:48 -04:00
|
|
|
request :modify_cache_cluster
|
2011-09-21 21:03:42 -04:00
|
|
|
request :reboot_cache_cluster
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-09-22 20:13:37 -04:00
|
|
|
request :create_cache_parameter_group
|
|
|
|
request :delete_cache_parameter_group
|
|
|
|
request :describe_cache_parameter_groups
|
2011-09-23 19:40:32 -04:00
|
|
|
request :modify_cache_parameter_group
|
2011-09-26 09:52:17 -04:00
|
|
|
request :reset_cache_parameter_group
|
2011-09-23 18:00:50 -04:00
|
|
|
request :describe_engine_default_parameters
|
2011-09-26 10:39:34 -04:00
|
|
|
request :describe_cache_parameters
|
2013-01-16 19:41:15 -05:00
|
|
|
request :describe_reserved_cache_nodes
|
2011-09-27 10:48:38 -04:00
|
|
|
|
|
|
|
request :create_cache_security_group
|
2011-09-27 10:52:46 -04:00
|
|
|
request :delete_cache_security_group
|
|
|
|
request :describe_cache_security_groups
|
|
|
|
request :authorize_cache_security_group_ingress
|
|
|
|
request :revoke_cache_security_group_ingress
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-09-21 21:59:17 -04:00
|
|
|
request :describe_events
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-09-27 11:03:11 -04:00
|
|
|
model_path 'fog/aws/models/elasticache'
|
2011-09-07 16:22:31 -04:00
|
|
|
model :cluster
|
|
|
|
collection :clusters
|
2011-07-13 17:18:58 -04:00
|
|
|
model :security_group
|
|
|
|
collection :security_groups
|
2011-09-23 18:04:07 -04:00
|
|
|
model :parameter_group
|
|
|
|
collection :parameter_groups
|
2011-09-27 10:48:38 -04:00
|
|
|
|
|
|
|
class Real
|
2012-06-18 04:44:51 -04:00
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
2011-09-27 10:48:38 -04:00
|
|
|
def initialize(options={})
|
2012-06-18 04:44:51 -04:00
|
|
|
@use_iam_profile = options[:use_iam_profile]
|
|
|
|
setup_credentials(options)
|
2011-09-27 10:48:38 -04:00
|
|
|
|
|
|
|
options[:region] ||= 'us-east-1'
|
2012-02-02 15:58:34 -05:00
|
|
|
@host = options[:host] || "elasticache.#{options[:region]}.amazonaws.com"
|
2011-09-27 10:52:46 -04:00
|
|
|
@path = options[:path] || '/'
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2011-09-02 12:49:21 -04:00
|
|
|
@connection = Fog::Connection.new(
|
|
|
|
"#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]
|
|
|
|
)
|
2011-09-27 10:48:38 -04:00
|
|
|
end
|
|
|
|
|
2011-09-27 10:52:46 -04:00
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
2011-09-27 10:48:38 -04:00
|
|
|
|
2011-09-27 10:52:46 -04:00
|
|
|
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]
|
|
|
|
|
|
|
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
|
|
|
end
|
|
|
|
|
2011-09-27 10:52:46 -04:00
|
|
|
def request(params)
|
2012-06-18 04:44:51 -04:00
|
|
|
refresh_credentials_if_expired
|
|
|
|
|
2011-09-27 10:52:46 -04:00
|
|
|
idempotent = params.delete(:idempotent)
|
|
|
|
parser = params.delete(:parser)
|
|
|
|
|
|
|
|
body = Fog::AWS.signed_params(
|
|
|
|
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-09-27 10:52:46 -04:00
|
|
|
:hmac => @hmac,
|
|
|
|
:host => @host,
|
|
|
|
:path => @path,
|
|
|
|
:port => @port,
|
2013-01-16 19:41:15 -05:00
|
|
|
#:version => '2011-07-15'
|
|
|
|
:version => '2012-11-15'
|
2011-09-27 10:52:46 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
begin
|
2013-07-02 22:39:23 -04:00
|
|
|
@connection.request({
|
2011-09-27 10:52:46 -04:00
|
|
|
: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
|
2013-07-02 22:39:23 -04:00
|
|
|
match = Fog::AWS::Errors.match_error(error)
|
|
|
|
raise if match.empty?
|
|
|
|
raise case match[:code]
|
|
|
|
when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', 'CacheClusterNotFound'
|
|
|
|
Fog::AWS::Elasticache::NotFound.slurp(error, match[:message])
|
|
|
|
when 'CacheSecurityGroupAlreadyExists'
|
|
|
|
Fog::AWS::Elasticache::IdentifierTaken.slurp(error, match[:message])
|
|
|
|
when 'InvalidParameterValue'
|
|
|
|
Fog::AWS::Elasticache::InvalidInstance.slurp(error, match[:message])
|
|
|
|
else
|
2013-07-03 13:00:07 -04:00
|
|
|
Fog::AWS::Elasticache::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
2013-07-02 22:39:23 -04:00
|
|
|
end
|
2011-09-27 10:52:46 -04:00
|
|
|
end
|
|
|
|
|
2011-09-27 10:48:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-07-26 20:08:10 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, region|
|
|
|
|
hash[region] = Hash.new do |region_hash, key|
|
|
|
|
region_hash[key] = {
|
|
|
|
:clusters => {}, # cache cluster data, indexed by cluster ID
|
2013-08-19 18:02:43 -04:00
|
|
|
:security_groups => {}, # security groups
|
2012-07-26 20:08:10 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@aws_credentials_expire_at = Time::now + 20
|
|
|
|
setup_credentials(options)
|
|
|
|
@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', 'sa-east-1'].include?(@region)
|
|
|
|
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def region_data
|
|
|
|
self.class.data[@region]
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.region_data[@aws_access_key_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.region_data.delete(@aws_access_key_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_credentials(options)
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
# returns an Array of (Mock) elasticache nodes, representated as Hashes
|
|
|
|
def create_cache_nodes(cluster_id, num_nodes = 1, port = '11211')
|
|
|
|
(1..num_nodes).map do |node_number|
|
|
|
|
node_id = "%04d" % node_number
|
|
|
|
{ # each hash represents a cache cluster node
|
|
|
|
"CacheNodeId" => node_id,
|
|
|
|
"Port" => port,
|
|
|
|
"ParameterGroupStatus" => "in-sync",
|
|
|
|
"CacheNodeStatus" => "available",
|
|
|
|
"CacheNodeCreateTime" => Time.now.utc.to_s,
|
|
|
|
"Address" =>
|
|
|
|
"#{cluster_id}.#{node_id}.use1.cache.amazonaws.com"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-09-27 10:48:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|