diff --git a/spug_api/apps/assets/host_exec.py b/spug_api/apps/assets/host_exec.py index ca88ef8..bd70562 100644 --- a/spug_api/apps/assets/host_exec.py +++ b/spug_api/apps/assets/host_exec.py @@ -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() diff --git a/spug_api/libs/ssh/__init__.py b/spug_api/libs/ssh/__init__.py index 83e675f..d116602 100644 --- a/spug_api/libs/ssh/__init__.py +++ b/spug_api/libs/ssh/__init__.py @@ -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 diff --git a/spug_web/src/components/assets/HostExec.vue b/spug_web/src/components/assets/HostExec.vue index c7443c7..f20ed66 100644 --- a/spug_web/src/components/assets/HostExec.vue +++ b/spug_web/src/components/assets/HostExec.vue @@ -168,11 +168,11 @@
** 开始执行 **
 
-                        
+                        
                     
@@ -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;