From 75dd069af85094d2e37217dd0af72fed4f3266e4 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 1 Jul 2022 11:28:41 +0200 Subject: [PATCH] Renaming snippets/tpl.240.pkgs-el7.sh -> snippets/tpl.250.pkgs-el7.sh --- lib/cr_vmware_tpl/cobbler.py | 39 ++++++++++++------- lib/cr_vmware_tpl/config.py | 3 ++ lib/cr_vmware_tpl/handler.py | 12 +++--- ...pl.240.pkgs-el7.sh => tpl.250.pkgs-el7.sh} | 2 +- snippets/tpl.250.pkgs-el8.sh | 2 +- 5 files changed, 38 insertions(+), 20 deletions(-) rename snippets/{tpl.240.pkgs-el7.sh => tpl.250.pkgs-el7.sh} (93%) diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 417c3c6..53d7f17 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -123,7 +123,7 @@ class Cobbler(BaseHandler): self.local_ks_file.unlink() # ------------------------------------------------------------------------- - def exec_cobbler(self, cmd, no_simulate=False): + def exec_cobbler(self, cmd, no_simulate=False, show_output=True): simulate = self.simulate if no_simulate: @@ -149,10 +149,11 @@ class Cobbler(BaseHandler): cmds.append(c) cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmds)) - return self.exec_ssh(cmd_str) + LOG.debug("Exec cobbler: " + cmd_str) + return self.exec_ssh(cmd_str, show_output=show_output) # ------------------------------------------------------------------------- - def exec_ssh(self, cmd): + def exec_ssh(self, cmd, show_output=False): ssh = None proc = None @@ -188,6 +189,14 @@ class Cobbler(BaseHandler): output = to_str(stdout.read()).strip() err = to_str(stderr.read()).strip() + if show_output: + if output == '' and err == '': + LOG.debug(_("No output.")) + if output: + LOG.debug(_("Output on {}:").format('STDOUT') + ' ' + output) + if err: + LOG.debug(_("Output on {}:").format('STDERR') + ' ' + err) + proc = CompletedProcess(cmd, retcode, output, err, start_dt=start_dt, end_dt=end_dt) except SSHException as e: @@ -263,7 +272,7 @@ class Cobbler(BaseHandler): def get_cobbler_version(self): """Trying to evaluate the version of Cobbler on the cobbler host.""" - proc = self.exec_cobbler('version', no_simulate=True) + proc = self.exec_cobbler('version', no_simulate=True, show_output=False) if proc.returncode != 0: err = _('No error message') @@ -363,7 +372,7 @@ class Cobbler(BaseHandler): """Trying to get a list of all configured distros.""" distro_list = [] - proc = self.exec_cobbler(('distro', 'list'), no_simulate=True) + proc = self.exec_cobbler(('distro', 'list'), no_simulate=True, show_output=False) for line in proc.stdout.splitlines(): distro = line.strip() if distro: @@ -379,7 +388,7 @@ class Cobbler(BaseHandler): repo_list = [] - proc = self.exec_cobbler(('repo', 'list'), no_simulate=True) + proc = self.exec_cobbler(('repo', 'list'), no_simulate=True, show_output=False) for line in proc.stdout.splitlines(): repo = line.strip() if repo: @@ -414,7 +423,7 @@ class Cobbler(BaseHandler): """Trying to get a list of all configured cobbler profiles.""" profile_list = [] - proc = self.exec_cobbler(('profile', 'list'), no_simulate=True) + proc = self.exec_cobbler(('profile', 'list'), no_simulate=True, show_output=False) for line in proc.stdout.splitlines(): profile = line.strip() if profile: @@ -611,7 +620,7 @@ class Cobbler(BaseHandler): cmd = ('profile', 'dumpvars', '--name', profile) - proc = self.exec_cobbler(cmd, no_simulate=True) + proc = self.exec_cobbler(cmd, no_simulate=True, show_output=False) vars_out += proc.stdout parser = configparser.RawConfigParser(**kwargs) @@ -946,7 +955,7 @@ class Cobbler(BaseHandler): ks_meta = ' '.join(ks_meta_list) args = ['system', 'add'] - args.append('--clobber') + # args.append('--clobber') args.append('--name') args.append(name) args.append('--profile') @@ -956,10 +965,13 @@ class Cobbler(BaseHandler): args.append('--comment') args.append(comment) if ks_meta: - args.append('--ksmeta') + if self.cfg.cobbler_major_version == 3: + args.append('--autoinstall-meta') + else: + args.append('--ksmeta') args.append(ks_meta) - args.append('--kickstart') - args.append(str(self.cfg.system_ks)) + # args.append('--kickstart') + # args.append(str(self.cfg.system_ks)) args.append('--power-type') args.append('apc') args.append('--hostname') @@ -1016,7 +1028,8 @@ class Cobbler(BaseHandler): def sync(self): """Executing 'cobbler sync' to apply environment, especially DHCPD configuration.""" - proc = self.exec_cobbler('sync') + proc = self.exec_cobbler('sync', show_output=False) + LOG.info(_("Executing cobbler sync ...")) if proc.returncode != 0: err = _('No error message') diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 4e9d9a9..2ed2dc2 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -1047,6 +1047,9 @@ class CrTplConfiguration(BaseMultiConfig): self.verify_cobbler_distros() + if not self.template_name_given: + self.template_name = self.current_distro.shortname + '-template' + # ------------------------------------------------------------------------- def verify_cobbler_distros(self): diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 4f8b523..adb24a9 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -178,9 +178,12 @@ class CrTplHandler(BaseHandler): if not self.cfg.os_id: msg = _("No ID for Operating system defined, please check the configuration.") raise HandlerError(msg) + + distro_info = self.cfg.current_distro + cur_ts = datetime.datetime.now() cur_ts_str = cur_ts.strftime('%Y-%m-%d-%H-%M-%S') - self.tpl_vm_hostname = self.cfg.os_id + '-' + cur_ts_str + self.tpl_vm_hostname = distro_info.shortname + '-' + cur_ts_str if initialized: self.initialized = True @@ -371,7 +374,6 @@ class CrTplHandler(BaseHandler): self.cobbler.ensure_create_motd() self.cobbler.ensure_postfix_files() self.cobbler.ensure_logrotate_files() - return 0 print_section_start('vmw_info', 'Collecting VMWare info', collapsed=True) self.vsphere.get_about() @@ -409,7 +411,7 @@ class CrTplHandler(BaseHandler): if self.tpl_vm: LOG.debug(_("Created VM as {cls}: {vm!r}").format( cls=self.tpl_vm.__class__.__name__, vm=self.tpl_vm)) - for device in self.tpl_vm.cfg.hardware.device: + for device in self.tpl_vm.config.hardware.device: if isinstance(device, vim.vm.device.VirtualEthernetCard): self.tpl_macaddress = device.macAddress LOG.debug(_("Found Ethernet card as {}.").format( @@ -618,9 +620,9 @@ class CrTplHandler(BaseHandler): def _get_storage_pod_obj(self, used_c_name): content = self.vsphere.service_instance.RetrieveContent() - dc = self.vsphere.get_obj(content, [vim.Datacenter], self.cfg.dc) + dc = self.vsphere.get_obj(content, [vim.Datacenter], self.cfg.vsphere_info.dc) if not dc: - raise VSphereDatacenterNotFoundError(self.cfg.dc) + raise VSphereDatacenterNotFoundError(self.cfg.vsphere_info.dc) for child in dc.datastoreFolder.childEntity: pod = self._get_storage_pod_obj_rec(child, used_c_name) diff --git a/snippets/tpl.240.pkgs-el7.sh b/snippets/tpl.250.pkgs-el7.sh similarity index 93% rename from snippets/tpl.240.pkgs-el7.sh rename to snippets/tpl.250.pkgs-el7.sh index 80129e7..dd10052 100644 --- a/snippets/tpl.240.pkgs-el7.sh +++ b/snippets/tpl.250.pkgs-el7.sh @@ -13,7 +13,7 @@ install_pkgs_el7() { log "Installing additional packages ..." echo - local -a pkgs_add=('colordiff' 'p7zip' 'screen') + local -a pkgs_add=('colordiff' 'git' 'p7zip' 'screen') local -a pkgs_remove=('nfs*' 'rpcbind') echo "Installing packages: ${pkgs_add[*]}" diff --git a/snippets/tpl.250.pkgs-el8.sh b/snippets/tpl.250.pkgs-el8.sh index a7774d9..3f46577 100644 --- a/snippets/tpl.250.pkgs-el8.sh +++ b/snippets/tpl.250.pkgs-el8.sh @@ -13,7 +13,7 @@ install_pkgs_centos8() { log "Installing additional packages ..." echo - local -a pkgs_add=('colordiff' 'p7zip' 'screen' 'NetworkManager-config-server') + local -a pkgs_add=('colordiff' 'git' 'p7zip' 'screen' 'NetworkManager-config-server') local -a pkgs_remove=('nfs*' 'rpcbind') echo "Installing packages: ${pkgs_add[*]}" -- 2.39.5