From 5600ed4c51fa73948ff94f6ba16e4fbbb682f8b8 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 17 Oct 2014 13:41:08 +0000 Subject: [PATCH] Fixes on domain backend --- orchestra/apps/domains/backends.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/orchestra/apps/domains/backends.py b/orchestra/apps/domains/backends.py index fbdc62f4..9f790a95 100644 --- a/orchestra/apps/domains/backends.py +++ b/orchestra/apps/domains/backends.py @@ -28,13 +28,25 @@ class Bind9MasterDomainBackend(ServiceController): domain.refresh_serial() context['zone'] = ';; %(banner)s\n' % context context['zone'] += domain.render_zone() - self.append("{ echo -e '%(zone)s' | diff -N -I'^;;' %(zone_path)s - ; } ||" - " { echo -e '%(zone)s' > %(zone_path)s; UPDATED=1; }" % context) + self.append(textwrap.dedent("""\ + { + 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) def update_conf(self, context): - self.append("grep '\s*zone\s*\"%(name)s\"\s*{' %(conf_path)s > /dev/null ||" - " { echo -e '%(conf)s' >> %(conf_path)s; UPDATED=1; }" % context) + self.append(textwrap.dedent("""\ + 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']: context['name'] = subdomain.name self.delete(subdomain) @@ -48,7 +60,7 @@ class Bind9MasterDomainBackend(ServiceController): if context['name'][0] in ('*', '_'): # These can never be top level domains return - self.append(textwrap.dedent(""" + self.append(textwrap.dedent("""\ cat -s <(sed -e 's/^};/};\\n/' named.conf.local) | \\ awk -v s="%(name)s" 'BEGIN { RS=""; s="zone \\""s"\\"" } $0!~s{ print $0"\\n" }' \\ > %(conf_path)s.tmp""" % context