From: Frank Brehm Date: Wed, 26 Oct 2022 09:11:19 +0000 (+0200) Subject: Evaluate all entries to sync and consider them and the entries to keep in removing... X-Git-Tag: 0.7.0^2~1^2~24 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=65e79ef397109d2ce35f7b35070e01d803b7cd62;p=pixelpark%2Fpp-admin-tools.git Evaluate all entries to sync and consider them and the entries to keep in removing enrtries on target instance. --- diff --git a/lib/pp_admintools/app/mirror_ldap.py b/lib/pp_admintools/app/mirror_ldap.py index f605264..809ebfa 100644 --- a/lib/pp_admintools/app/mirror_ldap.py +++ b/lib/pp_admintools/app/mirror_ldap.py @@ -36,7 +36,7 @@ from .ldap import BaseLdapApplication from ..argparse_actions import NonNegativeItegerOptionAction from ..argparse_actions import LimitedFloatOptionAction -__version__ = '0.5.1' +__version__ = '0.5.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -84,6 +84,7 @@ class MirrorLdapApplication(BaseLdapApplication): self.structural_entr_dns = [] self.non_structural_entr_dns = [] self.keep_entry_dns = [] + self.sync_entry_dns = [] desc = _( "Mirror the content of a complete LDAP instance (server or cluster) to " @@ -266,6 +267,7 @@ class MirrorLdapApplication(BaseLdapApplication): "(except the base DN entry, of course).")) self.get_current_tgt_entries() + self.eval_sync_entries() self.clean_tgt_non_struct_entries() self.clean_tgt_struct_entries() @@ -283,6 +285,34 @@ class MirrorLdapApplication(BaseLdapApplication): if self.verbose > 4: LOG.debug("Current target entries:\n" + pp(self.tgt_dns_current.dict())) + # ------------------------------------------------------------------------- + def eval_sync_entries(self): + """Evaluating entries, which have to be synced, instead of to be removed and recreated.""" + + self.sync_entry_dns = [] + LOG.debug(_( + "Evaluating DNs of all target entries, which have to be synchronized, " + "instead of removing and recreating them.")) + + base_dn = self.tgt_connect_info.base_dn + + self.sync_entry_dns.append(base_dn) + + for dn in self.keep_entry_dns: + + tokens = self.re_dn_separator.split(dn) + while len(tokens): + tokens.pop(0) + if not len(tokens): + break + parent_dn = ','.join(tokens) + if base_dn not in parent_dn: + break + if parent_dn not in self.sync_entry_dns: + self.sync_entry_dns.append(parent_dn) + + LOG.debug("DNs of sync entries:\n" + pp(self.sync_entry_dns)) + # ------------------------------------------------------------------------- def register_dn_tokens(self, dn, entry, registry): @@ -320,6 +350,15 @@ class MirrorLdapApplication(BaseLdapApplication): self.empty_line() for dn in sorted(list(self.tgt_dns_current.keys()), key=cmp_to_key(self.compare_ldap_dns)): + + if dn in self.keep_entry_dns: + LOG.debug(_("Entry {!r} is set to be kept.").format(dn)) + continue + + if dn in self.sync_entry_dns: + LOG.debug(_("Entry {!r} is set to be synchronized.").format(dn)) + continue + entry = self.tgt_dns_current[dn] if 'childs' not in entry: LOG.error("Found entry {dn!r}:\n{e}".format(dn=dn, e=pp(entry))) @@ -350,6 +389,15 @@ class MirrorLdapApplication(BaseLdapApplication): dns = sorted(list(self.tgt_dns_current.keys()), key=cmp_to_key(self.compare_ldap_dns)) for dn in list(reversed(dns[1:])): + + if dn in self.keep_entry_dns: + LOG.debug(_("Entry {!r} is set to be kept.").format(dn)) + continue + + if dn in self.sync_entry_dns: + LOG.debug(_("Entry {!r} is set to be synchronized.").format(dn)) + continue + entry = self.tgt_dns_current[dn] if not entry['childs']: continue