37 lines
839 B
Ruby
37 lines
839 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]
|
|
yield name, host_part
|
|
end
|
|
end
|
|
|
|
def name
|
|
@subnet.arpa.gsub(/\.$/, "")
|
|
end
|
|
|
|
def write_zone_file(path)
|
|
zone_template = Template.new(CONFIG_ROOT.join("templates/rdns-zone.erb"))
|
|
zone_template.write(path.join("zones", name), zone: self, data: data)
|
|
end
|
|
end
|
|
end
|