U - 主机管理 支持同同ip多端口主机批量执行 #17

1.x v1.2.0
雷二猛 2019-10-28 13:35:57 +08:00
parent 1d6f3e66c1
commit 485725d185
3 changed files with 17 additions and 11 deletions

View File

@ -95,11 +95,16 @@ def exec_host_command():
def hosts_exec(q, ip, port, command):
ssh_client = get_ssh_client(ip, port)
q.destroyed.append(ssh_client.close)
output = ssh_exec_command_with_stream(ssh_client, command)
for line in output:
q.put({ip: line})
q.put({ip: '\n** 执行完成 **'})
q.done()
key = '%s:%s' % (ip, port)
try:
ssh_client = get_ssh_client(ip, port)
q.destroyed.append(ssh_client.close)
output = ssh_exec_command_with_stream(ssh_client, command)
for line in output:
q.put({key: line})
q.put({key: '\n** 执行完成 **'})
q.done()
except Exception as e:
q.put({key: '%s\n' % e})
q.put({key: '\n** 执行异常结束 **'})
q.done()

View File

@ -38,6 +38,7 @@ def get_ssh_client(hostname, port):
hostname,
port=port,
username='root',
timeout=5,
pkey=RSAKey.from_private_key(StringIO(Setting.ssh_private_key)))
return ssh_client

View File

@ -168,11 +168,11 @@
<el-collapse>
<el-collapse-item v-for="i in multipleSelection" :key="i.ip" :name="i.ip">
<template slot="title">
<el-tag type="info" style="margin-right: 15px">{{ i.name + '(' + i.ssh_ip + ')'}}</el-tag>
<el-tag type="info" style="margin-right: 15px">{{`${i.name}(${i.ssh_ip}:${i.ssh_port})`}}</el-tag>
</template>
<pre>** 开始执行 **
<template v-for="line in exec_output"><span v-if="line[i.ssh_ip]">{{line[i.ssh_ip]}}</span></template>
<template v-for="line in exec_output"><span v-if="line[`${i.ssh_ip}:${i.ssh_port}`]">{{line[`${i.ssh_ip}:${i.ssh_port}`]}}</span></template>
</pre>
</el-collapse-item>
</el-collapse>
@ -313,7 +313,7 @@
save_select_host() {
let hosts = [], hosts_id = [];
for (let v of this.multipleSelection) {
hosts.push( v.name + '(' + v.ssh_ip + ')');
hosts.push(`${v.name}(${v.ssh_ip}:${v.ssh_port})`);
hosts_id.push(v.id);
}
this.selected_host_id = hosts_id;