2011-06-16 17:51:13 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 20:52:11 -04:00
|
|
|
require 'fog/dynect/models/dns/record'
|
2011-06-16 17:51:13 -04:00
|
|
|
|
|
|
|
module Fog
|
2011-07-14 20:22:43 -04:00
|
|
|
module DNS
|
|
|
|
class Dynect
|
2011-06-16 17:51:13 -04:00
|
|
|
|
|
|
|
class Records < Fog::Collection
|
|
|
|
|
|
|
|
attribute :zone
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
model Fog::DNS::Dynect::Record
|
2011-06-16 17:51:13 -04:00
|
|
|
|
2012-01-30 10:08:47 -05:00
|
|
|
def all(options = {})
|
2011-07-14 20:22:43 -04:00
|
|
|
requires :zone
|
|
|
|
data = []
|
2013-09-21 15:23:05 -04:00
|
|
|
service.get_all_records(zone.domain, options).body['data'].each do |url|
|
2013-09-21 15:38:15 -04:00
|
|
|
(_, _, t, _, fqdn, id) = url.split('/')
|
2013-09-21 15:23:05 -04:00
|
|
|
type = t.gsub(/Record$/, '')
|
2013-09-23 15:43:20 -04:00
|
|
|
|
|
|
|
# leave out the default, read only records
|
|
|
|
# by putting this here we don't make the secondary request for these records
|
|
|
|
next if ['NS', 'SOA'].include?(type)
|
|
|
|
|
|
|
|
record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data']
|
|
|
|
|
|
|
|
data << {
|
|
|
|
:identity => record['record_id'],
|
|
|
|
:fqdn => record['fqdn'],
|
|
|
|
:type => record['record_type'],
|
|
|
|
:rdata => record['rdata']
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(record_id)
|
|
|
|
requires :zone
|
|
|
|
|
2013-09-25 15:21:20 -04:00
|
|
|
list = service.get_all_records(zone.domain, {}).body['data']
|
2013-09-23 15:43:20 -04:00
|
|
|
url = list.detect { |e| e =~ /\/#{record_id}$/ }
|
2013-09-25 15:21:20 -04:00
|
|
|
return unless url
|
2013-09-23 15:43:20 -04:00
|
|
|
(_, _, t, _, fqdn, id) = url.split('/')
|
|
|
|
type = t.gsub(/Record$/, '')
|
|
|
|
record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data']
|
|
|
|
|
|
|
|
new({
|
|
|
|
:identity => record['record_id'],
|
|
|
|
:fqdn => record['fqdn'],
|
|
|
|
:type => record['record_type'],
|
|
|
|
:rdata => record['rdata']
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2011-06-16 17:51:13 -04:00
|
|
|
def new(attributes = {})
|
2011-06-16 18:04:01 -04:00
|
|
|
requires :zone
|
2013-09-23 15:43:20 -04:00
|
|
|
super({:zone => zone}.merge!(attributes))
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|