40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_dns.rb', line 40
def self.build_config(host)
forward = {}
reverse = {}
host.region.network.addresses.all.each do |address|
next unless address
next if address.ips.empty?
unless address.name!
Construqt.logger.warn "unreference address #{address.ips.map{|i| i.to_string}}"
next
end
name = host.region.network.fqdn(address.name!)
domain = host.region.network.domain
forward[domain] ||= []
address.ips.each do |ip|
next if ip.to_i == ip.network.to_i && ((ip.ipv6? && ip.prefix < 128) || (ip.ipv4? && ip.prefix < 32))
forward[domain] << "#{"%-42s" % "#{name}."} 3600 IN #{ip.ipv4? ? 'A' : 'AAAA'} #{ip.to_s}"
if ip.ipv4?
forward[domain] << "#{"ipv4-%-37s" % "#{name}."} 3600 IN A #{ip.to_s}"
end
if ip.ipv6?
forward[domain] << "#{"ipv6-%-37s" % "#{name}."} 3600 IN AAAA #{ip.to_s}"
end
network = host.region.network.to_network(ip.network)
reverse[network] ||= {}
reverse[network][ip.reverse.to_s] ||= "#{ip.reverse} 3600 IN PTR #{name}."
end
end
include = {}
forward.each do |domain, lines|
include[domain] = "/etc/bind/tables/#{domain}.forward"
host.result.add(self, (host.region, domain), Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::DNS), "etc/bind/tables", "#{domain}.forward")
host.result.add(self, lines.sort.join("\n"), Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::DNS), "etc/bind/tables", "#{domain}.forward")
end
reverse.each do |domain, lines|
include[domain.rev_domains.first] = "/etc/bind/tables/#{domain}.reverse"
host.result.add(self, (host.region, domain.rev_domains.first), Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::DNS), "etc/bind/tables", "#{domain.to_s}.reverse")
host.result.add(self, lines.values.sort.join("\n"), Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::DNS), "etc/bind/tables", "#{domain.to_s}.reverse")
end
include.each do |domain,path|
host.result.add(self, <<DNS, Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::DNS), "etc/bind/named.conf.local")
zone "#{domain.to_s}" {
type master;
file "#{path}";
notify yes;
allow-query { any; };
};
DNS
end
end
|