ffdc: Add examples for ffdc/plugins modules
Test:
- Standalon plugin example modules
Signed-off-by: Peter D Phan <peterp@us.ibm.com>
Change-Id: I2721ffd066fdfbf74e1b1ebc1dc46637a29ce225
diff --git a/ffdc/plugins/ssh_execution.py b/ffdc/plugins/ssh_execution.py
new file mode 100644
index 0000000..d544d58
--- /dev/null
+++ b/ffdc/plugins/ssh_execution.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+
+import os
+import sys
+
+# ---------Set sys.path for pluqin execution---------------------------------------
+# Absolute path to this plugin
+abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+# full_path to plugins parent directory
+full_path = abs_path.split('plugins')[0]
+sys.path.append(full_path)
+# Walk path and append to sys.path
+for root, dirs, files in os.walk(full_path):
+ for found_dir in dirs:
+ sys.path.append(os.path.join(root, found_dir))
+
+# ssh_utility is in ../lib
+from ssh_utility import SSHRemoteclient
+
+
+def ssh_execute_cmd(hostname,
+ username,
+ password,
+ command,
+ timeout=60):
+ r"""
+ Description of argument(s):
+
+ hostname Name/IP of the remote (targeting) host
+ username User on the remote host with access to FFCD files
+ password Password for user on remote host
+ command Command to run on remote host
+ timeout Time, in second, to wait for command completion
+ """
+ ssh_remoteclient = SSHRemoteclient(hostname,
+ username,
+ password)
+
+ cmd_exit_code = 0
+ err = ''
+ response = ''
+ if ssh_remoteclient.ssh_remoteclient_login():
+
+ """
+ cmd_exit_code: command exit status from remote host
+ err: stderr from remote host
+ response: stdout from remote host
+ """
+ cmd_exit_code, err, response = \
+ ssh_remoteclient.execute_command(command, timeout)
+
+ # Close ssh session
+ if ssh_remoteclient:
+ ssh_remoteclient.ssh_remoteclient_disconnect()
+
+ return response
diff --git a/ffdc/plugins/telnet_execution.py b/ffdc/plugins/telnet_execution.py
new file mode 100644
index 0000000..7ae23c1
--- /dev/null
+++ b/ffdc/plugins/telnet_execution.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+
+import os
+import sys
+
+# ---------Set sys.path for pluqin execution---------------------------------------
+# Absolute path to this plugin
+abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+# full_path to plugins parent directory
+full_path = abs_path.split('plugins')[0]
+sys.path.append(full_path)
+# Walk path and append to sys.path
+for root, dirs, files in os.walk(full_path):
+ for found_dir in dirs:
+ sys.path.append(os.path.join(root, found_dir))
+
+from telnet_utility import TelnetRemoteclient
+
+
+def telnet_execute_cmd(hostname,
+ username,
+ password,
+ command,
+ timeout=60):
+ r"""
+ Description of argument(s):
+
+ hostname Name/IP of the remote (targeting) host
+ username User on the remote host with access to FFCD files
+ password Password for user on remote host
+ command Command to run on remote host
+ timeout Time, in second, to wait for command completion
+ """
+ telnet_remoteclient = TelnetRemoteclient(hostname,
+ username,
+ password)
+ result = ''
+ if telnet_remoteclient.tn_remoteclient_login():
+ # result: stdout from remote host
+ result = \
+ telnet_remoteclient.execute_command(command, timeout)
+
+ # Close telnet session
+ if telnet_remoteclient:
+ telnet_remoteclient.tn_remoteclient_disconnect()
+
+ return result