]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Applying flake8 rules to lib/cr_tf/terraform/vm.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2019 16:11:48 +0000 (17:11 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2019 16:11:48 +0000 (17:11 +0100)
lib/cr_tf/terraform/vm.py

index 85e219abacd489522bae2ff4b1492f811f001c4a..782b1d1c436b91e0bf4d3c5bc06ce068449df4c0 100644 (file)
@@ -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):