From b26982929ddad4ef1aad1fb2248806af2ad6d9ab Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 17 Oct 2014 20:03:41 +0000 Subject: [PATCH] Optimizes domain backend --- TODO.md | 9 ++++- orchestra/apps/domains/backends.py | 38 +++++++++---------- .../domains/tests/functional_tests/tests.py | 4 +- orchestra/apps/websites/settings.py | 1 + 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/TODO.md b/TODO.md index 74d56f1c..7089dcaf 100644 --- a/TODO.md +++ b/TODO.md @@ -139,9 +139,16 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * move bill contact to bills apps -* autocreate .orchestra.lan * Backend optimization * fields = () * ignore_fields = () * based on a merge set of save(update_fields) + + +textwrap.dedent( \\) + +* accounts + * short name / long name + * contact inlines + * autocreate stuff (email/.orchestra.lan) diff --git a/orchestra/apps/domains/backends.py b/orchestra/apps/domains/backends.py index 8af24edf..723871a1 100644 --- a/orchestra/apps/domains/backends.py +++ b/orchestra/apps/domains/backends.py @@ -1,3 +1,4 @@ +import re import textwrap from django.utils.translation import ugettext_lazy as _ @@ -29,31 +30,29 @@ class Bind9MasterDomainBackend(ServiceController): context['zone'] = ';; %(banner)s\n' % context context['zone'] += domain.render_zone() 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 + echo -e '%(zone)s' > %(zone_path)s.tmp + diff -N -I'^\s*;;' %(zone_path)s %(zone_path)s.tmp || UPDATED=1 + mv %(zone_path)s.tmp %(zone_path)s""" % context )) self.update_conf(context) def update_conf(self, context): self.append(textwrap.dedent("""\ - cat -s <(sed -e 's/^};/};\\n/' %(conf_path)s) | \\ - awk -v s=pangea.cat 'BEGIN { RS=""; s="zone \\""s"\\"" } $0~s{ print }' | \\ - diff -B -I"^\s*//" - <(echo '%(conf)s') || { - cat -s <(sed -e 's/^};/};\\n/' %(conf_path)s) | \\ - awk -v s="%(name)s" 'BEGIN { RS=""; s="zone \\""s"\\"" } $0!~s{ print $0"\\n" }' \\ - > %(conf_path)s.tmp - echo -e '%(conf)s' >> %(conf_path)s.tmp - mv %(conf_path)s.tmp %(conf_path)s + sed '/zone "%(name)s".*/,/^\s*};\s*$/!d' %(conf_path)s | diff -B -I"^\s*//" - <(echo '%(conf)s') || { + sed -i -e '/zone "%(name)s".*/,/^\s*};/d' \\ + -e 'N; /^\\n$/d; P; D' %(conf_path)s + echo '%(conf)s' >> %(conf_path)s UPDATED=1 }""" % context )) - for subdomain in context['subdomains']: - context['name'] = subdomain.name - self.delete(subdomain) + # Delete ex-top-domains that are now subdomains + self.append(textwrap.dedent("""\ + sed -i -e '/zone ".*\.%(name)s".*/,/^\s*};\s*$/d' \\ + -e 'N; /^\\n$/d; P; D' %(conf_path)s""" % context + )) + if 'zone_path' in context: + context['zone_subdomains_path'] = re.sub(r'^(.*/)', r'\1*.', context['zone_path']) + self.append('rm -f %(zone_subdomains_path)s' % context) def delete(self, domain): context = self.get_context(domain) @@ -65,9 +64,8 @@ class Bind9MasterDomainBackend(ServiceController): # These can never be top level domains return self.append(textwrap.dedent("""\ - cat -s <(sed -e 's/^};/};\\n/' %(conf_path)s) | \\ - awk -v s="%(name)s" 'BEGIN { RS=""; s="zone \\""s"\\"" } $0!~s{ print $0"\\n" }' \\ - > %(conf_path)s.tmp""" % context + sed -e '/zone ".*\.%(name)s".*/,/^\s*};\s*$/d' \\ + -e 'N; /^\\n$/d; P; D' %(conf_path)s > %(conf_path)s.tmp""" % context )) self.append('diff -B -I"^\s*//" %(conf_path)s.tmp %(conf_path)s || UPDATED=1' % context) self.append('mv %(conf_path)s.tmp %(conf_path)s' % context) diff --git a/orchestra/apps/domains/tests/functional_tests/tests.py b/orchestra/apps/domains/tests/functional_tests/tests.py index da5ecce4..981f703f 100644 --- a/orchestra/apps/domains/tests/functional_tests/tests.py +++ b/orchestra/apps/domains/tests/functional_tests/tests.py @@ -180,7 +180,7 @@ class DomainTestMixin(object): self.add(self.ns1_name, self.ns1_records) self.add(self.ns2_name, self.ns2_records) self.add(self.domain_name, self.domain_records) - self.addCleanup(partial(self.delete, self.domain_name)) +# self.addCleanup(self.delete, self.domain_name) self.validate_add(self.MASTER_SERVER_ADDR, self.domain_name) time.sleep(1) self.validate_add(self.SLAVE_SERVER_ADDR, self.domain_name) @@ -198,7 +198,7 @@ class DomainTestMixin(object): self.add(self.ns1_name, self.ns1_records) self.add(self.ns2_name, self.ns2_records) self.add(self.domain_name, self.domain_records) - self.addCleanup(partial(self.delete, self.domain_name)) + self.addCleanup(self.delete, self.domain_name) self.update(self.domain_name, self.domain_update_records) time.sleep(0.5) self.validate_update(self.MASTER_SERVER_ADDR, self.domain_name) diff --git a/orchestra/apps/websites/settings.py b/orchestra/apps/websites/settings.py index 89c81300..ffcaea49 100644 --- a/orchestra/apps/websites/settings.py +++ b/orchestra/apps/websites/settings.py @@ -45,6 +45,7 @@ WEBSITES_OPTIONS = getattr(settings, 'WEBSITES_OPTIONS', { WEBSITES_BASE_APACHE_CONF = getattr(settings, 'WEBSITES_BASE_APACHE_CONF', '/etc/apache2/') + WEBSITES_WEBALIZER_PATH = getattr(settings, 'WEBSITES_WEBALIZER_PATH', '/home/httpd/webalizer/')