2010-12-11 20:01:33 -05:00
|
|
|
module Fog
|
|
|
|
module Zerigo
|
2010-12-21 16:45:53 -05:00
|
|
|
class DNS < Fog::Service
|
2010-12-11 20:01:33 -05:00
|
|
|
|
2010-12-21 16:45:53 -05:00
|
|
|
requires :zerigo_email, :zerigo_token
|
2010-12-16 18:31:24 -05:00
|
|
|
recognizes :timeout, :persistent
|
2011-01-07 21:14:39 -05:00
|
|
|
recognizes :provider # remove post deprecation
|
2010-12-11 20:01:33 -05:00
|
|
|
|
2011-01-07 19:12:04 -05:00
|
|
|
model_path 'fog/dns/models/zerigo'
|
2010-12-22 23:36:53 -05:00
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
2010-12-11 20:01:33 -05:00
|
|
|
|
2011-01-14 13:41:12 -05:00
|
|
|
request_path 'fog/dns/requests/zerigo'
|
2010-12-22 23:36:53 -05:00
|
|
|
request :count_hosts
|
2010-12-12 09:51:52 -05:00
|
|
|
request :count_zones
|
2010-12-22 23:36:53 -05:00
|
|
|
request :create_host
|
2010-12-12 09:51:52 -05:00
|
|
|
request :create_zone
|
2010-12-22 23:36:53 -05:00
|
|
|
request :delete_host
|
2010-12-12 18:02:02 -05:00
|
|
|
request :delete_zone
|
|
|
|
request :find_hosts
|
|
|
|
request :get_host
|
2010-12-22 23:36:53 -05:00
|
|
|
request :get_zone
|
|
|
|
request :get_zone_stats
|
|
|
|
request :list_zones
|
|
|
|
request :list_hosts
|
2010-12-12 18:02:02 -05:00
|
|
|
request :update_host
|
2010-12-22 23:36:53 -05:00
|
|
|
request :update_zone
|
2010-12-11 20:01:33 -05:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset_data(keys=data.keys)
|
|
|
|
for key in [*keys]
|
|
|
|
data.delete(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-01-07 21:14:39 -05:00
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::Zerigo::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Zerigo') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
2010-12-15 18:45:19 -05:00
|
|
|
@zerigo_email = options[:zerigo_email]
|
2010-12-21 16:45:53 -05:00
|
|
|
@zerigo_token = options[:zerigo_token]
|
2010-12-15 18:45:19 -05:00
|
|
|
@data = self.class.data[@zerigo_email]
|
2010-12-11 20:01:33 -05:00
|
|
|
@data = self.class.data[@zerigo_password]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-01-07 21:14:39 -05:00
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::Zerigo::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Zerigo') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
2011-02-16 20:25:50 -05:00
|
|
|
require 'fog/core/parser'
|
|
|
|
|
2011-01-07 21:14:39 -05:00
|
|
|
@zerigo_email = options[:zerigo_email]
|
2010-12-21 16:45:53 -05:00
|
|
|
@zerigo_token = options[:zerigo_token]
|
2010-12-11 20:01:33 -05:00
|
|
|
@host = options[:host] || "ns.zerigo.com"
|
|
|
|
@port = options[:port] || 80
|
|
|
|
@scheme = options[:scheme] || 'http'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:headers] ||= {}
|
2010-12-21 16:45:53 -05:00
|
|
|
key= "#{@zerigo_email}:#{@zerigo_token}"
|
2010-12-11 20:01:33 -05:00
|
|
|
params[:headers].merge!({
|
|
|
|
'Authorization' => "Basic #{Base64.encode64(key).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
|
2010-12-21 16:45:53 -05:00
|
|
|
Fog::Zerigo::DNS::NotFound.slurp(error)
|
2010-12-11 20:01:33 -05:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|