]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Applying flake8 rules to lib/cr_vmware_tpl/config.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 24 Apr 2018 13:33:43 +0000 (15:33 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 24 Apr 2018 13:33:43 +0000 (15:33 +0200)
lib/cr_vmware_tpl/config.py

index 0a6e61d54098a0dc1e79f642be6fc13f380c63cd..38eab36c35afccf6fdac3c94e8f9b509aa7f43c8 100644 (file)
@@ -26,7 +26,7 @@ from .errors import PpError
 
 from .obj import PpBaseObject
 
-__version__ = '0.5.6'
+__version__ = '0.5.7'
 LOG = logging.getLogger(__name__)
 
 
@@ -206,120 +206,133 @@ class CrTplConfiguration(PpBaseObject):
     def eval_config(self, config):
         """Evaluating of all found configuration options."""
 
-        re_excl_ds = re.compile(r'^\s*excluded?[-_]datastores?\s*$', re.IGNORECASE)
-        re_split_ds = re.compile(r'[,;\s]+')
-
         for section in config.sections():
 
             if self.verbose > 2:
                 LOG.debug("Options of section {!r} ...".format(section))
 
             if section.lower() == 'default' or section.lower() == 'global':
+                self._eval_config_global(config, section)
+            elif section.lower() == 'vsphere':
+                self._eval_config_vsphere(config, section)
+            elif section.lower() == 'template':
+                self._eval_config_template(config, section)
+
+    # -------------------------------------------------------------------------
+    def _eval_config_global(self, config, section):
+
+        if self.verbose > 2:
+            LOG.debug("Checking config section {!r} ...".format(section))
+
+        for (key, value) in config.items(section):
+            if key.lower() == 'verbose':
+                val = int(value)
+                if val > self.verbose:
+                    self.verbose = val
 
-                for (key, value) in config.items(section):
-
-                    if self.verbose > 2:
-                        LOG.debug("Key {k!r}, value {v!r}.".format(k=key, v=value))
-
-                    if key.lower() == 'verbose':
-                        val = int(value)
-                        if val > self.verbose:
-                            self.verbose = val
-
-            if section.lower() == 'vsphere':
-
-                for (key, value) in config.items(section):
-
-                    if self.verbose > 2:
-                        LOG.debug("Key {k!r}, value {v!r}.".format(k=key, v=value))
-
-                    if key.lower() == 'host':
-                        self.vsphere_host = value
-                        continue
-                    if key.lower() == 'port':
-                        self.vsphere_port = int(value)
-                        continue
-                    if key.lower() == 'user':
-                        self.vsphere_user = value
-                        continue
-                    if key.lower() == 'password':
-                        self.password = value
-                        continue
-                    if key.lower() == 'folder':
-                        self.folder = value
-                    if key.lower() == 'dc':
-                        self.dc = value
-
-                    if key.lower() == 'max_nr_templates_stay':
-                        v = int(value)
-                        if v < 1:
-                            LOG.error((
-                                "Value {val} for max_nr_templates_stay is less than {minval}, "
-                                "using {default}.").format(
-                                    val=v, minval=1,
-                                    default=self.default_max_nr_templates_stay))
-                        elif v >= 100:
-                            LOG.error((
-                                "Value {val} for max_nr_templates_stay is greater than {maxval}, "
-                                "using {default}.").format(
-                                    val=v, maxval=100,
-                                    default=self.default_max_nr_templates_stay))
-                        else:
-                            self.max_nr_templates_stay = v
-
-                    if re_excl_ds.search(key):
-                        datastores = re_split_ds.split(value.strip())
-                        self.excluded_datastores = datastores
+        return
+
+    # -------------------------------------------------------------------------
+    def _eval_config_vsphere(self, config, section):
+
+        if self.verbose > 2:
+            LOG.debug("Checking config section {!r} ...".format(section))
+
+        re_excl_ds = re.compile(r'^\s*excluded?[-_]datastores?\s*$', re.IGNORECASE)
+        re_split_ds = re.compile(r'[,;\s]+')
 
+        for (key, value) in config.items(section):
+
+            if key.lower() == 'host':
+                self.vsphere_host = value
+                continue
+            elif key.lower() == 'port':
+                self.vsphere_port = int(value)
+                continue
+            elif key.lower() == 'user':
+                self.vsphere_user = value
+                continue
+            elif key.lower() == 'password':
+                self.password = value
+                continue
+            elif key.lower() == 'folder':
+                self.folder = value
+            elif key.lower() == 'dc':
+                self.dc = value
+
+            elif key.lower() == 'max_nr_templates_stay':
+                v = int(value)
+                if v < 1:
+                    LOG.error((
+                        "Value {val} for max_nr_templates_stay is less than {minval}, "
+                        "using {default}.").format(
+                            val=v, minval=1,
+                            default=self.default_max_nr_templates_stay))
+                elif v >= 100:
+                    LOG.error((
+                        "Value {val} for max_nr_templates_stay is greater than {maxval}, "
+                        "using {default}.").format(
+                            val=v, maxval=100,
+                            default=self.default_max_nr_templates_stay))
+                else:
+                    self.max_nr_templates_stay = v
+
+            elif re_excl_ds.search(key):
+                datastores = re_split_ds.split(value.strip())
+                self.excluded_datastores = datastores
+
+        return
+
+    # -------------------------------------------------------------------------
+    def _eval_config_template(self, config, section):
+
+        if self.verbose > 2:
+            LOG.debug("Checking config section {!r} ...".format(section))
+
+        for (key, value) in config.items(section):
+            if key.lower() == 'vm':
+                self.template_vm = value
                 continue
+            elif key.lower() == 'name':
+                self.template_name = value
+            elif key.lower() == 'data_size_gb':
+                self.data_size_gb = float(value)
+            elif key.lower() == 'data_size_mb':
+                self.data_size_gb = float(value) / 1024.0
+            elif key.lower() == 'data_size_kb':
+                self.data_size_gb = float(value) / 1024.0 / 1024.0
+            elif key.lower() == 'data_size':
+                self.data_size_gb = float(value) / 1024.0 / 1024.0 / 1024.0
+            elif key.lower() == 'num_cpus':
+                self.num_cpus = int(value)
+            elif key.lower() == 'ram_gb':
+                self.ram_mb = int(float(value) * 1024.0)
+            elif key.lower() == 'ram_mb':
+                self.ram_mb = int(value)
+            elif key.lower() == 'network':
+                self.network = value.strip()
+            elif key.lower() == 'mac_address':
+                v = value.strip().lower()
+                if v:
+                    self.mac_address = v
+            elif key.lower() == 'max_wait_for_finish_install':
+                v = float(value)
+                if v < self.min_max_wait_for_finish_install:
+                    LOG.error((
+                        "Value {val} for max_wait_for_finish_install is less than "
+                        "{minval}, using {default} seconds.").format(
+                            val=v, minval=self.min_max_wait_for_finish_install,
+                            default=self.default_max_wait_for_finish_install))
+                elif v > self.max_max_wait_for_finish_install:
+                    LOG.error((
+                        "Value {val} for max_wait_for_finish_install is greater than "
+                        "{maxval}, using {default} seconds.").format(
+                            val=v, maxval=self.max_max_wait_for_finish_install,
+                            default=self.default_max_wait_for_finish_install))
+                else:
+                    self.max_wait_for_finish_install = v
 
-            if section.lower() == 'template':
-
-                for (key, value) in config.items(section):
-                    if self.verbose > 2:
-                        LOG.debug("Key {k!r}, value {v!r}.".format(k=key, v=value))
-
-                    if key.lower() == 'vm':
-                        self.template_vm = value
-                        continue
-                    if key.lower() == 'name':
-                        self.template_name = value
-                    if key.lower() == 'data_size_gb':
-                        self.data_size_gb = float(value)
-                    if key.lower() == 'data_size_mb':
-                        self.data_size_gb = float(value) / 1024.0
-                    if key.lower() == 'data_size_kb':
-                        self.data_size_gb = float(value) / 1024.0 / 1024.0
-                    if key.lower() == 'data_size':
-                        self.data_size_gb = float(value) / 1024.0 / 1024.0 / 1024.0
-                    if key.lower() == 'num_cpus':
-                        self.num_cpus = int(value)
-                    if key.lower() == 'ram_gb':
-                        self.ram_mb = int(float(value) * 1024.0)
-                    if key.lower() == 'ram_mb':
-                        self.ram_mb = int(value)
-                    if key.lower() == 'network':
-                        self.network = value.strip()
-                    if key.lower() == 'mac_address':
-                        v = value.strip().lower()
-                        if v:
-                            self.mac_address = v
-                    if key.lower() == 'max_wait_for_finish_install':
-                        v = float(value)
-                        if v < self.min_max_wait_for_finish_install:
-                            LOG.error((
-                                "Value {val} for max_wait_for_finish_install is less than "
-                                "{minval}, using {default} seconds.").format(
-                                    val=v, minval=self.min_max_wait_for_finish_install,
-                                    default=self.default_max_wait_for_finish_install))
-                        elif v > self.max_max_wait_for_finish_install:
-                            LOG.error((
-                                "Value {val} for max_wait_for_finish_install is greater than "
-                                "{maxval}, using {default} seconds.").format(
-                                    val=v, maxval=self.max_max_wait_for_finish_install,
-                                    default=self.default_max_wait_for_finish_install))
-                        else:
-                            self.max_wait_for_finish_install = v
+        return
 
 
 # =============================================================================