]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Adding flag for migrating only structural entries
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 30 Nov 2020 15:09:22 +0000 (16:09 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 30 Nov 2020 15:09:22 +0000 (16:09 +0100)
lib/ldap_migration/__init__.py

index b2f93117aa36da085a75fdef9c9903166a400272..20710114ca565dda081938b20c0b6630a14f7ccb 100644 (file)
@@ -36,7 +36,7 @@ from ldap3.core.exceptions import LDAPException
 # Own modules
 from fb_tools.colored import ColoredFormatter
 from fb_tools.errors import IoTimeoutError
-from fb_tools.common import pp, is_sequence, human2mbytes
+from fb_tools.common import pp, is_sequence, human2mbytes, to_bool
 from fb_tools.app import BaseApplication, DirectoryOptionAction
 from fb_tools.config import CfgFileOptionAction
 from fb_tools.errors import FbAppError
@@ -45,7 +45,7 @@ from .config import LDAPMigrationConfiguration
 from .idict import CaseInsensitiveDict
 from .istringset import CaseInsensitiveStringSet
 
-__version__ = '0.8.0'
+__version__ = '0.8.1'
 
 LOG = logging.getLogger(__name__)
 CFG_BASENAME = 'ldap-migration.ini'
@@ -182,6 +182,8 @@ class LDAPMigrationApplication(BaseApplication):
         self._cfg_file = None
         self.config = None
 
+        self._only_struct = False
+
         description = "This application migrates a complete LDAP DIT to a new LDAP server. "
         description += "During the migration all pointless ObljectClasses and "
         description += "Atributes are removed from the entries."
@@ -231,6 +233,16 @@ class LDAPMigrationApplication(BaseApplication):
         """Configuration file."""
         return self._cfg_file
 
+    # -------------------------------------------------------------------------
+    @property
+    def only_struct(self):
+        """Flag, whether only structural components should be migrated."""
+        return self._only_struct
+
+    @only_struct.setter
+    def only_struct(self, value):
+        self._only_struct = to_bool(value)
+
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
@@ -248,6 +260,7 @@ class LDAPMigrationApplication(BaseApplication):
         res['attribute_types'] = self.attribute_types.as_dict(short=short)
         res['cfg_dir'] = self.cfg_dir
         res['cfg_file'] = self.cfg_file
+        res['only_struct'] = self.only_struct
         res['dns'] = self.dns.as_dict(short=short)
         res['struct_dns'] = self.struct_dns.as_dict(short=short)
         res['integer_attribute_types'] = self.integer_attribute_types.as_list()
@@ -291,6 +304,11 @@ class LDAPMigrationApplication(BaseApplication):
                 "This option is valid only in simulation mode."),
         )
 
+        app_group.add_argument(
+            '-S', '--struct', '--only-struct', action="store_true", dest="struct",
+            help="Migrate only structural entries (entries with childs).",
+        )
+
         app_group.add_argument(
             '-c', '--config', '--config-file', dest='cfg_file', metavar='FILE',
             action=CfgFileOptionAction,
@@ -423,6 +441,9 @@ class LDAPMigrationApplication(BaseApplication):
                 LOG.warn("Limition should only be done in simulation mode.")
             print()
 
+        if self.args.struct:
+            self.only_struct = True
+
         self.initialized = True
 
     # -------------------------------------------------------------------------
@@ -992,7 +1013,7 @@ class LDAPMigrationApplication(BaseApplication):
 
     # -------------------------------------------------------------------------
     def migrate_entries(self):
-        """The main routine if this application."""
+        """The main routine of this application."""
 
         print()
         LOG.info("Migrating all entries from source to target LDAP cluster.")
@@ -1008,8 +1029,10 @@ class LDAPMigrationApplication(BaseApplication):
             if not self.migrate_structural_entries(fh):
                 return False
 
-            if not self.migrate_all_entries(fh):
-                return False
+            if not self.only_struct:
+
+                if not self.migrate_all_entries(fh):
+                    return False
 
         print()
         return True
@@ -1020,6 +1043,7 @@ class LDAPMigrationApplication(BaseApplication):
         print()
         LOG.info("Migrating all structural entries from source to target LDAP cluster.")
 
+        print("####################", file=fh, flush=True)
         print("# Structural entries", file=fh, flush=True)
         print("####################", file=fh, flush=True)
 
@@ -1053,6 +1077,7 @@ class LDAPMigrationApplication(BaseApplication):
         LOG.info("Migrating all entries from source to target LDAP cluster.")
 
         print("", file=fh, flush=True)
+        print("#############", file=fh, flush=True)
         print("# All entries", file=fh, flush=True)
         print("#############", file=fh, flush=True)