Add 'restartable tempmon client' conditional logic

This commit is contained in:
Lance Edgar 2016-12-10 11:56:25 -06:00
parent 16f00b02df
commit aa9c7abdb5
2 changed files with 17 additions and 8 deletions

View file

@ -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'):
<div class="buttons">
<button type="button" id="restart-client">Restart this Client</button>
</div>

View file

@ -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()