mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|elb] add support for ELB connection draining
This commit is contained in:
parent
258635a6bc
commit
7555a71703
7 changed files with 66 additions and 7 deletions
|
@ -35,6 +35,23 @@ module Fog
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def connection_draining?
|
||||||
|
requires :id
|
||||||
|
service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining']['Enabled']
|
||||||
|
end
|
||||||
|
|
||||||
|
def connection_draining_timeout
|
||||||
|
requires :id
|
||||||
|
service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining']['Timeout']
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_connection_draining(enabled, timeout=nil)
|
||||||
|
requires :id
|
||||||
|
attrs = {'Enabled' => enabled}
|
||||||
|
attrs['Timeout'] = timeout if timeout
|
||||||
|
service.modify_load_balancer_attributes(id, 'ConnectionDraining' => attrs)
|
||||||
|
end
|
||||||
|
|
||||||
def cross_zone_load_balancing?
|
def cross_zone_load_balancing?
|
||||||
requires :id
|
requires :id
|
||||||
service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing']['Enabled']
|
service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing']['Enabled']
|
||||||
|
|
|
@ -13,6 +13,8 @@ module Fog
|
||||||
def start_element(name, attrs = [])
|
def start_element(name, attrs = [])
|
||||||
super
|
super
|
||||||
case name
|
case name
|
||||||
|
when 'ConnectionDraining'
|
||||||
|
@connection_draining = {}
|
||||||
when 'CrossZoneLoadBalancing'
|
when 'CrossZoneLoadBalancing'
|
||||||
@cross_zone_load_balancing = {}
|
@cross_zone_load_balancing = {}
|
||||||
end
|
end
|
||||||
|
@ -23,7 +25,16 @@ module Fog
|
||||||
when 'Enabled'
|
when 'Enabled'
|
||||||
if @cross_zone_load_balancing
|
if @cross_zone_load_balancing
|
||||||
@cross_zone_load_balancing['Enabled'] = value == 'true' ? true : false
|
@cross_zone_load_balancing['Enabled'] = value == 'true' ? true : false
|
||||||
|
elsif @connection_draining
|
||||||
|
@connection_draining['Enabled'] = value == 'true' ? true : false
|
||||||
end
|
end
|
||||||
|
when 'Timeout'
|
||||||
|
if @connection_draining
|
||||||
|
@connection_draining['Timeout'] = value.to_i
|
||||||
|
end
|
||||||
|
when 'ConnectionDraining'
|
||||||
|
@response['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining'] = @connection_draining
|
||||||
|
@connection_draining = nil
|
||||||
when 'CrossZoneLoadBalancing'
|
when 'CrossZoneLoadBalancing'
|
||||||
@response['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing'] = @cross_zone_load_balancing
|
@response['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing'] = @cross_zone_load_balancing
|
||||||
@cross_zone_load_balancing = nil
|
@cross_zone_load_balancing = nil
|
||||||
|
|
|
@ -122,7 +122,10 @@ module Fog
|
||||||
},
|
},
|
||||||
'Instances' => [],
|
'Instances' => [],
|
||||||
'ListenerDescriptions' => listeners,
|
'ListenerDescriptions' => listeners,
|
||||||
'LoadBalancerAttributes' => {'CrossZoneLoadBalancing' => {'Enabled' => false}},
|
'LoadBalancerAttributes' => {
|
||||||
|
'ConnectionDraining' => {'Enabled' => false, 'Timeout' => 300},
|
||||||
|
'CrossZoneLoadBalancing' => {'Enabled' => false}
|
||||||
|
},
|
||||||
'LoadBalancerName' => lb_name,
|
'LoadBalancerName' => lb_name,
|
||||||
'Policies' => {
|
'Policies' => {
|
||||||
'AppCookieStickinessPolicies' => [],
|
'AppCookieStickinessPolicies' => [],
|
||||||
|
|
|
@ -17,6 +17,9 @@ module Fog
|
||||||
# * 'RequestId'<~String> - Id of request
|
# * 'RequestId'<~String> - Id of request
|
||||||
# * 'DescribeLoadBalancerAttributesResult'<~Hash>:
|
# * 'DescribeLoadBalancerAttributesResult'<~Hash>:
|
||||||
# * 'LoadBalancerAttributes'<~Hash>
|
# * 'LoadBalancerAttributes'<~Hash>
|
||||||
|
# * 'ConnectionDraining'<~Hash>
|
||||||
|
# * 'Enabled'<~Boolean> - whether connection draining is enabled
|
||||||
|
# * 'Timeout'<~Integer> - max time (in seconds) to keep existing conns open before deregistering instances.
|
||||||
# * 'CrossZoneLoadBalancing'<~Hash>
|
# * 'CrossZoneLoadBalancing'<~Hash>
|
||||||
# * 'Enabled'<~Boolean> - whether crosszone load balancing is enabled
|
# * 'Enabled'<~Boolean> - whether crosszone load balancing is enabled
|
||||||
def describe_load_balancer_attributes(lb_name)
|
def describe_load_balancer_attributes(lb_name)
|
||||||
|
|
|
@ -8,13 +8,16 @@ module Fog
|
||||||
|
|
||||||
# Sets attributes of the load balancer
|
# Sets attributes of the load balancer
|
||||||
#
|
#
|
||||||
# Currently the only attribute that can be set is whether CrossZoneLoadBalancing
|
# Currently the only attributes that can be set are whether CrossZoneLoadBalancing
|
||||||
# is enabled
|
# or ConnectionDraining are enabled. You can also set the Timeout for ConnectionDraining.
|
||||||
#
|
#
|
||||||
# http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_ModifyLoadBalancerAttributes.html
|
# http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_ModifyLoadBalancerAttributes.html
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * lb_name<~String> - Name of the ELB
|
# * lb_name<~String> - Name of the ELB
|
||||||
# * options<~Hash>
|
# * options<~Hash>
|
||||||
|
# * 'ConnectionDraining'<~Hash>:
|
||||||
|
# * 'Enabled'<~Boolean> whether to enable connection draining
|
||||||
|
# * 'Timeout'<~Integer> max time to keep existing conns open before deregistering instances
|
||||||
# * 'CrossZoneLoadBalancing'<~Hash>:
|
# * 'CrossZoneLoadBalancing'<~Hash>:
|
||||||
# * 'Enabled'<~Boolean> whether to enable cross zone load balancing
|
# * 'Enabled'<~Boolean> whether to enable cross zone load balancing
|
||||||
#
|
#
|
||||||
|
@ -38,7 +41,7 @@ module Fog
|
||||||
def modify_load_balancer_attributes(lb_name, attributes)
|
def modify_load_balancer_attributes(lb_name, attributes)
|
||||||
raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
|
raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
|
||||||
|
|
||||||
if attributes['CrossZoneLoadBalancing']
|
if attributes['CrossZoneLoadBalancing'] || attributes['ConnectionDraining']
|
||||||
load_balancer['LoadBalancerAttributes'].merge! attributes
|
load_balancer['LoadBalancerAttributes'].merge! attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,14 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
||||||
returns(@availability_zones) { elb.availability_zones.sort }
|
returns(@availability_zones) { elb.availability_zones.sort }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tests('connection_draining') do
|
||||||
|
returns(false) { elb.connection_draining? }
|
||||||
|
returns(300) { elb.connection_draining_timeout }
|
||||||
|
elb.set_connection_draining(true, 60)
|
||||||
|
returns(true) { elb.connection_draining? }
|
||||||
|
returns(60) { elb.connection_draining_timeout }
|
||||||
|
end
|
||||||
|
|
||||||
tests('cross_zone_load_balancing') do
|
tests('cross_zone_load_balancing') do
|
||||||
returns(false) {elb.cross_zone_load_balancing?}
|
returns(false) {elb.cross_zone_load_balancing?}
|
||||||
elb.cross_zone_load_balancing = true
|
elb.cross_zone_load_balancing = true
|
||||||
|
|
|
@ -37,9 +37,23 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("modify_load_balancer_attributes") do
|
tests("modify_load_balancer_attributes") do
|
||||||
Fog::AWS[:elb].modify_load_balancer_attributes(@load_balancer_id, 'CrossZoneLoadBalancing' => {'Enabled' => true}).body
|
attributes = {
|
||||||
response = Fog::AWS[:elb].describe_load_balancer_attributes(@load_balancer_id).body
|
'ConnectionDraining' => {'Enabled' => true, 'Timeout' => 600},
|
||||||
response['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing']['Enabled'] == true
|
'CrossZoneLoadBalancing' => {'Enabled' => true}
|
||||||
|
}
|
||||||
|
Fog::AWS[:elb].modify_load_balancer_attributes(@load_balancer_id, attributes).body
|
||||||
|
response = Fog::AWS[:elb].describe_load_balancer_attributes(@load_balancer_id).
|
||||||
|
body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']
|
||||||
|
|
||||||
|
tests("ConnectionDraining is enabled") do
|
||||||
|
response['ConnectionDraining']['Enabled'] == true
|
||||||
|
end
|
||||||
|
tests("ConnectionDraining has a 600 second Timeout").returns(600) do
|
||||||
|
response['ConnectionDraining']['Timeout']
|
||||||
|
end
|
||||||
|
tests("CrossZoneLoadBalancing is enabled") do
|
||||||
|
response['CrossZoneLoadBalancing']['Enabled'] == true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#configure_health_check").formats(AWS::ELB::Formats::CONFIGURE_HEALTH_CHECK) do
|
tests("#configure_health_check").formats(AWS::ELB::Formats::CONFIGURE_HEALTH_CHECK) do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue