mirror of https://github.com/openspug/spug
U 批量执行输出内容自适应屏幕宽度
parent
93a5beb43d
commit
9ca6e1dee8
|
@ -14,8 +14,9 @@ def exec_worker_handler(job):
|
||||||
|
|
||||||
|
|
||||||
class Job:
|
class Job:
|
||||||
def __init__(self, key, name, hostname, port, username, pkey, command, interpreter, params=None, token=None):
|
def __init__(self, key, name, hostname, port, username, pkey, command, interpreter, params=None, token=None,
|
||||||
self.ssh = SSH(hostname, port, username, pkey)
|
term=None):
|
||||||
|
self.ssh = SSH(hostname, port, username, pkey, term=term)
|
||||||
self.key = key
|
self.key = key
|
||||||
self.command = self._handle_command(command, interpreter)
|
self.command = self._handle_command(command, interpreter)
|
||||||
self.token = token
|
self.token = token
|
||||||
|
|
|
@ -92,9 +92,14 @@ class TaskView(View):
|
||||||
@auth('exec.task.do')
|
@auth('exec.task.do')
|
||||||
def patch(self, request):
|
def patch(self, request):
|
||||||
form, error = JsonParser(
|
form, error = JsonParser(
|
||||||
Argument('token', help='参数错误')
|
Argument('token', help='参数错误'),
|
||||||
|
Argument('cols', type=int, required=False),
|
||||||
|
Argument('rows', type=int, required=False)
|
||||||
).parse(request.body)
|
).parse(request.body)
|
||||||
if error is None:
|
if error is None:
|
||||||
|
term = None
|
||||||
|
if form.cols and form.rows:
|
||||||
|
term = {'width': form.cols, 'height': form.rows}
|
||||||
rds = get_redis_connection()
|
rds = get_redis_connection()
|
||||||
task = ExecHistory.objects.get(digest=form.token)
|
task = ExecHistory.objects.get(digest=form.token)
|
||||||
for host in Host.objects.filter(id__in=json.loads(task.host_ids)):
|
for host in Host.objects.filter(id__in=json.loads(task.host_ids)):
|
||||||
|
@ -108,7 +113,8 @@ class TaskView(View):
|
||||||
username=host.username,
|
username=host.username,
|
||||||
command=task.command,
|
command=task.command,
|
||||||
pkey=host.private_key,
|
pkey=host.private_key,
|
||||||
params=json.loads(task.params)
|
params=json.loads(task.params),
|
||||||
|
term=term
|
||||||
)
|
)
|
||||||
rds.rpush(settings.EXEC_WORKER_KEY, json.dumps(data))
|
rds.rpush(settings.EXEC_WORKER_KEY, json.dumps(data))
|
||||||
return json_response(error=error)
|
return json_response(error=error)
|
||||||
|
|
|
@ -52,12 +52,13 @@ AuthHandler._finalize_pubkey_algorithm = _finalize_pubkey_algorithm
|
||||||
|
|
||||||
class SSH:
|
class SSH:
|
||||||
def __init__(self, hostname, port=22, username='root', pkey=None, password=None, default_env=None,
|
def __init__(self, hostname, port=22, username='root', pkey=None, password=None, default_env=None,
|
||||||
connect_timeout=10):
|
connect_timeout=10, term=None):
|
||||||
self.stdout = None
|
self.stdout = None
|
||||||
self.client = None
|
self.client = None
|
||||||
self.channel = None
|
self.channel = None
|
||||||
self.sftp = None
|
self.sftp = None
|
||||||
self.exec_file = None
|
self.exec_file = None
|
||||||
|
self.term = term or {}
|
||||||
self.eof = 'Spug EOF 2108111926'
|
self.eof = 'Spug EOF 2108111926'
|
||||||
self.default_env = default_env
|
self.default_env = default_env
|
||||||
self.regex = re.compile(r'Spug EOF 2108111926 (-?\d+)[\r\n]?')
|
self.regex = re.compile(r'Spug EOF 2108111926 (-?\d+)[\r\n]?')
|
||||||
|
@ -179,7 +180,7 @@ class SSH:
|
||||||
return self.channel
|
return self.channel
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
self.channel = self.client.invoke_shell()
|
self.channel = self.client.invoke_shell(**self.term)
|
||||||
command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n'
|
command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n'
|
||||||
command = self._handle_command(command, self.default_env)
|
command = self._handle_command(command, self.default_env)
|
||||||
self.channel.sendall(command)
|
self.channel.sendall(command)
|
||||||
|
|
|
@ -64,7 +64,9 @@ function OutView(props) {
|
||||||
term.write(message)
|
term.write(message)
|
||||||
socket.send('ok');
|
socket.send('ok');
|
||||||
fitPlugin.fit()
|
fitPlugin.fit()
|
||||||
http.patch('/api/exec/do/', {token: store.token})
|
const formData = fitPlugin.proposeDimensions()
|
||||||
|
formData.token = store.token
|
||||||
|
http.patch('/api/exec/do/', formData)
|
||||||
}
|
}
|
||||||
socket.onmessage = e => {
|
socket.onmessage = e => {
|
||||||
if (e.data === 'pong') {
|
if (e.data === 'pong') {
|
||||||
|
|
Loading…
Reference in New Issue