I have a number of devices I need to test. To do so I need to execute commands over an SSH. I'm using Python and Paramiko. Here is the question. Every time I am running a command over SSH, does Paramiko open a new SSH session and creates a new process or keeps it open until I close it? It is important for be because I will have to run thousands of tests. Opening a new session each time will take a few extra seconds. If I can save this time over thousands of tests, I can save a lot of time.
If it doesn't keep the session open, how do I keep it open so I could execute commands without logging in every time, is it even possible? If it is not possible with Paramiko, can I do it with other modules?
I found this but they all seem to be either wrappers around Paramiko or they are outdated.
Her is an example of command I'm trying to execute:
hostname = '192.168.3.4'
port = 22
username = 'username'
password = 'mypassword'
s = paramiko.SSHClient()
s.load_system_host_keys()
s.connect(hostname, port, username, password)
command = 'ls -lah'
(stdin, stdout, stderr) = s.exec_command(command)
(stdin, stdout, stderr) = s.exec_command(command)
(stdin, stdout, stderr) = s.exec_command(command)
(stdin, stdout, stderr) = s.exec_command(command)