From: Frank Brehm Date: Wed, 6 Nov 2019 16:11:48 +0000 (+0100) Subject: Applying flake8 rules to lib/cr_tf/terraform/vm.py X-Git-Tag: 1.3.7~1^2~5 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=f7b34f7bef7aa8e0366cfd8fd5cfd4040ad1d699;p=pixelpark%2Fcreate-terraform.git Applying flake8 rules to lib/cr_tf/terraform/vm.py --- diff --git a/lib/cr_tf/terraform/vm.py b/lib/cr_tf/terraform/vm.py index 85e219a..782b1d1 100644 --- a/lib/cr_tf/terraform/vm.py +++ b/lib/cr_tf/terraform/vm.py @@ -37,7 +37,7 @@ from .disk import TerraformDisk, TerraformDiskDict from .interface import TerraformInterface -__version__ = '1.4.2' +__version__ = '1.4.3' LOG = logging.getLogger(__name__) @@ -428,56 +428,8 @@ class TerraformVm(HandlingObject): if key.lower() == 'puppet' and isinstance(value, Mapping): for (p_key, p_value) in value.items(): - - p_value_stripped = p_value.strip() - if verbose > 2: - LOG.debug(_("Evaluating sub key of {d!r}: {k!r} => {v!r}").format( - d='puppet', k=p_key, v=p_value_stripped)) - - if p_key.lower() == 'contact' and p_value_stripped: - if cls.re_invalid_chars.search(p_value_stripped): - LOG.error(_("Invalid puppet contact name {!r}.").format(p_value)) - else: - vm.puppet_contact = p_value_stripped - continue - - if p_key.lower() == 'customer' and p_value_stripped: - if cls.re_invalid_chars.search(p_value_stripped): - LOG.error(_("Invalid puppet customer name {!r}.").format(p_value)) - else: - vm.puppet_customer = p_value_stripped - continue - - if p_key.lower() == 'project' and p_value_stripped: - if cls.re_invalid_chars.search(p_value_stripped): - LOG.error(_("Invalid puppet customer project name {!r}.").format(p_value)) - else: - vm.puppet_project = p_value_stripped - continue - - if p_key.lower() == 'role' and p_value_stripped: - if cls.re_invalid_chars.search(p_value_stripped): - LOG.error(_("Invalid puppet role {!r}.").format(p_value)) - else: - vm.puppet_role = p_value_stripped - continue - - if p_key.lower() == 'tier' and p_value_stripped: - if cls.re_invalid_chars.search(p_value_stripped): - LOG.error(_("Invalid puppet tier {!r}.").format(p_value)) - else: - vm.puppet_tier = p_value_stripped - continue - - if cls.re_key_env.search(p_key) and p_value_stripped: - if verbose > 2: - LOG.debug(_("Setting Puppet environment to {!r}.").format(p_value_stripped)) - LOG.debug - if cls.re_invalid_chars.search(p_value_stripped): - LOG.error(_("Invalid puppet environment {!r}.").format(p_value)) - else: - vm.puppet_env = p_value_stripped - + cls._apply_puppetsub_vmdef2vm( + vm=vm, p_key=p_key, p_value=p_value, verbose=verbose) return True if cls.re_key_has_puppet.search(key): @@ -529,7 +481,7 @@ class TerraformVm(HandlingObject): if cls.re_key_puppet_env.search(key) and val_stripped: if verbose > 2: - LOG.debug(_("Setting Puppet environment to {!r}.").format(p_value_stripped)) + LOG.debug(_("Setting Puppet environment to {!r}.").format(val_stripped)) if cls.re_invalid_chars.search(val_stripped): LOG.error(_("Invalid puppet environment {!r}.").format(value)) else: @@ -538,6 +490,62 @@ class TerraformVm(HandlingObject): return False + # ------------------------------------------------------------------------- + @classmethod + def _apply_puppetsub_vmdef2vm(cls, vm, p_key, p_value, verbose=0): + + p_value_stripped = p_value.strip() + if verbose > 2: + LOG.debug(_("Evaluating sub key of {d!r}: {k!r} => {v!r}").format( + d='puppet', k=p_key, v=p_value_stripped)) + + if p_key.lower() == 'contact' and p_value_stripped: + if cls.re_invalid_chars.search(p_value_stripped): + LOG.error(_("Invalid puppet contact name {!r}.").format(p_value)) + else: + vm.puppet_contact = p_value_stripped + return + + if p_key.lower() == 'customer' and p_value_stripped: + if cls.re_invalid_chars.search(p_value_stripped): + LOG.error(_("Invalid puppet customer name {!r}.").format(p_value)) + else: + vm.puppet_customer = p_value_stripped + return + + if p_key.lower() == 'project' and p_value_stripped: + if cls.re_invalid_chars.search(p_value_stripped): + LOG.error(_("Invalid puppet customer project name {!r}.").format(p_value)) + else: + vm.puppet_project = p_value_stripped + return + + if p_key.lower() == 'role' and p_value_stripped: + if cls.re_invalid_chars.search(p_value_stripped): + LOG.error(_("Invalid puppet role {!r}.").format(p_value)) + else: + vm.puppet_role = p_value_stripped + return + + if p_key.lower() == 'tier' and p_value_stripped: + if cls.re_invalid_chars.search(p_value_stripped): + LOG.error(_("Invalid puppet tier {!r}.").format(p_value)) + else: + vm.puppet_tier = p_value_stripped + return + + if cls.re_key_env.search(p_key) and p_value_stripped: + if verbose > 2: + LOG.debug( + _("Setting Puppet environment to {!r}.").format(p_value_stripped)) + LOG.debug + if cls.re_invalid_chars.search(p_value_stripped): + LOG.error(_("Invalid puppet environment {!r}.").format(p_value)) + else: + vm.puppet_env = p_value_stripped + + return + # ------------------------------------------------------------------------- def __copy__(self):