2011-02-24 20:14:50 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class DNSimple
|
2011-02-24 20:14:50 -05:00
|
|
|
|
|
|
|
class Record < Fog::Model
|
2011-05-27 13:30:20 -04:00
|
|
|
extend Fog::Deprecation
|
|
|
|
deprecate :ip, :value
|
|
|
|
deprecate :ip=, :value=
|
2011-02-24 20:14:50 -05:00
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name
|
2011-05-27 13:30:20 -04:00
|
|
|
attribute :value, :aliases => "content"
|
2011-02-24 20:14:50 -05:00
|
|
|
attribute :ttl
|
|
|
|
attribute :created_at
|
|
|
|
attribute :updated_at
|
|
|
|
attribute :zone_id, :aliases => "domain_id"
|
|
|
|
attribute :type, :aliases => "record_type"
|
|
|
|
attribute :priority, :aliases => "prio"
|
|
|
|
|
|
|
|
def initialize(attributes={})
|
|
|
|
self.ttl ||= 3600
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-02-24 20:42:24 -05:00
|
|
|
connection.delete_record(zone.domain, identity)
|
2011-02-24 20:14:50 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def zone
|
|
|
|
@zone
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2011-05-27 13:30:20 -04:00
|
|
|
requires :name, :type, :value
|
2011-02-24 20:14:50 -05:00
|
|
|
options = {}
|
|
|
|
options[:prio] = priority if priority
|
|
|
|
options[:ttl] = ttl if ttl
|
2011-03-09 19:28:57 -05:00
|
|
|
|
|
|
|
# decide whether its a new record or update of an existing
|
|
|
|
if id.nil?
|
2011-05-27 13:30:20 -04:00
|
|
|
data = connection.create_record(zone.domain, name, type, value, options)
|
2011-03-09 19:28:57 -05:00
|
|
|
else
|
|
|
|
options[:name] = name if name
|
2011-05-27 13:30:20 -04:00
|
|
|
options[:content] = value if value
|
2011-03-09 19:28:57 -05:00
|
|
|
options[:type] = type if type
|
|
|
|
data = connection.update_record(zone.domain, id, options)
|
|
|
|
end
|
|
|
|
|
2011-02-24 20:42:24 -05:00
|
|
|
merge_attributes(data.body["record"])
|
2011-02-24 20:14:50 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def zone=(new_zone)
|
|
|
|
@zone = new_zone
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|