Ticket #820

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
>From de9d887f451d0bf1c18930f7b006efd4a759d458 Mon Sep 17 00:00:00 2001
From: Simo Sorce <sso...@redhat.com>
Date: Fri, 21 Jan 2011 14:32:55 -0500
Subject: [PATCH 1/2] Populate shared tree with replica related values

Fixes: https://fedorahosted.org/freeipa/ticket/820
---
 install/tools/ipa-replica-install |    1 +
 ipaserver/install/dsinstance.py   |   22 ++++++++++++++++++++++
 ipaserver/install/replication.py  |   29 +++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/install/tools/ipa-replica-install b/install/tools/ipa-replica-install
index 3c912a759ac10ef69b4828b67dae4feef4d504fa..69c0e7eac73d1f80bb900d13370e7d5e3325e1ed 100755
--- a/install/tools/ipa-replica-install
+++ b/install/tools/ipa-replica-install
@@ -445,6 +445,7 @@ def main():
         print "ipa-client-install returned: " + str(e)
         raise RuntimeError("Failed to configure the client")
 
+    ds.replica_populate()
     ds.init_memberof()
 
 try:
diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py
index 5da9d17d4417031920495254ff566ee235234bfb..c6be13735a0789ae02b6466cf2bee0702c23bacf 100644
--- a/ipaserver/install/dsinstance.py
+++ b/ipaserver/install/dsinstance.py
@@ -734,3 +734,25 @@ class DsInstance(service.Service):
     def __root_autobind(self):
         self._ldap_mod("root-autobind.ldif")
 
+    def replica_populate(self):
+        self.ldap_connect()
+
+        dn = "cn=default,ou=profile,%s" % self.suffix
+        try:
+            ret = self.admin_conn.search_s(dn, ldap.SCOPE_BASE,
+                                           '(objectclass=*)')[0]
+            srvlist = ret.data.get('defaultServerList')
+            if len(srvlist) > 0:
+                srvlist = srvlist[0].split()
+            if not self.fqdn in srvlist:
+                srvlist.append(self.fqdn)
+                attr = ' '.join(srvlist)
+                mod = [(ldap.MOD_REPLACE, 'defaultServerList', attr)]
+                self.admin_conn.modify_s(dn, mod)
+        except ldap.NO_SUCH_OBJECT:
+            pass
+        except ldap.TYPE_OR_VALUE_EXISTS:
+            pass
+
+        self.ldap_disconnect()
+
diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
index 756bb5595226d49e31edf5ce5afd12d26ac26758..5c69fb25fd2d824ab6a8105e57f145f8ada1a90b 100644
--- a/ipaserver/install/replication.py
+++ b/ipaserver/install/replication.py
@@ -732,6 +732,11 @@ class ReplicationManager:
         return IPA_REPLICA
 
     def replica_cleanup(self, replica, realm, force=False):
+        """
+        This function removes information about the replica in parts
+        of the shared tree that expose it, so clients stop trying to
+        use this replica.
+        """
 
         err = None
 
@@ -792,6 +797,30 @@ class ReplicationManager:
         except errors.NotFound:
             pass
         except Exception, e:
+            if not force:
+                raise e
+            elif not err:
+                err = e
+
+        try:
+            dn = 'cn=default,ou=profile,%s' % self.suffix
+            ret = self.conn.search_s(dn, ldap.SCOPE_BASE,
+                                     '(objectclass=*)')[0]
+            srvlist = ret.data.get('defaultServerList')
+            if len(srvlist) > 0:
+                srvlist = srvlist[0].split()
+            if self.hostname in srvlist:
+                srvlist.remove(self.hostname)
+                attr = ' '.join(srvlist)
+                mod = [(ldap.MOD_REPLACE, 'defaultServerList', attr)]
+                self.conn.modify_s(dn, mod)
+        except ldap.NO_SUCH_OBJECT:
+            pass
+        except ldap.NO_SUCH_ATTRIBUTE:
+            pass
+        except ldap.TYPE_OR_VALUE_EXISTS:
+            pass
+        except Exception, e:
             if force and err:
                 raise err
             else:
-- 
1.7.3.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to