2012-04-27 06:26:16 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Serverlove < Fog::Service
|
2012-04-27 09:35:08 -04:00
|
|
|
|
|
|
|
API_HOST = "api.z1-man.serverlove.com"
|
|
|
|
|
2012-04-27 07:11:33 -04:00
|
|
|
requires :serverlove_uuid, :serverlove_api_key
|
|
|
|
|
|
|
|
recognizes :serverlove_api_url
|
|
|
|
|
|
|
|
request_path 'fog/serverlove/requests/compute'
|
2012-06-22 06:06:36 -04:00
|
|
|
|
|
|
|
# Image
|
2012-04-29 16:38:29 -04:00
|
|
|
request :get_image
|
2012-04-29 12:36:16 -04:00
|
|
|
request :get_images
|
|
|
|
request :destroy_image
|
|
|
|
request :create_image
|
|
|
|
request :update_image
|
Added loading of standard image.
Currently not working:
Expected(204) <=> Actual(404 Not Found)
request => {:connect_timeout=>60, :headers=>{"Authorization"=>"Basic YWE4ZWIxYzktYzc4OC00MDlmLWJmZjQtYjAyMjVjMDE0MDQ1OkFkZ1hYSGVUTmY3TTJHR1l2NEI3WkpnWE1ISkJMY1E2dlJBejRZUUg=", "Accept"=>"application/json", "Host"=>"api.z1-man.serverlove.com:443", "Content-Length"=>0}, :instrumentor_name=>"excon", :mock=>false, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/Users/seanhandley/.rvm/gems/ruby-1.9.3-p125@fog_gem/gems/excon-0.14.1/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"api.z1-man.serverlove.com", :path=>"/drives/aea15650-5001-4cb8-8146-8c9835f5b880/image/679f5f44-0be7-4745-a658-cccd4334c1aa", :port=>"443", :query=>nil, :scheme=>"https", :method=>"post", :expects=>204}
response => #<Excon::Response:0x007ff661811848 @body="Operation failed: drive not found\n", @headers={"Server"=>"BaseHTTP/0.3 Python/2.6.6", "Date"=>"Fri, 22 Jun 2012 15:03:50 GMT", "X-Elastic-Error"=>"missing drive", "Connection"=>"close", "Content-Type"=>"text/plain"}, @status=404> (Excon::Errors::NotFound)
2012-06-22 11:09:17 -04:00
|
|
|
request :load_standard_image
|
2012-06-22 06:06:36 -04:00
|
|
|
|
|
|
|
# Server
|
|
|
|
request :get_servers
|
2012-07-15 07:40:03 -04:00
|
|
|
request :get_server
|
|
|
|
request :destroy_server
|
|
|
|
request :create_server
|
|
|
|
request :update_server
|
|
|
|
request :start_server
|
|
|
|
request :stop_server
|
|
|
|
request :shutdown_server
|
|
|
|
request :reset_server
|
2012-06-22 06:06:36 -04:00
|
|
|
|
|
|
|
model_path 'fog/serverlove/models/compute'
|
2012-04-27 07:11:33 -04:00
|
|
|
|
2012-04-29 12:36:16 -04:00
|
|
|
model :image
|
|
|
|
collection :images
|
2012-04-27 09:43:52 -04:00
|
|
|
|
2012-06-22 06:03:29 -04:00
|
|
|
model :server
|
|
|
|
collection :servers
|
|
|
|
|
2012-04-27 07:11:33 -04:00
|
|
|
class Mock
|
|
|
|
|
|
|
|
def initialize(options)
|
|
|
|
@serverlove_uuid = options[:serverlove_uuid] || Fog.credentials[:serverlove_uuid]
|
|
|
|
@serverlove_api_key = options[:serverlove_api_key] || Fog.credentials[:serverlove_api_key]
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(options)
|
|
|
|
raise "Not implemented"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options)
|
|
|
|
@api_uuid = options[:serverlove_uuid] || Fog.credentials[:serverlove_uuid]
|
|
|
|
@api_key = options[:serverlove_api_key] || Fog.credentials[:serverlove_api_key]
|
2012-04-27 09:35:08 -04:00
|
|
|
@api_host = options[:serverlove_api_url] || Fog.credentials[:serverlove_api_url] || API_HOST
|
2012-04-27 07:11:33 -04:00
|
|
|
|
2012-04-27 09:35:08 -04:00
|
|
|
@connection = Fog::Connection.new("https://#{@api_uuid}:#{@api_key}@#{@api_host}")
|
2012-04-27 07:11:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
2012-04-27 09:08:24 -04:00
|
|
|
params = params.merge!(
|
|
|
|
:headers => {
|
2012-04-27 09:35:08 -04:00
|
|
|
"Accept" => "application/json"
|
2012-04-27 09:31:12 -04:00
|
|
|
}
|
2012-04-27 09:08:24 -04:00
|
|
|
)
|
2012-04-29 09:03:46 -04:00
|
|
|
params[:body] = encode_pairs(params[:options]) unless params[:options].nil?
|
2012-04-27 07:11:33 -04:00
|
|
|
response = @connection.request(params)
|
|
|
|
|
|
|
|
raise_if_error!(response)
|
|
|
|
|
2012-04-27 10:17:56 -04:00
|
|
|
response.body = Fog::JSON.decode(response.body) if response.body && response.body.length > 0
|
2012-04-27 07:11:33 -04:00
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
2012-04-29 09:03:46 -04:00
|
|
|
def encode_pairs(params)
|
|
|
|
params.keys.collect do |key|
|
|
|
|
"#{key} #{params[key]}"
|
|
|
|
end.join("\n")
|
|
|
|
end
|
|
|
|
|
2012-06-22 06:03:29 -04:00
|
|
|
# TODO
|
2012-04-27 07:11:33 -04:00
|
|
|
def raise_if_error!(response)
|
|
|
|
case response.status
|
|
|
|
when 400 then
|
|
|
|
raise 'omg'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-04-27 06:26:16 -04:00
|
|
|
end
|
|
|
|
end
|
2012-04-27 16:53:39 -04:00
|
|
|
end
|