2010-09-08 18:00:47 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Slicehost < Fog::Service
|
2010-09-08 18:00:47 -04:00
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :slicehost_password
|
|
|
|
recognizes :host, :port, :scheme, :persistent
|
2010-09-08 18:00:47 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
model_path 'fog/compute/models/slicehost'
|
2010-09-08 18:00:47 -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/slicehost'
|
2010-09-08 18:00:47 -04:00
|
|
|
request :create_slice
|
|
|
|
request :delete_slice
|
|
|
|
request :get_backups
|
|
|
|
request :get_flavor
|
|
|
|
request :get_flavors
|
|
|
|
request :get_image
|
|
|
|
request :get_images
|
|
|
|
request :get_slice
|
|
|
|
request :get_slices
|
|
|
|
request :reboot_slice
|
|
|
|
|
|
|
|
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-08 18:00:47 -04:00
|
|
|
def initialize(options={})
|
|
|
|
@slicehost_password = options[:slicehost_password]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@slicehost_password]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@slicehost_password)
|
2010-09-08 18:00:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-02-16 20:25:50 -05:00
|
|
|
require 'fog/core/parser'
|
|
|
|
|
2010-09-08 18:00:47 -04:00
|
|
|
@slicehost_password = options[:slicehost_password]
|
|
|
|
@host = options[:host] || "api.slicehost.com"
|
|
|
|
@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[:headers] ||= {}
|
|
|
|
params[:headers].merge!({
|
|
|
|
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).delete("\r\n")}"
|
|
|
|
})
|
|
|
|
case params[:method]
|
|
|
|
when 'DELETE', 'GET', 'HEAD'
|
|
|
|
params[:headers]['Accept'] = 'application/xml'
|
|
|
|
when 'POST', 'PUT'
|
|
|
|
params[:headers]['Content-Type'] = 'application/xml'
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
2010-11-29 23:07:47 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2010-09-08 18:00:47 -04:00
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::Slicehost::NotFound.slurp(error)
|
2010-09-08 18:00:47 -04:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|