diff --git a/lib/fog/compute.rb b/lib/fog/compute.rb index c7a168135..bfcfeaf06 100644 --- a/lib/fog/compute.rb +++ b/lib/fog/compute.rb @@ -66,6 +66,9 @@ module Fog when :rackspace require 'fog/rackspace/compute' Fog::Compute::Rackspace.new(attributes) + when :serverlove + require 'fog/serverlove/compute' + Fog::Compute::Serverlove.new(attributes) when :slicehost warn "[DEPRECATION] `slicehost` is deprecated. Please use `rackspace` instead." require 'fog/slicehost/compute' diff --git a/lib/fog/serverlove/compute.rb b/lib/fog/serverlove/compute.rb index 44e796a55..c22152105 100644 --- a/lib/fog/serverlove/compute.rb +++ b/lib/fog/serverlove/compute.rb @@ -2,6 +2,64 @@ module Fog module Compute class Serverlove < Fog::Service + APR_URL = "https://api.z1-man.serverlove.com/" + + requires :serverlove_uuid, :serverlove_api_key + + recognizes :serverlove_api_url + + request_path 'fog/serverlove/requests/compute' + request :get_drives + + 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] + @api_url = options[:serverlove_api_url] || Fog.credentials[:serverlove_api_url] + + @connection = Fog::Connection.new(@api_url) + end + + def request(params) + params = params.merge!(header_for_basic_auth) + response = @connection.request(params) + + raise_if_error!(response) + + response.body = Fog::JSON.decode(response.body) + + response + end + + def header_for_basic_auth + { + "Authorization" => "Basic #{Base64.encode64("#{@uuid}:#{@api_key}").delete("\r\n")}" + } + end + + def raise_if_error!(response) + case response.status + when 400 then + raise 'omg' + end + end + + end + end end end \ No newline at end of file diff --git a/lib/fog/serverlove/requests/get_drives.rb b/lib/fog/serverlove/requests/get_drives.rb new file mode 100644 index 000000000..0cf863888 --- /dev/null +++ b/lib/fog/serverlove/requests/get_drives.rb @@ -0,0 +1,13 @@ +module Fog + module Compute + class Serverlove + class Real + + def get_drives + request("get", "/drives/list", [200]) + end + + end + end + end +end \ No newline at end of file