Class: Dyndnsd::Generator::Bind

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndnsd/generator/bind.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain, updater_params) ⇒ Bind

Returns a new instance of Bind.

Parameters:

  • domain (String)
  • updater_params (Hash{String => Object})


8
9
10
11
12
13
14
# File 'lib/dyndnsd/generator/bind.rb', line 8

def initialize(domain, updater_params)
  @domain = domain
  @ttl = updater_params['ttl']
  @dns = updater_params['dns']
  @email_addr = updater_params['email_addr']
  @additional_zone_content = updater_params['additional_zone_content']
end

Instance Method Details

#generate(db) ⇒ String

Parameters:

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dyndnsd/generator/bind.rb', line 18

def generate(db)
  out = []
  out << "$TTL #{@ttl}"
  out << "$ORIGIN #{@domain}."
  out << ''
  out << "@ IN SOA #{@dns} #{@email_addr} ( #{db['serial']} 3h 5m 1w 1h )"
  out << "@ IN NS #{@dns}"
  out << ''
  db['hosts'].each do |hostname, ips|
    ips.each do |ip|
      ip = IPAddr.new(ip).native
      type = ip.ipv6? ? 'AAAA' : 'A'
      name = hostname.chomp(".#{@domain}")
      out << "#{name} IN #{type} #{ip}"
    end
  end
  out << ''
  out << @additional_zone_content
  out << ''
  out.join("\n")
end