From: Frank Brehm Date: Wed, 11 Apr 2018 15:16:35 +0000 (+0200) Subject: Config option to exclude datastores X-Git-Tag: 0.1.1~42 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=aa176358a8acb84bb151a2457e1b183671445452;p=pixelpark%2Fcreate-vmware-tpl.git Config option to exclude datastores --- diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index fcf9244..10958df 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -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': diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 0501adf..52c0a7d 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -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: