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:
parent
4c95f8e209
commit
9dd24ab2bd
8 changed files with 203 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ module Fog
|
|||
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :zone
|
||||
super({ :zone => zone }.merge!(attributes))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
57
lib/fog/dreamhost/models/dns/zone.rb
Normal file
57
lib/fog/dreamhost/models/dns/zone.rb
Normal 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
|
||||
37
lib/fog/dreamhost/models/dns/zones.rb
Normal file
37
lib/fog/dreamhost/models/dns/zones.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue