mirror of https://github.com/openspug/spug
A api add schedule time
parent
25dd1f0216
commit
876ca336c9
|
@ -4,25 +4,26 @@ from libs.ssh import SSH
|
||||||
from apps.host.models import Host
|
from apps.host.models import Host
|
||||||
from apps.setting.utils import AppSetting
|
from apps.setting.utils import AppSetting
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
def local_executor(q, command):
|
def local_executor(q, command):
|
||||||
exit_code, out = -1, None
|
exit_code, out, now = -1, None, time.time()
|
||||||
try:
|
try:
|
||||||
task = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
task = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
exit_code = task.wait()
|
exit_code = task.wait()
|
||||||
out = task.stdout.read() + task.stderr.read()
|
out = task.stdout.read() + task.stderr.read()
|
||||||
finally:
|
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):
|
def host_executor(q, host, pkey, command):
|
||||||
exit_code, out = -1, None
|
exit_code, out, now = -1, None, time.time()
|
||||||
try:
|
try:
|
||||||
cli = SSH(host.hostname, host.port, host.username, pkey=pkey)
|
cli = SSH(host.hostname, host.port, host.username, pkey=pkey)
|
||||||
exit_code, out = cli.exec_command(command)
|
exit_code, out = cli.exec_command(command)
|
||||||
finally:
|
finally:
|
||||||
q.put((host.id, exit_code, out.decode()))
|
q.put((host.id, exit_code, time.time() - now, out.decode()))
|
||||||
|
|
||||||
|
|
||||||
def dispatch(command, targets):
|
def dispatch(command, targets):
|
||||||
|
|
Loading…
Reference in New Issue