1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

start of work to support Zerigo DNS service

have defined all the requests in compute.rb
have the 1st request - list_zones working
This commit is contained in:
Athir Nuaimi 2010-12-11 20:01:33 -05:00
parent 8c6ecb91d1
commit 15d35d3e0c
6 changed files with 212 additions and 0 deletions

View file

@ -82,4 +82,5 @@ require 'fog/rackspace'
require 'fog/slicehost'
require 'fog/terremark'
require 'fog/vcloud'
require 'fog/zerigo'
require 'fog/google'

21
lib/fog/zerigo.rb Normal file
View file

@ -0,0 +1,21 @@
require 'nokogiri'
require 'fog/core/parser'
module Fog
module Zerigo
extend Fog::Provider
service_path 'fog/zerigo'
service :compute
def self.new(attributes = {})
location = caller.first
warning = "[yellow][WARN] Fog::Zerigo#new is deprecated, use Fog::Zerigo::Compute#new instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
Fog::Zerigo::Compute.new(attributes)
end
end
end

25
lib/fog/zerigo/bin.rb Normal file
View file

@ -0,0 +1,25 @@
class Zerigo < Fog::Bin
class << self
def class_for(key)
case key
when :compute
Fog::Zerigo::Compute
else
raise ArgumentError, "Unrecognized service: #{key}"
end
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = class_for(key).new
end
@@connections[service]
end
def services
[:compute]
end
end
end

98
lib/fog/zerigo/compute.rb Normal file
View file

@ -0,0 +1,98 @@
module Fog
module Zerigo
class Compute < Fog::Service
requires :zerigo_user, :zerigo_password, &inject_parameter_specs
recognizes :timeout, :persistent, &inject_parameter_specs
# model_path 'fog/zerigo/models/compute'
# model :server
# collection :servers
request_path 'fog/zerigo/requests/compute'
request :list_zones
# request :count_zones
# request :get_zone
# request :get_zone_stats
# request :get_blank_zone
# request :create_zone
# request :update_zone
# request :delete_zone
# request :list_hosts
# request :count_hosts
# request :get_host
# request :get_blank_host
# request :create_host
# request :update_host
# request :delete_host
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={})
@zerigo_user = options[:zerigo_user]
@zerigo_password = options[:zerigo_password]
@data = self.class.data[@zerigo_user]
@data = self.class.data[@zerigo_password]
end
end
class Real
def initialize(options={})
@zerigo_user = options[:zerigo_user]
@zerigo_password = options[:zerigo_password]
@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)
key= "#{@zerigo_user}:#{@zerigo_password}"
params[:headers] ||= {}
key= "#{@zerigo_user}:#{@zerigo_password}"
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
Fog::Zerigo::Compute::NotFound.slurp(error)
else
error
end
end
response
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module Zerigo
module Compute
class ListZones < Fog::Parsers::Base
def reset
@zone = {}
@response = { 'zones' => [] }
end
def end_element(name)
case name
when 'default-ttl', 'id', 'nx-ttl'
@zone[name] = @value.to_i
when 'created-at', 'updated-at', 'domain', 'hostmaster', 'custom-nameservers', 'slave-nameservers', 'custom-ns', 'ns-type', 'ns1', 'notes'
@zone[name] = @value
when 'zone'
@response['zones'] << @zone
@zone = {}
end
end
end
end
end
end
end

View file

@ -0,0 +1,37 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/list_zones'
# Get list of all DNS zones hosted on Slicehost (for this account)
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'origin'<~String> - domain name to host (ie example.com)
# * 'id'<~Integer> - Id of the zone
# * 'ttl'<~Integer> - TimeToLive (ttl) for the domain, in seconds (> 60)
# * 'active'<~String> - whether zone is active in Slicehost DNS server - 'Y' or 'N'
def list_zones
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Zerigo::Compute::ListZones.new,
:path => '/api/1.1/zones.xml'
)
end
end
class Mock
def list_zones
Fog::Mock.not_implemented
end
end
end
end
end