A api add schedule time

pull/22/head
雷二猛 2019-11-29 13:53:58 +08:00
parent 25dd1f0216
commit 876ca336c9
1 changed files with 5 additions and 4 deletions

View File

@ -4,25 +4,26 @@ from libs.ssh import SSH
from apps.host.models import Host
from apps.setting.utils import AppSetting
import subprocess
import time
def local_executor(q, command):
exit_code, out = -1, None
exit_code, out, now = -1, None, time.time()
try:
task = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
exit_code = task.wait()
out = task.stdout.read() + task.stderr.read()
finally:
q.put(('local', exit_code, out.decode()))
q.put(('local', exit_code, time.time() - now, out.decode()))
def host_executor(q, host, pkey, command):
exit_code, out = -1, None
exit_code, out, now = -1, None, time.time()
try:
cli = SSH(host.hostname, host.port, host.username, pkey=pkey)
exit_code, out = cli.exec_command(command)
finally:
q.put((host.id, exit_code, out.decode()))
q.put((host.id, exit_code, time.time() - now, out.decode()))
def dispatch(command, targets):