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

Merge pull request #839 from brianhartsock/master

[rackspace|lb] Support setting algorithm when creating a load balancer
This commit is contained in:
Brian Hartsock 2012-04-06 15:36:57 -07:00
commit 328ac2857d
4 changed files with 33 additions and 2 deletions

View file

@ -178,7 +178,14 @@ module Fog
private private
def create def create
requires :name, :protocol, :port, :virtual_ips, :nodes requires :name, :protocol, :port, :virtual_ips, :nodes
data = connection.create_load_balancer(name, protocol, port, virtual_ips_hash, nodes_hash)
if algorithm
options = { :algorithm => algorithm }
else
options = {}
end
data = connection.create_load_balancer(name, protocol, port, virtual_ips_hash, nodes_hash, options)
merge_attributes(data.body['loadBalancer']) merge_attributes(data.body['loadBalancer'])
end end

View file

@ -2,7 +2,7 @@ module Fog
module Rackspace module Rackspace
class LoadBalancers class LoadBalancers
class Real class Real
def create_load_balancer(name, protocol, port, virtual_ips, nodes) def create_load_balancer(name, protocol, port, virtual_ips, nodes, options = {})
data = { data = {
'loadBalancer' => { 'loadBalancer' => {
'name' => name, 'name' => name,
@ -13,6 +13,9 @@ module Fog
#Is algorithm allowed on create? #Is algorithm allowed on create?
} }
} }
data['loadBalancer']['algorithm'] = options[:algorithm] if options.has_key? :algorithm
request( request(
:body => MultiJson.encode(data), :body => MultiJson.encode(data),
:expects => 202, :expects => 202,

View file

@ -127,6 +127,18 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer', ['rackspace']) do
@instance.wait_for { ready? } @instance.wait_for { ready? }
end end
tests('create(...with algorithm...)') do
attributes = LOAD_BALANCER_ATTRIBUTES.clone
attributes[:algorithm] = 'LEAST_CONNECTIONS'
@lb = @service.load_balancers.create attributes
returns('LEAST_CONNECTIONS') { @lb.algorithm }
@lb.wait_for { ready? }
@lb.destroy
end
tests('failure') do tests('failure') do
@lb = @service.load_balancers.new LOAD_BALANCER_ATTRIBUTES @lb = @service.load_balancers.new LOAD_BALANCER_ATTRIBUTES
tests('#usage => Requires ID').raises(ArgumentError) do tests('#usage => Requires ID').raises(ArgumentError) do

View file

@ -14,6 +14,15 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace'
data data
end end
tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...with algorithm)").formats(LOAD_BALANCER_FORMAT) do
data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}],
[{ :address => '10.0.0.1', :port => 80, :condition => 'ENABLED'}],
{ :algorithm => 'LEAST_CONNECTIONS' }).body
@lb_id = data['loadBalancer']['id']
returns('LEAST_CONNECTIONS') { data['loadBalancer']['algorithm'] }
data
end
tests("#update_load_balancer(#{@lb_id}) while immutable").raises(Fog::Rackspace::LoadBalancers::ServiceError) do tests("#update_load_balancer(#{@lb_id}) while immutable").raises(Fog::Rackspace::LoadBalancers::ServiceError) do
@service.update_load_balancer(@lb_id, { :port => 80 }).body @service.update_load_balancer(@lb_id, { :port => 80 }).body
end end