# import copy
import logging
import re
-# import sys
+import time
+import sys
from functools import cmp_to_key
from pathlib import Path
from .ldap import BaseLdapApplication
from ..xlate import XLATOR
-__version__ = '0.9.0'
+__version__ = '0.9.2'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
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."""
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 = {}
'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()
# -------------------------------------------------------------------------
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()
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):