diff --git a/tailbone/templates/tempmon/clients/view.mako b/tailbone/templates/tempmon/clients/view.mako index 126c00a4..2a508f73 100644 --- a/tailbone/templates/tempmon/clients/view.mako +++ b/tailbone/templates/tempmon/clients/view.mako @@ -15,7 +15,7 @@ ${parent.body()} -% if instance.enabled and request.has_perm('tempmon.clients.restart'): +% if instance.enabled and master.restartable_client(instance) and request.has_perm('tempmon.clients.restart'):
diff --git a/tailbone/views/tempmon/clients.py b/tailbone/views/tempmon/clients.py index 92d8f062..1383f28b 100644 --- a/tailbone/views/tempmon/clients.py +++ b/tailbone/views/tempmon/clients.py @@ -105,18 +105,27 @@ class TempmonClientView(MasterView): del fs.probes del fs.online + def restartable_client(self, client): + return True + def restart(self): client = self.get_instance() - try: - subprocess.check_output(['ssh', client.hostname, 'sudo service tempmon-client restart'], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as error: - self.request.session.flash("Failed to restart client: {}".format(error.output), 'error') + if self.restartable_client(client): + try: + subprocess.check_output(get_restart_cmd(client), + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as error: + self.request.session.flash("Failed to restart client: {}".format(error.output), 'error') + else: + self.request.session.flash("Client has been restarted: {}".format( + self.get_instance_title(client))) else: - self.request.session.flash("Client has been restarted: {}".format( - self.get_instance_title(client))) + self.request.session.flash("Restart not supported for client: {}".format(client), 'error') return self.redirect(self.get_action_url('view', client)) + def get_restart_cmd(self, client): + return ['ssh', client.hostname, 'sudo service tempmon-client restart'] + @classmethod def defaults(cls, config): route_prefix = cls.get_route_prefix()