Fixes on domain backend

This commit is contained in:
Marc 2014-10-17 13:41:08 +00:00
parent 34d4b4c808
commit 5600ed4c51
1 changed files with 17 additions and 5 deletions

View File

@ -28,13 +28,25 @@ class Bind9MasterDomainBackend(ServiceController):
domain.refresh_serial() domain.refresh_serial()
context['zone'] = ';; %(banner)s\n' % context context['zone'] = ';; %(banner)s\n' % context
context['zone'] += domain.render_zone() context['zone'] += domain.render_zone()
self.append("{ echo -e '%(zone)s' | diff -N -I'^;;' %(zone_path)s - ; } ||" self.append(textwrap.dedent("""\
" { echo -e '%(zone)s' > %(zone_path)s; UPDATED=1; }" % context) {
echo -e '%(zone)s' | diff -N -I'^\s*;;' %(zone_path)s -
} || {
echo -e '%(zone)s' > %(zone_path)s
UPDATED=1
}""" % context
))
self.update_conf(context) self.update_conf(context)
def update_conf(self, context): def update_conf(self, context):
self.append("grep '\s*zone\s*\"%(name)s\"\s*{' %(conf_path)s > /dev/null ||" self.append(textwrap.dedent("""\
" { echo -e '%(conf)s' >> %(conf_path)s; UPDATED=1; }" % context) cat -s <(sed -e 's/^};/};\n/' named.conf.local) | \\
awk -v s=pangea.cat 'BEGIN { RS=""; s="zone \\""s"\\"" } $0~s{ print }' | \\
diff -I"^\s*//" - <(echo '%(conf)s') || {
echo -e '%(conf)s' >> %(conf_path)s
UPDATED=1
}""" % context
))
for subdomain in context['subdomains']: for subdomain in context['subdomains']:
context['name'] = subdomain.name context['name'] = subdomain.name
self.delete(subdomain) self.delete(subdomain)
@ -48,7 +60,7 @@ class Bind9MasterDomainBackend(ServiceController):
if context['name'][0] in ('*', '_'): if context['name'][0] in ('*', '_'):
# These can never be top level domains # These can never be top level domains
return return
self.append(textwrap.dedent(""" self.append(textwrap.dedent("""\
cat -s <(sed -e 's/^};/};\\n/' named.conf.local) | \\ cat -s <(sed -e 's/^};/};\\n/' named.conf.local) | \\
awk -v s="%(name)s" 'BEGIN { RS=""; s="zone \\""s"\\"" } $0!~s{ print $0"\\n" }' \\ awk -v s="%(name)s" 'BEGIN { RS=""; s="zone \\""s"\\"" } $0!~s{ print $0"\\n" }' \\
> %(conf_path)s.tmp""" % context > %(conf_path)s.tmp""" % context