2010-12-22 23:36:53 -05:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 15:40:47 -04:00
|
|
|
require 'fog/zerigo/models/dns/record'
|
2010-12-22 23:36:53 -05:00
|
|
|
|
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class Zerigo
|
2010-12-22 23:36:53 -05:00
|
|
|
|
|
|
|
class Records < Fog::Collection
|
|
|
|
|
|
|
|
attribute :zone
|
|
|
|
|
2011-06-15 20:25:01 -04:00
|
|
|
model Fog::DNS::Zerigo::Record
|
2013-03-13 04:35:12 -04:00
|
|
|
|
|
|
|
# List all domains
|
|
|
|
# @param [Hash] options Options to pass to the underlying API call
|
|
|
|
# @option options [String] :fqdn search for the given fqdn
|
|
|
|
def all(options = {})
|
2010-12-22 23:36:53 -05:00
|
|
|
requires :zone
|
2013-03-13 04:35:12 -04:00
|
|
|
if options[:fqdn]
|
|
|
|
hosts = service.find_hosts(options[:fqdn], zone.id).body['hosts']
|
|
|
|
load(hosts)
|
2010-12-22 23:36:53 -05:00
|
|
|
else
|
2013-03-13 04:35:12 -04:00
|
|
|
parent = zone.collection.get(zone.identity)
|
|
|
|
if parent
|
|
|
|
merge_attributes(parent.records.attributes)
|
|
|
|
load(parent.records.map {|record| record.attributes})
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2010-12-22 23:36:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(record_id)
|
2012-12-22 18:21:16 -05:00
|
|
|
data = service.get_host(record_id).body
|
2010-12-22 23:36:53 -05:00
|
|
|
new(data)
|
2011-01-03 18:39:38 -05:00
|
|
|
rescue Fog::Service::NotFound
|
2010-12-22 23:36:53 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def new(attributes = {})
|
|
|
|
requires :zone
|
|
|
|
super({ :zone => zone }.merge!(attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|