From e0459733db368f5fc8d0ad2cd88d54a4dee9fe8b Mon Sep 17 00:00:00 2001 From: Aaron Suggs Date: Sat, 9 Apr 2011 15:56:45 -0400 Subject: [PATCH 1/2] [aws|elb] Stub out missing requests. --- lib/fog/aws/elb.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 7511b5e77..d28a4939c 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -6,14 +6,22 @@ module Fog recognizes :region, :host, :path, :port, :scheme, :persistent request_path 'fog/aws/requests/elb' + #request :configure_health_check + #request :create_app_cookie_stickiness_policy + #request :create_db_cookie_stickiness_policy request :create_load_balancer + #request :create_load_balancer_listeners request :delete_load_balancer + #request :delete_load_balancer_listeners + #request :delete_load_balancer_policy request :deregister_instances_from_load_balancer request :describe_instance_health request :describe_load_balancers request :disable_availability_zones_for_load_balancer request :enable_availability_zones_for_load_balancer request :register_instances_with_load_balancer + #request :set_load_balancer_listener_ssl_certificate + #request :set_load_balancer_policies_of_listener class Mock From 082adf861ac29089bbd799017296297756faefab Mon Sep 17 00:00:00 2001 From: Aaron Suggs Date: Sat, 9 Apr 2011 16:54:24 -0400 Subject: [PATCH 2/2] [aws|elb] Add configure_health_check request --- lib/fog/aws/elb.rb | 2 +- .../aws/parsers/elb/configure_health_check.rb | 37 +++++++++++++++++ .../requests/elb/configure_health_check.rb | 41 +++++++++++++++++++ tests/aws/requests/elb/helper.rb | 10 +++++ tests/aws/requests/elb/load_balancer_tests.rb | 12 ++++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 lib/fog/aws/parsers/elb/configure_health_check.rb create mode 100644 lib/fog/aws/requests/elb/configure_health_check.rb diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index d28a4939c..344669dde 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -6,7 +6,7 @@ module Fog recognizes :region, :host, :path, :port, :scheme, :persistent request_path 'fog/aws/requests/elb' - #request :configure_health_check + request :configure_health_check #request :create_app_cookie_stickiness_policy #request :create_db_cookie_stickiness_policy request :create_load_balancer diff --git a/lib/fog/aws/parsers/elb/configure_health_check.rb b/lib/fog/aws/parsers/elb/configure_health_check.rb new file mode 100644 index 000000000..6764bc9ce --- /dev/null +++ b/lib/fog/aws/parsers/elb/configure_health_check.rb @@ -0,0 +1,37 @@ +module Fog + module Parsers + module AWS + module ELB + + class ConfigureHealthCheck < Fog::Parsers::Base + + def reset + @health_check = {} + @response = { 'ConfigureHealthCheckResult' => {}, 'ResponseMetadata' => {} } + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'Target' + @health_check[name] = @value + when 'Interval', 'Timeout', 'UnhealthyThreshold', 'HealthyThreshold' + @health_check[name] = @value.to_i + + when 'HealthCheck' + @response['ConfigureHealthCheckResult'][name] = @health_check + + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/elb/configure_health_check.rb b/lib/fog/aws/requests/elb/configure_health_check.rb new file mode 100644 index 000000000..651ffc0d4 --- /dev/null +++ b/lib/fog/aws/requests/elb/configure_health_check.rb @@ -0,0 +1,41 @@ +module Fog + module AWS + class ELB + class Real + + require 'fog/aws/parsers/elb/configure_health_check' + + # Enables the client to define an application healthcheck for the instances. + # See http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/index.html?API_ConfigureHealthCheck.html + # + # ==== Parameters + # * lb_name<~String> - Name of the ELB + # * health_check<~Hash> - A hash of parameters describing the health check + # * 'HealthyThreshold'<~Integer> - Specifies the number of consecutive + # health probe successes required before moving the instance to the Healthy state. + # * 'Interval'<~Integer> - Specifies the approximate interval, in seconds, + # between health checks of an individual instance. + # * 'Target'<~String> - Specifies the instance being checked. + # The protocol is either TCP or HTTP. The range of valid ports is one (1) through 65535. + # * 'Timeout'<~Integer> - Specifies the amount of time, in seconds, + # during which no response means a failed health probe. + # * 'UnhealthyThreshold'<~Integer> - Specifies the number of consecutive + # health probe failures required before moving the instance to the Unhealthy state. + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def configure_health_check(lb_name, health_check) + params = {'LoadBalancerName' => lb_name} + health_check.each {|key, value| params["HealthCheck.#{key}"] = value } + + request({ + 'Action' => 'ConfigureHealthCheck', + :parser => Fog::Parsers::AWS::ELB::ConfigureHealthCheck.new + }.merge!(params)) + end + + end + end + end +end diff --git a/tests/aws/requests/elb/helper.rb b/tests/aws/requests/elb/helper.rb index 9cefcb01e..6c24c4cab 100644 --- a/tests/aws/requests/elb/helper.rb +++ b/tests/aws/requests/elb/helper.rb @@ -25,6 +25,16 @@ class AWS 'DescribeLoadBalancersResult' => {'LoadBalancerDescriptions' => [LOAD_BALANCER]} }) + CONFIGURE_HEALTH_CHECK = BASIC.merge({ + 'ConfigureHealthCheckResult' => {'HealthCheck' => { + 'Target' => String, + 'Interval' => Integer, + 'Timeout' => Integer, + 'UnhealthyThreshold' => Integer, + 'HealthyThreshold' => Integer + }} + }) + DELETE_LOAD_BALANCER = BASIC.merge({ 'DeleteLoadBalancerResult' => NilClass }) diff --git a/tests/aws/requests/elb/load_balancer_tests.rb b/tests/aws/requests/elb/load_balancer_tests.rb index 8324f3c9f..822704368 100644 --- a/tests/aws/requests/elb/load_balancer_tests.rb +++ b/tests/aws/requests/elb/load_balancer_tests.rb @@ -14,6 +14,18 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do AWS[:elb].describe_load_balancers.body end + tests("#configure_health_check").formats(AWS::ELB::Formats::CONFIGURE_HEALTH_CHECK) do + health_check = { + 'Target' => 'HTTP:80/index.html', + 'Interval' => 10, + 'Timeout' => 5, + 'UnhealthyThreshold' => 2, + 'HealthyThreshold' => 3 + } + + AWS[:elb].configure_health_check(@load_balancer_id, health_check).body + end + tests("#delete_load_balancer").formats(AWS::ELB::Formats::DELETE_LOAD_BALANCER) do AWS[:elb].delete_load_balancer(@load_balancer_id).body end