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:
commit
328ac2857d
4 changed files with 33 additions and 2 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue