From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 8CBDB138A1A for ; Mon, 5 Jan 2015 23:12:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9E9ADE0870; Mon, 5 Jan 2015 23:12:44 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2B4EBE085E for ; Mon, 5 Jan 2015 23:12:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 02E093406FB for ; Mon, 5 Jan 2015 23:12:41 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6205FEF49 for ; Mon, 5 Jan 2015 23:12:37 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1420496513.8e07d01d44825fdd10d2354d79ed4b06c9bfc856.dolsen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys-ldap/gkeyldap/config.py gkeys-ldap/gkeyldap/connect.py X-VCS-Directories: gkeys-ldap/gkeyldap/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 8e07d01d44825fdd10d2354d79ed4b06c9bfc856 X-VCS-Branch: master Date: Mon, 5 Jan 2015 23:12:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 5101cd01-f914-426b-bc9f-4707f8bc9516 X-Archives-Hash: 590803a3a49eefa830c56dd4ee697f50 commit: 8e07d01d44825fdd10d2354d79ed4b06c9bfc856 Author: Pavlos Ratis gentoo org> AuthorDate: Mon Jan 5 19:42:53 2015 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Mon Jan 5 22:21:53 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=8e07d01d gkeyldap: redundancy to ldap slaves --- gkeys-ldap/gkeyldap/config.py | 4 ++-- gkeys-ldap/gkeyldap/connect.py | 27 ++++++++++++++++----------- 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)