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

119 lines
3.5 KiB
Ruby
Raw Normal View History

module Fog
module GoGrid
class Compute < Fog::Service
requires :go_grid_api_key, :go_grid_shared_secret
recognizes :host, :path, :port, :scheme, :persistent
2011-01-07 21:14:39 -05:00
recognizes :provider # remove post deprecation
2011-01-07 19:52:09 -05:00
model_path 'fog/compute/models/go_grid'
model :image
collection :images
model :server
collection :servers
2011-01-07 19:52:09 -05:00
request_path 'fog/compute/requests/go_grid'
request :common_lookup_list
request :grid_image_get
request :grid_image_list
request :grid_ip_list
request :grid_loadbalancer_list
request :grid_server_add
request :grid_server_delete
request :grid_server_get
request :grid_server_list
request :grid_server_power
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={})
2011-01-07 21:14:39 -05:00
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::GoGrid::Compute.new is deprecated, use Fog::Compute.new(:provider => 'GoGrid') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end
@go_grid_api_key = options[:go_grid_api_key]
@go_grid_shared_secret = options[:go_grid_shared_secret]
@data = self.class.data[@go_grid_api_key]
end
end
class Real
def initialize(options={})
2011-01-07 21:14:39 -05:00
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::GoGrid::Compute.new is deprecated, use Fog::Compute.new(:provider => 'GoGrid') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end
require 'digest/md5'
require 'json'
@go_grid_api_key = options[:go_grid_api_key]
@go_grid_shared_secret = options[:go_grid_shared_secret]
@host = options[:host] || "api.gogrid.com"
@path = options[:path] || "/api"
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end
def reload
@connection.reset
end
def request(params)
params = {
:expects => 200,
:method => 'GET'
}.merge!(params)
params[:query] ||= {}
params[:query].merge!({
'api_key' => @go_grid_api_key,
'format' => 'json',
'sig' => Digest::MD5.hexdigest("#{@go_grid_api_key}#{@go_grid_shared_secret}#{Time.now.to_i}"),
2010-10-11 02:16:40 -04:00
'v' => '1.5'
})
begin
response = @connection.request(
params.merge!(:path => "#{@path}/#{params[:path]}")
)
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::GoGrid::Compute::NotFound.slurp(error)
else
error
end
end
unless response.body.empty?
response.body = JSON.parse(response.body)
end
response
end
end
end
end
end