First, we collect the connection parameters such as hostname, port, username, and password. These parameters are then passed to the print_remote_cpu_info() function.
This function creates an SSH client session by calling the transport class of paramiko. The connection is made thereafter using the supplied username and password. We can create a raw communication session using open_channel() on the SSH client. In order to execute a command on the remote host, exec_command() can be used.
After sending the command to the remote host, the response from the remote host can be caught by blocking the recv_ready() event of the session object. We can create two lists, stdout_data and stderr_data, and use them to store the remote output and error messages.
When the command exits in the remote machine, it can be detected using the exit_status_ready() method, and the remote session data can be concatenated using the join() string method.
Finally, the session and client connection can be closed using the close() method on each object.