Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #
- # untitled
- #
- # Created by Tom Lazar on 2006-07-05.
- # Copyright (c) 2006 tomster.org. All rights reserved.
- #
- import sys
- import os
- from amara import binderytools
- from helpers import *
- from email import *
- from convenience import get_hosting
- from helpers import openForWriting
- from hostingconfig import tinydnsdata, DNS_HOSTS
- from sshconnect import SSHHost
- def createTinyDNSData(hosting=None):
- """ Write the domain infos to a tinydns compatible file. """
- if not hosting:
- hosting = get_hosting()
- file = openForWriting(tinydnsdata)
- domains = hosting.doc.xml_xpath(u"//domain[@status='active' and @admin='yes']")
- for domain in domains:
- nshosts = domain.xml_xpath(u"specs/dns")
- mxhosts = domain.xml_xpath(u"specs/mx")
- hosts = domain.xml_xpath(u"specs/host")
- zone = str(domain.name)
- if nshosts:
- zonestring = "Z%s:%s.:hostmaster.tomster.org." % (zone, nshosts[0])
- file.write(zonestring)
- file.write("\n")
- for nshost in nshosts:
- file.write("&%s::%s" % (zone, nshost))
- file.write("\n")
- for mxhost in mxhosts:
- file.write("@%s::%s:%s" % (zone, str(mxhost), str(mxhost.prio)))
- file.write("\n")
- for host in hosts:
- file.write("+%s:%s" % (fqdn(str(host), zone), str(host.ipaddr)))
- file.write("\n")
- else:
- print ">> No DNS entries found for %s. Skipping this domain!" % zone
- file.close()
- def uploadTinyDNSData(hosting=None):
- """ Uploads the tinydns data file to each server specified in `hostingconfig` and
- and issues a make command there to activate the new data (if available).
- """
- if not hosting:
- hosting = get_hosting()
- for host in DNS_HOSTS:
- connect = SSHHost(hostname=host['hostname'], \
- username=host['username'], \
- keyfile=host['keyfile'], \
- port=host['port'])
- print "uploading to %s." % host['hostname']
- connect.copy(tinydnsdata, host['datafile'])
- if host.has_key('makefolder'):
- print "rebuiding database."
- connect.execute("cd %s ; make" % host['makefolder'])
- return
- def fqdn(host=None, domain=None):
- if domain is None:
- return None
- elif host is None or host == '':
- return domain
- else:
- return "%s.%s" % (host, domain)
- def main():
- hosting = get_hosting()
- createTinyDNSData(hosting)
- uploadTinyDNSData(hosting)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment