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

[brightbox] Rough LoadBalancer model in place

This commit is contained in:
Paul Thornthwaite 2010-12-03 14:54:50 +00:00
parent 26358ecb98
commit e355a5ccb4
4 changed files with 85 additions and 4 deletions

View file

@ -14,6 +14,8 @@ module Fog
model :flavor
collection :images
model :image
collection :load_balancers
model :load_balancer
collection :zones
model :zone
collection :cloud_ips

View file

@ -0,0 +1,50 @@
require 'fog/core/model'
module Fog
module Brightbox
class Compute
class LoadBalancer < Fog::Model
identity :id
attribute :url
attribute :name
attribute :status
attribute :resource_type
attribute :nodes
attribute :policy
attribute :healthcheck
attribute :listeners
attribute :account
def ready?
status == 'active'
end
def save
requires :nodes, :listeners, :healthcheck
options = {
:nodes => nodes,
:listeners => listeners,
:healthcheck => healthcheck,
:policy => policy,
:name => name
}.delete_if {|k,v| v.nil? || v == "" }
data = connection.create_load_balancer(options)
merge_attributes(data)
true
end
def destroy
requires :identity
connection.destroy_load_balancer(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/brightbox/models/compute/load_balancer'
module Fog
module Brightbox
class Compute
class LoadBalancers < Fog::Collection
model Fog::Brightbox::Compute::LoadBalancer
def all
data = connection.list_load_balancers
load(data)
end
def get(identifier)
data = connection.get_load_balancer(identifier)
new(data)
rescue Excon::Errors::NotFound
nil
end
end
end
end
end

View file

@ -25,6 +25,8 @@ Shindo.tests('Brightbox::Compute | load balancer requests', ['brightbox']) do
data
end
Brightbox[:compute].load_balancers.get(@load_balancer_id).wait_for { ready? }
# tests("#list_load_balancers()").formats(Brightbox::Compute::Formats::Collection::LOAD_BALANCERS) do
# Brightbox[:compute].list_load_balancers
# end
@ -33,10 +35,9 @@ Shindo.tests('Brightbox::Compute | load balancer requests', ['brightbox']) do
Brightbox[:compute].get_load_balancer(@load_balancer_id)
end
# May fail since the load balancer is likely to still be "creating" when this test is called
# tests("#destroy_load_balancer('#{@load_balancer_id}')").formats(Brightbox::Compute::Formats::Full::LOAD_BALANCER) do
# Brightbox[:compute].destroy_load_balancer(@load_balancer_id)
# end
tests("#destroy_load_balancer('#{@load_balancer_id}')").formats(Brightbox::Compute::Formats::Full::LOAD_BALANCER) do
Brightbox[:compute].destroy_load_balancer(@load_balancer_id)
end
end