From: Frank Brehm Date: Thu, 25 May 2023 10:47:49 +0000 (+0200) Subject: Adding a short sleep after each write action X-Git-Tag: 0.9.0~1^2~19 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=d35c5e6ab0a42d6465bfa2354298bb5ebd0b0467;p=pixelpark%2Fpp-admin-tools.git Adding a short sleep after each write action --- diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index e84e497..3646c86 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -12,7 +12,8 @@ from __future__ import absolute_import # import copy import logging import re -# import sys +import time +import sys from functools import cmp_to_key from pathlib import Path @@ -30,7 +31,7 @@ from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.9.0' +__version__ = '0.9.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -97,6 +98,9 @@ class BarracudaSyncApp(BaseLdapApplication): apply_default_ldap_instance_if_not_given = True default_default_ldap_instance = 'dpx-prod-mail' + default_wait_interval = 0.1 + max_wait_interval = 10 + # ------------------------------------------------------------------------- def __init__(self, appname=None, base_dir=None): """Construct the application object.""" @@ -107,6 +111,7 @@ class BarracudaSyncApp(BaseLdapApplication): self.postmap_command = Path('/sbin') / self.default_postmap_command self.postfix_origin = self.default_origin + self.wait_interval = self.default_wait_interval self.lookup_table_types = [] self.existing_aliases = {} @@ -140,6 +145,13 @@ class BarracudaSyncApp(BaseLdapApplication): 'should be located. Default: {!r}.').format(self.default_barracuda_base_dn), ) + sync_group.add_argument( + '-W', '--wait', dest='wait', metavar=_('SECONDS'), type=float, + help=_( + 'The time in seconds to wait after each write action to not overload ' + 'the LDAP servers. Default: {} seconds.').format(self.default_wait_interval), + ) + super(BarracudaSyncApp, self).init_arg_parser() # ------------------------------------------------------------------------- @@ -155,6 +167,18 @@ class BarracudaSyncApp(BaseLdapApplication): if self.args.base_dn and self.args.base_dn.strip(): self.barracuda_base_dn = self.args.base_dn.strip() + if self.args.wait is not None: + wait = self.args.wait + if wait < 0 or wait > self.max_wait_interval: + msg = _( + 'Invalid value for wait ({v} seconds) given, it must not be less than ' + 'zero or greater {m} seconds.').format(v=wait, m=self.max_wait_interval) + LOG.error(msg) + self.empty_line() + self.arg_parser.print_usage(sys.stdout) + self.exit(1) + self.wait_interval = wait + self._check_postfix_commands() self._check_postfix_table_types() self._get_postfix_default_db_type() @@ -823,7 +847,9 @@ class BarracudaSyncApp(BaseLdapApplication): dn = 'cn=' + cn + ',' + self.barracuda_base_dn (oclasses, attributes) = self._create_ldap_entry_for_create(cn) LOG.info(_('Creating LDAP alias {a!r} => {dn!r}.').format(a=cn, dn=dn)) - # self.add_entry(inst, dn, oclasses, attributes) + self.add_entry(inst, dn, oclasses, attributes) + if self.wait_interval: + time.sleep(self.wait_interval) # ------------------------------------------------------------------------- def _run(self):