snap
Remote Snapshot Execution for GONet Devices.
This script provides functionality to remotely run the gonet4.py imaging script on a GONet device, optionally upload a local configuration file, and download newly created image files. It handles SSH and SCP connections securely and efficiently, including file hashing to avoid redundant uploads.
Functions
list_remote_files()
: Lists files in a remote directory.get_local_file_hash()
: Computes a hash of a local file.get_remote_file_hash()
: Retrieves the hash of a remote file.upload_if_different()
: Uploads a file only if it differs from the remote version.run_remote_script_with_live_output()
: Executes a command remotely with live output streaming.snap()
: Main entry point to execute a snapshot and transfer resulting images.
Functions:
- GONet_Wizard.commands.snap.list_remote_files(ssh, folder)[source]
List files in a remote folder using SSH.
- Parameters:
ssh (
paramiko.client.SSHClient
) – An active SSH client connection to the remote GONet device.folder (
str
) – Path to the remote folder to list.
- Returns:
A set of filenames found in the remote folder.
- Return type:
- GONet_Wizard.commands.snap.get_local_file_hash(filepath, algo='sha256')[source]
Compute the hash of a local file.
- GONet_Wizard.commands.snap.get_remote_file_hash(ssh, remote_path, algo='sha256')[source]
Compute the hash of a remote file using SSH.
- Parameters:
ssh (
paramiko.client.SSHClient
) – An active SSH client connection.remote_path (
str
) – Path to the remote file.algo (
str
, optional) – Hashing algorithm (default is ‘sha256’).
- Returns:
The remote file’s hash, or None if the file does not exist or cannot be read.
- Return type:
str
orNone
- GONet_Wizard.commands.snap.upload_if_different(ssh, local_path, remote_path)[source]
Upload a file only if it differs from the remote version.
- Parameters:
ssh (
paramiko.client.SSHClient
) – SSH connection to the GONet device.local_path (
str
) – Path to the local file.remote_path (
str
) – Destination path on the remote device.
- Return type:
None
- GONet_Wizard.commands.snap.run_remote_script_with_live_output(ssh, command)[source]
Run a remote command and stream stdout in real time.
- Parameters:
ssh (
paramiko.client.SSHClient
) – SSH connection to the GONet device.command (
str
) – The command to run remotely.
- Return type:
None
- GONet_Wizard.commands.snap.take_snapshot(ssh, config_file_path=None)[source]
Run the GONet imaging script remotely and download new files.
This function: - Checks current files in the image folder - Optionally uploads a config file if provided - Executes gonet4.py on the remote device - Downloads any newly created image files to the local machine
- Parameters:
ssh (
paramiko.client.SSHClient
) – SSH connection (automatically provided by the decorator).config_file_path (
str
, optional) – Local path to a configuration file to be used with gonet4.py.
- Return type:
None
Notes
Files are downloaded to the folder defined by
LOCAL_OUTPUT_FOLDER
.Requires appropriate environment variables as defined in
GONet_Wizard.commands.settings.GONetConfig
.