Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

Commit

Permalink
added register_instances_with_load_balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Rasmussen authored and grempe committed Aug 11, 2009
1 parent 3a36dd3 commit e0dab97
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
38 changes: 38 additions & 0 deletions lib/AWS/ELB/load_balancers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ def describe_load_balancers( options = {} )

return response_generator(:action => "DescribeLoadBalancers", :params => params)
end

# Amazon Developer Guide Docs:
#
# This API adds new instances to the LoadBalancer.
#
# Once the instance is registered, it starts receiving traffic and
# requests from the LoadBalancer. Any instance that is not in any of the
# Availability Zones registered for the LoadBalancer will be moved to
# the OutOfService state. It will move to the InService state when the
# Availability Zone is added to the LoadBalancer.
#
# You must have been the one who created the LoadBalancer. In other
# words, in order to successfully call this API, you must provide the
# same account credentials as those that were used to create the
# LoadBalancer.
#
# NOTE: Completion of this API does not guarantee that operation has
# completed. Rather, it means that the request has been registered and
# the changes will happen shortly.
#
# Required Arguments:
#
# :instances => Array of Strings
# :load_balancer_name => String
#
def register_instances_with_load_balancer( options = {} )
raise ArgumentError, "No :instances provided" if options[:instances].nil? || options[:instances].empty?
raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?

params = {}

params.merge!(pathlist('Instances.member', [options[:instances]].flatten))
params['LoadBalancerName'] = options[:load_balancer_name]

return response_generator(:action => "RegisterInstancesWithLoadBalancer", :params => params)
end


end
end
end
1 change: 0 additions & 1 deletion lib/AWS/responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def self.parse(options = {})
# NOTE: Parsing the response as a nested set of Response objects was extremely
# memory intensive and appeared to leak (the memory was not freed on subsequent requests).
# It was changed to return the raw XmlSimple response.

response = XmlSimple.xml_in(options[:xml], options[:parse_options])

return response
Expand Down
28 changes: 28 additions & 0 deletions test/test_ELB_load_balancers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@
</ResponseMetadata>
</DescribeLoadBalancersResponse>
RESPONSE

@valid_register_instances_with_load_balancer_params = {
:load_balancer_name => 'Test Name',
:instances => ['i-6055fa09']
}

@register_instances_with_load_balancer_response_body = <<-RESPONSE
<RegisterInstancesWithLoadBalancerResult>
<Instances>
<member>
<InstanceId>i-6055fa09</InstanceId>
</member>
</Instances>
</RegisterInstancesWithLoadBalancerResult>
RESPONSE
end

specify "should be able to be created" do
Expand Down Expand Up @@ -115,4 +130,17 @@

response.DescribeLoadBalancersResult.LoadBalancerDescriptions.member.length.should == 1
end

specify "should be able to be register instances to load balancers with register_instances_with_load_balancer" do
@elb.stubs(:make_request).with('RegisterInstancesWithLoadBalancer', {
'LoadBalancerName' => 'Test Name',
'Instances.member.1' => 'i-6055fa09'
}).returns stub(:body => @register_instances_with_load_balancer_response_body, :is_a? => true)

response = @elb.register_instances_with_load_balancer(@valid_register_instances_with_load_balancer_params)
response.should.be.an.instance_of Hash

response.Instances.member.length.should == 1
end

end

0 comments on commit e0dab97

Please sign in to comment.