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

[dreamhost|dns] Emulate zone model and collection, added tests

Dreamhost API has no concept of Zone, but we can emulate it.
This commit is contained in:
Sergio Rubio 2013-01-21 23:26:30 +01:00
parent 4c95f8e209
commit 9dd24ab2bd
8 changed files with 203 additions and 1 deletions

View file

@ -10,7 +10,9 @@ module Fog
model_path 'fog/dreamhost/models/dns'
model :record
model :zone
collection :records
collection :zones
request_path 'fog/dreamhost/requests/dns'
request :create_record

View file

@ -28,6 +28,11 @@ module Fog
end
def new(attributes = {})
requires :zone
super({ :zone => zone }.merge!(attributes))
end
end
end
end

View file

@ -0,0 +1,57 @@
require 'fog/core/model'
require 'fog/dreamhost/models/dns/records'
module Fog
module DNS
class Dreamhost
#
# Dreamhost API has no concept of 'Zone', but we
# can emulate it.
#
# http://wiki.dreamhost.com/API/Dns_commands
#
class Zone < Fog::Model
identity :id
attribute :domain, :aliases => 'name'
#
# There's no destroy API call
#
def destroy
raise NotImplementedError.new
end
#
# Return a list of records for this zone
#
def records
@records ||= begin
Fog::DNS::Dreamhost::Records.new( :zone => self, :service => service )
end
end
#
# Return the Dreamhost nameserver list
#
def nameservers
[
"ns1.dreamhost.com",
"ns2.dreamhost.com",
"ns3.dreamhost.com",
]
end
#
# There's no zone create API call
#
def save
raise NotImplementedError.new
end
end
end
end
end

View file

@ -0,0 +1,37 @@
require 'fog/core/collection'
require 'fog/dreamhost/models/dns/zone'
module Fog
module DNS
class Dreamhost
#
# Dreamhost API has no concept of 'Zone', but we
# can emulate it.
#
# http://wiki.dreamhost.com/API/Dns_commands
#
class Zones < Fog::Collection
model Fog::DNS::Dreamhost::Zone
def all
clear
zones = []
service.records.each do |r|
zones << { :id => r.zone, :domain => r.zone }
end
load(zones)
end
def get(zone_id)
service.zones.find { |z| z.domain == zone_id }
rescue Excon::Errors::NotFound
nil
end
end
end
end
end