From 0e0b125d9956b0f75472618d2b25509c29d438a5 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 10 Jan 2019 18:01:23 -0600 Subject: [PATCH] Make command configurable, for restarting tempmon-client can even configure it per client if necessary --- tailbone/templates/tempmon/clients/view.mako | 32 ++++++++------------ tailbone/views/tempmon/clients.py | 12 ++++++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tailbone/templates/tempmon/clients/view.mako b/tailbone/templates/tempmon/clients/view.mako index 362bc5dc..64116e60 100644 --- a/tailbone/templates/tempmon/clients/view.mako +++ b/tailbone/templates/tempmon/clients/view.mako @@ -1,8 +1,8 @@ ## -*- coding: utf-8; -*- <%inherit file="/master/view.mako" /> -<%def name="head_tags()"> - ${parent.head_tags()} +<%def name="extra_javascript()"> + ${parent.extra_javascript()} - - -% if instance.enabled and master.restartable_client(instance) and request.has_perm('{}.restart'.format(route_prefix)): -
-

Client Tools

-
- +<%def name="object_helpers()"> + % if instance.enabled and master.restartable_client(instance) and request.has_perm('{}.restart'.format(route_prefix)): +
+

Client Tools

+
+ +
-
-% endif + % endif + -
- ${form.render()|n} -
- -% if master.has_rows: - ${rows_grid|n} -% endif +${parent.body()} diff --git a/tailbone/views/tempmon/clients.py b/tailbone/views/tempmon/clients.py index dc5d54ce..d38d38f2 100644 --- a/tailbone/views/tempmon/clients.py +++ b/tailbone/views/tempmon/clients.py @@ -28,6 +28,7 @@ from __future__ import unicode_literals, absolute_import import subprocess +from rattail.config import parse_list from rattail_tempmon.db import model as tempmon import colander @@ -199,7 +200,8 @@ class TempmonClientView(MasterView): g.set_sort_defaults('taken', 'desc') def restartable_client(self, client): - return True + cmd = self.get_restart_cmd(client) + return bool(cmd) def restart(self): client = self.get_instance() @@ -217,7 +219,13 @@ class TempmonClientView(MasterView): return self.redirect(self.get_action_url('view', client)) def get_restart_cmd(self, client): - return ['ssh', client.hostname, 'sudo service tempmon-client restart'] + name = 'rattail.tempmon.client.restart' + cmd = self.rattail_config.get('rattail.tempmon', 'client.restart.{}'.format(client.config_key)) + if not cmd: + cmd = self.rattail_config.get('rattail.tempmon', 'client.restart') + if cmd: + cmd = cmd.format(hostname=client.hostname) + return parse_list(cmd) @classmethod def defaults(cls, config):