]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding modifying of existing aliases.
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 26 May 2023 09:43:58 +0000 (11:43 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 26 May 2023 09:43:58 +0000 (11:43 +0200)
lib/pp_admintools/app/barracuda_sync.py

index 294cc626dca7560d2346310aea009795a3a5c623..5a4f54ec2770530052b2a5e1be4a28a2517acf2b 100644 (file)
@@ -31,7 +31,7 @@ from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE
 from .ldap import BaseLdapApplication
 from ..xlate import XLATOR
 
-__version__ = '0.9.4'
+__version__ = '0.9.5'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -843,7 +843,9 @@ class BarracudaSyncApp(BaseLdapApplication):
         LOG.info(_('Removing all no more used alias entries ...'))
         inst = self.ldap_instances[0]
 
-        if not len(self.aliases_to_remove):
+        nr_aliases = len(self.aliases_to_remove)
+
+        if not nr_aliases:
             msg = _('No aliases found to remove in LDAP.')
             LOG.info(msg)
             if self.wait_interval:
@@ -855,6 +857,14 @@ class BarracudaSyncApp(BaseLdapApplication):
             if self.wait_interval:
                 time.sleep(self.wait_interval)
 
+        self.empty_line()
+        msg = ngettext(
+            'One alias entry removed in LDAP.', '{} alias entries removed in LDAP.',
+            nr_aliases).format(nr_aliases)
+        LOG.info(msg)
+        if self.wait_interval:
+            time.sleep(self.wait_interval * 10)
+
     # -------------------------------------------------------------------------
     def add_failing_ldap_entries(self):
         """Create failing LDAP entries."""
@@ -862,7 +872,9 @@ class BarracudaSyncApp(BaseLdapApplication):
         LOG.info(_('Adding failing LDAP aliases ...'))
         inst = self.ldap_instances[0]
 
-        if not len(self.aliases_to_create):
+        nr_aliases = len(self.aliases_to_create)
+
+        if not nr_aliases:
             msg = _('No aliases found to create in LDAP.')
             LOG.info(msg)
             if self.wait_interval:
@@ -877,6 +889,45 @@ class BarracudaSyncApp(BaseLdapApplication):
             if self.wait_interval:
                 time.sleep(self.wait_interval)
 
+        self.empty_line()
+        msg = ngettext(
+            'One alias entry created in LDAP.', '{} alias entries created in LDAP.',
+            nr_aliases).format(nr_aliases)
+        LOG.info(msg)
+        if self.wait_interval:
+            time.sleep(self.wait_interval * 10)
+
+    # -------------------------------------------------------------------------
+    def modify_existing_entries(self):
+        """Modify existing LDAP entries below the Barracuda container."""
+        self.empty_line()
+        LOG.info(_('Modifying existing alieas entries ...'))
+        inst = self.ldap_instances[0]
+
+        nr_aliases = len(self.aliases_to_modify.keys())
+
+        if not nr_aliases:
+            msg = _('No aliases found to mofify in LDAP.')
+            LOG.info(msg)
+            if self.wait_interval:
+                time.sleep(self.wait_interval * 10)
+            return
+
+        for dn in sorted(self.aliases_to_modify.keys(), key=cmp_to_key(self.compare_ldap_dns)):
+            modify_data = self.aliases_to_modify[dn]
+            LOG.info(_('Modifying LDAP alias {!r} ...').format(dn))
+            self.modify_entry(inst, dn, modify_data)
+            if self.wait_interval:
+                time.sleep(self.wait_interval)
+
+        self.empty_line()
+        msg = ngettext(
+            'One alias entry modified in LDAP.', '{} alias entries modified in LDAP.',
+            nr_aliases).format(nr_aliases)
+        LOG.info(msg)
+        if self.wait_interval:
+            time.sleep(self.wait_interval * 10)
+
     # -------------------------------------------------------------------------
     def _run(self):
 
@@ -887,6 +938,11 @@ class BarracudaSyncApp(BaseLdapApplication):
         self.eval_diffs()
         self.remove_old_alias_entries()
         self.add_failing_ldap_entries()
+        self.modify_existing_entries()
+
+        self.empty_line()
+        LOG.info(_('Finished.'))
+        self.empty_line()
 
 
 # =============================================================================