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 = []
|
2012-12-22 18:27:58 -05:00
|
|
|
service.get_node_list(zone.domain, options).body['data'].each do |fqdn|
|
|
|
|
records = service.get_record('ANY', zone.domain, fqdn).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,
|
|
|
|
:fqdn => fqdn,
|
|
|
|
:type => tokens[2][0...-6] # everything before 'Record'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
data.concat(records)
|
2011-06-19 04:09:58 -04:00
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
# leave out the default, read only records
|
|
|
|
data = data.reject {|record| ['NS', 'SOA'].include?(record[:type])}
|
|
|
|
|
2011-06-19 04:09:58 -04:00
|
|
|
load(data)
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(record_id)
|
2011-07-14 20:22:43 -04:00
|
|
|
# FIXME: can this be done more efficiently?
|
|
|
|
all.detect {|record| record.identity == record_id}
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new(attributes = {})
|
2011-06-16 18:04:01 -04:00
|
|
|
requires :zone
|
|
|
|
super({ :zone => zone }.merge!(attributes))
|
2011-06-16 17:51:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|