]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Config option to exclude datastores
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 11 Apr 2018 15:16:35 +0000 (17:16 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 11 Apr 2018 15:16:35 +0000 (17:16 +0200)
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/handler.py

index fcf924496c40d4e932d844c2b94ffcfa7e98a3a4..10958df563fcb0cfabe4b36cb233da7b56688465 100644 (file)
@@ -12,6 +12,7 @@ from __future__ import absolute_import
 import sys
 import os
 import logging
+import re
 
 # Third party modules
 import six
@@ -81,6 +82,8 @@ class CrTplConfiguration(PpBaseObject):
         self.mac_address = self.default_mac_address
         self.max_wait_for_finish_install = self.default_max_wait_for_finish_install
 
+        self.excluded_datastores = []
+
         self.encoding = 'utf-8'
 
         super(CrTplConfiguration, self).__init__(
@@ -198,6 +201,9 @@ 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:
@@ -239,6 +245,10 @@ class CrTplConfiguration(PpBaseObject):
                     if key.lower() == 'dc':
                         self.dc = value
 
+                    if re_excl_ds.search(key):
+                        datastores = re_split_ds.split(value.strip())
+                        self.excluded_datastores = datastores
+
                 continue
 
             if section.lower() == 'template':
index 0501adf293c6b481fb87b3ae38156e678043fa91..52c0a7d9d4b479cc449f9fc93fe5653d9bcf2e95 100644 (file)
@@ -476,6 +476,9 @@ class CrTplHandler(PpBaseObject):
                 if self.verbose > 2:
                     LOG.debug("Datastore {!r} seems to be local.".format(child.summary.name))
                 return
+            if child.summary.name in self.config.excluded_datastores:
+                LOG.debug("Datastore {!r} is excluded.".format(child.summary.name))
+                return
             free_bytes = child.summary.freeSpace
             free_gbytes = float(free_bytes) / 1024.0 / 1024.0 / 1024.0
             if free_bytes >= self.config.data_size: