2010-09-07 19:26:01 -04:00
|
|
|
module Fog
|
|
|
|
module Bluebox
|
2010-09-08 15:07:45 -04:00
|
|
|
class Compute < Fog::Service
|
2010-09-07 19:26:01 -04:00
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :bluebox_api_key, :bluebox_customer_id
|
|
|
|
recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent
|
2010-09-07 19:26:01 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
model_path 'fog/compute/models/bluebox'
|
2010-09-07 19:26:01 -04:00
|
|
|
model :flavor
|
|
|
|
collection :flavors
|
|
|
|
model :image
|
|
|
|
collection :images
|
|
|
|
model :server
|
|
|
|
collection :servers
|
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
request_path 'fog/compute/requests/bluebox'
|
2010-09-07 19:26:01 -04:00
|
|
|
request :create_block
|
|
|
|
request :destroy_block
|
|
|
|
request :get_block
|
|
|
|
request :get_blocks
|
|
|
|
request :get_product
|
|
|
|
request :get_products
|
|
|
|
request :get_template
|
|
|
|
request :get_templates
|
|
|
|
request :reboot_block
|
|
|
|
|
|
|
|
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={})
|
2010-10-29 17:58:28 -04:00
|
|
|
require 'json'
|
2010-09-07 19:26:01 -04:00
|
|
|
@bluebox_api_key = options[:bluebox_api_key]
|
|
|
|
@bluebox_customer_id = options[:bluebox_customer_id]
|
|
|
|
@host = options[:bluebox_host] || "boxpanel.blueboxgrp.com"
|
|
|
|
@port = options[:bluebox_port] || 443
|
|
|
|
@scheme = options[:bluebox_scheme] || 'https'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
|
|
|
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}))
|
2010-11-29 23:07:47 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2010-09-07 19:26:01 -04:00
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2010-09-08 17:00:43 -04:00
|
|
|
Fog::Bluebox::Compute::NotFound.slurp(error)
|
2010-09-07 19:26:01 -04:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
unless response.body.empty?
|
|
|
|
response.body = JSON.parse(response.body)
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|