From bf69c5377146158ccbdff3868197a2238bdb1c59 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 3 Sep 2021 11:31:52 +0200 Subject: [PATCH] Adding option for adding or removing allowed puppet environments --- etc/create-terraform.ini.default | 2 +- lib/cr_tf/config.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/etc/create-terraform.ini.default b/etc/create-terraform.ini.default index d16a949..cf35896 100644 --- a/etc/create-terraform.ini.default +++ b/etc/create-terraform.ini.default @@ -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 diff --git a/lib/cr_tf/config.py b/lib/cr_tf/config.py index aa1b490..5827703 100644 --- a/lib/cr_tf/config.py +++ b/lib/cr_tf/config.py @@ -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) # ============================================================================= -- 2.39.5