]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Adding option for adding or removing allowed puppet environments
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 3 Sep 2021 09:31:52 +0000 (11:31 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 3 Sep 2021 09:31:52 +0000 (11:31 +0200)
etc/create-terraform.ini.default
lib/cr_tf/config.py

index d16a949adf34df4ccfcf343eda343d13b643e734..cf358968ceb34992dc653803d7af9c18e9bc8467 100644 (file)
@@ -139,6 +139,6 @@ cluster = test-vmcc-l105-01
 ; environment will be removed from the list of allowed Puppet environments.
 ; Environment must start with a lowercase letter, and then there may be lowercase
 ; letters, digits or underscores.
-;additional_puppet_environments = dev_fbrehm, dev_lutbeie
+;puppet_environments = dev_fbrehm, dev_lutbeie
 
 # vim: filetype=dosini
index aa1b490fa027de7bba6b0410d48e8c532f945e40..5827703ceb84e971c90898f8f1466158f7370bf4 100644 (file)
@@ -32,7 +32,7 @@ from .errors import CrTfConfigError
 
 from .xlate import XLATOR
 
-__version__ = '1.3.8'
+__version__ = '1.4.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -433,6 +433,8 @@ class CrTfConfiguration(BaseConfiguration):
     default_tf_backend_scheme = 'https'
     default_tf_backend_path_prefix = 'terraform'
 
+    re_list_split = re.compile(r'\s*[,:\s]+\s*')
+
     default_puppetmaster = 'puppetmaster03.pixelpark.com'
     default_puppetca = 'puppetca01.pixelpark.com'
 
@@ -462,6 +464,9 @@ class CrTfConfiguration(BaseConfiguration):
         self.puppetca = self.default_puppetca
         self.pdns_comment_account = self.default_pdns_comment_account
 
+        self.puppet_envs_add = set()
+        self.puppet_envs_delete = set()
+
         self.vsphere = {}
 
         self._disk_size = self.default_disk_size
@@ -884,6 +889,10 @@ class CrTfConfiguration(BaseConfiguration):
         re_backend_scheme = re.compile(r'^\s*backend[_-]?scheme\s*$', re.IGNORECASE)
         re_backend_path_prefix = re.compile(r'^\s*backend[_-]?path[_-]?prefix\s*$', re.IGNORECASE)
 
+        # re_list_split
+        re_puppet_envs = re.compile(r'^\s*puppet[_-]?env(?:ironment)?s?\s*$', re.IGNORECASE)
+        re_puppet_env = re.compile(r'^([+-])?([a-z](?:[a-z0-9_]*[a-z0-9])?)$', re.IGNORECASE)
+
         for (key, value) in config.items(section):
             if re_root_pw.search(key) and value.strip():
                 self.vm_root_password = value
@@ -903,6 +912,22 @@ class CrTfConfiguration(BaseConfiguration):
                 self.tf_backend_scheme = value.strip().lower()
             elif re_backend_path_prefix.search(key) and value.strip():
                 self.tf_backend_path_prefix = value.strip()
+            elif re_puppet_envs.search(key) and value.strip():
+                v = value.strip()
+                env_list = self.re_list_split.split(v)
+                for env in env_list:
+                    match = re_puppet_env.match(env)
+                    if not match:
+                        msg = _("Invalid puppet environment {env!r} found in {k!r}.").format(
+                                env=env, k=key)
+                        LOG.warn(msg)
+                        continue
+                    sign = match.group(1)
+                    val = match.group(2).lower()
+                    if sign == '-':
+                        self.puppet_envs_delete.add(val)
+                    else:
+                        self.puppet_envs_add.add(val)
 
 
 # =============================================================================