2010-09-07 19:58:14 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class GoGrid < Fog::Service
|
2010-09-07 19:58:14 -04:00
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :go_grid_api_key, :go_grid_shared_secret
|
|
|
|
recognizes :host, :path, :port, :scheme, :persistent
|
2010-09-07 19:58:14 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
model_path 'fog/compute/models/go_grid'
|
2010-10-11 22:53:24 -04:00
|
|
|
model :image
|
|
|
|
collection :images
|
|
|
|
model :server
|
|
|
|
collection :servers
|
2011-01-30 18:11:36 -05:00
|
|
|
model :password
|
|
|
|
collection :passwords
|
2010-09-07 19:58:14 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
request_path 'fog/compute/requests/go_grid'
|
2010-09-07 19:58:14 -04:00
|
|
|
request :common_lookup_list
|
2010-10-11 22:53:24 -04:00
|
|
|
request :grid_image_get
|
2010-09-07 19:58:14 -04:00
|
|
|
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
|
2011-01-30 18:11:36 -05:00
|
|
|
request :support_password_get
|
|
|
|
request :support_password_list
|
2010-09-07 19:58:14 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-17 22:40:17 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2010-09-07 19:58:14 -04:00
|
|
|
def initialize(options={})
|
|
|
|
@go_grid_api_key = options[:go_grid_api_key]
|
|
|
|
@go_grid_shared_secret = options[:go_grid_shared_secret]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@go_grid_api_key]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@go_grid_api_key)
|
2010-09-07 19:58:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2010-10-29 17:58:28 -04:00
|
|
|
require 'digest/md5'
|
|
|
|
require 'json'
|
2010-09-07 19:58:14 -04:00
|
|
|
@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'
|
2010-09-07 19:58:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request(
|
|
|
|
params.merge!(:path => "#{@path}/#{params[:path]}")
|
|
|
|
)
|
2010-11-29 23:07:47 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2010-09-07 19:58:14 -04:00
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::GoGrid::NotFound.slurp(error)
|
2010-09-07 19:58:14 -04:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
unless response.body.empty?
|
|
|
|
response.body = JSON.parse(response.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|