| Class | Dsadmin::Admind::DnsConfig |
| In: |
lib/dsadmin/admind/dns_config.rb
|
| Parent: | Object |
# File lib/dsadmin/admind/dns_config.rb, line 132
132: def initialize
133: @cron = Dsadmin::Admind::CronProxy.new
134: @collectors = Array.new
135: @rebuildjob = nil
136:
137: @rebuild_mutex = Mutex.new
138: @queued_rebuild_mutex = Mutex.new
139: end
Add a Proc that collects / generates DNS aliases from one or more other sources (e.g. virtual host definitions).
The Proc has to return an array of DnsAlias objects or objects that provide the same attribute readers. It is highly recommended to use DnsAlias::Simple objects for this to get good efficiency.
Note that aliases in the dns alias table (i.e. those explicitly defined by the user) always override automatically generated ones.
# File lib/dsadmin/admind/dns_config.rb, line 98
98: def add_alias_collector(aProc)
99: @collectors << aProc
100: end
Triggers a configuration rebuild/update.
# File lib/dsadmin/admind/dns_config.rb, line 37
37: def rebuild
38: # We use @queued_rebuild_mutex to allow at most one more rebuild to
39: # be queued once a reload is underway. This allows for safe yet
40: # more or less efficient handling of cases where the alias list
41: # is changed by another thread while a rebuild triggered
42: # by a previous change is already underway.
43: @queued_rebuild_mutex.try_lock or return true
44:
45: zf_sect = cfg.get('modules/dns/aliases_zonefile', Dsadmin::ConfigSection)
46: zf_path = Dsadmin::SystemPath.new(zf_sect)
47: cmdsect = cfg.get('modules/dns/update_command', Dsadmin::ConfigSection)
48: cmd = Dsadmin::SystemCommand.new(cmdsect)
49:
50: @rebuild_mutex.synchronize {
51: @queued_rebuild_mutex.unlock
52:
53: entries = build_entries
54:
55: zf_path.open({}, "w") { |zonefile|
56: zonefile.puts(entries)
57: }
58:
59: cmd.exec
60: }
61: end
Schedule periodic config rebuilds via Cron
# File lib/dsadmin/admind/dns_config.rb, line 73
73: def schedule_rebuild
74: return if @rebuildjob
75:
76: req = Dsadmin::Request.new_simple(:dns, :update)
77:
78: spec = Dsadmin::Admind::CronjobSpec.new
79: spec.request = req
80: spec.last_run_time = Time.at(0)
81: spec.timespec = "+30m"
82: spec.failure_policy = Dsadmin::Admind::Cron::RETRY_EXP015
83: spec.delay_policy = Dsadmin::Admind::Cron::RETRY_REG15
84:
85: @rebuildjob = @cron.add(spec)
86: end
# File lib/dsadmin/admind/dns_config.rb, line 64
64: def trigger_rebuild
65: schedule_rebuild unless @rebuildjob
66:
67: log.debug("Triggering dns rebuild run")
68: @cron.forcerun(@rebuildjob)
69: end
Generate a nameserver configfile A entry (String) for the given host alias.
| fqdn: | Fully qualified hostname |
| ip: | IP adress (ipv4) |
| ttl: | Time To Live in seconds |
Currently tinydns-specific. Override/change to match the syntax of a different server.
# File lib/dsadmin/admind/dns_config.rb, line 126
126: def build_alias_entry(fqdn, ip, ttl)
127: "+#{fqdn}:#{ip}:#{ttl}:"
128: end
# File lib/dsadmin/admind/dns_config.rb, line 142
142: def build_entries
143: tmp = Hash.new
144: elists = Array.new
145:
146: @collectors.each { |cur| elists << cur.call }
147: elists << DnsAlias.find(:all)
148:
149: elists.each { |list|
150: list.each { |item|
151: tmp[item.hostname] = item
152: }
153: }
154:
155: entries = Array.new
156: targets = DnsTarget.find(:all)
157:
158: tmp.values.each { |current|
159: entries.push(*build_from_single_record(current, targets))
160: }
161:
162: return entries
163: end
Build (a) proper alias definition(s) from a single alias definition.
# File lib/dsadmin/admind/dns_config.rb, line 167
167: def build_from_single_record(anAlias, targets)
168: target = targets.find { |cur| cur.id == anAlias.dns_target_id }
169: ip = target.ipv4
170: ttl = anAlias.ttl || target.ttl
171:
172: if(anAlias.fully_qualified?)
173: #puts "fully qualified: #{anAlias.hostname}"
174: return [build_alias_entry(anAlias.hostname, ip, ttl)]
175: else
176: res = []
177: dns_domains.each { |domain|
178: host = [anAlias.hostname, domain].join(".")
179: res << build_alias_entry(host, ip, ttl)
180: }
181: return res
182: end
183: end