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

Rackspace LB: Health Monitor requests

This commit is contained in:
Brian Hartsock 2011-07-27 21:12:46 -04:00
parent e5ab6bb603
commit 9b110de605
6 changed files with 127 additions and 0 deletions

View file

@ -80,6 +80,9 @@ module Fog
request :get_connection_throttling
request :remove_connection_throttling
request :set_connection_throttling
request :get_monitor
request :set_monitor
request :remove_monitor
class Real
def initialize(options={})

View file

@ -0,0 +1,15 @@
module Fog
module Rackspace
class LoadBalancer
class Real
def get_monitor(load_balancer_id)
request(
:expects => 200,
:path => "loadbalancers/#{load_balancer_id}/healthmonitor",
:method => 'GET'
)
end
end
end
end
end

View file

@ -0,0 +1,15 @@
module Fog
module Rackspace
class LoadBalancer
class Real
def remove_monitor(load_balancer_id)
request(
:expects => [200, 202],
:path => "loadbalancers/#{load_balancer_id}/healthmonitor",
:method => 'DELETE'
)
end
end
end
end
end

View file

@ -0,0 +1,31 @@
module Fog
module Rackspace
class LoadBalancer
class Real
def set_monitor(load_balancer_id, type, delay, timeout, attempsBeforeDeactivation, options = {})
data = {
'type' => type,
'delay' => delay,
'timeout' => timeout,
'attemptsBeforeDeactivation' => attempsBeforeDeactivation
}
if options.has_key? :path
data['path'] = options[:path]
end
if options.has_key? :body_regex
data['bodyRegex'] = options[:body_regex]
end
if options.has_key? :status_regex
data['statusRegex'] = options[:status_regex]
end
request(
:body => data.to_json,
:expects => [200, 202],
:path => "loadbalancers/#{load_balancer_id}/healthmonitor",
:method => 'PUT'
)
end
end
end
end
end

View file

@ -31,6 +31,17 @@ ACCESS_LIST_FORMAT = {
}
]
}
HEALTH_MONITOR_FORMAT = {
'healthMonitor' => {
'type' => Fog::Nullable::String,
'delay' => Fog::Nullable::Integer,
'timeout' => Fog::Nullable::Integer,
'attemptsBeforeDeactivation' => Fog::Nullable::Integer,
'path' => Fog::Nullable::String,
'bodyRegex' => Fog::Nullable::String,
'statusRegex' => Fog::Nullable::String
}
}
STATUS_ACTIVE = 'ACTIVE'

View file

@ -0,0 +1,52 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | monitor', ['rackspace']) do
@service = Fog::Rackspace::LoadBalancer.new
@lb = @service.load_balancers.create({
:name => ('fog' + Time.now.to_i.to_s),
:protocol => 'HTTP',
:port => 80,
:virtual_ips => [{ :type => 'PUBLIC'}],
:nodes => [{ :address => '10.0.0.1', :port => 80, :condition => 'ENABLED'}]
})
tests('success') do
@lb.wait_for { ready? }
tests("#get_monitor(#{@lb.id})").formats(HEALTH_MONITOR_FORMAT) do
@service.get_monitor(@lb.id).body
end
@lb.wait_for { ready? }
tests("#set_monitor(#{@lb.id}, 'CONNECT', 5, 5, 5)").succeeds do
@service.set_monitor(@lb.id, 'CONNECT', 5, 5, 5)
end
@lb.wait_for { ready? }
tests("#set_monitor(#{@lb.id}, 'HTTP', 5, 5, 5, :path => '/', :body_regex => '^200$', :status_regex => '^2[0-9][0-9]$')").succeeds do
@service.set_monitor(@lb.id, 'HTTP', 5, 5, 5, :path => '/', :body_regex => '^200$', :status_regex => '2[0-9][0-9]$')
end
@lb.wait_for { ready? }
tests("#get_monitor(#{@lb.id})").formats(HEALTH_MONITOR_FORMAT) do
@service.get_monitor(@lb.id).body
end
@lb.wait_for { ready? }
tests("#remove_monitor()").succeeds do
@service.remove_monitor(@lb.id)
end
end
tests('failure') do
tests("#set_monitor(#{@lb.id}, 'HTP', 5, 5, 5, 5)").raises(Fog::Rackspace::LoadBalancer::BadRequest) do
@service.set_monitor(@lb.id, 5, 5, 5, 5)
end
tests("#remove_monitor(#{@lb.id}) => No Monitor").raises(Fog::Rackspace::LoadBalancer::ServiceError) do
@service.remove_monitor(@lb.id)
end
end
@lb.wait_for { ready? }
@lb.destroy
end