Skip to content

Commit

Permalink
U - 主机管理 支持同同ip多端口主机批量执行 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Oct 28, 2019
1 parent 1d6f3e6 commit 485725d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
21 changes: 13 additions & 8 deletions spug_api/apps/assets/host_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions spug_api/libs/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spug_web/src/components/assets/HostExec.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 485725d

Please sign in to comment.