# Own modules
from fb_tools.config import ConfigError, BaseConfiguration
-__version__ = '1.0.0'
+__version__ = '1.1.1'
LOG = logging.getLogger(__name__)
default_ram_mb = 4 * 1024
default_network = '192.168.88.0_23'
default_mac_address = '00:16:3e:54:ab:2b'
+ default_max_wait_for_general = 15
default_max_wait_for_finish_install = 60 * 60
default_max_nr_templates_stay = 4
default_vmware_cfg_version = 'vmx-13'
default_os_version = 'oracleLinux7_64Guest'
+ min_max_wait_for_finish_general = 2
min_max_wait_for_finish_install = 3 * 60
+ max_max_wait_for_finish_general = 60 * 60
max_max_wait_for_finish_install = 24 * 60 * 60
limit_max_nr_templates_stay = 100
self.ram_mb = self.default_ram_mb
self.network = self.default_network
self.mac_address = self.default_mac_address
+ self.max_wait_for_general = self.default_max_wait_for_general
+ self.max_wait_for_create_vm = None
+ self.max_wait_for_poweron_vm = None
+ self.max_wait_for_shutdown_vm = None
self.max_wait_for_finish_install = self.default_max_wait_for_finish_install
self.max_nr_templates_stay = self.default_max_nr_templates_stay
self.vmware_cfg_version = self.default_vmware_cfg_version
if section_name.lower() == 'template':
self._eval_config_template(config, section_name)
return
+ if section_name.lower() == 'timeouts':
+ self._eval_config_timeouts(config, section_name)
+ return
if self.verbose > 1:
LOG.debug("Unhandled configuration section {!r}.".format(section_name))
self.vmware_cfg_version = value.strip()
elif key.lower() == 'os_version':
self.os_version = value.strip()
- 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
+
+ self._eval_config_timeouts(config, section_name)
return
+ # -------------------------------------------------------------------------
+ def _eval_timeout_value(self, prop_name, value, min_val, max_val, default_val):
+
+ if self.verbose > 2:
+ LOG.debug("Checking value {v!r} for {p} ...".format(v=value, p=prop_name))
+ if self.verbose > 3:
+ LOG.debug((
+ "Minimal value: {min_val}, maximum value: {max_val}, "
+ "default value: {def_val}.").format(
+ min_val=min_val, max_val=max_val, def_val=default_val))
+
+ v = float(value)
+
+ if v < min_val:
+ msg = (
+ "Value {val} for {prop} is less than {min_val}, "
+ "using {def_val} seconds.").format(val=v, min_val=min_val, def_val=default_val)
+ LOG.error(msg)
+ return
-# =============================================================================
+ if v < min_val:
+ msg = (
+ "Value {val} for {prop} is greater than {max_val}, "
+ "using {def_val} seconds.").format(val=v, max_val=max_val, def_val=default_val)
+ LOG.error(msg)
+ return
+
+ if self.verbose > 2:
+ msg = "Setting timeout {p!r} to {v:0.1f} seconds.".format(p=prop_name, v=v)
+ LOG.debug(msg)
+ setattr(self, prop_name, v)
+ # -------------------------------------------------------------------------
+ def _eval_config_timeouts(self, config, section_name):
+
+ if self.verbose > 1:
+ LOG.debug("Checking config section {!r} for timeouts ...".format(section_name))
+
+ for (key, value) in config.items(section_name):
+ if key.lower() == 'max_wait_for_general':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_general', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.default_max_wait_for_general)
+
+ for (key, value) in config.items(section_name):
+ if key.lower() == 'max_wait_for_create_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_create_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.max_wait_for_general)
+ elif key.lower() == 'max_wait_for_poweron_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_poweron_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.max_wait_for_general)
+ elif key.lower() == 'max_wait_for_shutdown_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_shutdown_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.max_wait_for_general)
+ elif key.lower() == 'max_wait_for_finish_install':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_finish_install', value=value,
+ min_val=self.min_max_wait_for_finish_install,
+ max_val=self.max_max_wait_for_finish_install,
+ default_val=self.default_max_wait_for_finish_install)
+
+ if self.max_wait_for_create_vm is None:
+ self.max_wait_for_create_vm = self.max_wait_for_general
+ if self.max_wait_for_poweron_vm is None:
+ self.max_wait_for_poweron_vm = self.max_wait_for_general
+ if self.max_wait_for_shutdown_vm is None:
+ self.max_wait_for_shutdown_vm = self.max_wait_for_general
+
+
+# =============================================================================
if __name__ == "__main__":
pass