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/aws/models/dns/record.rb

82 lines
2.1 KiB
Ruby
Raw Normal View History

2011-01-03 17:45:50 -05:00
require 'fog/core/model'
module Fog
module DNS
class AWS
2011-01-03 17:45:50 -05:00
class Record < Fog::Model
extend Fog::Deprecation
deprecate :ip, :value
deprecate :ip=, :value=
2011-01-03 17:45:50 -05:00
identity :name, :aliases => ['Name']
2011-01-03 17:45:50 -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']
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
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
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
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
2011-01-03 17:45:50 -05:00
private
def zone=(new_zone)
@zone = new_zone
end
def attributes_to_options(action)
requires :name, :ttl, :type, :zone
requires_one :value, :alias_target
{
:action => action,
:name => name,
:resource_records => [*value],
:alias_target => symbolize_keys(alias_target),
:ttl => ttl,
:type => type
}
end
2011-01-03 17:45:50 -05:00
end
end
end
end