2011-06-16 17:51:13 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2011-07-14 20:22:43 -04:00
|
|
|
module DNS
|
|
|
|
class Dynect
|
2011-06-16 17:51:13 -04:00
|
|
|
|
|
|
|
class Record < Fog::Model
|
|
|
|
extend Fog::Deprecation
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
identity :id
|
|
|
|
attribute :name, :aliases => [:fqdn, 'fqdn']
|
|
|
|
attribute :rdata
|
|
|
|
attribute :serial_style
|
2011-06-16 17:51:13 -04:00
|
|
|
attribute :ttl
|
2011-07-14 20:22:43 -04:00
|
|
|
attribute :type, :aliases => 'record_type'
|
2011-06-16 17:51:13 -04:00
|
|
|
|
|
|
|
def destroy
|
2011-07-14 20:22:43 -04:00
|
|
|
requires :identity, :name, :type, :zone
|
2012-12-22 18:27:58 -05:00
|
|
|
service.delete_record(type, zone.identity, name, identity)
|
2011-07-14 20:22:43 -04:00
|
|
|
true
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2011-09-03 16:41:53 -04:00
|
|
|
requires :name, :type, :rdata, :zone
|
2011-07-14 20:22:43 -04:00
|
|
|
|
|
|
|
options = {
|
|
|
|
:ttl => ttl
|
|
|
|
}
|
|
|
|
options.delete_if {|key, value| value.nil?}
|
|
|
|
|
2012-12-22 18:27:58 -05:00
|
|
|
data = service.post_record(type, zone.identity, name, rdata, options).body['data']
|
2011-07-14 20:22:43 -04:00
|
|
|
# avoid overwriting zone object with zone string
|
|
|
|
data = data.reject {|key, value| key == 'zone'}
|
|
|
|
merge_attributes(data)
|
|
|
|
|
|
|
|
zone.publish
|
2012-12-22 18:27:58 -05:00
|
|
|
records = service.get_record(type, zone.identity, name).body['data']
|
2011-07-14 20:22:43 -04:00
|
|
|
# data in format ['/REST/xRecord/domain/fqdn/identity]
|
|
|
|
records.map! do |record|
|
|
|
|
tokens = record.split('/')
|
|
|
|
{
|
|
|
|
:identity => tokens.last,
|
|
|
|
:type => tokens[2][0...-6] # everything before 'Record'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
record = records.detect {|record| record[:type] == type}
|
|
|
|
merge_attributes(record)
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def zone
|
|
|
|
@zone
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
2011-07-14 20:22:43 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def zone=(new_zone)
|
|
|
|
@zone = new_zone
|
|
|
|
end
|
|
|
|
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|