Optimizes domain backend

This commit is contained in:
Marc 2014-10-17 20:03:41 +00:00
parent 183b503274
commit b26982929d
4 changed files with 29 additions and 23 deletions

View file

@ -139,9 +139,16 @@ Remember that, as always with QuerySets, any subsequent chained methods which im
* move bill contact to bills apps
* autocreate <account>.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/<account>.orchestra.lan)

View file

@ -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)

View file

@ -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)

View file

@ -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/')