1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|elb] Marker support for describe_load_balancers.

This commit is contained in:
Dan Peterson 2012-04-22 22:46:17 -03:00
parent f8098a5369
commit 169f5e754c
3 changed files with 29 additions and 4 deletions

View file

@ -11,8 +11,16 @@ module Fog
end
def all
data = connection.describe_load_balancers.body['DescribeLoadBalancersResult']['LoadBalancerDescriptions']
load(data)
result = []
marker = nil
finished = false
while !finished
data = connection.describe_load_balancers('Marker' => marker).body
result.concat(data['DescribeLoadBalancersResult']['LoadBalancerDescriptions'])
marker = data['DescribeLoadBalancersResult']['NextMarker']
finished = marker.nil?
end
load(result) # data is an array of attribute hashes
end
def get(identity)

View file

@ -111,6 +111,8 @@ module Fog
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'NextMarker'
@results['NextMarker'] = value
when 'DescribeLoadBalancersResponse'
@response['DescribeLoadBalancersResult'] = @results
end

View file

@ -8,7 +8,9 @@ module Fog
# Describe all or specified load balancers
#
# ==== Parameters
# * lb_name<~Array> - List of load balancer names to describe, defaults to all
# * 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
#
# ==== Returns
# * response<~Excon::Response>:
@ -42,6 +44,7 @@ module Fog
# * '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
# * 'NextMarker'<~String> - Marker to specify for next page
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})[/]")
@ -78,7 +81,15 @@ module Fog
end.compact
else
self.data[:load_balancers].map { |lb, values| values.dup }
end[0...400]
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
response = Excon::Response.new
response.status = 200
@ -96,6 +107,10 @@ module Fog
}
}
if next_marker
response.body['DescribeLoadBalancersResult']['NextMarker'] = next_marker
end
response
end
end