Module: check_mk
Branch: master
Commit: f2ca67a691fb09cb68c51d7ab229657044578eaa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f2ca67a691fb09…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 5 18:02:54 2018 +0200
Centralized background job detail url computation
Change-Id: Id390fde3b160cef8697d08d8d2b6941ad92bbe19
---
cmk/gui/gui_background_job.py | 14 +++++++++++
cmk/gui/userdb.py | 4 +++
cmk/gui/wato/__init__.py | 48 ++++++++++++++++--------------------
cmk/gui/wato/pages/bulk_discovery.py | 9 ++-----
cmk/gui/wato/pages/users.py | 6 ++---
5 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/cmk/gui/gui_background_job.py b/cmk/gui/gui_background_job.py
index 1564a9b..ada2388 100644
--- a/cmk/gui/gui_background_job.py
+++ b/cmk/gui/gui_background_job.py
@@ -183,6 +183,20 @@ class GUIBackgroundJob(GUIBackgroundJobSnapshottedFunctions):
self.update_status({"acknowledged_by": user_id})
+ def detail_url(self):
+ """Returns the URL that displays the job detail
page"""
+ return html.makeuri_contextless([
+ ("mode", "background_job_details"),
+ ("job_id", self.get_job_id()),
+ ("back_url", self._back_url()),
+ ], filename="wato.py")
+
+
+ def _back_url(self):
+ """Returns either None or the URL that the job detail page may be
link back"""
+ return None
+
+
@classmethod
def get_concrete_subclasses(cls):
# Note: Due to the strange execfile plugin mechanism, there is a risk
diff --git a/cmk/gui/userdb.py b/cmk/gui/userdb.py
index 91657ab..de4ba97 100644
--- a/cmk/gui/userdb.py
+++ b/cmk/gui/userdb.py
@@ -1330,6 +1330,10 @@ class UserSyncBackgroundJob(gui_background_job.GUIBackgroundJob):
super(UserSyncBackgroundJob, self).__init__(self.job_prefix, **kwargs)
+ def _back_url(self):
+ return html.makeuri_contextless([("mode", "users")],
filename="wato.py")
+
+
def do_sync(self, job_interface, add_to_changelog, enforce_sync):
job_interface.send_progress_update(_("Synchronization started..."))
if self._execute_sync_action(job_interface, add_to_changelog, enforce_sync):
diff --git a/cmk/gui/wato/__init__.py b/cmk/gui/wato/__init__.py
index a529deb..100f63d 100644
--- a/cmk/gui/wato/__init__.py
+++ b/cmk/gui/wato/__init__.py
@@ -324,6 +324,21 @@ class RenameHostsBackgroundJob(WatoBackgroundJob):
raise MKGeneralException(_("Another renaming operation is currently in
progress"))
+ def _back_url(self):
+ return html.makeuri([])
+
+
+
+class RenameHostBackgroundJob(RenameHostsBackgroundJob):
+ def __init__(self, host, title=None):
+ super(RenameHostBackgroundJob, self).__init__(title)
+ self._host = host
+
+
+ def _back_url(self):
+ return self._host.folder().url()
+
+
#.
# .--Main----------------------------------------------------------------.
# | __ __ _ |
@@ -1861,11 +1876,7 @@ class ModeBulkRenameHost(WatoMode):
html.context_button(_("Folder"),
watolib.folder_preserving_link([("mode", "folder")]),
"back")
host_renaming_job = RenameHostsBackgroundJob()
if host_renaming_job.is_available():
- html.context_button(_("Last result"), html.makeuri([
- ("mode", "background_job_details"),
- ("job_id", host_renaming_job.get_job_id()),
- ("back_url", html.makeuri([])),
- ], filename="wato.py"), "background_job_details")
+ html.context_button(_("Last result"),
host_renaming_job.detail_url(), "background_job_details")
def action(self):
@@ -1897,13 +1908,7 @@ class ModeBulkRenameHost(WatoMode):
except background_job.BackgroundJobAlreadyRunning, e:
raise MKGeneralException(_("Another host renaming job is already
running: %s") % e)
- job_id = host_renaming_job.get_job_id()
- job_details_url = html.makeuri_contextless([
- ("mode", "background_job_details"),
- ("job_id", job_id),
- ("back_url", html.makeuri([])),
- ], filename="wato.py")
- html.response.http_redirect(job_details_url)
+ html.response.http_redirect(host_renaming_job.detail_url())
elif c == False: # not yet confirmed
return ""
else:
@@ -2138,13 +2143,9 @@ class ModeRenameHost(WatoMode):
global_buttons()
html.context_button(_("Host Properties"), self._host.edit_url(),
"back")
- host_renaming_job = RenameHostsBackgroundJob()
+ host_renaming_job = RenameHostBackgroundJob(self._host)
if host_renaming_job.is_available():
- html.context_button(_("Last result"), html.makeuri([
- ("mode", "background_job_details"),
- ("job_id", host_renaming_job.get_job_id()),
- ("back_url", html.makeuri([])),
- ], filename="wato.py"), "background_job_details")
+ html.context_button(_("Last result"),
host_renaming_job.detail_url(), "background_job_details")
def action(self):
@@ -2160,7 +2161,7 @@ class ModeRenameHost(WatoMode):
if c:
# Creating pending entry. That makes the site dirty and that will force a
sync of
# the config to that site before the automation is being done.
- host_renaming_job = RenameHostsBackgroundJob(title=_("Renaming of %s
-> %s") % (self._host.name(), newname))
+ host_renaming_job = RenameHostBackgroundJob(self._host,
title=_("Renaming of %s -> %s") % (self._host.name(), newname))
renamings = [(watolib.Folder.current(), self._host.name(), newname)]
host_renaming_job.set_function(rename_hosts_background_job, renamings)
@@ -2169,14 +2170,7 @@ class ModeRenameHost(WatoMode):
except background_job.BackgroundJobAlreadyRunning, e:
raise MKGeneralException(_("Another host renaming job is already
running: %s") % e)
- job_id = host_renaming_job.get_job_id()
-
- job_details_url = html.makeuri_contextless([
- ("mode", "background_job_details"),
- ("job_id", job_id),
- ("back_url", self._host.folder().url()),
- ], filename="wato.py")
- html.response.http_redirect(job_details_url)
+ html.response.http_redirect(host_renaming_job.detail_url())
elif c == False: # not yet confirmed
return ""
diff --git a/cmk/gui/wato/pages/bulk_discovery.py b/cmk/gui/wato/pages/bulk_discovery.py
index 9d40a8f..9ff0949 100644
--- a/cmk/gui/wato/pages/bulk_discovery.py
+++ b/cmk/gui/wato/pages/bulk_discovery.py
@@ -65,13 +65,8 @@ class BulkDiscoveryBackgroundJob(WatoBackgroundJob):
super(BulkDiscoveryBackgroundJob, self).__init__(self.job_prefix, **kwargs)
- # TODO: Move something like this to one of the parent classes
- def detail_url(self):
- return html.makeuri_contextless([
- ("mode", "background_job_details"),
- ("job_id", self.get_job_id()),
- ("back_url", watolib.Folder.current().url()),
- ], filename="wato.py")
+ def _back_url(self):
+ return watolib.Folder.current().url()
def do_execute(self, mode, use_cache, do_scan, error_handling, tasks,
job_interface=None):
diff --git a/cmk/gui/wato/pages/users.py b/cmk/gui/wato/pages/users.py
index 07b90fb..72ca9fa 100644
--- a/cmk/gui/wato/pages/users.py
+++ b/cmk/gui/wato/pages/users.py
@@ -85,6 +85,7 @@ class ModeUsers(WatoMode):
def __init__(self):
super(ModeUsers, self).__init__()
+ self._job = userdb.UserSyncBackgroundJob()
self._job_snapshot = userdb.UserSyncBackgroundJob().get_status_snapshot()
@@ -100,7 +101,7 @@ class ModeUsers(WatoMode):
if userdb.sync_possible():
if not self._job_snapshot.is_running():
html.context_button(_("Sync users"),
html.makeactionuri([("_sync", 1)]), "replicate")
- html.context_button(_("Last sync result"),
self._job_details_url(), "background_job_details")
+ html.context_button(_("Last sync result"),
self._job.detail_url(), "background_job_details")
if config.user.may("general.notify"):
@@ -189,8 +190,7 @@ class ModeUsers(WatoMode):
def _job_details_link(self):
- job = userdb.UserSyncBackgroundJob().get_status_snapshot()
- return html.render_a("%s" % job.get_title(),
href=self._job_details_url())
+ return html.render_a("%s" % self._job.get_title(),
href=self._job.detail_url())
def _job_details_url(self):