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 18from telnet_utility import TelnetRemoteclient # NOQA 19 20 21def telnet_execute_cmd(hostname, username, password, command, timeout=60): 22 r""" 23 Description of argument(s): 24 25 hostname Name/IP of the remote (targeting) host 26 username User on the remote host with access to FFCD files 27 password Password for user on remote host 28 command Command to run on remote host 29 timeout Time, in second, to wait for command completion 30 """ 31 telnet_remoteclient = TelnetRemoteclient(hostname, username, password) 32 result = "" 33 if telnet_remoteclient.tn_remoteclient_login(): 34 # result: stdout from remote host 35 result = telnet_remoteclient.execute_command(command, timeout) 36 37 # Close telnet session 38 if telnet_remoteclient: 39 telnet_remoteclient.tn_remoteclient_disconnect() 40 41 return result 42