]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Changing logging
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Jan 2022 16:50:37 +0000 (17:50 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Jan 2022 16:50:37 +0000 (17:50 +0100)
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/handler.py

index fd28cd35f160b56d314029b1f0ee059454252eec..ec427794c5027adda03c992262695c9ee98dda50 100644 (file)
@@ -42,7 +42,7 @@ from .config import CrTplConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '0.6.7'
+__version__ = '0.6.8'
 
 LOG = logging.getLogger(__name__)
 
@@ -440,6 +440,8 @@ class Cobbler(BaseHandler):
         remote_dir = docroot / self.config.system_status
 
         LOG.info(_("Ensuring currentness of rsyslog config files ..."))
+        print_section_start(
+            'ensure_rsyslog_cfg_files', 'Ensuring rsyslog config files.', collapsed=True)
 
         for local_cfg_file in files_dir.glob('*rsyslog.conf*'):
             remote_cfg_file = remote_dir / local_cfg_file.name
@@ -447,6 +449,8 @@ class Cobbler(BaseHandler):
                 loc=str(local_cfg_file), rem=str(remote_cfg_file)))
             self.ensure_remote_file(local_cfg_file, remote_cfg_file, check_parent=False)
 
+        print_section_end('ensure_rsyslog_cfg_files')
+
     # -------------------------------------------------------------------------
     def ensure_profile_ks(self):
 
@@ -730,7 +734,6 @@ class Cobbler(BaseHandler):
         os_id = self.config.os_id
 
         LOG.info(_("Creating new system {!r} ...").format(name))
-        print_section_start('add_system', "Creating new system ...", collapsed=True)
 
         if not comment:
             comment = "VMWare template for creating a {} system.".format(os_id)
@@ -782,10 +785,8 @@ class Cobbler(BaseHandler):
                 err = proc.stdout
             msg = _("Error creating a cobbler system - returncode was {rc}: {err}").format(
                 rc=proc.returncode, err=err)
-            print_section_end('add_system')
             raise ExpectedCobblerError(msg)
 
-        print_section_end('add_system')
         self.sync()
 
     # -------------------------------------------------------------------------
index dd153ab4a9de6c1e5c555a3797c757b1fe87bd2c..6b91e4ef1c5b1b6e111820af965966e0a83038a9 100644 (file)
@@ -38,13 +38,15 @@ from fb_tools.vsphere.server import VsphereServer
 from fb_tools.vsphere.iface import VsphereVmInterface
 from fb_tools.vsphere.ds import VsphereDatastore
 
+from . import print_section_start, print_section_end
+
 from .config import CrTplConfiguration
 
 from .cobbler import Cobbler
 
 from .xlate import XLATOR
 
-__version__ = '1.8.5'
+__version__ = '1.8.6'
 
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
@@ -268,9 +270,11 @@ class CrTplHandler(BaseHandler):
         self.cobbler.ensure_postfix_files()
         self.cobbler.ensure_logrotate_files()
 
+        print_section_start('vmw_info', 'Collecting VMWare info', collapsed=True)
         self.vsphere.get_about()
         self.vsphere.get_clusters()
         self.cluster = self.vsphere.get_cluster_by_name(self.config.vsphere_cluster)
+        print_section_end('vmw_info')
         if self.cluster:
             LOG.debug(_("Found VSphere cluster {!r}.").format(self.cluster.name))
         else:
@@ -283,8 +287,14 @@ class CrTplHandler(BaseHandler):
                 n=self.config.network, c=self.cluster.name))
             return 6
 
+        print_section_start('vmw_networks', 'Collecting VSPhere networks ...', collapsed=True)
         self.vsphere.get_networks()
+        print_section_end('vmw_networks')
+
+        print_section_start('vmw_folder', 'Ensuring VSPhere folder ...', collapsed=True)
         self.vsphere.ensure_vm_folder(self.config.folder)
+        print_section_end('vmw_folder')
+
         self.check_for_temp_tpl_vm(no_error=True)
         self.select_data_store()
 
@@ -364,7 +374,10 @@ class CrTplHandler(BaseHandler):
     # -------------------------------------------------------------------------
     def check_for_temp_tpl_vm(self, no_error=False):
 
-        LOG.debug(_("First checking, whether {!r} exists ...").format(self.tpl_vm_fqdn))
+        LOG.info(_("First checking, whether {!r} exists ...").format(self.tpl_vm_fqdn))
+        print_section_start(
+            'check_existing_template', "Checking for existence of template ...",
+            collapsed=True)
         vm = self.vsphere.get_vm(self.tpl_vm_fqdn, no_error=no_error)
 
         if vm:
@@ -375,22 +388,29 @@ class CrTplHandler(BaseHandler):
                 msg = "Info about Temporary VM {!r}:".format(self.tpl_vm_fqdn)
                 msg += '\n' + pp(vm.config)
                 LOG.debug(msg)
+            print_section_end('check_existing_template')
             raise TempVmExistsError(self.tpl_vm_fqdn)
 
         LOG.debug(_("Temporary VM {!r} does not exists, will be created.").format(
             self.tpl_vm_fqdn))
+        print_section_end('check_existing_template')
 
     # -------------------------------------------------------------------------
     def get_temp_tpl_vm(self):
 
-        return self.vsphere.get_vm(self.tpl_vm_fqdn, as_vmw_obj=True)
+        print_section_start('get_temp_tpl_vm', "Get created template VM ...", collapsed=True)
+        vm = self.vsphere.get_vm(self.tpl_vm_fqdn, as_vmw_obj=True)
+        print_section_end('get_temp_tpl_vm')
+
+        return vm
 
     # -------------------------------------------------------------------------
     def select_data_store(self):
 
-        LOG.debug(_(
+        LOG.info(_(
             "Selecting a SAN based datastore with at least {:0.1f} GiB available "
             "space.").format(self.config.data_size_gb))
+        print_section_start('select_data_store', "Selecting data store ...", collapsed=True)
 
         self.vsphere.get_ds_clusters()
         self.vsphere.get_datastores()
@@ -411,11 +431,13 @@ class CrTplHandler(BaseHandler):
             ds_to_use = self.select_simple_data_store()
 
         if not ds_to_use:
+            print_section_end('select_data_store')
             raise NoDatastoreFoundError(self.config.data_size_gb)
 
         self.tpl_data_store = ds_to_use
         LOG.info(_("Using datastore {!r} for volume of temporary VM to create.").format(
             ds_to_use.name))
+        print_section_end('select_data_store')
         return
 
     # -------------------------------------------------------------------------