39 lines
935 B
Ruby
39 lines
935 B
Ruby
module Lxc
|
|
class RdnsZone
|
|
def initialize(data, subnet)
|
|
@data = data
|
|
@subnet = NetAddr::CIDR.create(subnet)
|
|
end
|
|
|
|
attr_reader :data
|
|
|
|
def [](key)
|
|
(data["zone"] || {})[key]
|
|
end
|
|
|
|
def pointers(&blk)
|
|
version = @subnet.version
|
|
|
|
@data["network"].each do |name, host|
|
|
ip = host["ipv#{version}"]
|
|
next unless ip
|
|
arpa = NetAddr::CIDR.create(ip).arpa
|
|
next unless arpa.end_with?(@subnet.arpa)
|
|
host_part = arpa[0, arpa.size - @subnet.arpa.size - 1]
|
|
# only allowed characters in FQDN
|
|
name = name.gsub(/[^a-zA-Z0-9\-]/, "-")
|
|
yield name, host_part
|
|
end
|
|
end
|
|
|
|
def name
|
|
@subnet.arpa.gsub(/\.$/, "")
|
|
end
|
|
|
|
def write_zone_file(path)
|
|
zone_template = Template.new(CONFIG_ROOT.join("hooks/templates/rdns-zone.erb"))
|
|
zone_template.write(path.join("zones", name), zone: self, data: data)
|
|
end
|
|
end
|
|
end
|