public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/
Date: Mon,  5 Jan 2015 23:12:37 +0000 (UTC)	[thread overview]
Message-ID: <1420496513.8e07d01d44825fdd10d2354d79ed4b06c9bfc856.dolsen@gentoo> (raw)

commit:     8e07d01d44825fdd10d2354d79ed4b06c9bfc856
Author:     Pavlos Ratis <dastergon <AT> gentoo <DOT> org>
AuthorDate: Mon Jan  5 19:42:53 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> 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)


             reply	other threads:[~2015-01-05 23:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-05 23:12 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-07-07 14:05 [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/ Brian Dolbec
2016-12-23 19:55 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-03-24  3:13 Brian Dolbec
2015-03-17 19:51 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2014-12-26 18:37 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-22 23:11 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420496513.8e07d01d44825fdd10d2354d79ed4b06c9bfc856.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox