From f397bf50ec02ef2a6d88fca3e1b7b75d8a639342 Mon Sep 17 00:00:00 2001 From: Benton Roberts Date: Fri, 23 Sep 2011 18:04:07 -0400 Subject: [PATCH] [aws|elasticache] implement Elasticache::ParameterGroup model and collection --- lib/fog/aws/elasticache.rb | 9 +++--- .../aws/models/elasticache/parameter_group.rb | 32 +++++++++++++++++++ .../models/elasticache/parameter_groups.rb | 30 +++++++++++++++++ .../create_cache_parameter_group.rb | 6 ++-- .../elasticache/parameter_groups_tests.rb | 17 ++++++++++ 5 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 lib/fog/aws/models/elasticache/parameter_group.rb create mode 100644 lib/fog/aws/models/elasticache/parameter_groups.rb create mode 100644 tests/aws/models/elasticache/parameter_groups_tests.rb diff --git a/lib/fog/aws/elasticache.rb b/lib/fog/aws/elasticache.rb index c7b048615..1dc90b9d9 100644 --- a/lib/fog/aws/elasticache.rb +++ b/lib/fog/aws/elasticache.rb @@ -37,8 +37,8 @@ module Fog collection :clusters model :security_group collection :security_groups - # model :parameter_group - # collection :parameter_groups + model :parameter_group + collection :parameter_groups class Mock def initalize(options={}) @@ -103,9 +103,8 @@ module Fog rescue Excon::Errors::HTTPStatusError => error if match = error.message.match(/(.*)<\/Code>/m) case match[1] - when 'CacheSecurityGroupNotFound' - raise Fog::AWS::Elasticache::NotFound - when 'CacheClusterNotFound' + when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', + 'CacheClusterNotFound' raise Fog::AWS::Elasticache::NotFound when 'CacheSecurityGroupAlreadyExists' raise Fog::AWS::Elasticache::IdentifierTaken diff --git a/lib/fog/aws/models/elasticache/parameter_group.rb b/lib/fog/aws/models/elasticache/parameter_group.rb new file mode 100644 index 000000000..67054d702 --- /dev/null +++ b/lib/fog/aws/models/elasticache/parameter_group.rb @@ -0,0 +1,32 @@ +require 'fog/core/model' + +module Fog + module AWS + class Elasticache + + class ParameterGroup < Fog::Model + + identity :id, :aliases => 'CacheParameterGroupName' + attribute :description, :aliases => 'Description' + attribute :family, :aliases => 'CacheParameterGroupFamily' + + def destroy + requires :id + connection.delete_cache_parameter_group(id) + true + end + + def save + requires :id + connection.create_cache_parameter_group( + id, + description = id, + family = 'memcached1.4' + ) + end + + end + + end + end +end diff --git a/lib/fog/aws/models/elasticache/parameter_groups.rb b/lib/fog/aws/models/elasticache/parameter_groups.rb new file mode 100644 index 000000000..2eceef459 --- /dev/null +++ b/lib/fog/aws/models/elasticache/parameter_groups.rb @@ -0,0 +1,30 @@ +require 'fog/core/collection' +require 'fog/aws/models/elasticache/parameter_group' + +module Fog + module AWS + class Elasticache + + class ParameterGroups < Fog::Collection + model Fog::AWS::Elasticache::ParameterGroup + + def all + load( + connection.describe_cache_parameter_groups.body['CacheParameterGroups'] + ) + end + + def get(identity) + new( + connection.describe_cache_parameter_groups( + identity + ).body['CacheParameterGroups'].first + ) + rescue Fog::AWS::Elasticache::NotFound + nil + end + end + + end + end +end diff --git a/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb b/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb index 61722c87c..cb9ffdab7 100644 --- a/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb +++ b/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb @@ -15,8 +15,7 @@ module Fog # === Returns # * response <~Excon::Response>: # * body <~Hash> - def create_cache_parameter_group(name, description = name, - family = 'memcached1.4') + def create_cache_parameter_group(name, description = name, family = 'memcached1.4') request({ 'Action' => 'CreateCacheParameterGroup', 'CacheParameterGroupName' => name, @@ -28,7 +27,8 @@ module Fog end class Mock - def create_cache_parameter_group(name, desciption=name) + def create_cache_parameter_group(name, description = name, + family = 'memcached1.4') Fog::Mock.not_implemented end end diff --git a/tests/aws/models/elasticache/parameter_groups_tests.rb b/tests/aws/models/elasticache/parameter_groups_tests.rb new file mode 100644 index 000000000..56d7306c8 --- /dev/null +++ b/tests/aws/models/elasticache/parameter_groups_tests.rb @@ -0,0 +1,17 @@ +Shindo.tests('AWS::Elasticache | parameter groups', ['aws', 'elasticache']) do + group_name = 'fog-test' + description = 'Fog Test' + + pending if Fog.mocking? + + model_tests( + AWS[:elasticache].parameter_groups, + {:id => group_name, :description => description}, false + ) + + collection_tests( + AWS[:elasticache].parameter_groups, + {:id => group_name, :description => description}, false + ) + +end