Changeset 582


Ignore:
Timestamp:
Jun 3, 2008, 2:05:10 AM (16 years ago)
Author:
broder
Message:

Attempting to close #92 and #93

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-dns/code/dnsserver.py

    r541 r582  
    2626                                  serial=1, refresh=3600, retry=900,
    2727                                  expire=3600000, minimum=21600, ttl=3600)
     28        self.ns = dns.Record_NS(name='ns1.xvm.mit.edu', ttl=3600)
     29   
    2830    def _lookup(self, name, cls, type, timeout = None):
    2931        for i in range(3):
     
    4143    def _lookup_unsafe(self, name, cls, type, timeout):
    4244        sipb_xen_database.clear_cache()
     45       
     46        ttl = 900
    4347        if name.lower() in self.domains:
    4448            domain = name.lower()
    4549        else:
     50            # This works because domain will remain bound after breaking out of the loop
    4651            for domain in self.domains:
    4752                if name.lower().endswith('.'+domain):
     
    5055                return defer.fail(failure.Failure(dns.DomainError(name)))
    5156        results = []
    52         if cls == dns.IN and type in (dns.A, dns.ALL_RECORDS):
    53             host = name[:-len(domain)-1]
    54             if not host:
    55                 ttl = 900
    56                 record = dns.Record_CNAME('sipb-xen-dev.mit.edu', ttl)
    57                 results.append(dns.RRHeader(name, dns.CNAME, dns.IN,
    58                                             ttl, record, auth=True))
    59             else:
    60                 value = sipb_xen_database.Machine.get_by(name=host)
    61                 if value is None or not value.nics:
    62                     return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
    63                 ip = value.nics[0].ip
    64                 if ip is None:  #Deactivated?
    65                     return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
    66                 ttl = 900
    67                 record = dns.Record_A(ip, ttl)
    68                 results.append(dns.RRHeader(name, dns.A, dns.IN,
    69                                             ttl, record, auth=True))
    7057        authority = []
    71         auth_record = dns.Record_NS(name='ns1.xvm.mit.edu', ttl=3600)
     58        additional = []
    7259        authority.append(dns.RRHeader(domain, dns.NS, dns.IN,
    73                                       3600, auth_record, auth=True))
    74         return defer.succeed((results, authority, []))
    75         #Doesn't exist
    76         return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
     60                                      3600, self.ns, auth=True))
     61        if cls == dns.IN:
     62            if type in (dns.A, dns.ALL_RECORDS):
     63                host = name[:-len(domain)-1]
     64                if not host:
     65                    record = dns.Record_CNAME('sipb-xen-dev.mit.edu', ttl)
     66                    results.append(dns.RRHeader(name, dns.CNAME, dns.IN,
     67                                                ttl, record, auth=True))
     68                else:
     69                    value = sipb_xen_database.Machine.get_by(name=host)
     70                    if value is None or not value.nics:
     71                        return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
     72                    ip = value.nics[0].ip
     73                    if ip is None:  #Deactivated?
     74                        return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
     75                    record = dns.Record_A(ip, ttl)
     76                    results.append(dns.RRHeader(name, dns.A, dns.IN,
     77                                                ttl, record, auth=True))
     78            elif type == dns.NS:
     79                results.append(dns.RRHeader(domain, dns.NS, dns.IN,
     80                                            ttl, self.ns, auth=True))
     81                authority = []
     82                record = dns.Record_A(address='18.181.0.62', ttl=ttl)
     83                additional.append(dns.RRHeader('ns1.xvm.mit.edu', dns.A, dns.IN,
     84                                               ttl, record, auth=True))
     85            elif type == dns.SOA:
     86                results.append(dns.RRHeader(domain, dns.SOA, dns.IN,
     87                                            ttl, self.soa, auth=True))
     88            return defer.succeed((results, authority, additional))
     89        else:
     90            #Doesn't exist
     91            return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
    7792
    7893if '__main__' == __name__:
Note: See TracChangeset for help on using the changeset viewer.