2011-01-03 17:45:50 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class AWS
|
2011-01-03 17:45: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-01-03 17:45:50 -05:00
|
|
|
|
2012-03-08 10:20:11 -05:00
|
|
|
identity :name, :aliases => ['Name']
|
2011-01-03 17:45:50 -05:00
|
|
|
|
2012-03-08 10:20:11 -05:00
|
|
|
attribute :value, :aliases => ['ResourceRecords']
|
|
|
|
attribute :ttl, :aliases => ['TTL']
|
|
|
|
attribute :type, :aliases => ['Type']
|
|
|
|
attribute :status, :aliases => ['Status']
|
|
|
|
attribute :created_at, :aliases => ['SubmittedAt']
|
|
|
|
attribute :alias_target, :aliases => ['AliasTarget']
|
2012-03-26 15:23:42 -04:00
|
|
|
attribute :change_id, :aliases => ['Id']
|
2012-03-28 16:50:56 -04:00
|
|
|
attribute :region, :aliases => ['Region']
|
|
|
|
attribute :weight, :aliases => ['Weight']
|
|
|
|
attribute :set_identifier,:aliases => ['SetIdentifier']
|
2011-01-03 17:45:50 -05:00
|
|
|
|
|
|
|
def initialize(attributes={})
|
2011-04-04 19:57:08 -04:00
|
|
|
self.ttl ||= 3600
|
2011-01-03 17:45:50 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-11-29 13:59:48 -05:00
|
|
|
options = attributes_to_options('DELETE')
|
2011-01-03 17:45:50 -05:00
|
|
|
connection.change_resource_record_sets(zone.id, [options])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def zone
|
|
|
|
@zone
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2011-11-29 13:59:48 -05:00
|
|
|
options = attributes_to_options('CREATE')
|
2011-01-03 17:45:50 -05:00
|
|
|
data = connection.change_resource_record_sets(zone.id, [options]).body
|
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2011-11-29 13:59:48 -05:00
|
|
|
def modify(new_attributes)
|
|
|
|
options = []
|
|
|
|
|
|
|
|
# Delete the current attributes
|
|
|
|
options << attributes_to_options('DELETE')
|
|
|
|
|
|
|
|
# Create the new attributes
|
|
|
|
merge_attributes(new_attributes)
|
|
|
|
options << attributes_to_options('CREATE')
|
|
|
|
|
|
|
|
data = connection.change_resource_record_sets(zone.id, options).body
|
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-03-26 15:23:42 -04:00
|
|
|
# Returns true if record is insync. May only be called for newly created or modified records that
|
|
|
|
# have a change_id and status set.
|
2012-03-26 16:40:19 -04:00
|
|
|
def ready?
|
2012-03-26 15:23:42 -04:00
|
|
|
requires :change_id, :status
|
|
|
|
status == 'INSYNC'
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
# If we have a change_id (newly created or modified), then reload performs a get_change to update status.
|
|
|
|
if change_id
|
|
|
|
data = connection.get_change(change_id).body
|
|
|
|
merge_attributes(data)
|
|
|
|
self
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-03 17:45:50 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def zone=(new_zone)
|
|
|
|
@zone = new_zone
|
|
|
|
end
|
|
|
|
|
2011-11-29 13:59:48 -05:00
|
|
|
def attributes_to_options(action)
|
2012-03-08 10:20:11 -05:00
|
|
|
requires :name, :ttl, :type, :zone
|
|
|
|
requires_one :value, :alias_target
|
2011-11-29 13:59:48 -05:00
|
|
|
{
|
2012-03-28 16:50:56 -04:00
|
|
|
:action => action,
|
|
|
|
:name => name,
|
|
|
|
:resource_records => [*value],
|
|
|
|
:alias_target => symbolize_keys(alias_target),
|
|
|
|
:ttl => ttl,
|
|
|
|
:type => type,
|
|
|
|
:weight => weight,
|
|
|
|
:set_identifier => set_identifier,
|
|
|
|
:region => region
|
2011-11-29 13:59:48 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2011-01-03 17:45:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|