2013-02-17 18:14:17 -05:00
|
|
|
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
|
|
|
|
|
2013-02-28 22:05:38 -05:00
|
|
|
request :add_machine_to_lb_application
|
2013-02-28 21:24:11 -05:00
|
|
|
|
2013-02-28 22:05:38 -05:00
|
|
|
request :add_machine_to_lb_backend
|
2013-02-28 21:24:11 -05:00
|
|
|
|
2013-02-28 22:05:38 -05:00
|
|
|
request :remove_machine_from_lb_backend
|
2013-02-28 21:24:11 -05:00
|
|
|
|
2013-02-28 22:05:38 -05:00
|
|
|
request :update_lb_backend_machine
|
2013-02-28 21:24:11 -05:00
|
|
|
|
2013-02-17 18:14:17 -05:00
|
|
|
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
|
2013-03-04 21:53:19 -05:00
|
|
|
unless response.body.empty? || params[:headers]['Accept'] == 'text/plain'
|
2013-02-17 18:14:17 -05:00
|
|
|
response.body = Fog::JSON.decode(response.body)
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|