2011-01-19 15:47:35 -05:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Voxel < Fog::Service
|
2011-01-19 15:47:35 -05:00
|
|
|
|
|
|
|
requires :voxel_api_key, :voxel_api_secret
|
2011-06-16 19:39:51 -04:00
|
|
|
recognizes :host, :port, :scheme, :persistent
|
2011-01-19 15:47:35 -05:00
|
|
|
|
|
|
|
model_path 'fog/compute/models/voxel'
|
|
|
|
model :image
|
|
|
|
collection :images
|
2011-01-19 17:07:04 -05:00
|
|
|
model :server
|
|
|
|
collection :servers
|
2011-01-19 15:47:35 -05:00
|
|
|
|
|
|
|
request_path 'fog/compute/requests/voxel'
|
|
|
|
request :images_list
|
2011-01-19 17:07:04 -05:00
|
|
|
request :devices_list
|
2011-02-23 18:00:56 -05:00
|
|
|
request :devices_power
|
2011-01-19 19:17:23 -05:00
|
|
|
request :voxcloud_create
|
|
|
|
request :voxcloud_status
|
2011-02-23 18:00:56 -05:00
|
|
|
request :voxcloud_delete
|
2011-01-19 15:47:35 -05:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
include Collections
|
2011-02-20 14:39:37 -05:00
|
|
|
|
|
|
|
def self.data
|
2011-03-10 14:16:55 -05:00
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {
|
|
|
|
:last_modified => { :servers => {}, :statuses => {}, :images => {} },
|
|
|
|
:servers => [],
|
|
|
|
:statuses => {},
|
|
|
|
:images => [
|
|
|
|
{'id' => 1, 'name' => "CentOS 4, 32-bit, base install"},
|
|
|
|
{'id' => 2, 'name' => "CentOS 4, 64-bit, base install"},
|
|
|
|
{'id' => 3, 'name' => "CentOS 5, 32-bit, base install"},
|
|
|
|
{'id' => 4, 'name' => "CentOS 5, 64-bit, base install"},
|
|
|
|
{'id' => 7, 'name' => "Fedora 10, 32-bit, base install"},
|
|
|
|
{'id' => 8, 'name' => "Fedora 10, 64-bit, base install"},
|
|
|
|
{'id' => 10, 'name' => "OpenSUSE 11, 64-bit, base install"},
|
|
|
|
{'id' => 11, 'name' => "Debian 5.0 \"lenny\", 32-bit, base install"},
|
|
|
|
{'id' => 12, 'name' => "Debian 5.0 \"lenny\", 64-bit, base install"},
|
|
|
|
{'id' => 13, 'name' => "Ubuntu 8.04 \"Hardy\", 32-bit, base install"},
|
|
|
|
{'id' => 14, 'name' => "Ubuntu 8.04 \"Hardy\", 64-bit, base install"},
|
|
|
|
{'id' => 15, 'name' => "Voxel Server Environment (VSE), 32-bit, base install"},
|
|
|
|
{'id' => 16, 'name' => "Voxel Server Environment (VSE), 64-bit, base install"},
|
|
|
|
{'id' => 32, 'name' => "Pantheon Official Mercury Stack for Drupal (based on VSE/64)"},
|
|
|
|
{'id' => 55, 'name' => "Ubuntu 10.04 \"Lucid\", 64-bit, base install"} ]
|
|
|
|
}
|
2011-02-20 14:39:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-17 22:40:17 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2011-02-20 14:39:37 -05:00
|
|
|
def initialize(options={})
|
2011-03-10 14:16:55 -05:00
|
|
|
@voxel_api_key = options[:voxel_api_key]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@voxel_api_key]
|
2011-02-20 14:39:37 -05:00
|
|
|
end
|
2011-03-10 14:16:55 -05:00
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@voxel_api_key)
|
|
|
|
end
|
|
|
|
|
2011-01-19 15:47:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
include Collections
|
|
|
|
|
|
|
|
def initialize(options = {})
|
2011-01-20 13:54:56 -05:00
|
|
|
require 'time'
|
|
|
|
require 'digest/md5'
|
|
|
|
|
|
|
|
@voxel_api_key = options[:voxel_api_key]
|
|
|
|
@voxel_api_secret = options[:voxel_api_secret]
|
|
|
|
|
2011-02-20 22:01:28 -05:00
|
|
|
@host = options[:host] || "api.voxel.net"
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2011-02-23 18:00:56 -05:00
|
|
|
@persistent = options[:persistent] || false
|
2011-02-20 22:01:28 -05:00
|
|
|
|
2011-01-20 13:54:56 -05:00
|
|
|
Excon.ssl_verify_peer = false
|
|
|
|
|
2011-02-20 22:01:28 -05:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent)
|
2011-01-19 15:47:35 -05:00
|
|
|
end
|
|
|
|
|
2011-02-23 18:00:56 -05:00
|
|
|
def request(method_name, options = {})
|
2011-01-20 13:54:56 -05:00
|
|
|
begin
|
2011-02-23 18:00:56 -05:00
|
|
|
parser = options.delete(:parser)
|
|
|
|
options.merge!({ :method => method_name, :timestamp => Time.now.xmlschema, :key => @voxel_api_key })
|
2011-01-20 13:54:56 -05:00
|
|
|
options[:api_sig] = create_signature(@voxel_api_secret, options)
|
2011-02-23 18:00:56 -05:00
|
|
|
data = @connection.request(
|
|
|
|
:method => "POST",
|
|
|
|
:query => options,
|
|
|
|
:parser => parser,
|
|
|
|
:path => "/version/1.0/"
|
|
|
|
)
|
|
|
|
unless data.body['stat'] == 'ok'
|
|
|
|
raise Fog::Voxel::Compute::Error, "#{data.body['err']['msg']}"
|
|
|
|
end
|
|
|
|
data
|
2011-01-20 13:54:56 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::Voxel::NotFound.slurp(error)
|
2011-01-20 13:54:56 -05:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_signature(secret, options)
|
|
|
|
to_sign = options.keys.map { |k| k.to_s }.sort.map { |k| "#{k}#{options[k.to_sym]}" }.join("")
|
|
|
|
Digest::MD5.hexdigest( secret + to_sign )
|
2011-01-19 15:47:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|