[checkmk-commits] Minor cleanups

Lars Michelsen lm at mathias-kettner.de
Wed Nov 9 11:08:18 CET 2016


Module: check_mk
Branch: master
Commit: e92822015c22d82c4c0fec8837a191f25a2e945e
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e92822015c22d82c4c0fec8837a191f25a2e945e

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Thu Nov  3 15:15:36 2016 +0100

Minor cleanups

---

 web/htdocs/wato.py    | 74 +++++++++------------------------------------------
 web/htdocs/watolib.py |  6 ++---
 2 files changed, 15 insertions(+), 65 deletions(-)

diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 98f2e18..54b876a 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -4354,7 +4354,7 @@ def create_random_hosts(folder, count, folders, levels):
 #   '----------------------------------------------------------------------'
 
 class ModeAuditLog(WatoMode):
-    log_path = "%s/audit.log" % log_dir
+    log_path = audit_log_path
 
     def __init__(self):
         self._options  = self._vs_audit_log_options().default_value()
@@ -4935,12 +4935,16 @@ class ModeActivateChanges(WatoMode, ActivateChanges):
             has_foreign = self._site_has_foreign_changes(site_id)
             can_activate_all = not has_foreign or config.user.may("wato.activateforeign")
 
+            need_restart = self._is_activate_needed(site_id)
+            need_sync    = self._is_sync_needed(site_id)
+            need_action  = need_restart or need_sync
+
             # TODO: Handle not logged in sites
             # if not config.site_is_local(site_id) and not "secret" in site:
 
             # Activation checkbox
-            table.cell("", css="buttons")
-            if can_activate_all:
+            if can_activate_all and need_action:
+                table.cell("", css="buttons")
                 html.checkbox("site_%s" % site_id, cssclass="site_checkbox")
 
             # Iconbuttons
@@ -4974,10 +4978,7 @@ class ModeActivateChanges(WatoMode, ActivateChanges):
             table.cell(_("Services"), css="number")
             html.a(site_status.get("num_services", ""), href="view.py?view_name=sitesvcs&site=%s" % site_id)
 
-            need_restart = self._is_activate_needed(site_id)
-            need_sync    = self._is_sync_needed(site_id)
-            uptodate = not (need_restart or need_sync)
-
+            # TODO: Cleanup
             # Start asynchronous replication
             #if sitestatus_do_async_replication:
             #    table.cell(_("Activation"), css="repprogress")
@@ -5005,15 +5006,16 @@ class ModeActivateChanges(WatoMode, ActivateChanges):
                 html.icon(_("This site is not update and needs a replication."), "need_replicate")
             if need_restart:
                 html.icon(_("This site needs a restart for activating the changes."), "need_restart")
-            if uptodate:
+            if not need_action:
                 html.icon(_("This site is up-to-date."), "siteuptodate")
 
             table.cell(_("Changes"), "%d" % len(self._changes_of_site(site_id)), css="number")
-            table.cell(_("Activate"))
-            if can_activate_all and (need_sync or need_restart):
+            if can_activate_all and need_action:
+                table.cell(_("Activate"))
                 html.jsbutton("activate_%s" % site_id, _("Activate"),
                               "activate_changes(\"site\", \"%s\")" % site_id, cssclass="activate_site")
 
+            # TODO: Cleanup
             ## Actions
             #table.cell(_("Activate"), css="buttons")
             ##if site_id not in activation_blocked_reasons.get("sites", {}):
@@ -5092,58 +5094,6 @@ class ModeAjaxStartActivation(WatoWebApiMode):
         }
 
 
-class ActivateChangesManager(object):
-    def __init__(self, sites, activate_until, comment=None, activate_foreign=False):
-        self._sites            = sites
-        self._activate_until   = activate_until
-        self._comment          = comment
-        self._activate_foreign = activate_foreign
-
-
-    # Creates the snapshot and starts the single site sync processes. In case these
-    # steps could not be started, exceptions are raised and have to be handled by
-    # the caller.
-    #
-    # On success a separate thread is started that writes it's state to a state file
-    # below "var/check_mk/wato/activation/<id>_general.state". The <id> is written to
-    # the javascript code and can be used for fetching the activation state while
-    # the activation is running.
-    #
-    # For each site a separate thread is started that controls the activation of the
-    # configuration on that site. The state is checked by the general activation
-    # thread.
-    def start(self):
-        self._create_snapshot()
-        self._start_activation()
-
-
-    # Lock WATO modifications during snapshot creation
-    def _create_snapshot(self):
-        lock_exclusive()
-
-        # TODO: Check that self._activate_until is the last made modification.
-        # If not, terminate this!
-
-        # TODO: Create the snapshot (check naming that multiple activations can be made)
-
-        unlock_exclusive()
-
-
-    def _start_activation(self):
-        for site_id in self._sites:
-            self._start_site_activation(site_id)
-
-
-    def _start_site_activation(self):
-        # TODO: Lock the site activation
-
-        # TODO: Perform the activation
-        # TODO: Confirm changes till (self._activate_until)
-
-        # TODO: Unlock site activation
-        pass
-
-
 
 class ModeAjaxActivationState(WatoWebApiMode):
     def page(self):
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 5986ad0..a105df8 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -128,6 +128,7 @@ sites_mk       = cmk.paths.default_config_dir + "/multisite.d/sites.mk"
 var_dir        = cmk.paths.var_dir + "/wato/"
 # TODO: Clean this up!
 log_dir        = var_dir + "log/"
+audit_log_path = log_dir + "audit.log"
 snapshot_dir   = var_dir + "snapshots/"
 repstatus_file = var_dir + "replication_status.mk"
 php_api_dir    = var_dir + "php-api/"
@@ -197,9 +198,8 @@ def log_entry(linkinfo, action, message, user_id=None):
     elif user_id == '':
         user_id = '-'
 
-    log_file = ModeAuditLog.log_path
-    make_nagios_directory(os.path.dirname(log_file))
-    with create_user_file(log_file, "ab") as f:
+    make_nagios_directory(os.path.dirname(audit_log_path))
+    with create_user_file(audit_log_path, "ab") as f:
         f.write("%d %s %s %s %s\n" % (int(time.time()), link, user_id, action, message))
 
 



More information about the checkmk-commits mailing list