]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding configuration of system_status and swap_size
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 10 Jun 2020 15:39:05 +0000 (17:39 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 10 Jun 2020 15:39:05 +0000 (17:39 +0200)
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/config.py

index fc4b31dcec8317af3a5d5c4760a612504572477a..810c3ff098fd8b9cb39c9a71c1971d3913a13a90 100644 (file)
@@ -37,7 +37,7 @@ from .config import CrTplConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '0.4.4'
+__version__ = '0.4.5'
 
 LOG = logging.getLogger(__name__)
 
@@ -61,8 +61,6 @@ class Cobbler(BaseHandler):
     A handler class for executing cobbler actions.
     """
 
-    valid_status = ('development', 'testing', 'acceptance', 'production')
-
     # -------------------------------------------------------------------------
     def __init__(
         self, appname=None, verbose=0, version=__version__, base_dir=None,
@@ -601,7 +599,16 @@ class Cobbler(BaseHandler):
             raise ExpectedCobblerError(msg)
 
     # -------------------------------------------------------------------------
-    def add_system(self, name, fqdn, mac_address, comment=None, status=None):
+    def ensure_system_ks(self):
+
+        local_ks_base = 'template-' + self.config.os_id + '.ks'
+        local_ks = self.base_dir / 'kickstart' / local_ks_base
+        remote_ks = self.config.system_ks
+
+        self.ensure_remote_file(local_ks, remote_ks)
+
+    # -------------------------------------------------------------------------
+    def add_system(self, name, fqdn, mac_address, comment=None):
         """Creating a new system."""
 
         profile = self.config.cobbler_profile
@@ -611,12 +618,11 @@ class Cobbler(BaseHandler):
 
         if not comment:
             comment = "VMWare template for creating a {} system.".format(os_id)
-        if not status:
-            status = 'development'
+        status = self.config.system_status
 
         ks_meta_list = []
         ks_meta_list.append("ROOT_PWD_HASH={}".format(self.config.get_root_pwd_hash()))
-        ks_meta_list.append("SWAP_SIZE_MB=512")
+        ks_meta_list.append("SWAP_SIZE_MB={}".format(self.config.swap_size_mb))
 
         ks_meta = None
         if ks_meta_list:
index d47341dec77cd169e9ea392663be212f1c05add1..58ed6fc898eba9f1fc3b79ab078c657a7edde9cd 100644 (file)
@@ -22,7 +22,7 @@ from fb_tools.config import ConfigError, BaseConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '1.5.4'
+__version__ = '1.5.5'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -107,6 +107,11 @@ class CrTplConfiguration(BaseConfiguration):
         mname = method.name.lower()
         method_list[mname] = method
 
+    valid_system_status = ('development', 'testing', 'acceptance', 'production')
+    default_system_status = 'development'
+
+    default_swap_size_mb = 512
+
     # -------------------------------------------------------------------------
     def __init__(
         self, appname=None, verbose=0, version=__version__, base_dir=None,
@@ -126,6 +131,7 @@ class CrTplConfiguration(BaseConfiguration):
         self.data_size_gb = self.default_data_size_gb
         self.num_cpus = self.default_num_cpus
         self.ram_mb = self.default_ram_mb
+        self.swap_size_mb = self.default_swap_size_mb
         self.network = self.default_network
         self.mac_address = self.default_mac_address
         self.max_wait_for_general = self.default_max_wait_for_general
@@ -162,6 +168,7 @@ class CrTplConfiguration(BaseConfiguration):
         self.cobbler_ws_base_url = self.default_cobbler_ws_base_url
         self.cobbler_ws_docroot = self.default_cobbler_ws_docroot
         self.cobbler_ws_rel_filesdir = self.default_cobbler_ws_rel_filesdir
+        self.system_status = self.default_system_status
 
         self.excluded_datastores = []
 
@@ -205,6 +212,13 @@ class CrTplConfiguration(BaseConfiguration):
         """The root password of the VM to create."""
         return self._root_password
 
+    # -------------------------------------------------------------------------
+    @property
+    def system_ks(self):
+        """The path to the system kickstart file."""
+        ks_base = 'template-' + self.os_id + '-' + self.system_status + '.ks'
+        return self.cobbler_ks_dir / ks_base
+
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
@@ -222,6 +236,7 @@ class CrTplConfiguration(BaseConfiguration):
         res['data_size_kb'] = self.data_size_kb
         res['data_size'] = self.data_size
         res['ram_gb'] = self.ram_gb
+        res['system_ks'] = self.system_ks
 
         res['root_password'] = None
         if self.root_password:
@@ -349,6 +364,7 @@ class CrTplConfiguration(BaseConfiguration):
         re_os_id_subst = re.compile(r'[^a-z0-9_-]+', re.IGNORECASE)
         re_vm_domain = re.compile(r'^\s*(?:vm[-_]?)?domain\s*$', re.IGNORECASE)
         re_root_pwd = re.compile(r'^\s*root[-_]?password\s*$', re.IGNORECASE)
+        re_swap_space = re.compile(r'^\s*swap[-_]?space(?:[-_]?mb)?\s*$', re.IGNORECASE)
 
         for (key, value) in config.items(section_name):
             if key.lower() == 'vm':
@@ -405,6 +421,9 @@ class CrTplConfiguration(BaseConfiguration):
             elif re_root_pwd.match(key) and value.strip():
                 self._root_password = value.strip()
                 continue
+            elif re_swap_space.match(key) and value.strip():
+                self.swap_size_mb = int(value)
+                continue
 
         return
 
@@ -512,6 +531,7 @@ class CrTplConfiguration(BaseConfiguration):
             r'^\s*(?:ws|webserver)[-_]?docroot\s*$', re.IGNORECASE)
         re_ws_rel_filesdir_key = re.compile(
             r'^\s*(?:ws|webserver)[-_]?rel(?:ative)?[-_]?filesdir\s*$', re.IGNORECASE)
+        rs_system_status = re.compile(r'^\s*system[-_]?status\s*$', re.IGNORECASE)
 
         for (key, value) in config.items(section_name):
             if key.lower() == 'distro' and value.strip() != '':
@@ -565,6 +585,18 @@ class CrTplConfiguration(BaseConfiguration):
                 continue
             if re_ws_rel_filesdir_key.match(key) and value.strip() != '':
                 self.cobbler_ws_rel_filesdir = Path(value.strip())
+                continue
+            if rs_system_status.match(key) and value.strip() != '':
+                val = value.strip().lower()
+                if val in self.valid_system_status:
+                    self.system_status = val
+                else:
+                    msg = _(
+                        "The value of {what!r} must be one of {valid!r}, "
+                        "but found {val!r}.").format(what='system_status',
+                        valid=self.valid_system_status, val=value)
+                    LOG.error(msg)
+                continue
 
     # -------------------------------------------------------------------------
     def get_root_pwd_hash(self, method='sha256'):