msl.network.ssh module
Helper functions for connecting to a remote computer via SSH.
Follow these instructions to install/enable an SSH server on Windows. You can also create an SSH server using the paramiko package (which is included when MSL-Network is installed).
The two functions start_manager()
and parse_console_script_kwargs()
are meant to be used together to automatically start a Network
Manager
, and possibly
Service
s, on a remote computer.
See Starting a Service from another computer for an example on how to start a Service
on a Raspberry Pi from another computer.
- msl.network.ssh.parse_console_script_kwargs()[source]
Parses the command line for keyword arguments sent from a remote computer.
New in version 0.4.
- Returns:
dict
– The keyword arguments that were passed fromstart_manager()
.
- msl.network.ssh.start_manager(host, console_script_path, *, ssh_username=None, ssh_password=None, timeout=10, as_sudo=False, missing_host_key_policy=None, paramiko_kwargs=None, **kwargs)[source]
Start a Network
Manager
on a remote computer.New in version 0.4.
- Parameters:
host (
str
) – The hostname (or IP address) of the remote computer. For example –'192.168.1.100'
,'raspberrypi'
,'pi@raspberrypi'
console_script_path (
str
) – The file path to where the console script is located on the remote computer.ssh_username (
str
, optional) – The username to use to establish the SSH connection. IfNone
and the ssh_username is not specified in host then you will be asked for the ssh_username.ssh_password (
str
, optional) – The password to use to establish the SSH connection. IfNone
then you will be asked for the ssh_password.timeout (
int
orfloat
, optional) – The maximum number of seconds to wait for the SSH connection.as_sudo (
bool
, optional) – Whether to run the console script as a superuser.missing_host_key_policy (
MissingHostKeyPolicy
, optional) – The policy to use when connecting to servers without a known host key. IfNone
then usesAutoAddPolicy
.paramiko_kwargs (
dict
, optional) – Additional keyword arguments that are passed tossh.connect
.kwargs – The keyword arguments in
run_forever()
, and if that console script also startsService
s on the remote computer as well, then the keyword arguments also found instart()
. The kwargs should be parsed byparse_console_script_kwargs()
on the remote computer.
- msl.network.ssh.connect(host, *, username=None, password=None, timeout=10, missing_host_key_policy=None, **kwargs)[source]
SSH to a remote computer.
New in version 0.4.
- Parameters:
host (
str
) – The hostname (or IP address) of the remote computer. For example –'192.168.1.100'
,'raspberrypi'
,'pi@raspberrypi'
username (
str
, optional) – The username to use to establish the SSH connection. IfNone
and the username is not specified in host then you will be asked for the username.password (
str
, optional) – The password to use to establish the SSH connection. IfNone
then you will be asked for the password.timeout (
int
orfloat
, optional) – The maximum number of seconds to wait for the SSH connection.missing_host_key_policy (
MissingHostKeyPolicy
, optional) – The policy to use when connecting to servers without a known host key. IfNone
then usesAutoAddPolicy
.kwargs – Additional keyword arguments that are passed to
SSHClient.connect
.
- Returns:
- msl.network.ssh.exec_command(ssh_client, command, *, timeout=10)[source]
Execute the SSH command on the remote computer.
New in version 0.4.
- Parameters:
- Raises:
RuntimeError – If an error occurred. Either a timeout or stderr on the remote computer contains text from executing the command.
- Returns: