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

[rackspace|loadbalancers] cleanup

pluralize service name
use multi_json
fix directory structure for consistency
This commit is contained in:
geemus 2011-08-04 16:21:22 -05:00
parent 4a2da72eab
commit d2e06e96ca
66 changed files with 102 additions and 100 deletions

View file

@ -9,8 +9,8 @@ class Rackspace < Fog::Bin
Fog::Compute::Rackspace
when :storage
Fog::Storage::Rackspace
when :load_balancer
Fog::Rackspace::LoadBalancer
when :load_balancers
Fog::Rackspace::LoadBalancers
else
raise ArgumentError, "Unrecognized service: #{key}"
end
@ -27,6 +27,8 @@ class Rackspace < Fog::Bin
Fog::Compute.new(:provider => 'Rackspace')
when :dns
Fog::DNS.new(:provider => 'Rackspace')
when :load_balancers
Fog::Rackspace::LoadBalancers.new
when :storage
Formatador.display_line("[yellow][WARN] Rackspace[:storage] is deprecated, use Storage[:rackspace] instead[/]")
Fog::Storage.new(:provider => 'Rackspace')

View file

@ -8,7 +8,7 @@ module Fog
service(:cdn, 'cdn/rackspace')
service(:compute, 'compute/rackspace')
service(:storage, 'storage/rackspace')
service(:load_balancer, 'rackspace/load_balancer')
service(:load_balancers, 'rackspace/load_balancers')
def self.authenticate(options)
rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com"

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer < Fog::Service
class LoadBalancers < Fog::Service
class ServiceError < Fog::Errors::Error
attr_reader :response_data
@ -10,7 +10,7 @@ module Fog
data = nil
message = nil
else
data = JSON.parse(error.response.body)
data = MultiJson.decode(error.response.body)
message = data['message']
end
@ -43,7 +43,7 @@ module Fog
recognizes :rackspace_auth_url
recognizes :rackspace_auth_token
model_path 'fog/rackspace/models'
model_path 'fog/rackspace/models/load_balancers'
collection :load_balancers
model :load_balancer
collection :nodes
@ -53,7 +53,7 @@ module Fog
collection :access_rules
model :access_rule
request_path 'fog/rackspace/requests'
request_path 'fog/rackspace/requests/load_balancers'
request :create_load_balancer
request :get_load_balancer
request :list_load_balancers
@ -90,7 +90,7 @@ module Fog
class Real
def initialize(options={})
require 'json'
require 'multi_json'
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url]
@ -135,7 +135,7 @@ module Fog
raise ServiceError.slurp error
end
unless response.body.empty?
response.body = JSON.parse(response.body)
response.body = MultiJson.decode(response.body)
end
response
end

View file

@ -2,7 +2,7 @@ require 'fog/core/model'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class AccessRule < Fog::Model
identity :id
@ -22,9 +22,9 @@ module Fog
connection.create_access_rule(load_balancer.id, address, type)
#Unfortunately, access rules creation doesn't return an ID, we require a subsequent list call and comparison
data = connection.list_access_rules(load_balancer.id).body['accessList']
.select { |ar| ar['address'] == address and ar['type'] == type }
.first
data = connection.list_access_rules(load_balancer.id).body['accessList'].select do |ar|
ar['address'] == address && ar['type'] == type
end.first
merge_attributes(data)
true
end

View file

@ -1,11 +1,11 @@
require 'fog/core/collection'
require 'fog/rackspace/models/access_rule'
require 'fog/rackspace/models/load_balancers/access_rule'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class AccessRules < Fog::Collection
model Fog::Rackspace::LoadBalancer::AccessRule
model Fog::Rackspace::LoadBalancers::AccessRule
attr_accessor :load_balancer

View file

@ -2,7 +2,7 @@ require 'fog/core/model'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class LoadBalancer < Fog::Model
#States
@ -36,7 +36,7 @@ module Fog
def access_rules
@access_rules ||= begin
Fog::Rackspace::LoadBalancer::AccessRules.new({
Fog::Rackspace::LoadBalancers::AccessRules.new({
:connection => connection,
:load_balancer => self})
end
@ -48,7 +48,7 @@ module Fog
def nodes
@nodes ||= begin
Fog::Rackspace::LoadBalancer::Nodes.new({
Fog::Rackspace::LoadBalancers::Nodes.new({
:connection => connection,
:load_balancer => self})
end
@ -60,7 +60,7 @@ module Fog
def virtual_ips
@virtual_ips ||= begin
Fog::Rackspace::LoadBalancer::VirtualIps.new({
Fog::Rackspace::LoadBalancers::VirtualIps.new({
:connection => connection,
:load_balancer => self})
end

View file

@ -1,13 +1,13 @@
require 'fog/core/collection'
require 'fog/rackspace/models/load_balancer'
require 'fog/rackspace/models/load_balancers/load_balancer'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class LoadBalancers < Fog::Collection
class LoadBalancerss < Fog::Collection
model Fog::Rackspace::LoadBalancer::LoadBalancer
model Fog::Rackspace::LoadBalancers::LoadBalancer
def all
data = connection.list_load_balancers.body['loadBalancers']
@ -18,7 +18,7 @@ module Fog
if load_balancer = connection.get_load_balancer(load_balancer_id).body['loadBalancer']
new(load_balancer)
end
rescue Fog::Rackspace::LoadBalancer::NotFound
rescue Fog::Rackspace::LoadBalancers::NotFound
nil
end
end

View file

@ -2,7 +2,7 @@ require 'fog/core/model'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Node < Fog::Model
identity :id

View file

@ -1,11 +1,11 @@
require 'fog/core/collection'
require 'fog/rackspace/models/node'
require 'fog/rackspace/models/load_balancers/node'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Nodes < Fog::Collection
model Fog::Rackspace::LoadBalancer::Node
model Fog::Rackspace::LoadBalancers::Node
attr_accessor :load_balancer
@ -20,7 +20,7 @@ module Fog
if node = connection.get_node(load_balancer.id, node_id).body['node']
new(node)
end
rescue Fog::Rackspace::LoadBalancer::NotFound
rescue Fog::Rackspace::LoadBalancers::NotFound
nil
end
end

View file

@ -2,7 +2,7 @@ require 'fog/core/model'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class VirtualIp < Fog::Model
identity :id

View file

@ -1,11 +1,11 @@
require 'fog/core/collection'
require 'fog/rackspace/models/virtual_ip'
require 'fog/rackspace/models/load_balancers/virtual_ip'
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class VirtualIps < Fog::Collection
model Fog::Rackspace::LoadBalancer::VirtualIp
model Fog::Rackspace::LoadBalancers::VirtualIp
attr_accessor :load_balancer

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def create_access_rule(load_balancer_id, address, type)
#TODO - This can actually support adding multiple access rules.
@ -12,7 +12,7 @@ module Fog
}
]}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "loadbalancers/#{load_balancer_id}/accesslist"

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def create_load_balancer(name, protocol, port, virtual_ips, nodes)
data = {
@ -14,7 +14,7 @@ module Fog
}
}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => 202,
:method => 'POST',
:path => 'loadbalancers.json'

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def create_node(load_balancer_id, address, port, condition, options = {})
data = {
@ -15,7 +15,7 @@ module Fog
data['nodes'][0]['weight'] = options[:weight]
end
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "loadbalancers/#{load_balancer_id}/nodes.json"

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def create_virtual_ip(load_balancer_id, type)
data = {
@ -8,7 +8,7 @@ module Fog
'ipVersion' => 'IPV6'
}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "loadbalancers/#{load_balancer_id}/virtualips.json"

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def delete_access_rule(load_balancer_id, access_rule_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def delete_all_access_rules(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def delete_load_balancer(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def delete_node(load_balancer_id, node_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def delete_nodes(load_balancer_id, *node_ids)
query_string = node_ids.collect { |node_id| "id=#{node_id}" }.join('&')

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def delete_virtual_ip(load_balancer_id, virtual_ip_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_connection_logging(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_connection_throttling(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_load_balancer(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_load_balancer_usage(load_balancer_id, options = {})
#TODO - Didn't implement usage/current. Not sure if it is needed

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_monitor(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_node(load_balancer_id, node_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_session_persistence(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def get_usage(options = {})
if options.has_key? :start_time and options.has_key? :end_time

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def list_access_rules(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def list_algorithms
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def list_load_balancers
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def list_nodes(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def list_protocols
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def list_virtual_ips(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def remove_connection_throttling(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def remove_monitor(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def remove_session_persistence(load_balancer_id)
request(

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def set_connection_logging(load_balancer_id, value)
data = {
@ -9,7 +9,7 @@ module Fog
}
}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:path => "loadbalancers/#{load_balancer_id}/connectionlogging",
:method => 'PUT'

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def set_connection_throttling(load_balancer_id, max_connections, min_connections, max_connection_rate, rate_interval)
data = {
@ -10,7 +10,7 @@ module Fog
'rateInterval' => rate_interval
}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:path => "loadbalancers/#{load_balancer_id}/connectionthrottle",
:method => 'PUT'

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def set_monitor(load_balancer_id, type, delay, timeout, attempsBeforeDeactivation, options = {})
data = {
@ -19,7 +19,7 @@ module Fog
data['statusRegex'] = options[:status_regex]
end
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:path => "loadbalancers/#{load_balancer_id}/healthmonitor",
:method => 'PUT'

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def set_session_persistence(load_balancer_id, persistence_type)
data = {
@ -9,7 +9,7 @@ module Fog
}
}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:path => "loadbalancers/#{load_balancer_id}/sessionpersistence",
:method => 'PUT'

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def update_load_balancer(load_balancer_id, options = {})
data = {
@ -12,7 +12,7 @@ module Fog
}
}
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => 202,
:method => 'PUT',
:path => "loadbalancers/#{load_balancer_id}.json"

View file

@ -1,6 +1,6 @@
module Fog
module Rackspace
class LoadBalancer
class LoadBalancers
class Real
def update_node(load_balancer_id, node_id, options = {})
data = {
@ -14,7 +14,7 @@ module Fog
end
#TODO - Do anything if no valid options are passed in?
request(
:body => data.to_json,
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'PUT',
:path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}.json"

View file

@ -1,7 +1,7 @@
module Shindo
class Tests
def given_a_load_balancer_service(&block)
@service = Fog::Rackspace::LoadBalancer.new
@service = Fog::Rackspace::LoadBalancers.new
instance_eval(&block)
end
def given_a_load_balancer(&block)

View file

@ -1,6 +1,6 @@
Shindo.tests('Fog::Rackspace::LoadBalancer', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers', ['rackspace']) do
@service = Fog::Rackspace::LoadBalancer.new
@service = Fog::Rackspace::LoadBalancers.new
tests('#algorithms').succeeds do
data = @service.algorithms

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | access_list', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | access_list', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | access_lists', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | access_lists', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer', ['rackspace']) do
LOAD_BALANCER_ATTRIBUTES = {
:name => 'fog' + Time.now.to_i.to_s,

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancers', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancers', ['rackspace']) do
given_a_load_balancer_service do
@lb_name = 'fog' + Time.now.to_i.to_s

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | node', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | node', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | nodes', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | nodes', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | virtual_ip', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | virtual_ip', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | virtual_ips', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | virtual_ips', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | access_lists_tests', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | access_lists_tests', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | algorithm_tests', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | algorithm_tests', ['rackspace']) do
ALGORITHMS_FORMAT = {
'algorithms' => [

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | connection_logging', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | connection_logging', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | connection_throttling', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | connection_throttling', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_tests', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace']) do
given_a_load_balancer_service do
tests('success') do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_usage', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_usage', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | monitor', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | monitor', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | load_balancer_tests', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | protocol_tests', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | protocol_tests', ['rackspace']) do
PROTOCOLS_FORMAT = {
'protocols' => [

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | session_persistence', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | session_persistence', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | usage', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | usage', ['rackspace']) do
given_a_load_balancer_service do
tests('success') do

View file

@ -1,4 +1,4 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | virtual_ip_tests', ['rackspace']) do
Shindo.tests('Fog::Rackspace::LoadBalancers | virtual_ip_tests', ['rackspace']) do
given_a_load_balancer_service do
given_a_load_balancer do