mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2164 from shawncatz/dynect_missing_record_data
fix missing record data in dynect dns
This commit is contained in:
commit
550a39119a
5 changed files with 97 additions and 20 deletions
|
@ -19,6 +19,7 @@ module Fog
|
||||||
request :delete_record
|
request :delete_record
|
||||||
request :delete_zone
|
request :delete_zone
|
||||||
request :get_node_list
|
request :get_node_list
|
||||||
|
request :get_all_records
|
||||||
request :get_record
|
request :get_record
|
||||||
request :get_zone
|
request :get_zone
|
||||||
request :post_record
|
request :post_record
|
||||||
|
@ -71,7 +72,7 @@ module Fog
|
||||||
@path = options[:path] || '/REST'
|
@path = options[:path] || '/REST'
|
||||||
@persistent = options[:persistent] || false
|
@persistent = options[:persistent] || false
|
||||||
@scheme = options[:scheme] || 'https'
|
@scheme = options[:scheme] || 'https'
|
||||||
@version = options[:version] || '2.3.1'
|
@version = options[:version] || '3.5.2'
|
||||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,31 +14,43 @@ module Fog
|
||||||
def all(options = {})
|
def all(options = {})
|
||||||
requires :zone
|
requires :zone
|
||||||
data = []
|
data = []
|
||||||
service.get_node_list(zone.domain, options).body['data'].each do |fqdn|
|
service.get_all_records(zone.domain, options).body['data'].each do |url|
|
||||||
records = service.get_record('ANY', zone.domain, fqdn).body['data']
|
(_, _, t, _, fqdn, id) = url.split('/')
|
||||||
|
type = t.gsub(/Record$/, '')
|
||||||
# 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)
|
|
||||||
end
|
|
||||||
|
|
||||||
# leave out the default, read only records
|
# leave out the default, read only records
|
||||||
data = data.reject {|record| ['NS', 'SOA'].include?(record[:type])}
|
# 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)
|
load(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(record_id)
|
def get(record_id)
|
||||||
# FIXME: can this be done more efficiently?
|
requires :zone
|
||||||
all.detect {|record| record.identity == record_id}
|
|
||||||
|
list = service.get_all_records(zone.domain, {}).body['data']
|
||||||
|
url = list.detect { |e| e =~ /\/#{record_id}$/ }
|
||||||
|
return unless url
|
||||||
|
(_, _, 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
|
end
|
||||||
|
|
||||||
def new(attributes = {})
|
def new(attributes = {})
|
||||||
|
|
56
lib/fog/dynect/requests/dns/get_all_records.rb
Normal file
56
lib/fog/dynect/requests/dns/get_all_records.rb
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
module Fog
|
||||||
|
module DNS
|
||||||
|
class Dynect
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# Get one or more node lists
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * zone<~String> - zone to lookup node lists for
|
||||||
|
# * options<~Hash>
|
||||||
|
# * fqdn<~String> - fully qualified domain name of node to lookup
|
||||||
|
|
||||||
|
def get_all_records(zone, options = {})
|
||||||
|
requested_fqdn = options['fqdn'] || options[:fqdn]
|
||||||
|
request(
|
||||||
|
:expects => 200,
|
||||||
|
:idempotent => true,
|
||||||
|
:method => :get,
|
||||||
|
:path => ['AllRecord', zone, requested_fqdn].compact.join('/')
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def get_all_records(zone, options = {})
|
||||||
|
raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
|
||||||
|
data = [zone[:zone]]
|
||||||
|
|
||||||
|
if fqdn = options[:fqdn]
|
||||||
|
data = data | zone[:records].collect { |type, records| records.select { |record| record[:fqdn] == fqdn } }.flatten.compact
|
||||||
|
else
|
||||||
|
data = data | zone[:records].collect { |type, records| records.collect { |record| record[:fqdn] } }.flatten
|
||||||
|
end
|
||||||
|
|
||||||
|
response.body = {
|
||||||
|
"status" => "success",
|
||||||
|
"data" => data,
|
||||||
|
"job_id" => Fog::Dynect::Mock.job_id,
|
||||||
|
"msgs" => [{
|
||||||
|
"INFO" => "get_tree: Here is your zone tree",
|
||||||
|
"SOURCE" => "BLL",
|
||||||
|
"ERR_CD" => nil,
|
||||||
|
"LVL" => "INFO"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,7 +16,7 @@ module Fog
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:idempotent => true,
|
:idempotent => true,
|
||||||
:method => :get,
|
:method => :get,
|
||||||
:path => ['NodeList', zone, requested_fqdn].compact.join('/')
|
:path => ['AllRecord', zone, requested_fqdn].compact.join('/')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -137,6 +137,14 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
||||||
@dns.get_node_list(@domain).body
|
@dns.get_node_list(@domain).body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get_all_records_format = shared_format.merge({
|
||||||
|
'data' => [String]
|
||||||
|
})
|
||||||
|
|
||||||
|
tests("get_all_records('#{@domain}')").formats(get_all_records_format) do
|
||||||
|
@dns.get_all_records(@domain).body
|
||||||
|
end
|
||||||
|
|
||||||
get_records_format = shared_format.merge({
|
get_records_format = shared_format.merge({
|
||||||
'data' => [String]
|
'data' => [String]
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue