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

Complete lifecycle for a load balancer

This commit is contained in:
Brian Hartsock 2011-07-08 16:39:22 -04:00
parent 34c01eda0f
commit 95dc27c1ab
7 changed files with 120 additions and 9 deletions

View file

@ -13,6 +13,9 @@ module Fog
request_path 'fog/rackspace/requests'
request :create_load_balancer
request :get_load_balancer
request :list_load_balancers
request :update_load_balancer
request :delete_load_balancer
class Real

View file

@ -10,6 +10,7 @@ module Fog
'protocol' => options[:protocol],
'virtualIps' => options[:virtualIps],
'nodes' => options[:nodes]
#Is algorithm allowed on create?
}
}
request(

View file

@ -5,7 +5,7 @@ module Fog
def delete_load_balancer(load_balancer_id)
request(
:expects => 202,
:path => "loadbalancers/#{load_balancer_id}",
:path => "loadbalancers/#{load_balancer_id}.json",
:method => 'DELETE'
)
end

View file

@ -0,0 +1,20 @@
module Fog
module Rackspace
class LoadBalancer
class Real
def get_load_balancer(load_balancer_id)
request(
:expects => 200,
:path => "loadbalancers/#{load_balancer_id}.json",
:method => 'GET'
)
end
end
class Mock
def get_load_balancer(options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,20 @@
module Fog
module Rackspace
class LoadBalancer
class Real
def list_load_balancers
request(
:expects => 200,
:method => 'GET',
:path => 'loadbalancers.json'
)
end
end
class Mock
def list_load_balancers
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Rackspace
class LoadBalancer
class Real
def update_load_balancer(load_balancer_id, options = {})
data = {
'loadBalancer' => {
'name' => options[:name],
'port' => options[:port],
'protocol' => options[:protocol],
'algorithm' => options[:algorithm]
}
}
request(
:body => data.to_json,
:expects => 202,
:method => 'PUT',
:path => "loadbalancers/#{load_balancer_id}.json"
)
end
end
class Mock
def update_load_balancer(options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -1,6 +1,27 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_tests', ['rackspace']) do
@load_balancer_format = {
NODE_FORMAT = {'address' => String, 'id' => Integer, 'status' => String, 'weight' => Fog::Nullable::Integer, 'port' => Integer, 'condition' => String}
VIRTUAL_IP_FORMAT = {'type' => String, 'id' => Integer, 'type' => String, 'ipVersion' => String, 'address' => String}
STATUS_ACTIVE = 'ACTIVE'
LOAD_BALANCERS_FORMAT = {
'loadBalancers' => [
{
'name' => String,
'id' => Integer,
'port' => Integer,
'protocol' => String,
'algorithm' => String,
'status' => String,
'virtualIps' => [VIRTUAL_IP_FORMAT],
'nodes' => [NODE_FORMAT],
'created' => { 'time' => String },
'updated' => { 'time' => String }
}]
}
LOAD_BALANCER_FORMAT = {
'loadBalancer' => {
'name' => String,
'id' => Integer,
@ -9,8 +30,8 @@ Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_tests', ['rackspace']
'algorithm' => String,
'status' => String,
'cluster' => { 'name' => String },
'virtualIps' => [{'type' => String, 'id' => Integer, 'type' => String, 'ipVersion' => String, 'address' => String}],
'nodes' => [{'address' => String, 'id' => Integer, 'status' => String, 'weight' => Integer, 'port' => Integer, 'condition' => String}],
'virtualIps' => [VIRTUAL_IP_FORMAT],
'nodes' => [NODE_FORMAT],
'created' => { 'time' => String },
'updated' => { 'time' => String },
'connectionLogging' => { 'enabled' => Fog::Boolean }
@ -21,18 +42,35 @@ Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_tests', ['rackspace']
@lb_id = nil
@lb = Fog::Rackspace::LoadBalancer.new
tests('#create_lb()').formats(@load_balancer_format) do
tests('#create_load_balancer()').formats(LOAD_BALANCER_FORMAT) do
data = @lb.create_load_balancer(:name => 'fog' + Time.now.to_i.to_s, :port => '80', :protocol => 'HTTP', :virtualIps => [{ :type => 'PUBLIC'}], :nodes => [{ :address => '10.0.0.1', :port => 80, :condition => 'ENABLED'}]).body
puts data
@lb_id = data['loadBalancer']['id']
data
end
puts "Sleeping..."
sleep(60)
tests("get_load_balancer(#{@lb_id})").formats(LOAD_BALANCER_FORMAT) do
@lb.get_load_balancer(@lb_id).body
end
tests("list_load_balancers()").formats(LOAD_BALANCERS_FORMAT) do
@lb.list_load_balancers.body
end
until @lb.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
sleep 10
end
tests("update_load_balancer()").succeeds do
@lb.update_load_balancer(@lb_id, { :port => 80 }).body
end
until @lb.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
sleep 10
end
tests("#delete_load_balancer(#{@ld_id})").succeeds do
@lb.delete_load_balancer(@lb_id)
@lb.delete_load_balancer(@lb_id).body
end
end