]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Renaming snippets/tpl.240.pkgs-el7.sh -> snippets/tpl.250.pkgs-el7.sh
authorFrank Brehm <frank@brehm-online.com>
Fri, 1 Jul 2022 09:28:41 +0000 (11:28 +0200)
committerFrank Brehm <frank@brehm-online.com>
Fri, 1 Jul 2022 09:28:41 +0000 (11:28 +0200)
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/handler.py
snippets/tpl.240.pkgs-el7.sh [deleted file]
snippets/tpl.250.pkgs-el7.sh [new file with mode: 0644]
snippets/tpl.250.pkgs-el8.sh

index 417c3c6776aa175563ac8e87d196bc86d0e0ae6e..53d7f17844f92584a462b6b2d7d587de186a52d9 100644 (file)
@@ -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')
index 4e9d9a999f18687dfb0f306def1be0f442cc0957..2ed2dc287d9b89bca9b6f097eb42668ed5f7a1de 100644 (file)
@@ -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):
 
index 4f8b523a66dc6c548ab53bf3772ba83125d51e0b..adb24a968d772553932509e3b68184ad747a14cd 100644 (file)
@@ -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.240.pkgs-el7.sh
deleted file mode 100644 (file)
index 80129e7..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-## !/bin/bash
-#raw
-
-#-----------------------------------------------------------
-install_pkgs_el7() {
-
-    echo -e "\e[0Ksection_start:$( date +%s ):ks_install_pkgs_el7[collapsed=true]\r\e[0KInstalling additional packages ..."
-    echo
-    echo "${HASH_LINE}"
-    echo "Calling install_pkgs_el7() ..."
-    echo
-    echo
-    log "Installing additional packages ..."
-    echo
-
-    local -a pkgs_add=('colordiff' 'p7zip' 'screen')
-    local -a pkgs_remove=('nfs*' 'rpcbind')
-
-    echo "Installing packages: ${pkgs_add[*]}"
-    yum install -y "${pkgs_add[@]}"
-
-    echo
-    echo "Removing packages: ${pkgs_remove[*]}"
-    yum remove -y "${pkgs_remove[@]}"
-
-    echo
-    echo "Creating /etc/gitconfig ..."
-    cat <<-EOF >/etc/gitconfig
-       [color]
-           ui = true
-       EOF
-
-    echo -e "\e[0Ksection_end:$( date +%s ):ks_install_pkgs_el7\r\e[0K"
-}
-
-install_pkgs_el7
-
-#end raw
-## vim: ts=4 et list
diff --git a/snippets/tpl.250.pkgs-el7.sh b/snippets/tpl.250.pkgs-el7.sh
new file mode 100644 (file)
index 0000000..dd10052
--- /dev/null
@@ -0,0 +1,39 @@
+## !/bin/bash
+#raw
+
+#-----------------------------------------------------------
+install_pkgs_el7() {
+
+    echo -e "\e[0Ksection_start:$( date +%s ):ks_install_pkgs_el7[collapsed=true]\r\e[0KInstalling additional packages ..."
+    echo
+    echo "${HASH_LINE}"
+    echo "Calling install_pkgs_el7() ..."
+    echo
+    echo
+    log "Installing additional packages ..."
+    echo
+
+    local -a pkgs_add=('colordiff' 'git' 'p7zip' 'screen')
+    local -a pkgs_remove=('nfs*' 'rpcbind')
+
+    echo "Installing packages: ${pkgs_add[*]}"
+    yum install -y "${pkgs_add[@]}"
+
+    echo
+    echo "Removing packages: ${pkgs_remove[*]}"
+    yum remove -y "${pkgs_remove[@]}"
+
+    echo
+    echo "Creating /etc/gitconfig ..."
+    cat <<-EOF >/etc/gitconfig
+       [color]
+           ui = true
+       EOF
+
+    echo -e "\e[0Ksection_end:$( date +%s ):ks_install_pkgs_el7\r\e[0K"
+}
+
+install_pkgs_el7
+
+#end raw
+## vim: ts=4 et list
index a7774d90639646ef4a3b0575c9604d75c5a02948..3f4657797db52ae0d34ee4599191599f1b032846 100644 (file)
@@ -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[*]}"