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()} ${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"> <div class="buttons">
<button type="button" id="restart-client">Restart this Client</button> <button type="button" id="restart-client">Restart this Client</button>
</div> </div>

View file

@ -105,18 +105,27 @@ class TempmonClientView(MasterView):
del fs.probes del fs.probes
del fs.online del fs.online
def restartable_client(self, client):
return True
def restart(self): def restart(self):
client = self.get_instance() client = self.get_instance()
try: if self.restartable_client(client):
subprocess.check_output(['ssh', client.hostname, 'sudo service tempmon-client restart'], try:
stderr=subprocess.STDOUT) subprocess.check_output(get_restart_cmd(client),
except subprocess.CalledProcessError as error: stderr=subprocess.STDOUT)
self.request.session.flash("Failed to restart client: {}".format(error.output), 'error') 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: else:
self.request.session.flash("Client has been restarted: {}".format( self.request.session.flash("Restart not supported for client: {}".format(client), 'error')
self.get_instance_title(client)))
return self.redirect(self.get_action_url('view', client)) 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 @classmethod
def defaults(cls, config): def defaults(cls, config):
route_prefix = cls.get_route_prefix() route_prefix = cls.get_route_prefix()