blob: 8318337de3128e7b9dd1f8a2400fa90c9cd57eb3 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Peter D Phan2f3a96e2021-07-29 12:12:02 -05002
3
4import os
5import sys
6
George Keishingc754b432025-04-24 14:27:14 +05307# ---------Set sys.path for pluqin execution----------------------------------
Peter D Phan2f3a96e2021-07-29 12:12:02 -05008# Absolute path to this plugin
9abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
10# full_path to plugins parent directory
Patrick Williams20f38712022-12-08 06:18:26 -060011full_path = abs_path.split("plugins")[0]
Peter D Phan2f3a96e2021-07-29 12:12:02 -050012sys.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
George Keishing09679892022-12-08 08:21:52 -060018from telnet_utility import TelnetRemoteclient # NOQA
George Keishing37c58c82022-12-08 07:42:54 -060019
Peter D Phan2f3a96e2021-07-29 12:12:02 -050020
Patrick Williams20f38712022-12-08 06:18:26 -060021def telnet_execute_cmd(hostname, username, password, command, timeout=60):
Peter D Phan2f3a96e2021-07-29 12:12:02 -050022 r"""
Patrick Williams20f38712022-12-08 06:18:26 -060023 Description of argument(s):
Peter D Phan2f3a96e2021-07-29 12:12:02 -050024
Patrick Williams20f38712022-12-08 06:18:26 -060025 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
Peter D Phan2f3a96e2021-07-29 12:12:02 -050030 """
Patrick Williams20f38712022-12-08 06:18:26 -060031 telnet_remoteclient = TelnetRemoteclient(hostname, username, password)
32 result = ""
Peter D Phan2f3a96e2021-07-29 12:12:02 -050033 if telnet_remoteclient.tn_remoteclient_login():
34 # result: stdout from remote host
Patrick Williams20f38712022-12-08 06:18:26 -060035 result = telnet_remoteclient.execute_command(command, timeout)
Peter D Phan2f3a96e2021-07-29 12:12:02 -050036
37 # Close telnet session
38 if telnet_remoteclient:
39 telnet_remoteclient.tn_remoteclient_disconnect()
40
41 return result