]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding RHSM user and password to configuration
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 20 Oct 2023 09:47:58 +0000 (11:47 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 20 Oct 2023 09:47:58 +0000 (11:47 +0200)
etc/create-vmware-template.ini.default
lib/cr_vmware_tpl/cobbler/system.py
lib/cr_vmware_tpl/config/__init__.py
lib/cr_vmware_tpl/config/eval.py

index 7d1df367666eed0034ef7addf5e019fa82aa4deb..0118d72c7159a81e6bb46f769b445e96bd567154 100644 (file)
 
 ;mac_address = 00:16:3e:54:ab:2b
 
+; The user to use for subscribe the template VM at Red Hat subsription management
+rhsm_user = dpx-subscriber
+
+; The password of the latter user
+;rhsm_pwd =
+
 [Timeouts]
 
 ; General timeout in seconds for create_vm, poweron_vm and shutdown_vm
index 4522e711b30313c8df372eeb6746b3e1b5849ced..22291284cf5182e1b6daee235f7961dccb3c08c1 100644 (file)
@@ -76,6 +76,8 @@ class CobblerSystem():
         ks_meta_list.append("SYSTEM_STATUS={}".format(status))
         ks_meta_list.append("WS_REL_FILESDIR={}".format(self.cfg.cobbler_ws_rel_filesdir))
         ks_meta_list.append("COBBLER_URL=http://{}".format(self.cfg.cobbler_host))
+        if rhsm_user is not None:
+            ks_meta_list.append("RHSM_USER={}
 
         ks_meta = None
         if ks_meta_list:
index d31788bd78259539eb2f7b76f7fe656ddb583598..276b742a17b0f01555f6c0a8b3f98ba79693174e 100644 (file)
@@ -38,7 +38,7 @@ from .eval import ConfigEval
 from .ldap import LdapConnectionInfo, LdapConnectionDict
 from .timeouts import ConfigTimeouts
 
-__version__ = '3.1.3'
+__version__ = '3.2.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -139,6 +139,8 @@ class CrTplConfiguration(BaseMultiConfig, ConfigCobbler, ConfigTimeouts, ConfigE
     re_ldap_section_w_name = re.compile(r'^\s*ldap\s*:\s*(\S+)')
     re_resolv_ns_entry = re.compile(r'^\s*nameserver\s+(\S+)')
 
+    default_rhsm_user = 'dpx-subscriber'
+
     # -------------------------------------------------------------------------
     def __init__(
         self, appname=None, verbose=0, version=__version__, base_dir=None,
@@ -210,6 +212,9 @@ class CrTplConfiguration(BaseMultiConfig, ConfigCobbler, ConfigTimeouts, ConfigE
 
         self.ldap_timeout = DEFAULT_TIMEOUT
 
+        self._rhsm_user = self.default_rhsm_user
+        self._rhsm_pwd = None
+
         super(CrTplConfiguration, self).__init__(
             appname=appname, verbose=verbose, version=version, base_dir=base_dir,
             append_appname_to_stems=append_appname_to_stems, config_dir=config_dir,
@@ -339,6 +344,18 @@ class CrTplConfiguration(BaseMultiConfig, ConfigCobbler, ConfigTimeouts, ConfigE
         """The path to the snippets dirctory, depending of the system status."""
         return self.cobbler_rootdir / 'snippets' / 'per_status' / self.system_status
 
+    # -------------------------------------------------------------------------
+    @property
+    def rhsm_user(self):
+        """The user to use for subscribing a RHEL host to RedHat subscription management."""
+        return self._rhsm_user
+
+    # -------------------------------------------------------------------------
+    @property
+    def rhsm_pwd(self):
+        """The password of the RHSM user."""
+        return self._rhsm_pwd
+
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
@@ -362,6 +379,8 @@ class CrTplConfiguration(BaseMultiConfig, ConfigCobbler, ConfigTimeouts, ConfigE
         res['data_size'] = self.data_size
         res['default_cobbler_nameservers'] = self.default_cobbler_nameservers
         res['ram_gb'] = self.ram_gb
+        res['rhsm_pwd'] = None
+        res['rhsm_user'] = self.rhsm_user
         res['system_ks'] = self.system_ks
         res['snippets_dir'] = self.snippets_dir
 
@@ -376,6 +395,12 @@ class CrTplConfiguration(BaseMultiConfig, ConfigCobbler, ConfigTimeouts, ConfigE
             else:
                 res['root_password'] = '********'
 
+        if self.rhsm_pwd:
+            if self.verbose > 4:
+                res['rhsm_pwd'] = self.rhsm_pwd
+            else:
+                res['rhsm_pwd'] = '********'
+
         return res
 
     # -------------------------------------------------------------------------
index 069e3e23309e7742b56fe6c3a3bd7804ed482e3f..54aa083b08d19bdaec292885a35e7046eda54c2c 100644 (file)
@@ -24,7 +24,7 @@ from ..xlate import XLATOR
 
 from .ldap import LdapConnectionInfo
 
-__version__ = '0.1.0'
+__version__ = '0.2.0'
 
 LOG = logging.getLogger(__name__)
 
@@ -190,6 +190,8 @@ class ConfigEval():
         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)
+        re_rhsm_user = re.compile(r'^\s*rhsm[-_]?user\s*$', re.IGNORECASE)
+        re_rhsm_pwd = re.compile(r'^\s*rhsm[-_]?(?:pwd|password)\s*$', re.IGNORECASE)
 
         for key in section.keys():
             value = section[key]
@@ -243,6 +245,12 @@ class ConfigEval():
             if re_swap_space.match(key) and value.strip():
                 self.swap_size_mb = int(value)
                 continue
+            if re_rhsm_user.match(key) and value.strip():
+                self._rhsm_user = value.strip()
+                continue
+            if re_rhsm_pwd.match(key):
+                self._rhsm_pwd = value
+                continue
 
         return