[python-ldap] Specificy multiple ldap servers for ldap.initialize

Michael Ströder michael at stroeder.com
Wed May 28 10:17:36 CEST 2014


Christian Kratzer wrote:
> what would be the most pythonic and elegant way to specify multiple ldap
> servers to connect to for HA purposes.
> 
> I run two ldap servers in two VM on two different hosts and have several
> scripts connecting to them.  I would like to make connection transparent when
> the primary server fails.
> 
> I currently have following leftover from my previous experiments:
> 
>     ldap_url = [ 'ldap://ldap1.cksoft.de/', 'ldap://ldap2.cksoft.de/' ]
>     l = ldap.initialize( ldap_url[0] )

ldap.initialize() simply passes argument uri to LDAPObject.__init__() which in
turn passes it directly to the OpenLDAP API. The OpenLDAP API expects a string
with all possible URIs separated with a space if you want libldap to do the
fail-over.

But letting libldap do the reconnect is pretty bad because your Python code
will never get noticed about to which server your application is actually
connected to.

Therefore I'd recommend to write your own thin wrapper around either
ldap.initialize() or LDAPObject.__init__(). This may depend on what your
favourite LDAPObject flavor is. Most times I'm using ReconnectLDAPObject.

Note that fail-over also comes in different flavors depending on whether DNS
round robin or a real load-balancer is part of the game.

Ciao, Michael.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2398 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20140528/f50cda50/attachment-0001.bin>


More information about the python-ldap mailing list