[Da-tools-commits] ./debian/userdir-ldap r401: ud-generate: Add performance optimization by resolving IP adresses for hosts
Peter Palfrader
peter at palfrader.org
Sat May 17 09:30:01 UTC 2008
------------------------------------------------------------
revno: 401
committer: Peter Palfrader <peter at palfrader.org>
branch nick: userdir-ldap
timestamp: Sat 2008-05-17 11:30:01 +0200
message:
ud-generate: Add performance optimization by resolving IP adresses for hosts
only once and caching the result. [aba]
modified:
debian/changelog
ud-generate
------------------------------------------------------------
revno: 349.2.43
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-17 09:27:06 +0000
+++ b/debian/changelog 2008-05-17 09:30:01 +0000
@@ -8,8 +8,10 @@
ud-replicate clients use their ssh host key to authenticate to the
db server. The code now supports this but the feature is still
disabled. [aba]
+ * ud-generate: Add performance optimization by resolving IP adresses
+ for hosts only once and caching the result. [aba]
- -- Peter Palfrader <weasel at debian.org> Sat, 17 May 2008 11:25:49 +0200
+ -- Peter Palfrader <weasel at debian.org> Sat, 17 May 2008 11:29:41 +0200
userdir-ldap (0.3.23) unstable; urgency=low
=== 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