diff options
-rwxr-xr-x | install/tools/ipa-replica-manage | 10 | ||||
-rw-r--r-- | ipaserver/install/replication.py | 20 | ||||
-rw-r--r-- | ipaserver/ipaldap.py | 36 |
3 files changed, 12 insertions, 54 deletions
diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage index 698a02f54..85535c0e6 100755 --- a/install/tools/ipa-replica-manage +++ b/install/tools/ipa-replica-manage @@ -299,12 +299,10 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False): dn = DN(('cn', replica2), ('cn', 'replicas'), ('cn', 'ipa'), ('cn', 'etc'), ipautil.realm_to_suffix(realm)) entries = repl1.conn.getList(dn, ldap.SCOPE_SUBTREE) - if len(entries) != 0: - dnset = repl1.conn.get_dns_sorted_by_length(entries, - reverse=True) - for dns in dnset: - for dn in dns: - repl1.conn.deleteEntry(dn) + if entries: + entries.sort(key=len, reverse=True) + for dn in entries: + repl1.conn.deleteEntry(dn) except Exception, e: print "Error deleting winsync replica shared info: %s" % convert_error(e) diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py index 1555fb993..d604cf7b3 100644 --- a/ipaserver/install/replication.py +++ b/ipaserver/install/replication.py @@ -1066,12 +1066,10 @@ class ReplicationManager(object): filter='(krbprincipalname=*/%s@%s)' % (replica, realm) entries = self.conn.getList(self.suffix, ldap.SCOPE_SUBTREE, filterstr=filter) - if len(entries) != 0: - dnset = self.conn.get_dns_sorted_by_length(entries, - reverse=True) - for dns in dnset: - for dn in dns: - self.conn.deleteEntry(dn) + if entries: + entries.sort(key=len, reverse=True) + for dn in entries: + self.conn.deleteEntry(dn) except errors.NotFound: pass except Exception, e: @@ -1109,12 +1107,10 @@ class ReplicationManager(object): try: dn = DN(('cn', replica), ('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), self.suffix) entries = self.conn.getList(dn, ldap.SCOPE_SUBTREE) - if len(entries) != 0: - dnset = self.conn.get_dns_sorted_by_length(entries, - reverse=True) - for dns in dnset: - for dn in dns: - self.conn.deleteEntry(dn) + if entries: + entries.sort(key=len, reverse=True) + for dn in entries: + self.conn.deleteEntry(dn) except errors.NotFound: pass except Exception, e: diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py index a84f8fac7..7253bc1f7 100644 --- a/ipaserver/ipaldap.py +++ b/ipaserver/ipaldap.py @@ -1794,42 +1794,6 @@ class IPAdmin(LDAPConnection): else: break return (done, exitCode) - def get_dns_sorted_by_length(self, entries, reverse=False): - """ - Sorts a list of entries [(dn, entry_attrs)] based on their DN. - Entries within the same node are not sorted in any meaningful way. - If Reverse is set to True, leaf entries are returned first. This is - useful to perform recursive deletes where you need to delete entries - starting from the leafs and go up to delete nodes only when all its - leafs are removed. - - Returns a list of list of dn's. Every dn in the dn list has - the same number of RDN's. The outer list is sorted according - to the number of RDN's in each inner list. - - Example: - - [['cn=bob', cn=tom], ['cn=bob,ou=people', cn=tom,ou=people]] - - dn's in list[0] have 1 RDN - dn's in list[1] have 2 RDN's - """ - - res = dict() - - for e in entries: - dn = e.dn - assert isinstance(dn, DN) - rdn_count = len(dn) - rdn_count_list = res.setdefault(rdn_count, []) - if dn not in rdn_count_list: - rdn_count_list.append(dn) - - keys = res.keys() - keys.sort(reverse=reverse) - - return map(res.get, keys) - def __getattr__(self, attrname): # This makes IPAdmin classes look like IPASimpleLDAPObjects # FIXME: for backwards compatibility only |