aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlos Ratis <dastergon@gentoo.org>2015-01-05 21:42:53 +0200
committerBrian Dolbec <dolsen@gentoo.org>2015-01-05 14:21:53 -0800
commit8e07d01d44825fdd10d2354d79ed4b06c9bfc856 (patch)
tree2a3564e8bfa217440e5587ea95a93b7ce2cd6701 /gkeys-ldap
parentpy2man: updates for sake of consistency (diff)
downloadgentoo-keys-8e07d01d44825fdd10d2354d79ed4b06c9bfc856.tar.gz
gentoo-keys-8e07d01d44825fdd10d2354d79ed4b06c9bfc856.tar.bz2
gentoo-keys-8e07d01d44825fdd10d2354d79ed4b06c9bfc856.zip
gkeyldap: redundancy to ldap slaves
Diffstat (limited to 'gkeys-ldap')
-rw-r--r--gkeys-ldap/gkeyldap/config.py4
-rw-r--r--gkeys-ldap/gkeyldap/connect.py27
2 files changed, 18 insertions, 13 deletions
diff --git a/gkeys-ldap/gkeyldap/config.py b/gkeys-ldap/gkeyldap/config.py
index 6e22a5c..f7fb837 100644
--- a/gkeys-ldap/gkeyldap/config.py
+++ b/gkeys-ldap/gkeyldap/config.py
@@ -1,8 +1,8 @@
#
#-*- coding:utf-8 -*-
-
-default_server = 'ldap://ldap1.gentoo.org'
+# Redundancy -- ldap{1,2,3,4}
+default_server = ['ldap://ldap%d.gentoo.org' % i for i in xrange(1,5)]
# add uid to the results so you don't have to
# separate it out of the results tuple[0] value
default_fields = ['uid', 'cn', 'mail', 'gentooStatus', 'gpgkey', 'gpgfingerprint']
diff --git a/gkeys-ldap/gkeyldap/connect.py b/gkeys-ldap/gkeyldap/connect.py
index 6c80e4f..9df6e24 100644
--- a/gkeys-ldap/gkeyldap/connect.py
+++ b/gkeys-ldap/gkeyldap/connect.py
@@ -20,7 +20,7 @@ class LdapConnect(object):
'''Class to connect on the configured LDAP server'''
def __init__(self, server=None, logger=None):
- self.server = server or default_server
+ self.server = server or default_server[0]
self.logger = logger
self.logger.debug('LdapConnect: __init__; server...: %s' % self.server)
self.ldap_connection = None
@@ -34,16 +34,21 @@ class LdapConnect(object):
if server:
self.server = server
self.logger.debug('LdapConnect: connect; new server: %s' % self.server)
- try:
- self.ldap_connection = ldap.initialize(self.server)
- self.ldap_connection.set_option(ldap.OPT_X_TLS_DEMAND, True)
- self.ldap_connection.start_tls_s()
- self.ldap_connection.simple_bind_s()
- except Exception as e:
- self.logger.error(
- 'LdapConnect: connect; failed to connect to server: %s' % self.server)
- self.logger.error("Exception was: %s" % str(e))
- self.logger.error("Aborting %s... Connection failed" % action)
+ connection = True
+ for ldap_slave in self.server:
+ try:
+ self.ldap_connection = ldap.initialize(self.server)
+ self.ldap_connection.set_option(ldap.OPT_X_TLS_DEMAND, True)
+ self.ldap_connection.start_tls_s()
+ self.ldap_connection.simple_bind_s()
+ except Exception as e:
+ self.logger.error(
+ 'LdapConnect: connect; failed to connect to server: %s' % self.server)
+ self.logger.error("Exception was: %s" % str(e))
+ self.logger.error("Connecting to the next LDAP slave...")
+ connection = False
+ continue
+ if not connection:
return False
self.logger.debug(
'LdapConnect: connect; connection: %s' % self.ldap_connection)