]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Bugfixing and notify about changed PDNS zones repeatedly.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 Jul 2024 11:37:47 +0000 (13:37 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 Jul 2024 11:37:47 +0000 (13:37 +0200)
lib/create_terraform/app.py
lib/create_terraform/config.py
lib/create_terraform/handler/__init__.py
lib/create_terraform/handler/dns.py

index dac63174923eefb83548ede500f2315fa4070b46..37864bbc17f866abeb24f2749fba8dc76d863c13 100644 (file)
@@ -42,7 +42,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__
 from .xlate import __mo_file__ as __xlate_mo_file__
 from .xlate import XLATOR, LOCALE_DIR, DOMAIN
 
-__version__ = '1.4.0'
+__version__ = '1.4.1'
 LOG = logging.getLogger(__name__)
 
 SIGNAL_NAMES = {
@@ -401,7 +401,7 @@ class CrTfApplication(BaseApplication):
         default_cfg_file = self.base_dir.joinpath('etc').joinpath(self.appname + '.ini')
         default_cfg_file_rel = Path(os.path.relpath(str(default_cfg_file), str(cur_dir)))
 
-        cr_tf_group =  self.arg_parser.add_argument_group(_('Special options for {}').format(
+        cr_tf_group = self.arg_parser.add_argument_group(_('Special options for {}').format(
             self.appname))
 
         cr_tf_group.add_argument(
index 1fe1e5c10b2a1bb8c593ef9a6d5e1bfc731a7f3a..3fc04e7c635c90cdda5d5e97bae1c9d123da63dc 100644 (file)
@@ -32,7 +32,7 @@ from .vs_config import VsphereConfig
 
 from .xlate import XLATOR
 
-__version__ = '1.9.1'
+__version__ = '1.10.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -52,6 +52,8 @@ class CrTfConfiguration(BaseConfiguration):
     default_pdns_api_path_prefix = DEFAULT_PDNS_API_PREFIX
     default_pdns_api_timeout = DEFAULT_PDNS_API_PORT
     default_pdns_comment_account = 'provisioning'
+    default_pdns_notifies_per_zone = 5
+    default_pdns_notify_wait = 1.0
 
     default_rhsm_user = 'dpx-subscriber'
 
@@ -122,6 +124,9 @@ class CrTfConfiguration(BaseConfiguration):
         self._pdns_api_use_https = self.default_pdns_api_use_https
         self._pdns_api_timeout = self.default_pdns_api_timeout
         self.pdns_api_path_prefix = self.default_pdns_api_path_prefix
+        self._pdns_notifies_per_zone = self.default_pdns_notifies_per_zone
+        self._pdns_notify_wait = self.default_pdns_notify_wait
+
         self.min_root_size_gb = self.default_min_root_size_gb
         self._vm_root_password = None
         self.tz_name = self.default_tz_name
@@ -239,6 +244,41 @@ class CrTfConfiguration(BaseConfiguration):
             raise ValueError(msg)
         self._pdns_api_timeout = val
 
+    # -----------------------------------------------------------
+    @property
+    def pdns_notifies_per_zone(self):
+        """Define, how many notifications should be sent after changing a DNS zone."""
+        return self._pdns_notifies_per_zone
+
+    @pdns_notifies_per_zone.setter
+    def pdns_notifies_per_zone(self, value):
+        if value is None:
+            self._pdns_notifies_per_zone = self.default_pdns_notifies_per_zone
+            return
+        val = int(value)
+        err_msg = _("Invalid number {!r} of DNS zone notifications given, must be > 0.")
+        if val <= 0:
+            raise ValueError(err_msg.format(value))
+        self._pdns_notifies_per_zone = val
+
+    # -----------------------------------------------------------
+    @property
+    def pdns_notify_wait(self):
+        """Define, how many notifications should be sent after changing a DNS zone."""
+        return self._pdns_notify_wait
+
+    @pdns_notify_wait.setter
+    def pdns_notify_wait(self, value):
+        if value is None:
+            self._pdns_notify_wait = self.default_pdns_notify_wait
+            return
+        val = float(value)
+        err_msg = _(
+            "Invalid notification interval {t!r} for zone notifications given, must be > 0.")
+        if val <= 0:
+            raise ValueError(err_msg.format(value))
+        self._pdns_notify_wait = val
+
     # -----------------------------------------------------------
     @property
     def vsphere_tag_cat_os_id(self):
@@ -453,24 +493,26 @@ class CrTfConfiguration(BaseConfiguration):
 
         res = super(CrTfConfiguration, self).as_dict(short=short)
 
-        res['simulate'] = self.simulate
+        res['disk_max_size'] = self.disk_max_size
+        res['disk_min_size'] = self.disk_min_size
+        res['disk_size'] = self.disk_size
         res['no_pdns'] = self.no_pdns
-        res['pdns_api_use_https'] = self.pdns_api_use_https
-        res['pdns_api_timeout'] = self.pdns_api_timeout
-        res['vm_root_password'] = None
         res['pdns_api_key'] = None
-        res['disk_size'] = self.disk_size
-        res['disk_min_size'] = self.disk_min_size
-        res['disk_max_size'] = self.disk_max_size
-        res['root_min_size'] = self.root_min_size
-        res['root_max_size'] = self.root_max_size
+        res['pdns_api_timeout'] = self.pdns_api_timeout
+        res['pdns_api_use_https'] = self.pdns_api_use_https
+        res['pdns_notifies_per_zone'] = self.pdns_api_timeout
+        res['pdns_notify_wait'] = self.pdns_api_timeout
         res['rhsm_user'] = self.rhsm_user
+        res['root_max_size'] = self.root_max_size
+        res['root_min_size'] = self.root_min_size
+        res['simulate'] = self.simulate
+        res['vm_root_password'] = None
+        res['vsphere_tag_cat_os_desc'] = self.vsphere_tag_cat_os_desc
         res['vsphere_tag_cat_os_id'] = self.vsphere_tag_cat_os_id
         res['vsphere_tag_cat_os_name'] = self.vsphere_tag_cat_os_name
-        res['vsphere_tag_cat_os_desc'] = self.vsphere_tag_cat_os_desc
+        res['vsphere_tag_os_rhel_desc'] = self.vsphere_tag_os_rhel_desc
         res['vsphere_tag_os_rhel_id'] = self.vsphere_tag_os_rhel_id
         res['vsphere_tag_os_rhel_name'] = self.vsphere_tag_os_rhel_name
-        res['vsphere_tag_os_rhel_desc'] = self.vsphere_tag_os_rhel_desc
 
         res['vsphere'] = {}
         for vsphere_name in self.vsphere.keys():
@@ -690,6 +732,9 @@ class CrTfConfiguration(BaseConfiguration):
         re_use_https = re.compile(r'^\s*(?:api[-_\.]?)?(?:use[-_\.]?)?https\s*$', re.IGNORECASE)
         re_prefix = re.compile(r'^\s*(?:api[-_\.]?)?(?:path[-_\.]?)?prefix\s*$', re.IGNORECASE)
         re_comment_account = re.compile(r'^\s*comment[-_\.]?account\s*$', re.IGNORECASE)
+        re_notifies_per_zone = re.compile(
+            r'^\s*notifies(?:(?:[-_\.]?per)?[-_\.]?zone)?\s*$', re.IGNORECASE)
+        re_notify_wait = re.compile(r'^\s*notify[-_\.]?(wait|sleep)\s*$', re.IGNORECASE)
 
         for (key, value) in config.items(section):
             if re_master.search(key) and value.strip():
@@ -715,6 +760,18 @@ class CrTfConfiguration(BaseConfiguration):
                 self.pdns_api_timeout = value.strip()
             elif re_comment_account.search(key) and value.strip():
                 self.pdns_comment_account = value.strip()
+            elif re_notifies_per_zone.search(key):
+                try:
+                    self.pdns_notifies_per_zone = value
+                except ValueError as e:
+                    raise CrTfConfigError(self.msg_invalid_type.format(
+                        f=self.config_file, s=section, v=value, n=key, e=e))
+            elif re_notify_wait.search(key):
+                try:
+                    self.pdns_notify_wait = value
+                except ValueError as e:
+                    raise CrTfConfigError(self.msg_invalid_type.format(
+                        f=self.config_file, s=section, v=value, n=key, e=e))
 
         return
 
index 755247b386b9cab8431b8399086a3d993c43d93e..b83bc3a523ee5c36ea6a002f80c9e867dba1d65f 100644 (file)
@@ -33,6 +33,7 @@ from fb_tools.handler import BaseHandler
 
 # Own modules
 from .dns import CrTfHandlerDnsMixin
+from .errors import ConsulApiNotFoundError
 from .files import CrTfHandlerFilesMixin
 from .first import CrTfHandlerFirstMixin
 from .read import CrTfHandlerReadMixin
@@ -49,7 +50,7 @@ from ..errors import AbortExecution
 
 from ..xlate import XLATOR
 
-__version__ = '4.3.0'
+__version__ = '4.3.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -614,11 +615,15 @@ class CreateTerraformHandler(
         retval = int(retval)
         root_logger = logging.getLogger()
 
+        has_handlers = False
+        if root_logger.handlers:
+            has_handlers = True
+
         if msg:
             if root_logger.handlers:
-               if retval:
+                if retval:
                     LOG.error(msg)
-               else:
+                else:
                     LOG.info(msg)
             if not has_handlers:
                 if hasattr(sys.stderr, 'buffer'):
index d20353e2b5642027a8c092564adfc95494332c56..4a05beef71c3841156a788d4f003620dd5ce81db 100644 (file)
@@ -12,6 +12,7 @@ from __future__ import absolute_import, print_function
 import ipaddress
 import logging
 import socket
+import time
 
 # Third party modules
 from fb_tools.common import RE_DOT_AT_END
@@ -23,7 +24,7 @@ from ..errors import AbortExecution
 
 from ..xlate import XLATOR
 
-__version__ = '0.2.0'
+__version__ = '0.3.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -133,6 +134,12 @@ class CrTfHandlerDnsMixin():
         zone = self.pdns.zones[zone_name]
         zone.increase_serial()
         zone.notify()
+        if self.config.pdns_notifies_per_zone > 1:
+            i = 1
+            while i < self.config.pdns_notifies_per_zone:
+                i += 1
+                time.sleep(self.config.pdns_notify_wait)
+                zone.notify()
 
     # --------------------------------------------------------------------------
     def _perform_dns_forward(self, fqdn, address):