2011-09-27 10:48:38 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2011-09-02 12:49:21 -04:00
|
|
|
class Elasticache < Fog::Service
|
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
|
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
|
|
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent
|
|
|
|
|
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
|
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 Mock
|
|
|
|
def initalize(options={})
|
|
|
|
Fog::Mock.not_implemented
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
|
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
|
|
|
|
|
|
|
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
|
|
|
|
def request(params)
|
|
|
|
idempotent = params.delete(:idempotent)
|
|
|
|
parser = params.delete(:parser)
|
|
|
|
|
|
|
|
body = Fog::AWS.signed_params(
|
|
|
|
params,
|
|
|
|
{
|
|
|
|
:aws_access_key_id => @aws_access_key_id,
|
|
|
|
:hmac => @hmac,
|
|
|
|
:host => @host,
|
|
|
|
:path => @path,
|
|
|
|
:port => @port,
|
|
|
|
:version => '2011-07-15'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2011-07-13 17:18:58 -04:00
|
|
|
if match = error.message.match(/<Code>(.*)<\/Code>/m)
|
|
|
|
case match[1]
|
2011-09-23 18:04:07 -04:00
|
|
|
when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound',
|
|
|
|
'CacheClusterNotFound'
|
2011-09-08 14:18:27 -04:00
|
|
|
raise Fog::AWS::Elasticache::NotFound
|
2011-07-13 17:18:58 -04:00
|
|
|
when 'CacheSecurityGroupAlreadyExists'
|
2011-09-02 12:49:21 -04:00
|
|
|
raise Fog::AWS::Elasticache::IdentifierTaken
|
2011-07-13 17:18:58 -04:00
|
|
|
when 'InvalidParameterValue'
|
2011-09-02 12:49:21 -04:00
|
|
|
raise Fog::AWS::Elasticache::InvalidInstance
|
2011-07-13 17:18:58 -04:00
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
2011-09-27 10:52:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
response
|
2011-09-27 10:48:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|