from .config import LDAPMigrationConfiguration
from .idict import CaseInsensitiveDict
-__version__ = '0.6.0'
+__version__ = '0.6.1'
LOG = logging.getLogger(__name__)
CFG_BASENAME = 'ldap-migration.ini'
return count_dns
+ # -------------------------------------------------------------------------
+ def migrate_entries(self):
+ """The main routine if this application."""
+
+ print()
+ LOG.info("Migrating all entries from source to target LDAP cluster.")
+ print()
+
+ self.migrate_structural_entries()
+
+ # -------------------------------------------------------------------------
+ def migrate_structural_entries(self):
+
+ LOG.info("Migrating all structural from source to target LDAP cluster.")
+
+ self._migrate_entries(self.struct_dns, is_root=True, with_acl=False)
+
+ # -------------------------------------------------------------------------
+ def _migrate_entries(self, cur_hash, is_root=False, with_acl=False):
+
+ if not is_root:
+
+ src_dn = cur_hash['dn']
+ LOG.debug("Migrating source DN {dn!r}.".format(dn=src_dn))
+
+ src_entry = None
+ tgt_entry = None
+
+ sfilter = '(objectClass=*)'
+ src_attrs = [ALL_ATTRIBUTES]
+ if with_acl:
+ src_attrs = ['aci', ALL_ATTRIBUTES]
+ tgt_attrs = [ALL_ATTRIBUTES]
+
+ src_status, src_result, src_response, _ = self.source.search(
+ search_base=src_dn, search_scope=BASE, search_filter=sfilter,
+ get_operational_attributes=True, attributes=src_attrs,
+ time_limit=self.config.timeout)
+
+ if src_status:
+
+ src_entry = src_response[0]
+
+ if self.verbose > 2:
+ LOG.debug("Result of searching for source DN {dn!r}:\n{res}".format(
+ dn=src_dn, res=pp(src_result)))
+ if self.verbose > 2:
+ LOG.debug("Response of searching for source DN {dn!r}:\n{res}".format(
+ dn=src_dn, res=pp(src_entry)))
+
+ tgt_dn = self.mangle_dn(src_dn)
+ if self.verbose > 1:
+ LOG.debug("Searching for target DN {dn!r}.".format(dn=tgt_dn))
+ tgt_status, tgt_result, tgt_response, _ = self.target.search(
+ search_base=tgt_dn, search_scope=BASE, search_filter=sfilter,
+ get_operational_attributes=with_acl, attributes=tgt_attrs,
+ time_limit=self.config.timeout)
+
+ target_entry = None
+ if tgt_status:
+ target_entry = tgt_response[0]
+ if self.verbose > 2:
+ LOG.debug("Result of searching for target DN {dn!r}:\n{res}".format(
+ dn=tgt_dn, res=pp(tgt_result)))
+ if self.verbose > 2:
+ LOG.debug("Response of searching for target DN {dn!r}:\n{res}".format(
+ dn=tgt_dn, res=pp(target_entry)))
+ else:
+ if self.verbose > 2:
+ LOG.debug("Target DN {dn!r} not found.".format(dn=tgt_dn))
+
+ else:
+ msg = "Did not found source entry with DN {!r} (WTF?).".format(src_dn)
+ LOG.error(msg)
+
+ for key in cur_hash['childs'].keys():
+ self._migrate_entries(cur_hash['childs'][key], is_root=False, with_acl=with_acl)
+
# -------------------------------------------------------------------------
def _run(self):
self.check_tmp_dir()
self.get_all_dns()
self.get_structural_dns()
- LOG.info("Sleeping ...")
- time.sleep(2)
+ self.migrate_entries()
finally:
self.disconnect()
pass
-# vim: fileencoding=utf-8 filetype=python ts=4
+# vim: fileencoding=utf-8 filetype=python ts=4 list