From 5a525855b5dd282e69d0c3ab63201e9c4bab3b26 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 22 Mar 2018 16:41:34 +0100 Subject: [PATCH] Adding configuration of size of data store volume --- etc/create-vmware-template.ini.default | 1 + lib/cr_vmware_tpl/config.py | 34 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/etc/create-vmware-template.ini.default b/etc/create-vmware-template.ini.default index 2cac709..9975532 100644 --- a/etc/create-vmware-template.ini.default +++ b/etc/create-vmware-template.ini.default @@ -18,5 +18,6 @@ ;name = oracle-linux-7.4-template +;data_size_gb = 30 ; vim: filetype=dosini diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 0b9f83f..22d71d9 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -26,7 +26,7 @@ from .errors import FunctionNotImplementedError, PpError from .obj import PpBaseObject -__version__ = '0.3.1' +__version__ = '0.4.1' LOG = logging.getLogger(__name__) @@ -52,6 +52,7 @@ class CrTplConfiguration(PpBaseObject): default_folder = 'templates' default_template_vm = 'template.pixelpark.com' default_template_name = 'oracle-linux-7.4-template' + default_data_size_gb = 30.0 # ------------------------------------------------------------------------- def __init__( @@ -66,6 +67,7 @@ class CrTplConfiguration(PpBaseObject): self.folder = self.default_folder self.template_vm = self.default_template_vm self.template_name = self.default_template_name + self.data_size_gb = self.default_data_size_gb self.encoding = 'utf-8' @@ -87,6 +89,24 @@ class CrTplConfiguration(PpBaseObject): if initialized: self.initialized = True + # ------------------------------------------------------------------------- + @property + def data_size_mb(self): + """Size of template volume in MiB.""" + return int(self.data_size_gb) * 1024 + + # ------------------------------------------------------------------------- + @property + def data_size_kb(self): + """Size of template volume in KiB.""" + return int(self.data_size_gb) * 1024 * 1024 + + # ------------------------------------------------------------------------- + @property + def data_size(self): + """Size of template volume in Bytes.""" + return int(self.data_size_gb) * 1024 * 1024 * 1024 + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -107,6 +127,10 @@ class CrTplConfiguration(PpBaseObject): res['default_folder'] = self.default_folder res['default_template_vm'] = self.default_template_vm res['default_template_name'] = self.default_template_name + res['default_data_size_gb'] = self.default_data_size_gb + res['data_size_mb'] = self.data_size_mb + res['data_size_kb'] = self.data_size_kb + res['data_size'] = self.data_size return res @@ -203,6 +227,14 @@ class CrTplConfiguration(PpBaseObject): 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 # ============================================================================= -- 2.39.5