From 0e98c1553e40e31a02548c4c89da4cf3bc5dd8d9 Mon Sep 17 00:00:00 2001 From: vapao Date: Tue, 2 Jun 2020 11:27:16 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E9=A1=B5=E9=9D=A2=E4=B8=8A=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=BE=97=E5=88=B0=E6=9B=B4=E5=A4=9A=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/schedule/executors.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spug_api/apps/schedule/executors.py b/spug_api/apps/schedule/executors.py index 6e4efaa..82affc0 100644 --- a/spug_api/apps/schedule/executors.py +++ b/spug_api/apps/schedule/executors.py @@ -3,11 +3,12 @@ # Released under the MIT License. from queue import Queue from threading import Thread -from libs.ssh import SSH +from libs.ssh import SSH, AuthenticationException from apps.host.models import Host from apps.setting.utils import AppSetting from django.db import close_old_connections import subprocess +import socket import time @@ -26,8 +27,13 @@ def host_executor(q, host, pkey, command): try: cli = SSH(host.hostname, host.port, host.username, pkey=pkey) exit_code, out = cli.exec_command(command) + out = out.decode() if out else None + except AuthenticationException: + out = 'ssh authentication fail' + except socket.error as e: + out = f'network error {e}' finally: - q.put((host.id, exit_code, round(time.time() - now, 3), out.decode() if out else None)) + q.put((host.id, exit_code, round(time.time() - now, 3), out)) def dispatch(command, targets):