mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Rackspace LB: Made some updates from the pull request
This commit is contained in:
parent
4d1ad7adb4
commit
4b81789cd5
11 changed files with 35 additions and 83 deletions
|
@ -7,7 +7,6 @@ module Fog
|
|||
|
||||
def self.slurp(error)
|
||||
#TODO Where is the best place to do this json require
|
||||
require 'json'
|
||||
if error.response.body.empty?
|
||||
data = nil
|
||||
message = nil
|
||||
|
@ -123,4 +122,3 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,25 +26,27 @@ module Fog
|
|||
end
|
||||
|
||||
def nodes
|
||||
@nodes
|
||||
@nodes ||= begin
|
||||
Fog::Rackspace::LoadBalancer::Nodes.new({
|
||||
:connection => connection,
|
||||
:load_balancer => self})
|
||||
end
|
||||
end
|
||||
|
||||
def nodes=(new_nodes=[])
|
||||
@nodes = Fog::Rackspace::LoadBalancer::Nodes.new({
|
||||
:connection => connection,
|
||||
:load_balancer => self})
|
||||
@nodes.load(new_nodes)
|
||||
nodes.load(new_nodes)
|
||||
end
|
||||
|
||||
def virtual_ips
|
||||
@virtual_ips
|
||||
@virtual_ips ||= begin
|
||||
Fog::Rackspace::LoadBalancer::VirtualIps.new({
|
||||
:connection => connection,
|
||||
:load_balancer => self})
|
||||
end
|
||||
end
|
||||
|
||||
def virtual_ips=(new_virtual_ips=[])
|
||||
@virtual_ips = Fog::Rackspace::LoadBalancer::VirtualIps.new({
|
||||
:connection => connection,
|
||||
:load_balancer => self})
|
||||
@virtual_ips.load(new_virtual_ips)
|
||||
virtual_ips.load(new_virtual_ips)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -69,7 +71,7 @@ module Fog
|
|||
private
|
||||
def create
|
||||
requires :name, :protocol, :port, :virtual_ips, :nodes
|
||||
data = connection.create_load_balancer(name, protocol, port, virtual_ips.to_object, nodes.to_object)
|
||||
data = connection.create_load_balancer(name, protocol, port, virtual_ips_hash, nodes_hash)
|
||||
merge_attributes(data.body['loadBalancer'])
|
||||
end
|
||||
|
||||
|
@ -85,6 +87,19 @@ module Fog
|
|||
#TODO - Should this bubble down to nodes? Without tracking changes this would be very inefficient.
|
||||
# For now, individual nodes will have to be saved individually after saving an LB
|
||||
end
|
||||
|
||||
def virtual_ips_hash
|
||||
virtual_ips.collect do |virtual_ip|
|
||||
{ :type => virtual_ip.type }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def nodes_hash
|
||||
nodes.collect do |node|
|
||||
{ :address => node.address, :port => node.port, :condition => node.condition, :weight => node.weight }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,10 +11,6 @@ module Fog
|
|||
|
||||
def all
|
||||
data = connection.list_load_balancers.body['loadBalancers']
|
||||
#TODO - Need to find a way to lazy load for performance.
|
||||
data = data.collect do |lb|
|
||||
connection.get_load_balancer(lb['id']).body['loadBalancer']
|
||||
end
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
|
|
@ -28,10 +28,6 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def to_object
|
||||
{ :address => address, :port => port, :condition => condition, :weight => weight }
|
||||
end
|
||||
|
||||
private
|
||||
def load_balancer
|
||||
collection.load_balancer
|
||||
|
|
|
@ -21,12 +21,6 @@ module Fog
|
|||
rescue Fog::Rackspace::LoadBalancer::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def to_object
|
||||
collect do |node|
|
||||
node.to_object
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,10 +25,6 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def to_object
|
||||
{ :type => type }
|
||||
end
|
||||
|
||||
private
|
||||
def load_balancer
|
||||
collection.load_balancer
|
||||
|
|
|
@ -21,12 +21,6 @@ module Fog
|
|||
data && new(data)
|
||||
end
|
||||
|
||||
def to_object
|
||||
collect do |node|
|
||||
node.to_object
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def all_raw
|
||||
connection.list_virtual_ips(load_balancer.id).body['virtualIps']
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer', ['rackspace']) do
|
||||
|
||||
@lb_name = 'fog' + Time.now.to_i.to_s
|
||||
model_tests(Fog::Rackspace::LoadBalancer.new.load_balancers,
|
||||
{
|
||||
:name => @lb_name,
|
||||
LOAD_BALANCER_ATTRIBUTES = {
|
||||
: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'}]
|
||||
},
|
||||
false) do
|
||||
}
|
||||
|
||||
@service = Fog::Rackspace::LoadBalancer.new
|
||||
|
||||
model_tests(@service.load_balancers, LOAD_BALANCER_ATTRIBUTES, false) do
|
||||
@instance.wait_for { ready? }
|
||||
|
||||
tests('#save => saving existing with port = 88').succeeds do
|
||||
|
|
|
@ -8,7 +8,6 @@ Shindo.tests('Fog::Rackspace::LoadBalancer | nodes', ['rackspace']) do
|
|||
:virtual_ips => [{ :type => 'PUBLIC'}],
|
||||
:nodes => [{ :address => '10.0.0.1', :port => 80, :condition => 'ENABLED'}]
|
||||
})
|
||||
#TODO - Add test to show that connection isn't passed to subcollections?
|
||||
@lb.wait_for { ready? }
|
||||
|
||||
begin
|
||||
|
|
|
@ -16,7 +16,7 @@ LOAD_BALANCERS_FORMAT = {
|
|||
'algorithm' => String,
|
||||
'status' => String,
|
||||
'virtualIps' => [VIRTUAL_IP_FORMAT],
|
||||
'nodes' => NODES_FORMAT,
|
||||
'nodes' => [SINGLE_NODE_FORMAT],
|
||||
'created' => { 'time' => String },
|
||||
'updated' => { 'time' => String }
|
||||
}]
|
||||
|
@ -31,7 +31,7 @@ LOAD_BALANCER_FORMAT = {
|
|||
'status' => String,
|
||||
'cluster' => { 'name' => String },
|
||||
'virtualIps' => [VIRTUAL_IP_FORMAT],
|
||||
'nodes' => [NODE_FORMAT],
|
||||
'nodes' => [SINGLE_NODE_FORMAT],
|
||||
'created' => { 'time' => String },
|
||||
'updated' => { 'time' => String },
|
||||
'connectionLogging' => { 'enabled' => Fog::Boolean }
|
||||
|
|
|
@ -1,42 +1,5 @@
|
|||
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_tests', ['rackspace']) do
|
||||
|
||||
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,
|
||||
'port' => Integer,
|
||||
'protocol' => String,
|
||||
'algorithm' => String,
|
||||
'status' => String,
|
||||
'cluster' => { 'name' => String },
|
||||
'virtualIps' => [VIRTUAL_IP_FORMAT],
|
||||
'nodes' => [NODE_FORMAT],
|
||||
'created' => { 'time' => String },
|
||||
'updated' => { 'time' => String },
|
||||
'connectionLogging' => { 'enabled' => Fog::Boolean }
|
||||
}}
|
||||
|
||||
@lb = Fog::Rackspace::LoadBalancer.new
|
||||
tests('success') do
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue