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:
parent
26358ecb98
commit
e355a5ccb4
4 changed files with 85 additions and 4 deletions
|
@ -14,6 +14,8 @@ module Fog
|
||||||
model :flavor
|
model :flavor
|
||||||
collection :images
|
collection :images
|
||||||
model :image
|
model :image
|
||||||
|
collection :load_balancers
|
||||||
|
model :load_balancer
|
||||||
collection :zones
|
collection :zones
|
||||||
model :zone
|
model :zone
|
||||||
collection :cloud_ips
|
collection :cloud_ips
|
||||||
|
|
50
lib/fog/brightbox/models/compute/load_balancer.rb
Normal file
50
lib/fog/brightbox/models/compute/load_balancer.rb
Normal 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
|
28
lib/fog/brightbox/models/compute/load_balancers.rb
Normal file
28
lib/fog/brightbox/models/compute/load_balancers.rb
Normal 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
|
|
@ -25,6 +25,8 @@ Shindo.tests('Brightbox::Compute | load balancer requests', ['brightbox']) do
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Brightbox[:compute].load_balancers.get(@load_balancer_id).wait_for { ready? }
|
||||||
|
|
||||||
# tests("#list_load_balancers()").formats(Brightbox::Compute::Formats::Collection::LOAD_BALANCERS) do
|
# tests("#list_load_balancers()").formats(Brightbox::Compute::Formats::Collection::LOAD_BALANCERS) do
|
||||||
# Brightbox[:compute].list_load_balancers
|
# Brightbox[:compute].list_load_balancers
|
||||||
# end
|
# end
|
||||||
|
@ -33,10 +35,9 @@ Shindo.tests('Brightbox::Compute | load balancer requests', ['brightbox']) do
|
||||||
Brightbox[:compute].get_load_balancer(@load_balancer_id)
|
Brightbox[:compute].get_load_balancer(@load_balancer_id)
|
||||||
end
|
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
|
||||||
# tests("#destroy_load_balancer('#{@load_balancer_id}')").formats(Brightbox::Compute::Formats::Full::LOAD_BALANCER) do
|
Brightbox[:compute].destroy_load_balancer(@load_balancer_id)
|
||||||
# Brightbox[:compute].destroy_load_balancer(@load_balancer_id)
|
end
|
||||||
# end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue