mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
ef3bec5ade
Zerigo records and zones were setting a TTL of 3600 on the model if no TTL was set in the response. On first glance this seems like A Good Thing - yes we want a default TTL! However, it masks the fact that a record might have no TTL set on it and is using the default TTL from the zone. If you're trying to use the model to determine if the TTL is set to some value (say 3600), but the value defaults to 3600 if it isn't set, then you have no way of knowing if it's right or not. This change forces you to set a TTL if you're performing an operation that requires one (#save).
69 lines
1.6 KiB
Ruby
69 lines
1.6 KiB
Ruby
require 'fog/core/model'
|
|
|
|
module Fog
|
|
module DNS
|
|
class Zerigo
|
|
|
|
class Record < Fog::Model
|
|
extend Fog::Deprecation
|
|
deprecate :ip, :value
|
|
deprecate :ip=, :value=
|
|
|
|
identity :id
|
|
|
|
attribute :created_at, :aliases => 'created-at'
|
|
attribute :value, :aliases => 'data'
|
|
attribute :domain, :aliases => 'fqdn'
|
|
attribute :name, :aliases => 'hostname'
|
|
attribute :description, :aliases => 'notes'
|
|
attribute :priority
|
|
attribute :ttl
|
|
attribute :type, :aliases => 'host-type'
|
|
attribute :updated_at, :aliases => 'updated-at'
|
|
attribute :zone_id, :aliases => 'zone-id'
|
|
|
|
def initialize(attributes={})
|
|
super
|
|
end
|
|
|
|
def destroy
|
|
requires :identity
|
|
service.delete_host(identity)
|
|
true
|
|
end
|
|
|
|
def zone
|
|
@zone
|
|
end
|
|
|
|
def save
|
|
requires :zone, :type, :value
|
|
options = {}
|
|
options[:hostname] = name if name
|
|
options[:notes] = description if description
|
|
options[:priority] = priority if priority
|
|
options[:ttl] = ttl if ttl
|
|
|
|
if persisted?
|
|
options[:host_type] = type
|
|
options[:data] = value
|
|
service.update_host(identity, options)
|
|
else
|
|
data = service.create_host(@zone.id, type, value, options)
|
|
merge_attributes(data.body)
|
|
end
|
|
|
|
true
|
|
end
|
|
|
|
private
|
|
|
|
def zone=(new_zone)
|
|
@zone = new_zone
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|