lxc-config/hooks/build-split-zone

52 lines
1.4 KiB
Plaintext
Raw Normal View History

2015-03-30 22:02:32 +00:00
#!/usr/bin/env ruby
require "resolv"
require_relative "lib/lxc"
class Resolver
def initialize
@stub_resolver = Resolv::DNS.new
@cache = {}
end
def resolve(name, delegated_subdomain, typeclass)
if name == "@"
fqdn = delegated_subdomain
else
fqdn = "#{name}.#{delegated_subdomain}"
end
result = @cache[fqdn + typeclass.to_s] ||= @stub_resolver.getresource(fqdn, typeclass)
if result == :no_record
nil
else
result
end
rescue Resolv::ResolvError => e
puts "warning: #{e}"
@cache[fqdn + typeclass.to_s] = :no_record
return nil
end
def a(name, delegated_subdomain)
result = resolve(name, delegated_subdomain, Resolv::DNS::Resource::IN::A)
return "" unless result
"#{name} A #{result.address.to_s}\n"
end
def aaaa(name, delegated_subdomain)
result = resolve(name, delegated_subdomain, Resolv::DNS::Resource::IN::AAAA)
return "" unless result
"#{name} AAAA #{result.address.to_s}\n"
end
end
template_path = Lxc::CONFIG_ROOT.join("templates/higgsboson.tk.zone.erb")
template = Lxc::Template.new(template_path)
serial = Time.new.to_i
resolver = Resolver.new
zones = [
["zones/higgsboson.tk.zone", :pub],
["zones/internal-eve.higgsboson.tk.zone", :eve],
["zones/internal-eva.higgsboson.tk.zone", :eva],
]
zones.each do |zone, type|
template.write(zone, resolver: resolver, serial: serial, type: type)
end
Lxc::Utils.sh("lxc-attach", "-n", "dns", "--", "rndc", "reload")