From 8b502b7b766f4d3ae2f836111bcb871efccfd545 Mon Sep 17 00:00:00 2001 From: Brian Hartsock Date: Sat, 31 Mar 2012 16:07:27 -0400 Subject: [PATCH] [rackspace|lb] added support for algorithm on create --- .../rackspace/models/load_balancers/load_balancer.rb | 9 ++++++++- .../requests/load_balancers/create_load_balancer.rb | 5 ++++- .../models/load_balancers/load_balancer_tests.rb | 12 ++++++++++++ .../requests/load_balancers/load_balancer_tests.rb | 9 +++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/fog/rackspace/models/load_balancers/load_balancer.rb b/lib/fog/rackspace/models/load_balancers/load_balancer.rb index c3ddbe027..0b123384d 100644 --- a/lib/fog/rackspace/models/load_balancers/load_balancer.rb +++ b/lib/fog/rackspace/models/load_balancers/load_balancer.rb @@ -178,7 +178,14 @@ module Fog private def create 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']) end diff --git a/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb b/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb index 232092a69..353494d96 100644 --- a/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb +++ b/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb @@ -2,7 +2,7 @@ module Fog module Rackspace class LoadBalancers class Real - def create_load_balancer(name, protocol, port, virtual_ips, nodes) + def create_load_balancer(name, protocol, port, virtual_ips, nodes, options = {}) data = { 'loadBalancer' => { 'name' => name, @@ -13,6 +13,9 @@ module Fog #Is algorithm allowed on create? } } + + data['loadBalancer']['algorithm'] = options[:algorithm] if options.has_key? :algorithm + request( :body => MultiJson.encode(data), :expects => 202, diff --git a/tests/rackspace/models/load_balancers/load_balancer_tests.rb b/tests/rackspace/models/load_balancers/load_balancer_tests.rb index 9245f6086..dc028a830 100644 --- a/tests/rackspace/models/load_balancers/load_balancer_tests.rb +++ b/tests/rackspace/models/load_balancers/load_balancer_tests.rb @@ -127,6 +127,18 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer', ['rackspace']) do @instance.wait_for { ready? } 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 @lb = @service.load_balancers.new LOAD_BALANCER_ATTRIBUTES tests('#usage => Requires ID').raises(ArgumentError) do diff --git a/tests/rackspace/requests/load_balancers/load_balancer_tests.rb b/tests/rackspace/requests/load_balancers/load_balancer_tests.rb index 61f3985dd..e23d71639 100644 --- a/tests/rackspace/requests/load_balancers/load_balancer_tests.rb +++ b/tests/rackspace/requests/load_balancers/load_balancer_tests.rb @@ -14,6 +14,15 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace' data 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 @service.update_load_balancer(@lb_id, { :port => 80 }).body end