2011-08-31 16:52:53 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'slicehost'))
|
|
|
|
require 'fog/dns'
|
|
|
|
|
2010-12-21 18:24:14 -05:00
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class Slicehost < Fog::Service
|
2010-12-21 18:24:14 -05:00
|
|
|
|
|
|
|
requires :slicehost_password
|
|
|
|
recognizes :host, :port, :scheme, :persistent
|
|
|
|
|
2011-08-24 20:47:21 -04:00
|
|
|
model_path 'fog/slicehost/models/dns'
|
2010-12-23 18:36:08 -05:00
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
2010-12-21 18:24:14 -05:00
|
|
|
|
2011-08-24 20:47:21 -04:00
|
|
|
request_path 'fog/slicehost/requests/dns'
|
2010-12-21 18:24:14 -05:00
|
|
|
request :create_record
|
|
|
|
request :create_zone
|
|
|
|
request :delete_record
|
|
|
|
request :delete_zone
|
|
|
|
request :get_record
|
|
|
|
request :get_records
|
|
|
|
request :get_zone
|
|
|
|
request :get_zones
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-19 10:05:33 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2010-12-21 18:24:14 -05: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-12-21 18:24:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-02-16 20:25:50 -05:00
|
|
|
require 'fog/core/parser'
|
|
|
|
|
2010-12-21 18:24:14 -05: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}))
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2011-06-15 20:25:01 -04:00
|
|
|
Fog::DNS::Slicehost::NotFound.slurp(error)
|
2010-12-21 18:24:14 -05:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|