Support xvm.mit.edu as well.
authorEric Price <ecprice@mit.edu>
Wed, 7 May 2008 23:21:10 +0000 (19:21 -0400)
committerEric Price <ecprice@mit.edu>
Wed, 7 May 2008 23:21:10 +0000 (19:21 -0400)
svn path=/trunk/packages/sipb-xen-dns/; revision=505

code/dnsserver.py

index 0cad87a..1a188c6 100755 (executable)
@@ -16,11 +16,11 @@ class DatabaseAuthority(common.ResolverBase):
 
     soa = None
 
-    def __init__(self, domain, database=None):
+    def __init__(self, domains, database=None):
         common.ResolverBase.__init__(self)
         if database is not None:
             sipb_xen_database.connect(database)
-        self.domain = domain
+        self.domains = domains
         self.soa = dns.Record_SOA(mname='sipb-xen-dev.mit.edu', 
                                   rname='sipb-xen.mit.edu',
                                   serial=1, refresh=3600, retry=900,
@@ -40,13 +40,20 @@ class DatabaseAuthority(common.ResolverBase):
 
     def _lookup_unsafe(self, name, cls, type, timeout):
         sipb_xen_database.clear_cache()
-        if not (name.lower() == self.domain or 
-                name.lower().endswith('.'+self.domain)):
-            #Not us
-            return defer.fail(failure.Failure(dns.DomainError(name)))
+        if name.lower() in self.domains:
+            domain = name.lower()
+        else:
+            found = False
+            for domain in self.domains:
+                if name.lower().endswith('.'+domain):
+                    found = True
+                    break
+            if not found:
+                #Not us
+                return defer.fail(failure.Failure(dns.DomainError(name)))
         results = []
         if cls == dns.IN and type in (dns.A, dns.ALL_RECORDS):
-            host = name[:-len(self.domain)-1]
+            host = name[:-len(domain)-1]
             value = sipb_xen_database.Machine.get_by(name=host)
             if value is None or not value.nics:
                 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
@@ -58,14 +65,15 @@ class DatabaseAuthority(common.ResolverBase):
             results.append(dns.RRHeader(name, dns.A, dns.IN, 
                                         ttl, record, auth=True))
         authority = []
-        authority.append(dns.RRHeader(self.domain, dns.SOA, dns.IN, 3600,
+        authority.append(dns.RRHeader(domain, dns.SOA, dns.IN, 3600,
                                       self.soa, auth=True))
         return defer.succeed((results, authority, []))
         #Doesn't exist
         return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
 
 if '__main__' == __name__:
-    resolver = DatabaseAuthority('servers.csail.mit.edu',
+    resolver = DatabaseAuthority(['servers.csail.mit.edu',
+                                  'xvm.mit.edu'],
                                  'postgres://sipb-xen@sipb-xen-dev/sipb_xen')
 
     verbosity = 0