From 9c3c57fe2e706dfaa75e2afb4b96d7c9704a0f6f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 18 Nov 2020 17:52:19 +0100 Subject: [PATCH] Adding counters --- lib/ldap_migration/__init__.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/ldap_migration/__init__.py b/lib/ldap_migration/__init__.py index 75f7a81..1a89060 100644 --- a/lib/ldap_migration/__init__.py +++ b/lib/ldap_migration/__init__.py @@ -37,7 +37,7 @@ from fb_tools.errors import FbAppError from .config import LDAPMigrationConfiguration from .idict import CaseInsensitiveDict -__version__ = '0.6.3' +__version__ = '0.6.4' LOG = logging.getLogger(__name__) CFG_BASENAME = 'ldap-migration.ini' @@ -174,6 +174,10 @@ class LDAPMigrationApplication(BaseApplication): self.limit = 0 + self.count_unchanged = 0 + self.count_added = 0 + self.count_modified = 0 + self.object_classes = CaseInsensitiveDict() self.attribute_types = CaseInsensitiveDict() self.dns = CaseInsensitiveDict() @@ -832,8 +836,20 @@ class LDAPMigrationApplication(BaseApplication): print() LOG.info("Migrating all structural from source to target LDAP cluster.") + self.count_unchanged = 0 + self.count_added = 0 + self.count_modified = 0 + self._migrate_entries(self.struct_dns, is_root=True, with_acl=False) + total = self.count_unchanged + self.count_added + self.count_modified + msg = ( + "Performed structural entries: {to} total, {ad} added, {mo} modified, " + "{un} unchanged.").format( + to=total, ad=self.count_added, mo=self.count_modified, + un=self.count_unchanged) + LOG.info(msg) + # ------------------------------------------------------------------------- def generate_target_entry(self, src_entry, src_dn, tgt_dn): @@ -941,6 +957,7 @@ class LDAPMigrationApplication(BaseApplication): if changes.keys(): return changes + self.count_unchanged += 1 if self.verbose: msg = "No changes on target entry {tdn!r} necessary.".format(tdn=tgt_dn) LOG.info(msg) @@ -1006,6 +1023,7 @@ class LDAPMigrationApplication(BaseApplication): msg = "Changes on target entry {tdn!r}:\n{ch}".format( tdn=tgt_dn, ch=pp(changes)) LOG.debug(msg) + self.count_modified += 1 if not self.simulate: self.target.modify(tgt_dn, changes) if wait: @@ -1023,6 +1041,7 @@ class LDAPMigrationApplication(BaseApplication): msg += "entry: {en}" msg = msg.format(dn=tgt_dn, oc=tgt_obj_classes, en=tgt_entry) LOG.debug(msg) + self.count_added += 1 if not self.simulate: self.target.add(tgt_dn, object_class=tgt_obj_classes, attributes=tgt_entry) if wait: -- 2.39.5