1#!/usr/bin/env python3 2 3 4import os 5import sys 6 7# ---------Set sys.path for pluqin execution--------------------------------------- 8# Absolute path to this plugin 9abs_path = os.path.abspath(os.path.dirname(sys.argv[0])) 10# full_path to plugins parent directory 11full_path = abs_path.split("plugins")[0] 12sys.path.append(full_path) 13# Walk path and append to sys.path 14for root, dirs, files in os.walk(full_path): 15 for found_dir in dirs: 16 sys.path.append(os.path.join(root, found_dir)) 17 18# ssh_utility is in ../lib 19from ssh_utility import SSHRemoteclient # NOQA 20 21 22def ssh_execute_cmd( 23 hostname, username, password, command, timeout=60, type=None 24): 25 r""" 26 Description of argument(s): 27 28 hostname Name/IP of the remote (targeting) host 29 username User on the remote host with access to FFCD files 30 password Password for user on remote host 31 command Command to run on remote host 32 timeout Time, in second, to wait for command completion 33 type Data type return as list or others. 34 """ 35 ssh_remoteclient = SSHRemoteclient(hostname, username, password) 36 37 cmd_exit_code = 0 38 err = "" 39 response = "" 40 if ssh_remoteclient.ssh_remoteclient_login(): 41 """ 42 cmd_exit_code: command exit status from remote host 43 err: stderr from remote host 44 response: stdout from remote host 45 """ 46 cmd_exit_code, err, response = ssh_remoteclient.execute_command( 47 command, int(timeout) 48 ) 49 50 # Close ssh session 51 if ssh_remoteclient: 52 ssh_remoteclient.ssh_remoteclient_disconnect() 53 54 if type == "list": 55 return response.split("\n") 56 else: 57 return response 58