2009-11-27 00:04:49 -05:00
|
|
|
module Fog
|
|
|
|
class Slicehost
|
|
|
|
|
|
|
|
if Fog.mocking?
|
|
|
|
def self.data
|
|
|
|
@data
|
|
|
|
end
|
|
|
|
def self.reset_data
|
|
|
|
@data = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-12 02:41:40 -05:00
|
|
|
def self.dependencies
|
|
|
|
[
|
|
|
|
"fog/slicehost/models/flavor.rb",
|
|
|
|
"fog/slicehost/models/flavors.rb",
|
|
|
|
"fog/slicehost/models/image.rb",
|
|
|
|
"fog/slicehost/models/images.rb",
|
|
|
|
"fog/slicehost/models/server.rb",
|
|
|
|
"fog/slicehost/models/servers.rb",
|
|
|
|
"fog/slicehost/parsers/create_slice.rb",
|
|
|
|
"fog/slicehost/parsers/get_backups.rb",
|
|
|
|
"fog/slicehost/parsers/get_flavor.rb",
|
|
|
|
"fog/slicehost/parsers/get_flavors.rb",
|
|
|
|
"fog/slicehost/parsers/get_image.rb",
|
|
|
|
"fog/slicehost/parsers/get_images.rb",
|
|
|
|
"fog/slicehost/parsers/get_slice.rb",
|
|
|
|
"fog/slicehost/parsers/get_slices.rb",
|
|
|
|
"fog/slicehost/requests/create_slice.rb",
|
|
|
|
"fog/slicehost/requests/delete_slice.rb",
|
|
|
|
"fog/slicehost/requests/get_backups.rb",
|
|
|
|
"fog/slicehost/requests/get_flavor.rb",
|
|
|
|
"fog/slicehost/requests/get_flavors.rb",
|
|
|
|
"fog/slicehost/requests/get_image.rb",
|
|
|
|
"fog/slicehost/requests/get_images.rb",
|
|
|
|
"fog/slicehost/requests/get_slice.rb",
|
|
|
|
"fog/slicehost/requests/get_slices.rb",
|
|
|
|
"fog/slicehost/requests/reboot_slice.rb"
|
|
|
|
]
|
|
|
|
end
|
2009-11-27 00:04:49 -05:00
|
|
|
|
2010-02-12 02:41:40 -05:00
|
|
|
def self.reload
|
|
|
|
self.dependencies.each {|dependency| load(dependency)}
|
2009-11-27 00:04:49 -05:00
|
|
|
if Fog.mocking?
|
|
|
|
reset_data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
2010-02-06 20:06:49 -05:00
|
|
|
unless @slicehost_password = options[:slicehost_password]
|
|
|
|
raise ArgumentError.new('slicehost_password is required to access slicehost')
|
2010-01-22 23:50:59 -05:00
|
|
|
end
|
2009-11-27 00:04:49 -05:00
|
|
|
@host = options[:host] || "api.slicehost.com"
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
2010-01-27 23:22:22 -05:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
2009-11-28 16:16:00 -05:00
|
|
|
headers = {
|
2010-02-06 20:06:49 -05:00
|
|
|
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).chomp!}"
|
2009-11-28 16:16:00 -05:00
|
|
|
}
|
|
|
|
case params[:method]
|
|
|
|
when 'DELETE', 'GET', 'HEAD'
|
|
|
|
headers['Accept'] = 'application/xml'
|
|
|
|
when 'POST', 'PUT'
|
|
|
|
headers['Content-Type'] = 'application/xml'
|
|
|
|
end
|
|
|
|
|
2009-11-27 00:04:49 -05:00
|
|
|
response = @connection.request({
|
|
|
|
:body => params[:body],
|
|
|
|
:expects => params[:expects],
|
2009-11-30 20:01:25 -05:00
|
|
|
:headers => headers.merge!(params[:headers] || {}),
|
2009-11-27 00:04:49 -05:00
|
|
|
:host => @host,
|
|
|
|
:method => params[:method],
|
|
|
|
:parser => params[:parser],
|
|
|
|
:path => params[:path]
|
|
|
|
})
|
2010-02-04 03:27:14 -05:00
|
|
|
|
2009-11-27 00:04:49 -05:00
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-12 02:41:40 -05:00
|
|
|
Fog::Slicehost.dependencies.each {|dependency| require(dependency)}
|