# rom ..config.ldap import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS
from ..config.ldap import DEFAULT_TIMEOUT
-__version__ = '0.10.2'
+__version__ = '0.10.3'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
return attribs
# -------------------------------------------------------------------------
- def modify_entry(self, inst, dn, changes, ldap=None):
+ def add_entry(self, inst, dn, object_classes, target_entry, ldap=None):
+ """Creating a LDAP entry."""
+ connect_info = self.cfg.ldap_connection[inst]
+ if not ldap:
+ ldap = self.ldap_connection[inst]
+
+ if self.verbose > 1:
+ msg = _("Creating changes on {uri} to DN {dn!r}:").format(
+ uri=connect_info.url, dn=dn)
+ LOG.debug(msg + '\n' + pp(changes))
+
+ if self.simulate:
+ LOG.info(_("Simulation mode - entry will not be created."))
+ return True
+
+ try:
+ req_status, req_result, req_response, req_whatever = ldap.add(
+ dn, object_class=object_classes, attributes=target_entry)
+ except LDAPException as e:
+ msg = _("Creation of entry {dn!r} NOT successfull - {c}: {e}").format(
+ dn=dn, c=e.__class__.__name__, e=e)
+ msg += '\nobjectClasses:\n' + pp(object_classes)
+ msg += "\nAttributes:\n" + pp(target_entry)
+ raise WriteLDAPItemError(msg)
+
+ # Example result on a not successful modification:
+ # { 'description': 'objectClassViolation',
+ # 'dn': '',
+ # 'message': 'attribute "loginShell" not allowed\n',
+ # 'referrals': None,
+ # 'result': 65,
+ # 'type': 'modifyResponse'}
+
+ if self.verbose > 1:
+ LOG.debug(_("Creation status: {!r}.").format(req_status))
+ if self.verbose > 2:
+ LOG.debug(_("Result of creating:") + '\n' + pp(req_result))
+
+ if not req_status:
+ msg = _("Creation NOT successful: {desc} - {msg}").format(
+ desc=req_result['description'], msg=req_result['message'].strip())
+ raise WriteLDAPItemError(msg)
+
+ LOG.debug(_('Creation successful.'))
+ return True
+
+
+ # -------------------------------------------------------------------------
+ def modify_entry(self, inst, dn, changes, ldap=None):
+ """Mofifying an existing LDAP entry."""
connect_info = self.cfg.ldap_connection[inst]
if not ldap:
ldap = self.ldap_connection[inst]
- # connect_info = self.cfg.ldap_connection[inst]
if self.verbose > 1:
msg = _("Applying changes on {uri} to DN {dn!r}:").format(
uri=connect_info.url, dn=dn)
from ..argparse_actions import NonNegativeItegerOptionAction
from ..argparse_actions import LimitedFloatOptionAction
-__version__ = '0.7.2'
+__version__ = '0.7.3'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
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
count += 1
else:
msg += '\nobjectClasses:\n' + pp(object_classes)
msg += "\nAttributes:\n" + pp(target_entry)
LOG.debug(msg)
+ self.add_entry(self.tgt_instance, dn, object_classes, target_entry)
self.mirrored_entries += 1
count += 1