lxc-zone: handle SRV-records

This commit is contained in:
Jörg Thalheim 2015-01-03 17:57:39 +01:00
parent acf532809a
commit 655cdbb427
2 changed files with 24 additions and 18 deletions

View File

@ -21,7 +21,6 @@ def atomic_write(path, content)
FileUtils.mv(temp_path, path)
end
class ZoneData
def initialize(data)
@data = data
@ -59,26 +58,30 @@ class RdnsData
end
end
json = JSON.load(File.open(CONTAINER_DATA))
json["zone"]["serial"] += 1
def main
json = JSON.load(File.open(CONTAINER_DATA))
json["zone"]["serial"] += 1
rdns_zone_template = File.read(TEMPLATE_PATH.join("rdns-zone.erb"))
zone_data = ZoneData.new(json)
rdns_zone_template = File.read(TEMPLATE_PATH.join("rdns-zone.erb"))
zone_data = ZoneData.new(json)
lxc_zone_template = File.read(TEMPLATE_PATH.join("lxc-zone.erb"))
zone = ERB.new(lxc_zone_template, nil, '-').result(zone_data.get_binding)
lxc_zone_template = File.read(TEMPLATE_PATH.join("lxc-zone.erb"))
zone = ERB.new(lxc_zone_template, nil, '-').result(zone_data.get_binding)
v4_subnet = NetAddr::CIDR.create(json["zone"]["v4_subnet"])
v4_rdns_path = ZONE_PATH.join(v4_subnet.arpa.gsub(/\.$/, ""))
v4_rdns_zone = ERB.new(rdns_zone_template, nil, '-').result(RdnsData.new(json, v4_subnet).get_binding)
v4_subnet = NetAddr::CIDR.create(json["zone"]["v4_subnet"])
v4_rdns_path = ZONE_PATH.join(v4_subnet.arpa.gsub(/\.$/, ""))
v4_rdns_zone = ERB.new(rdns_zone_template, nil, '-').result(RdnsData.new(json, v4_subnet).get_binding)
v6_subnet = NetAddr::CIDR.create(json["zone"]["v6_subnet"])
v6_rdns_path = ZONE_PATH.join(v6_subnet.arpa.gsub(/\.$/, ""))
v6_rdns_zone = ERB.new(rdns_zone_template, nil, '-').result(RdnsData.new(json, v6_subnet).get_binding)
v6_subnet = NetAddr::CIDR.create(json["zone"]["v6_subnet"])
v6_rdns_path = ZONE_PATH.join(v6_subnet.arpa.gsub(/\.$/, ""))
v6_rdns_zone = ERB.new(rdns_zone_template, nil, '-').result(RdnsData.new(json, v6_subnet).get_binding)
atomic_write(LXC_ZONE, zone)
atomic_write(v4_rdns_path, v4_rdns_zone)
atomic_write(v6_rdns_path, v6_rdns_zone)
atomic_write(CONTAINER_DATA, JSON.pretty_generate(json))
atomic_write(LXC_ZONE, zone)
atomic_write(v4_rdns_path, v4_rdns_zone)
atomic_write(v6_rdns_path, v6_rdns_zone)
atomic_write(CONTAINER_DATA, JSON.pretty_generate(json))
system("lxc-attach", "-e", "-n", DNS_CONTAINER, "--", "rec_control", "reload-zones")
system("lxc-attach", "-e", "-n", DNS_CONTAINER, "--", "rec_control", "reload-zones")
end
main

View File

@ -10,6 +10,9 @@
<% if value["cname"] -%>
<%= name %> CNAME <%= value["cname"] %>
<% end -%>
<% if value["srv"] -%>
<%= name %> SRV <%= value["srv"] %>
<% end -%>
<% if value["ipv4"] -%>
<%= name %> A <%= ip(value["ipv4"]) %>
ipv4.<%= name %> A <%= ip(value["ipv4"]) %>