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

copy & paste to get Blocks LB API working

This commit is contained in:
Josh Yotty 2013-02-17 15:14:17 -08:00
parent 886e9156d8
commit 9342298844
13 changed files with 417 additions and 0 deletions

77
lib/fog/bluebox/blb.rb Normal file
View file

@ -0,0 +1,77 @@
require 'fog/bluebox'
module Fog
module Bluebox
class BLB < Fog::Service
requires :bluebox_api_key, :bluebox_customer_id
recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent
model_path 'fog/bluebox/models/blb'
model :lb_application
collection :lb_applications
model :lb_service
collection :lb_services
model :lb_backend
collection :lb_backends
request_path 'fog/bluebox/requests/blb'
request :get_lb_application
request :get_lb_applications
request :get_lb_service
request :get_lb_services
request :get_lb_backend
request :get_lb_backends
class Mock
end
class Real
def initialize(options={})
@bluebox_api_key = options[:bluebox_api_key]
@bluebox_customer_id = options[:bluebox_customer_id]
@connection_options = options[:connection_options] || {}
@host = options[:bluebox_host] || "boxpanel.bluebox.net"
@persistent = options[:persistent] || false
@port = options[:bluebox_port] || 443
@scheme = options[:bluebox_scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
def reload
@connection.reset
end
def request(params)
params[:headers] ||= {}
params[:headers].merge!({
'Authorization' => "Basic #{Base64.encode64([@bluebox_customer_id, @bluebox_api_key].join(':')).delete("\r\n")}"
})
begin
response = @connection.request(params.merge!({:host => @host}))
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Compute::Bluebox::NotFound.slurp(error)
else
error
end
end
unless response.body.empty?
response.body = Fog::JSON.decode(response.body)
end
response
end
end
end
end
end

View file

@ -0,0 +1,21 @@
require 'fog/core/model'
module Fog
module Bluebox
class BLB
class Application < Fog::Model
identity :id
attribute :name
attribute :ip_v4
attribute :ip_v6
attribute :services
attribute :description
attribute :created, :aliases => 'created_at'
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
module Fog
module Bluebox
class BLB
class Applications < Fog::Collection
def all
data = service.get_blocks.body
load(data)
end
def bootstrap(new_attributes = {})
server = create(new_attributes)
server.wait_for { ready? }
server.setup(:key_data => [server.private_key])
server
end
def get(server_id)
if server_id && server = service.get_block(server_id).body
new(server)
end
rescue Fog::Compute::Bluebox::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'fog/core/model'
module Fog
module Bluebox
class BLB
class Backend < Fog::Model
identity :id
attribute :name
attribute :machines
attribute :monitoring_url
attribute :monitoring_url_hostname
attribute :acl_name
attribute :acl_rule
attribute :check_interval
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
module Fog
module Bluebox
class BLB
class Applications < Fog::Collection
def all
data = service.get_blocks.body
load(data)
end
def bootstrap(new_attributes = {})
server = create(new_attributes)
server.wait_for { ready? }
server.setup(:key_data => [server.private_key])
server
end
def get(server_id)
if server_id && server = service.get_block(server_id).body
new(server)
end
rescue Fog::Compute::Bluebox::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,24 @@
require 'fog/core/model'
module Fog
module Bluebox
class BLB
class Service < Fog::Model
identity :id
attribute :name
attribute :port
attribute :backends
attribute :private
attribute :status_url
attribute :status_username
attribute :status_password
attribute :created, :aliases => 'created_at'
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
module Fog
module Bluebox
class BLB
class Applications < Fog::Collection
def all
data = service.get_blocks.body
load(data)
end
def bootstrap(new_attributes = {})
server = create(new_attributes)
server.wait_for { ready? }
server.setup(:key_data => [server.private_key])
server
end
def get(server_id)
if server_id && server = service.get_block(server_id).body
new(server)
end
rescue Fog::Compute::Bluebox::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Bluebox
class BLB
class Real
# Get details of a lb_application.
#
# ==== Parameters
# * lb_application_id<~Integer> - Id of block to lookup
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# TODO
def get_lb_application(lb_application_id)
request(
:expects => 200,
:method => 'GET',
:path => "api/lb_applications/#{lb_application_id}.json"
)
end
end
class Mock
end
end
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Bluebox
class BLB
class Real
# Get list of blocks
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'ip-v4'<~Array> - Ip addresses
# * 'ip-v6'<~String> - IP v6 address
# * 'name'<~String> - The hostname
# * 'source-ip-v4'<~String> - Where traffic comes from
# * 'services'<~Array> - Listening services
def get_lb_applications
request(
:expects => 200,
:method => 'GET',
:path => 'api/lb_applications.json'
)
end
end
class Mock
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Bluebox
class BLB
class Real
# Get details of a lb_backend.
#
# ==== Parameters
# * lb_service_id - service backend belongs to
# * lb_backend_id<~Integer> - backend to look up
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# TODO
def get_lb_backend(lb_service_id, lb_backend_id)
request(
:expects => 200,
:method => 'GET',
:path => "api/lb_services/#{lb_service_id}/lb_backends/#{lb_backend_id}.json"
)
end
end
class Mock
end
end
end
end

View file

@ -0,0 +1,32 @@
module Fog
module Bluebox
class BLB
class Real
# Get list of backends
#
# ==== Parameters
# * lb_service_id - service containing backends
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'ip-v4'<~Array> - Ip addresses
# * 'ip-v6'<~String> - IP v6 address
# * 'name'<~String> - The hostname
# * 'source-ip-v4'<~String> - Where traffic comes from
# * 'services'<~Array> - Listening services
def get_lb_backends(lb_service_id)
request(
:expects => 200,
:method => 'GET',
:path => "api/lb_services/#{lb_service_id}/lb_backends.json"
)
end
end
class Mock
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Bluebox
class BLB
class Real
# Get details of a lb_service.
#
# ==== Parameters
# * lb_application_id<~String> - Id of application the service is in
# * lb_service_id<~String> - Id of service to lookup
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# TODO
def get_lb_service(lb_application_id, lb_service_id)
request(
:expects => 200,
:method => 'GET',
:path => "api/lb_applications/#{lb_application_id}/lb_services/#{lb_service_id}.json"
)
end
end
class Mock
end
end
end
end

View file

@ -0,0 +1,27 @@
module Fog
module Bluebox
class BLB
class Real
# Get list of load balancing services
#
# ==== Parameters
# * lb_application_id<~String> - Id of application services to list
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
def get_lb_services(lb_application_id)
request(
:expects => 200,
:method => 'GET',
:path => "api/lb_applications/#{lb_application_id}/lb_services.json"
)
end
end
class Mock
end
end
end
end