From aebf6e0f4ca4e91af772d0d0626ddade33d01760 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 20 Oct 2023 11:47:58 +0200 Subject: [PATCH] Adding RHSM user and password to configuration --- etc/create-vmware-template.ini.default | 6 ++++++ lib/cr_vmware_tpl/cobbler/system.py | 2 ++ lib/cr_vmware_tpl/config/__init__.py | 27 +++++++++++++++++++++++++- lib/cr_vmware_tpl/config/eval.py | 10 +++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/etc/create-vmware-template.ini.default b/etc/create-vmware-template.ini.default index 7d1df36..0118d72 100644 --- a/etc/create-vmware-template.ini.default +++ b/etc/create-vmware-template.ini.default @@ -40,6 +40,12 @@ ;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 diff --git a/lib/cr_vmware_tpl/cobbler/system.py b/lib/cr_vmware_tpl/cobbler/system.py index 4522e71..2229128 100644 --- a/lib/cr_vmware_tpl/cobbler/system.py +++ b/lib/cr_vmware_tpl/cobbler/system.py @@ -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: diff --git a/lib/cr_vmware_tpl/config/__init__.py b/lib/cr_vmware_tpl/config/__init__.py index d31788b..276b742 100644 --- a/lib/cr_vmware_tpl/config/__init__.py +++ b/lib/cr_vmware_tpl/config/__init__.py @@ -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 # ------------------------------------------------------------------------- diff --git a/lib/cr_vmware_tpl/config/eval.py b/lib/cr_vmware_tpl/config/eval.py index 069e3e2..54aa083 100644 --- a/lib/cr_vmware_tpl/config/eval.py +++ b/lib/cr_vmware_tpl/config/eval.py @@ -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 -- 2.39.5