From bb21207fa8978d6dcf80e55d4e470f1d1a057847 Mon Sep 17 00:00:00 2001 From: Benton Roberts Date: Wed, 21 Sep 2011 21:03:42 -0400 Subject: [PATCH] [aws|elasticache] implement RebootCacheCluster --- lib/fog/aws/elasticache.rb | 2 +- .../elasticache/reboot_cache_cluster.rb | 44 +++++++++++++++++++ .../elasticache/cache_cluster_tests.rb | 16 +++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb diff --git a/lib/fog/aws/elasticache.rb b/lib/fog/aws/elasticache.rb index dcb7a3ffb..1f50c93a4 100644 --- a/lib/fog/aws/elasticache.rb +++ b/lib/fog/aws/elasticache.rb @@ -14,7 +14,7 @@ module Fog request :delete_cache_cluster request :describe_cache_clusters request :modify_cache_cluster - #request :reboot_cache_cluster + request :reboot_cache_cluster #request :create_cache_parameter_group #request :delete_cache_parameter_group diff --git a/lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb b/lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb new file mode 100644 index 000000000..ecfb10262 --- /dev/null +++ b/lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb @@ -0,0 +1,44 @@ +module Fog + module AWS + class Elasticache + class Real + + require 'fog/aws/parsers/elasticache/single_cache_cluster' + + # Reboots some or all of an existing cache cluster's nodes + # Returns a cache cluster description + # + # === Required Parameters + # * id <~String> - The ID of the existing cluster to be rebooted + # === Optional Parameters + # * nodes_to_reboot <~Array> - Array of node IDs to reboot + # === Returns + # * response <~Excon::Response>: + # * body <~Hash> + def reboot_cache_cluster(id, nodes_to_reboot) + # Construct CacheNodeIdsToReboot parameters in the format: + # CacheNodeIdsToReboot.member.N => "node_id" + node_ids = nodes_to_reboot || [] + node_id_params = node_ids.inject({}) do |node_hash, node_id| + index = node_ids.index(node_id) + 1 + node_hash["CacheNodeIdsToReboot.member.#{index}"] = node_id + node_hash + end + # Merge the CacheNodeIdsToReboot parameters with the normal options + request(node_id_params.merge( + 'Action' => 'RebootCacheCluster', + 'CacheClusterId' => id, + :parser => Fog::Parsers::AWS::Elasticache::SingleCacheCluster.new + )) + end + + end + + class Mock + def reboot_cache_cluster + Fog::Mock.not_implemented + end + end + end + end +end diff --git a/tests/aws/requests/elasticache/cache_cluster_tests.rb b/tests/aws/requests/elasticache/cache_cluster_tests.rb index 3b6316c80..227e96f13 100644 --- a/tests/aws/requests/elasticache/cache_cluster_tests.rb +++ b/tests/aws/requests/elasticache/cache_cluster_tests.rb @@ -73,6 +73,22 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache'] body['CacheCluster'] end + tests( + '#reboot_cache_cluster - reboot a node' + ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do + c = AWS[:elasticache].clusters.get(CLUSTER_ID) + node_id = c.nodes.last['CacheNodeId'] + Formatador.display_line "Rebooting node #{node_id}..." + body = AWS[:elasticache].reboot_cache_cluster(c.id, [ node_id ]).body + returns('rebooting cache cluster nodes') do + body['CacheCluster']['CacheClusterStatus'] + end + body['CacheCluster'] + end + + Formatador.display_line "Waiting for cluster #{CLUSTER_ID}..." + AWS[:elasticache].clusters.get(CLUSTER_ID).wait_for {ready?} + tests( '#modify_cache_cluster - remove a node' ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do