Module: check_mk
Branch: master
Commit: 3605225ea7a0e4fb4162e3760e89c7c441af0c30
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3605225ea7a0e4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed May 10 08:39:04 2017 +0200
4672 FIX Activation: Discard of changes is now possible again
The "discard changes" button which could be used to revert the pending
changes in WATO to the last activated configuration was removes during
1.4 development.
The main reason for this is that the snapshot feature of WATO is being
dropped and replaced in Check_MK 1.5 by some better mechanism.
Change-Id: Ic746638a44639a6fbf05d0090b8b89eba22c9f6f
---
.werks/4672 | 16 ++++++++++
web/htdocs/js/wato.js | 2 ++
web/htdocs/wato.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++---
web/htdocs/watolib.py | 28 ++++++++++-------
4 files changed, 118 insertions(+), 15 deletions(-)
diff --git a/.werks/4672 b/.werks/4672
new file mode 100644
index 0000000..3efcb69
--- /dev/null
+++ b/.werks/4672
@@ -0,0 +1,16 @@
+Title: Activation: Discard of changes is now possible again
+Level: 2
+Component: wato
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1494398195
+
+The "discard changes" button which could be used to revert the pending
+changes in WATO to the last activated configuration was removes during
+1.4 development.
+
+The main reason for this is that the snapshot feature of WATO is being
+dropped and replaced in Check_MK 1.5 by some better mechanism.
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index 3415c0d..aa28f57 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -645,6 +645,8 @@ function lock_activation_controls(lock)
var elements = [];
elements.push(document.getElementById("activate_affected"));
elements.push(document.getElementById("activate_selected"));
+ // TODO: Remove once new changes mechanism has been implemented
+ elements.push(document.getElementById("discard_changes_button"));
elements =
elements.concat(Array.prototype.slice.call(document.getElementsByName("activate_p_comment"),
0));
elements =
elements.concat(Array.prototype.slice.call(document.getElementsByClassName("site_checkbox"),
0));
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 4279ffb..226cbb3 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -5235,18 +5235,97 @@ class ModeActivateChanges(WatoMode, ActivateChanges):
def buttons(self):
home_button()
+ # TODO: Remove once new changes mechanism has been implemented
+ if config.user.may("wato.activate") and self.has_changes() and
self._get_last_wato_snapshot_file():
+ html.context_button(_("Discard Changes!"),
+ html.makeactionuri([("_action", "discard")]),
+ "discard", id="discard_changes_button")
+
if config.user.may("wato.sites"):
html.context_button(_("Site Configuration"),
folder_preserving_link([("mode", "sites")]), "sites")
if config.user.may("wato.auditlog"):
html.context_button(_("Audit Log"),
folder_preserving_link([("mode", "auditlog")]), "auditlog")
- #if config.guitests_enabled:
- # html.context_button(_("Reschedule All"),
"guitest_reschedule_all.py", "guitest")
-
def action(self):
- pass
+ if html.var("_action") != "discard":
+ return
+
+ if not html.check_transaction():
+ return
+
+ # TODO: Remove once new changes mechanism has been implemented
+ # Now remove all currently pending changes by simply restoring the last
automatically
+ # taken snapshot. Then activate the configuration. This should revert all pending
changes.
+ file_to_restore = self._get_last_wato_snapshot_file()
+
+ if not file_to_restore:
+ raise MKUserError(None, _('There is no WATO snapshot to be
restored.'))
+
+ msg = _("Discarded pending changes (Restored %s)") % file_to_restore
+
+ # All sites and domains can be affected by a restore: Better restart everything.
+ add_change("changes-discarded", msg, sites=self.activation_site_ids(),
+ domains=ConfigDomain.enabled_domains(),
+ need_restart=True)
+
+ self._extract_snapshot(file_to_restore)
+ execute_activate_changes([ d.ident for d in ConfigDomain.enabled_domains() ])
+
+ for site_id in self.activation_site_ids():
+ self.confirm_site_changes(site_id)
+
+ html.header(self.title(), javascripts=["wato"], stylesheets=wato_styles,
+ show_body_start=display_options.enabled(display_options.H),
+ show_top_heading=display_options.enabled(display_options.T))
+ html.open_div(class_="wato")
+
+ html.begin_context_buttons()
+ home_button()
+ html.end_context_buttons()
+
+ html.message(_("Successfully discarded all pending changes."))
+ html.javascript("hide_changes_buttons();")
+ html.footer()
+
+ return False
+
+
+ # TODO: Remove once new changes mechanism has been implemented
+ def _extract_snapshot(self, snapshot_file):
+ self._extract_from_file(snapshot_dir + snapshot_file, backup_domains)
+
+
+ # TODO: Remove once new changes mechanism has been implemented
+ def _extract_from_file(self, filename, elements):
+ import tarfile
+ if type(elements) == list:
+ multitar.extract(tarfile.open(filename, "r"), elements)
+
+ elif type(elements) == dict:
+ multitar.extract_domains(tarfile.open(filename, "r"), elements)
+
+
+ # TODO: Remove once new changes mechanism has been implemented
+ def _get_last_wato_snapshot_file(self):
+ for snapshot_file in self._get_snapshots():
+ status = get_snapshot_status(snapshot_file)
+ if status['type'] == 'automatic' and not
status['broken']:
+ return snapshot_file
+
+
+ # TODO: Remove once new changes mechanism has been implemented
+ def _get_snapshots(self):
+ snapshots = []
+ try:
+ for f in os.listdir(snapshot_dir):
+ if os.path.isfile(snapshot_dir + f):
+ snapshots.append(f)
+ snapshots.sort(reverse=True)
+ except OSError:
+ pass
+ return snapshots
def page(self):
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 1131060..5133622 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -218,17 +218,7 @@ def log_audit(linkinfo, action, message, user_id = None):
def confirm_all_local_changes():
- site_id = config.omd_site()
-
- try:
- os.unlink(site_changes_path(site_id))
- except OSError, e:
- if e.errno == 2:
- pass # Not existant -> OK
- else:
- raise
-
- need_sidebar_reload()
+ ActivateChanges().confirm_site_changes(config.omd_site())
#
@@ -3992,6 +3982,18 @@ class ActivateChanges(object):
return changes
+ def confirm_site_changes(self, site_id):
+ try:
+ os.unlink(site_changes_path(site_id))
+ except OSError, e:
+ if e.errno == 2:
+ pass # Not existant -> OK
+ else:
+ raise
+
+ need_sidebar_reload()
+
+
def _save_site_changes(self, site_id, changes):
# First truncate the file
open(site_changes_path(site_id), "w")
@@ -5027,6 +5029,7 @@ def execute_activate_changes(domains):
# '----------------------------------------------------------------------'
# TODO: May be removed in near future.
+# TODO: Remove once new changes mechanism has been implemented
def create_snapshot(comment):
make_nagios_directory(snapshot_dir)
@@ -5053,6 +5056,7 @@ def create_snapshot(comment):
return snapshot_name
+# TODO: Remove once new changes mechanism has been implemented
def do_create_snapshot(data):
snapshot_name = data["snapshot_name"]
snapshot_dir = cmk.paths.var_dir + "/wato/snapshots"
@@ -5141,6 +5145,7 @@ def do_create_snapshot(data):
shutil.rmtree(work_dir)
+# TODO: Remove once new changes mechanism has been implemented
def do_snapshot_maintenance():
snapshots = []
for f in os.listdir(snapshot_dir):
@@ -5157,6 +5162,7 @@ def do_snapshot_maintenance():
# Returns status information for snapshots or snapshots in progress
+# TODO: Remove once new changes mechanism has been implemented
def get_snapshot_status(snapshot, validate_checksums = False):
if type(snapshot) == tuple:
name, file_stream = snapshot