2009-11-27 00:04:49 -05:00
|
|
|
module Fog
|
2010-03-17 23:51:55 -04:00
|
|
|
module Slicehost
|
2010-06-12 18:31:17 -04:00
|
|
|
extend Fog::Service
|
|
|
|
|
|
|
|
requires :slicehost_password
|
|
|
|
|
|
|
|
model_path 'fog/slicehost/models'
|
|
|
|
model 'flavor'
|
|
|
|
model 'flavors'
|
|
|
|
model 'image'
|
|
|
|
model 'images'
|
|
|
|
model 'server'
|
|
|
|
model 'servers'
|
|
|
|
|
|
|
|
request_path 'fog/slicehost/requests'
|
|
|
|
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'
|
2009-11-27 00:04:49 -05:00
|
|
|
|
2010-03-17 23:51:55 -04:00
|
|
|
class Mock
|
2010-06-12 18:31:17 -04:00
|
|
|
include Collections
|
2010-03-17 23:51:55 -04:00
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
2009-11-27 00:04:49 -05:00
|
|
|
end
|
|
|
|
|
2010-03-17 23:51:55 -04:00
|
|
|
def self.reset_data(keys=data.keys)
|
|
|
|
for key in [*keys]
|
|
|
|
data.delete(key)
|
|
|
|
end
|
2010-01-22 23:50:59 -05:00
|
|
|
end
|
2010-03-17 23:51:55 -04:00
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@slicehost_password = options[:slicehost_password]
|
|
|
|
@data = self.class.data[@slicehost_password]
|
|
|
|
end
|
|
|
|
|
2009-11-27 00:04:49 -05:00
|
|
|
end
|
|
|
|
|
2010-03-17 23:51:55 -04:00
|
|
|
class Real
|
2010-06-12 18:31:17 -04:00
|
|
|
include Collections
|
2010-03-17 23:51:55 -04:00
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@slicehost_password = options[:slicehost_password]
|
|
|
|
@host = options[:host] || "api.slicehost.com"
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2010-06-19 21:56:38 -04:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
2009-11-28 16:16:00 -05:00
|
|
|
end
|
|
|
|
|
2010-03-17 23:51:55 -04:00
|
|
|
def request(params)
|
2010-06-02 11:31:33 -04:00
|
|
|
params[:headers] ||= {}
|
|
|
|
params[:headers].merge!({
|
|
|
|
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).delete("\r\n")}"
|
|
|
|
})
|
2010-03-17 23:51:55 -04:00
|
|
|
case params[:method]
|
|
|
|
when 'DELETE', 'GET', 'HEAD'
|
2010-06-02 11:31:33 -04:00
|
|
|
params[:headers]['Accept'] = 'application/xml'
|
2010-03-17 23:51:55 -04:00
|
|
|
when 'POST', 'PUT'
|
2010-06-02 11:31:33 -04:00
|
|
|
params[:headers]['Content-Type'] = 'application/xml'
|
2010-03-17 23:51:55 -04:00
|
|
|
end
|
2010-02-04 03:27:14 -05:00
|
|
|
|
2010-06-01 00:39:17 -04:00
|
|
|
begin
|
2010-06-05 17:25:30 -04:00
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
2010-06-01 00:39:17 -04:00
|
|
|
rescue Excon::Errors::Error => error
|
2010-06-09 20:53:54 -04:00
|
|
|
raise case error
|
2010-06-01 00:39:17 -04:00
|
|
|
when Excon::Errors::NotFound
|
2010-06-12 02:11:02 -04:00
|
|
|
Fog::Slicehost::NotFound.slurp(error)
|
2010-06-01 00:39:17 -04:00
|
|
|
else
|
2010-06-09 20:53:54 -04:00
|
|
|
error
|
2010-06-01 00:39:17 -04:00
|
|
|
end
|
|
|
|
end
|
2009-11-27 00:04:49 -05:00
|
|
|
|
2010-03-17 23:51:55 -04:00
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-11-27 00:04:49 -05:00
|
|
|
end
|
|
|
|
end
|