2010-05-02 03:13:35 -04:00
module Fog
module AWS
2010-09-03 04:11:45 -04:00
class ELB
2010-05-02 03:13:35 -04:00
class Real
2010-06-12 18:31:17 -04:00
require 'fog/aws/parsers/elb/describe_load_balancers'
2010-05-02 03:13:35 -04:00
# Describe all or specified load balancers
#
# ==== Parameters
2012-04-22 21:46:17 -04:00
# * options<~Hash>
# * 'LoadBalancerNames'<~Array> - List of load balancer names to describe, defaults to all
# * 'Marker'<String> - Indicates where to begin in your list of load balancers
2010-05-02 03:13:35 -04:00
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeLoadBalancersResult'<~Hash>:
# * 'LoadBalancerDescriptions'<~Array>
2011-05-30 18:08:58 -04:00
# * 'AvailabilityZones'<~Array> - list of availability zones covered by this load balancer
2013-07-31 22:43:38 -04:00
# * 'BackendServerDescriptions'<~Array>:
# * 'InstancePort'<~Integer> - the port on which the back-end server is listening
# * 'PolicyNames'<~Array> - list of policy names enabled for the back-end server
2011-05-30 18:57:07 -04:00
# * 'CanonicalHostedZoneName'<~String> - name of the Route 53 hosted zone associated with the load balancer
# * 'CanonicalHostedZoneNameID'<~String> - ID of the Route 53 hosted zone associated with the load balancer
2010-05-02 03:13:35 -04:00
# * 'CreatedTime'<~Time> - time load balancer was created
2011-05-30 18:08:58 -04:00
# * 'DNSName'<~String> - external DNS name of load balancer
2010-05-02 03:13:35 -04:00
# * 'HealthCheck'<~Hash>:
# * 'HealthyThreshold'<~Integer> - number of consecutive health probe successes required before moving the instance to the Healthy state
# * 'Timeout'<~Integer> - number of seconds after which no response means a failed health probe
# * 'Interval'<~Integer> - interval (in seconds) between health checks of an individual instance
# * 'UnhealthyThreshold'<~Integer> - number of consecutive health probe failures that move the instance to the unhealthy state
# * 'Target'<~String> - string describing protocol type, port and URL to check
2011-05-30 18:08:58 -04:00
# * 'Instances'<~Array> - list of instances that the load balancer balances between
# * 'ListenerDescriptions'<~Array>
# * 'PolicyNames'<~Array> - list of policies enabled
# * 'Listener'<~Hash>:
# * 'InstancePort'<~Integer> - port on instance that requests are sent to
# * 'Protocol'<~String> - transport protocol used for routing in [TCP, HTTP]
# * 'LoadBalancerPort'<~Integer> - port that load balancer listens on for requests
# * 'LoadBalancerName'<~String> - name of load balancer
2010-05-02 03:13:35 -04:00
# * 'Policies'<~Hash>:
# * 'LBCookieStickinessPolicies'<~Array> - list of Load Balancer Generated Cookie Stickiness policies for the LoadBalancer
# * 'AppCookieStickinessPolicies'<~Array> - list of Application Generated Cookie Stickiness policies for the LoadBalancer
2011-05-30 18:57:07 -04:00
# * 'SourceSecurityGroup'<~Hash>:
# * 'GroupName'<~String> - Name of the source security group to use with inbound security group rules
# * 'OwnerAlias'<~String> - Owner of the source security group
2012-04-22 21:46:17 -04:00
# * 'NextMarker'<~String> - Marker to specify for next page
2012-04-22 21:04:03 -04:00
def describe_load_balancers ( options = { } )
unless options . is_a? ( Hash )
Fog :: Logger . deprecation ( " describe_load_balancers with #{ options . class } is deprecated, use all('LoadBalancerNames' => []) instead [light_black]( #{ caller . first } )[/] " )
options = { 'LoadBalancerNames' = > [ options ] . flatten }
end
if names = options . delete ( 'LoadBalancerNames' )
options . update ( Fog :: AWS . indexed_param ( 'LoadBalancerNames.member' , [ * names ] ) )
end
2010-05-02 03:13:35 -04:00
request ( {
'Action' = > 'DescribeLoadBalancers' ,
:parser = > Fog :: Parsers :: AWS :: ELB :: DescribeLoadBalancers . new
2012-04-22 21:04:03 -04:00
} . merge! ( options ) )
2010-05-02 03:13:35 -04:00
end
end
2011-07-06 19:11:14 -04:00
class Mock
2012-04-22 21:04:03 -04:00
def describe_load_balancers ( options = { } )
unless options . is_a? ( Hash )
Fog :: Logger . deprecation ( " describe_load_balancers with #{ options . class } is deprecated, use all('LoadBalancerNames' => []) instead [light_black]( #{ caller . first } )[/] " )
options = { 'LoadBalancerNames' = > [ options ] . flatten }
end
lb_names = options [ 'LoadBalancerNames' ] || [ ]
2011-07-06 19:11:14 -04:00
lb_names = [ * lb_names ]
load_balancers = if lb_names . any?
lb_names . map do | lb_name |
2011-07-07 17:53:10 -04:00
lb = self . data [ :load_balancers ] . find { | name , data | name == lb_name }
2011-07-06 19:11:14 -04:00
raise Fog :: AWS :: ELB :: NotFound unless lb
2011-10-25 16:56:30 -04:00
lb [ 1 ] . dup
2011-07-06 19:11:14 -04:00
end . compact
else
2011-10-25 16:56:30 -04:00
self . data [ :load_balancers ] . map { | lb , values | values . dup }
2012-04-22 21:46:17 -04:00
end
marker = options . fetch ( 'Marker' , 0 ) . to_i
if load_balancers . count - marker > 400
next_marker = marker + 400
load_balancers = load_balancers [ marker ... next_marker ]
else
next_marker = nil
end
2011-07-06 19:11:14 -04:00
response = Excon :: Response . new
response . status = 200
response . body = {
'ResponseMetadata' = > {
'RequestId' = > Fog :: AWS :: Mock . request_id
} ,
'DescribeLoadBalancersResult' = > {
2011-12-19 19:14:27 -05:00
'LoadBalancerDescriptions' = > load_balancers . map do | lb |
lb [ 'Instances' ] = lb [ 'Instances' ] . map { | i | i [ 'InstanceId' ] }
lb [ 'Policies' ] = lb [ 'Policies' ] . reject { | name , policies | name == 'Proper' }
lb
end
2011-07-06 19:11:14 -04:00
}
}
2012-04-22 21:46:17 -04:00
if next_marker
2012-08-16 16:17:42 -04:00
response . body [ 'DescribeLoadBalancersResult' ] [ 'NextMarker' ] = next_marker . to_s
2012-04-22 21:46:17 -04:00
end
2011-07-06 19:11:14 -04:00
response
end
end
2010-05-02 03:13:35 -04:00
end
end
end