from ..errors import DpxLdapSessionError
from ..xlate import XLATOR
-__version__ = '1.2.1'
+__version__ = '1.2.2'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
for dn in sorted(self.tgt_dns_current.keys(), key=cmp_to_key(self.compare_ldap_dns)):
+ if self.verbose == 1:
+ self.print_dot()
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)))
for dn in list(reversed(dns)):
+ if self.verbose == 1:
+ self.print_dot()
entry = self.tgt_dns_current[dn]
if not entry['childs']:
continue
for dn in dns:
+ if self.verbose == 1:
+ self.print_dot()
if self.mirror_entry(dn):
count += 1
for dn in dns:
+ if self.verbose == 1:
+ self.print_dot()
if dn in self.src_struct_dns:
continue
attributes = ['member', 'uniqueMember']
for dn in dns:
-
- if dn in self.keep_entry_dns:
- if self.verbose > 1:
- LOG.debug(_('Entry {!r} is set to be kept.').format(dn))
- continue
-
- if self.verbose > 1:
- self.empty_line()
- if self.verbose > 1:
- LOG.debug(_('Mirroring entry {!r} ...').format(dn))
-
- try:
- src_entry = self.get_entry(dn, self.src_instance, attributes)
- except LDAPSocketReceiveError as e:
- msg = _('Error on reading entry {!r} from source:').format(dn) + ' ' + str(e)
- raise DpxLdapReadError(msg)
- if not src_entry:
- msg = _('Did not found {!r} in the source LDAP.').format(dn)
- LOG.warn(msg)
- continue
- src_attribs = self.normalized_attributes(src_entry, omit_memberof=True)
- src_attribs_dict = src_attribs.dict()
- if self.verbose > 2:
- LOG.debug('Got source entry:\n' + pp(src_attribs_dict))
-
- try:
- tgt_entry = self.get_entry(dn, self.tgt_instance, attributes, tries=1)
- except LDAPSocketReceiveError as e:
- msg = _('Error on reading entry {!r} from target:').format(dn) + ' ' + str(e)
- raise DpxLdapReadError(msg)
- if not tgt_entry:
- LOG.warn(_('Target entry {!r} not found.').format(dn))
- continue
-
- tgt_attribs = self.normalized_attributes(tgt_entry, omit_memberof=True)
- tgt_attribs_dict = tgt_attribs.dict()
-
- if self.verbose > 2:
- LOG.debug('Got target entry:\n' + pp(tgt_attribs_dict))
-
- changes = self.generate_modify_data(dn, src_attribs, tgt_attribs)
- if changes:
- self.empty_line()
- LOG.info(_('Modifying entry {!r} ...').format(dn))
- msg = _('Got modify data for DN {!r}:').format(dn)
- LOG.debug(msg + '\n' + pp(changes))
- self.modify_entry(self.tgt_instance, dn, changes)
- self.mirrored_entries += 1
+ if self.update_membership(dn, attributes):
count += 1
- if dn not in self.mirrored_dns:
- self.total_updated += 1
- if self.wait_after_write and not self.simulate:
- time.sleep(self.wait_after_write * 2)
- else:
- if self.verbose > 1:
- LOG.debug(_('No changes necessary on DN {!r}.').format(dn))
- continue
if count:
self.empty_line()
msg = _('Mirrored no group entries to target LDAP instance.')
LOG.info(msg)
+ # -------------------------------------------------------------------------
+ def update_membership(self, dn, attributes):
+ """Update all 'member' and 'uniqueMember' attributes of given dn."""
+ if dn in self.keep_entry_dns:
+ if self.verbose > 1:
+ LOG.debug(_('Entry {!r} is set to be kept.').format(dn))
+ return False
+
+ if self.verbose == 1:
+ self.print_dot()
+
+ if self.verbose > 1:
+ LOG.debug(_('Mirroring entry {!r} ...').format(dn))
+
+ try:
+ src_entry = self.get_entry(dn, self.src_instance, attributes)
+ except LDAPSocketReceiveError as e:
+ msg = _('Error on reading entry {!r} from source:').format(dn) + ' ' + str(e)
+ raise DpxLdapReadError(msg)
+ if not src_entry:
+ msg = _('Did not found {!r} in the source LDAP.').format(dn)
+ LOG.warn(msg)
+ return False
+ src_attribs = self.normalized_attributes(src_entry, omit_memberof=True)
+ src_attribs_dict = src_attribs.dict()
+ if self.verbose > 2:
+ LOG.debug('Got source entry:\n' + pp(src_attribs_dict))
+
+ try:
+ tgt_entry = self.get_entry(dn, self.tgt_instance, attributes, tries=1)
+ except LDAPSocketReceiveError as e:
+ msg = _('Error on reading entry {!r} from target:').format(dn) + ' ' + str(e)
+ raise DpxLdapReadError(msg)
+ if not tgt_entry:
+ LOG.warn(_('Target entry {!r} not found.').format(dn))
+ return False
+
+ tgt_attribs = self.normalized_attributes(tgt_entry, omit_memberof=True)
+ tgt_attribs_dict = tgt_attribs.dict()
+
+ if self.verbose > 2:
+ LOG.debug('Got target entry:\n' + pp(tgt_attribs_dict))
+
+ changes = self.generate_modify_data(dn, src_attribs, tgt_attribs)
+ changed = False
+ if changes:
+ self.empty_line()
+ LOG.info(_('Modifying entry {!r} ...').format(dn))
+ msg = _('Got modify data for DN {!r}:').format(dn)
+ LOG.debug(msg + '\n' + pp(changes))
+ self.modify_entry(self.tgt_instance, dn, changes)
+ self.mirrored_entries += 1
+ changed = True
+ if dn not in self.mirrored_dns:
+ self.total_updated += 1
+ if self.wait_after_write and not self.simulate:
+ time.sleep(self.wait_after_write * 2)
+ else:
+ if self.verbose > 1:
+ LOG.debug(_('No changes necessary on DN {!r}.').format(dn))
+
+ return changed
+
# =============================================================================
if __name__ == '__main__':