2010-05-24 13:29:01 -04:00
|
|
|
module Fog
|
|
|
|
module Bluebox
|
2010-05-24 14:03:52 -04:00
|
|
|
require 'fog/bluebox/models/images'
|
2010-06-02 11:55:06 -04:00
|
|
|
require 'fog/bluebox/requests/get_templates'
|
2010-05-24 14:03:52 -04:00
|
|
|
require 'fog/bluebox/models/flavors'
|
2010-06-02 11:55:06 -04:00
|
|
|
require 'fog/bluebox/requests/get_products'
|
2010-05-24 14:03:52 -04:00
|
|
|
require 'fog/bluebox/models/flavor'
|
2010-06-02 11:55:06 -04:00
|
|
|
require 'fog/bluebox/requests/get_product'
|
2010-05-24 14:03:52 -04:00
|
|
|
require 'fog/bluebox/models/servers'
|
|
|
|
require 'fog/bluebox/requests/get_blocks'
|
|
|
|
require 'fog/bluebox/models/server'
|
|
|
|
require 'fog/bluebox/requests/get_block'
|
|
|
|
require 'fog/bluebox/requests/create_block'
|
|
|
|
require 'fog/bluebox/requests/destroy_block'
|
|
|
|
require 'fog/bluebox/requests/reboot_block'
|
2010-05-24 13:29:01 -04:00
|
|
|
|
|
|
|
def self.new(options={})
|
|
|
|
|
|
|
|
unless options[:bluebox_api_key]
|
|
|
|
raise ArgumentError.new('bluebox_api_key is required to access Blue Box')
|
|
|
|
end
|
|
|
|
if Fog.mocking?
|
|
|
|
Fog::Bluebox::Mock.new(options)
|
|
|
|
else
|
|
|
|
Fog::Bluebox::Real.new(options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset_data(keys=Mock.data.keys)
|
|
|
|
Mock.reset_data(keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset_data(keys=data.keys)
|
|
|
|
for key in [*keys]
|
|
|
|
data.delete(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@bluebox_api_key = options[:bluebox_api_key]
|
|
|
|
@data = self.class.data[@bluebox_api_key]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@bluebox_api_key = options[:bluebox_api_key]
|
2010-05-24 14:03:52 -04:00
|
|
|
@host = options[:bluebox_host] || "boxpanel.blueboxgrp.com"
|
|
|
|
@port = options[:bluebox_port] || 443
|
|
|
|
@scheme = options[:bluebox_scheme] || 'https'
|
2010-05-24 13:29:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
2010-06-02 11:31:33 -04:00
|
|
|
params[:headers] ||= {}
|
|
|
|
params[:headers].merge!({
|
|
|
|
'Authorization' => "Basic #{Base64.encode64(@bluebox_api_key).delete("\r\n")}"
|
|
|
|
})
|
2010-05-24 13:29:01 -04:00
|
|
|
case params[:method]
|
|
|
|
when 'DELETE', 'GET', 'HEAD'
|
2010-06-02 11:31:33 -04:00
|
|
|
params[:headers]['Accept'] = 'application/xml'
|
2010-05-24 13:29:01 -04:00
|
|
|
when 'POST', 'PUT'
|
2010-06-02 11:31:33 -04:00
|
|
|
params[:headers]['Content-Type'] = 'application/xml'
|
2010-05-24 13:29:01 -04:00
|
|
|
end
|
|
|
|
|
2010-06-02 00:45:07 -04:00
|
|
|
@connection.request({:host => @host}.merge!(params))
|
2010-05-24 13:29:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|