diff --git a/lib/fog/aws/elasticache.rb b/lib/fog/aws/elasticache.rb index ed9c7d40a..779deb98e 100644 --- a/lib/fog/aws/elasticache.rb +++ b/lib/fog/aws/elasticache.rb @@ -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 diff --git a/lib/fog/aws/parsers/elasticache/describe_parameter_groups.rb b/lib/fog/aws/parsers/elasticache/describe_parameter_groups.rb new file mode 100644 index 000000000..81040b746 --- /dev/null +++ b/lib/fog/aws/parsers/elasticache/describe_parameter_groups.rb @@ -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 diff --git a/lib/fog/aws/parsers/elasticache/parameter_group_parser.rb b/lib/fog/aws/parsers/elasticache/parameter_group_parser.rb new file mode 100644 index 000000000..d53f5e0f5 --- /dev/null +++ b/lib/fog/aws/parsers/elasticache/parameter_group_parser.rb @@ -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 diff --git a/lib/fog/aws/parsers/elasticache/single_parameter_group.rb b/lib/fog/aws/parsers/elasticache/single_parameter_group.rb new file mode 100644 index 000000000..ad9200208 --- /dev/null +++ b/lib/fog/aws/parsers/elasticache/single_parameter_group.rb @@ -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 diff --git a/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb b/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb new file mode 100644 index 000000000..61722c87c --- /dev/null +++ b/lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb @@ -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 diff --git a/lib/fog/aws/requests/elasticache/delete_cache_parameter_group.rb b/lib/fog/aws/requests/elasticache/delete_cache_parameter_group.rb new file mode 100644 index 000000000..3704fb741 --- /dev/null +++ b/lib/fog/aws/requests/elasticache/delete_cache_parameter_group.rb @@ -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 diff --git a/lib/fog/aws/requests/elasticache/describe_cache_parameter_groups.rb b/lib/fog/aws/requests/elasticache/describe_cache_parameter_groups.rb new file mode 100644 index 000000000..f3423fc7a --- /dev/null +++ b/lib/fog/aws/requests/elasticache/describe_cache_parameter_groups.rb @@ -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 diff --git a/tests/aws/requests/elasticache/helper.rb b/tests/aws/requests/elasticache/helper.rb index 3e0e64060..6d7077f40 100644 --- a/tests/aws/requests/elasticache/helper.rb +++ b/tests/aws/requests/elasticache/helper.rb @@ -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 diff --git a/tests/aws/requests/elasticache/parameter_group_tests.rb b/tests/aws/requests/elasticache/parameter_group_tests.rb new file mode 100644 index 000000000..4fb1fc9b4 --- /dev/null +++ b/tests/aws/requests/elasticache/parameter_group_tests.rb @@ -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