2010-12-23 18:36:08 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Slicehost
|
|
|
|
class DNS
|
|
|
|
|
|
|
|
class Record < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :active
|
2010-12-23 19:47:47 -05:00
|
|
|
attribute :ip, :aliases => 'ip'
|
2010-12-23 18:36:08 -05:00
|
|
|
attribute :name
|
2010-12-23 19:47:47 -05:00
|
|
|
attribute :description, :aliases => 'aux'
|
2010-12-23 18:36:08 -05:00
|
|
|
attribute :ttl
|
2010-12-23 19:47:47 -05:00
|
|
|
attribute :type, :aliases => 'record_type'
|
2010-12-23 18:36:08 -05:00
|
|
|
attribute :zone_id
|
|
|
|
|
|
|
|
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_record(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def zone
|
|
|
|
@zone
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
|
|
|
requires :ip, :name, :type, :zone
|
|
|
|
options = {}
|
|
|
|
options[:active] = active ? 'Y' : 'N'
|
2011-01-03 18:39:38 -05:00
|
|
|
options[:aux] = description if description
|
2010-12-23 18:36:08 -05:00
|
|
|
options[:ttl] = ttl if ttl
|
|
|
|
data = connection.create_record(type, zone.id, name, ip, options)
|
|
|
|
merge_attributes(data.body)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def zone=(new_zone)
|
|
|
|
@zone = new_zone
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|