[Da-tools-commits] ./da-tools/userdir-ldap-common r392: Add performance optimization by caching IP adresses in ud-generate as a precondition for automatically adding aliases

Andreas Barth aba at not.so.argh.org
Fri May 16 17:58:28 UTC 2008


------------------------------------------------------------
revno: 392
committer: Andreas Barth <aba at not.so.argh.org>
branch nick: userdir-ldap-common
timestamp: Fri 2008-05-16 17:58:28 +0000
message:
  Add performance optimization by caching IP adresses in ud-generate as a precondition for automatically adding aliases
modified:
  debian/changelog
  ud-generate
-------------- next part --------------
=== modified file 'debian/changelog'
--- a/debian/changelog	2008-05-16 17:40:19 +0000
+++ b/debian/changelog	2008-05-16 17:58:28 +0000
@@ -2,6 +2,8 @@
 
   * Add compatibility to dchroot-dsa to ud-replicate.
   * Add (disabled) generation of authorized_keys suiteable for sshdist.
+  * Add performance optimization by caching IP adresses in ud-generate
+    (as a precondition for automatically adding aliases)
 
  -- Andreas Barth <aba at not.so.argh.org>  Fri, 16 May 2008 17:35:19 +0000
 

=== modified file 'ud-generate'
--- a/ud-generate	2008-05-16 17:40:19 +0000
+++ b/ud-generate	2008-05-16 17:58:28 +0000
@@ -701,6 +701,24 @@
    raise;
   Done(File,F,None);
 
+# cache IP adresses
+HostToIPCache = {}
+def HostToIP(Host):
+    global HostToIPCache
+    if not Host in HostToIPCache:
+        IPAdressesT = None
+        try:
+            IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
+        except socket.gaierror, (code):
+            if code[0] != -2: raise
+        IPAdresses = []
+        for addr in IPAdressesT:
+            if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
+            else: IPAdresses += [addr[1]]
+        HostToIPCache[Host] = IPAdresses
+    return HostToIPCache[Host]
+
+
 # Generate the ssh known hosts file
 def GenSSHKnown(l,File,mode=None):
   F = None;
@@ -722,23 +740,12 @@
       SHost = Host.find(".")
       if SHost != None: HostNames += [Host[0:SHost]]
 
-      IPAdressesT = None
-      IPAdresses = []
-      # get IP adresses back as "proto adress" to distinguish between v4 and v6
-      try:
-         IPAdressesT = set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)])
-      except:
-         if code[0] != -2: raise
-      for addr in IPAdressesT:
-         if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
-	 else: IPAdresses += [addr[1]]
-
       for I in x[1]["sshRSAHostKey"]:
          if mode and mode == 'authorized_keys':
-            #Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,from="%s" %s' % (Host, ",".join(HNames + IPAdresses), I)
+            #Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,from="%s" %s' % (Host, ",".join(HNames + HostToIP(Host)), I)
             Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
          else:
-            Line = "%s %s" %(",".join(HostNames + IPAdresses), I);
+            Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
          Line = Sanitize(Line) + "\n";
          F.write(Line);
   # Oops, something unspeakable happened.



More information about the Da-tools-commits mailing list