2014-08-18 08:29:43 +00:00
|
|
|
#!/usr/bin/env ruby
|
2015-01-30 08:08:18 +00:00
|
|
|
require "json"
|
|
|
|
require "pathname"
|
|
|
|
require_relative "lib/lxc"
|
2014-08-18 08:29:43 +00:00
|
|
|
|
|
|
|
DNS_CONTAINER = "dns"
|
|
|
|
|
2016-02-02 22:15:17 +00:00
|
|
|
def dns_zone(registry, template, zone_name)
|
|
|
|
root_path = Pathname.new(File.expand_path("../..", __FILE__))
|
|
|
|
zone_template = Lxc::Template.new(root_path.join("hooks/templates/#{template}.erb"))
|
|
|
|
zone = registry.data["zone"] || {}
|
|
|
|
zone_template.write(root_path.join("zones",
|
|
|
|
"#{zone_name}.zone"),
|
|
|
|
data: registry.data,
|
|
|
|
zone: zone)
|
|
|
|
end
|
|
|
|
|
2015-01-30 08:08:18 +00:00
|
|
|
def main
|
|
|
|
registry = Lxc::Registry.new
|
|
|
|
registry.data["zone"] ||= {}
|
|
|
|
registry.data["zone"]["serial"] += 1
|
|
|
|
registry.save
|
|
|
|
|
|
|
|
root_path = Lxc::CONFIG_ROOT
|
2015-12-13 19:24:00 +00:00
|
|
|
|
2016-02-02 22:15:17 +00:00
|
|
|
if subnet = registry.data["zone"]["ula-subnet"]
|
|
|
|
zone = Lxc::RdnsZone.new(registry.data, "ula", subnet)
|
|
|
|
zone.write_zone_file(root_path)
|
2014-08-18 08:29:43 +00:00
|
|
|
end
|
|
|
|
|
2016-02-02 22:15:17 +00:00
|
|
|
if subnet = registry.data["zone"]["ipv4-subnet"]
|
|
|
|
zone = Lxc::RdnsZone.new(registry.data, "ipv4", subnet)
|
|
|
|
zone.write_zone_file(root_path)
|
2014-08-18 08:29:43 +00:00
|
|
|
end
|
|
|
|
|
2016-02-02 22:15:17 +00:00
|
|
|
if domain = registry.data["zone"]["ipv6-domain"]
|
|
|
|
dns_zone(registry, "ipv6-zone", domain)
|
2015-11-29 18:30:38 +00:00
|
|
|
end
|
|
|
|
|
2016-02-02 22:15:17 +00:00
|
|
|
if domain = registry.data["zone"]["dn42-domain"]
|
|
|
|
dns_zone(registry, "dn42-zone", domain)
|
|
|
|
end
|
2014-08-18 08:29:43 +00:00
|
|
|
|
2015-01-30 08:08:18 +00:00
|
|
|
Lxc::Utils.sh("lxc-attach", "-n", DNS_CONTAINER, "--", "rndc", "reload")
|
2015-01-03 16:57:39 +00:00
|
|
|
end
|
2014-08-18 08:29:43 +00:00
|
|
|
|
2015-01-03 16:57:39 +00:00
|
|
|
main
|