1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/slicehost/models/dns/zone.rb
2010-12-23 15:36:08 -08:00

69 lines
1.5 KiB
Ruby

require 'fog/core/model'
require 'fog/slicehost/models/dns/records'
module Fog
module Slicehost
class DNS
class Zone < Fog::Model
identity :id
attribute :active
attribute :domain, :aliases => 'origin'
attribute :ttl
def initialize(attributes={})
self.active ||= true
self.ttl ||= 3600
super
end
def active=(new_active)
attributes[:active] = case new_active
when false, 'N'
false
when true, 'Y'
true
end
end
def destroy
requires :identity
connection.delete_zone(identity)
true
end
def records
@records ||= begin
Fog::Zerigo::DNS::Records.new(
:zone => self,
:connection => connection
)
end
end
def nameservers
[
'ns1.slicehost.net',
'ns2.slicehost.net',
'ns3.slicehost.net'
]
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :active, :domain, :ttl
options = {}
options[:active] = active ? 'Y' : 'N'
options[:ttl] = ttl
data = connection.create_zone(domain, options)
merge_attributes(data.body)
true
end
end
end
end
end