1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|elasticache] implement basic parameter group requests

This commit is contained in:
Benton Roberts 2011-09-22 20:13:37 -04:00 committed by geemus
parent 199693733b
commit 56d2c35fab
9 changed files with 250 additions and 3 deletions

View file

@ -16,12 +16,13 @@ module Fog
request :modify_cache_cluster
request :reboot_cache_cluster
#request :create_cache_parameter_group
#request :delete_cache_parameter_group
#request :describe_cache_parameter_groups
request :create_cache_parameter_group
request :delete_cache_parameter_group
request :describe_cache_parameter_groups
#request :modify_cache_parameter_group
#request :reset_cache_parameter_group
#request :describe_engine_default_parameters
#request :describe_cache_parameters
request :create_cache_security_group
request :delete_cache_security_group

View file

@ -0,0 +1,27 @@
module Fog
module Parsers
module AWS
module Elasticache
require 'fog/aws/parsers/elasticache/parameter_group_parser'
class DescribeParameterGroups < ParameterGroupParser
def reset
super
@response['CacheParameterGroups'] = []
end
def end_element(name)
case name
when 'CacheParameterGroup'
@response["#{name}s"] << @parameter_group
reset_parameter_group
else
super
end
end
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module AWS
module Elasticache
require 'fog/aws/parsers/elasticache/base'
class ParameterGroupParser < Base
def reset
super
reset_parameter_group
end
def reset_parameter_group
@parameter_group = {}
end
def end_element(name)
case name
when 'Description', 'CacheParameterGroupName', 'CacheParameterGroupFamily'
@parameter_group[name] = value
else
super
end
end
end
end
end
end
end

View file

@ -0,0 +1,22 @@
module Fog
module Parsers
module AWS
module Elasticache
require 'fog/aws/parsers/elasticache/parameter_group_parser'
class SingleParameterGroup < ParameterGroupParser
def end_element(name)
case name
when 'CacheParameterGroup'
@response[name] = @parameter_group
reset_parameter_group
else
super
end
end
end
end
end
end
end

View file

@ -0,0 +1,37 @@
module Fog
module AWS
class Elasticache
class Real
require 'fog/aws/parsers/elasticache/single_parameter_group'
# creates a cache parameter group
#
# === Parameters
# * name <~String> - The name for the Cache Parameter Group
# === Optional Parameters
# * description <~String> - The description for the Cache Parameter Group
# * family <~String> - The description for the Cache Parameter Group
# === Returns
# * response <~Excon::Response>:
# * body <~Hash>
def create_cache_parameter_group(name, description = name,
family = 'memcached1.4')
request({
'Action' => 'CreateCacheParameterGroup',
'CacheParameterGroupName' => name,
'Description' => description,
'CacheParameterGroupFamily' => family,
:parser => Fog::Parsers::AWS::Elasticache::SingleParameterGroup.new
})
end
end
class Mock
def create_cache_parameter_group(name, desciption=name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,31 @@
module Fog
module AWS
class Elasticache
class Real
require 'fog/aws/parsers/elasticache/base'
# deletes a cache parameter group
#
# === Parameters
# * name <~String> - The name for the Cache Parameter Group
# === Returns
# * response <~Excon::Response>:
# * body <~Hash>
def delete_cache_parameter_group(name)
request({
'Action' => 'DeleteCacheParameterGroup',
'CacheParameterGroupName' => name,
:parser => Fog::Parsers::AWS::Elasticache::Base.new
})
end
end
class Mock
def delete_cache_parameter_group(name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module AWS
class Elasticache
class Real
require 'fog/aws/parsers/elasticache/describe_parameter_groups'
# Returns a list of CacheParameterGroup descriptions
#
# === Parameters (optional)
# * name <~String> - The name of an existing cache parameter group
# * options <~Hash> (optional):
# * :marker <~String> - marker provided in the previous request
# * :max_records <~Integer> - the maximum number of records to include
def describe_cache_parameter_groups(name = nil, options = {})
request({
'Action' => 'DescribeCacheParameterGroups',
'CacheParameterGroupName' => name,
'Marker' => options[:marker],
'MaxRecords' => options[:max_records],
:parser => Fog::Parsers::AWS::Elasticache::DescribeParameterGroups.new
}.merge(options))
end
end
class Mock
def describe_cache_parameter_groups(name = nil, options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -16,6 +16,15 @@ class AWS
SINGLE_SECURITY_GROUP = BASIC.merge('CacheSecurityGroup' => SECURITY_GROUP)
DESCRIBE_SECURITY_GROUPS = BASIC.merge('CacheSecurityGroups' => [SECURITY_GROUP])
# Cache Parameter Groups
PARAMETER_GROUP = {
'CacheParameterGroupFamily' => String,
'CacheParameterGroupName' => String,
'Description' => String,
}
SINGLE_PARAMETER_GROUP = BASIC.merge('CacheParameterGroup' => PARAMETER_GROUP)
DESCRIBE_PARAMETER_GROUPS = BASIC.merge('CacheParameterGroups' => [PARAMETER_GROUP])
# Cache Clusters - more parameters get added as the lifecycle progresses
CACHE_CLUSTER = {
'AutoMinorVersionUpgrade' => String, # actually TrueClass or FalseClass

View file

@ -0,0 +1,56 @@
Shindo.tests('AWS::Elasticache | parameter group requests', ['aws', 'elasticache']) do
tests('success') do
pending if Fog.mocking?
name = 'fog-test'
description = 'Fog Test Parameter Group'
tests(
'#create_cache_parameter_group'
).formats(AWS::Elasticache::Formats::SINGLE_PARAMETER_GROUP) do
body = AWS[:elasticache].create_cache_parameter_group(name, description).body
group = body['CacheParameterGroup']
returns(name) { group['CacheParameterGroupName'] }
returns(description) { group['Description'] }
returns('memcached1.4') { group['CacheParameterGroupFamily'] }
body
end
tests(
'#describe_cache_parameter_groups without options'
).formats(AWS::Elasticache::Formats::DESCRIBE_PARAMETER_GROUPS) do
body = AWS[:elasticache].describe_cache_parameter_groups.body
returns(true, "has #{name}") do
body['CacheParameterGroups'].any? do |group|
group['CacheParameterGroupName'] == name
end
end
body
end
tests(
'#describe_cache_parameter_groups with name'
).formats(AWS::Elasticache::Formats::DESCRIBE_PARAMETER_GROUPS) do
body = AWS[:elasticache].describe_cache_parameter_groups(name).body
returns(1, "size of 1") { body['CacheParameterGroups'].size }
returns(name, "has #{name}") do
body['CacheParameterGroups'].first['CacheParameterGroupName']
end
body
end
tests(
'#delete_cache_parameter_group'
).formats(AWS::Elasticache::Formats::BASIC) do
body = AWS[:elasticache].delete_cache_parameter_group(name).body
end
end
tests('failure') do
# TODO:
# Create a duplicate parameter group
# List a missing parameter group
# Delete a missing parameter group
end
end