Drivers API¶
Drivers provide low-level hardware control and protocol implementations.
Power Drivers¶
VesyncPowerDriver¶
- class adi_lg_plugins.drivers.vesyncdriver.VesyncPowerDriver(target, name)[source]¶
Bases:
Driver,PowerResetMixin,PowerProtocolVesyncPowerDriver - Driver using a Vesync Smart Outlet to control a target’s power - https://github.com/webdjoe/pyvesync. Uses pyvesync tool to control the outlet.
- on()[source]¶
Turn on all configured VeSync outlets.
This method powers on all outlets specified in the VesyncOutlet resource configuration. If multiple outlets are configured, they will all be turned on sequentially.
- Raises:
Exception – If outlet control fails or outlets are not found.
- off()[source]¶
Turn off all configured VeSync outlets.
This method powers off all outlets specified in the VesyncOutlet resource configuration. If multiple outlets are configured, they will all be turned off sequentially.
- Raises:
Exception – If outlet control fails or outlets are not found.
- reset()[source]¶
Perform a power reset cycle on all outlets.
This method turns off the outlets, waits for the configured delay period, then turns them back on. This is useful for hard-resetting hardware.
The delay duration is configured in the VesyncOutlet resource.
- Raises:
Exception – If outlet control fails.
- cycle()[source]¶
Power cycle all outlets (same as reset).
Alias for reset(). Turns off the outlets, waits for the configured delay, then turns them back on.
- Raises:
Exception – If outlet control fails.
- get()[source]¶
Get the current power state of all outlets.
- Returns:
True if all configured outlets are on, False otherwise.
- Return type:
- __init__(target, name)¶
Method generated by attrs for class VesyncPowerDriver.
- Return type:
None
CyberPowerDriver¶
- class adi_lg_plugins.drivers.cyberpowerdriver.CyberPowerDriver(target, name)[source]¶
Bases:
Driver,PowerResetMixin,PowerProtocolCyberPowerDriver - Driver using a CyberPower PDU to control a target’s power
- __init__(target, name)¶
Method generated by attrs for class CyberPowerDriver.
- Return type:
None
- on()[source]¶
Turn on the configured CyberPower PDU outlet.
Uses SNMP to send an ‘immediateOn’ command to the outlet specified in the CyberPowerOutlet resource configuration.
- Raises:
CyberPowerPduException – If SNMP communication fails.
- off()[source]¶
Turn off the configured CyberPower PDU outlet.
Uses SNMP to send an ‘immediateOff’ command to the outlet specified in the CyberPowerOutlet resource configuration.
- Raises:
CyberPowerPduException – If SNMP communication fails.
- reset()[source]¶
Perform a power reset cycle on the outlet.
This method turns off the outlet, waits for the configured delay period, then turns it back on. Useful for hard-resetting hardware.
The delay duration is configured in the CyberPowerOutlet resource.
- Raises:
CyberPowerPduException – If SNMP communication fails.
CyberPowerPdu¶
- class adi_lg_plugins.drivers.cyberpowerdriver.CyberPowerPdu(host)[source]¶
Bases:
objectClass to query & control a CyberPower PDU via SNMP.
Tested on the PDU15SWHVIEC8FNET. I don’t understand SNMP well enough to have any idea if this would be expected to work on other models.
This class is basically just a piece of copy-pasted pysnmp code and a depository for comments.
- Parameters:
host (str) – IP address or hostname of the PDU on the network
- outlet_state_oids = {'cancelPendingCommand': 7, 'delayedOff': 5, 'delayedOn': 4, 'delayedReboot': 6, 'immediateOff': 2, 'immediateOn': 1, 'immediateReboot': 3, 'outletIdentify': 8}¶
HomeAssistantPowerDriver¶
- class adi_lg_plugins.drivers.homeassistantdriver.HomeAssistantPowerDriver(target, name)[source]¶
Bases:
Driver,PowerResetMixin,PowerProtocolHomeAssistantPowerDriver - Driver using a Home Assistant switch/outlet to control a target’s power via the Home Assistant REST API.
- get()[source]¶
Get the current power state.
- Returns:
True if the switch is on, False otherwise.
- Return type:
- __init__(target, name)¶
Method generated by attrs for class HomeAssistantPowerDriver.
- Return type:
None
HomeAssistantClient¶
Shell and File Transfer¶
ADIShellDriver¶
- class adi_lg_plugins.drivers.shelldriver.ADIShellDriver(target, name, prompt, login_prompt, username, password=None, keyfile='', login_timeout=60, console_ready='', await_login_timeout=2, post_login_settle_time=0)[source]¶
Bases:
CommandMixin,Driver,CommandProtocol,FileTransferProtocolADIShellDriver - Driver to execute commands on the shell ADIShellDriver binds on top of a ConsoleProtocol.
On activation, the ADIShellDriver will look for the login prompt on the console, and login to provide shell access.
- Parameters:
prompt (regex) – the shell prompt to detect
login_prompt (regex) – the login prompt to detect
username (str) – username to login with
password (str) – password to login with
keyfile (str) – keyfile to bind mount over users authorized keys
login_timeout (int) – optional, timeout for login prompt detection
console_ready (regex) – optional, pattern used by the kernel to inform the user that a console can be activated by pressing enter.
await_login_timeout (int) – optional, time in seconds of silence that needs to pass before sending a newline to device.
post_login_settle_time (int) – optional, seconds of silence after logging in before check for a prompt. Useful when the console is interleaved with boot output which may interrupt prompt detection.
- get_status()[source]¶
Returns the status of the shell-driver. 0 means not connected/found, 1 means shell
- put_bytes(buf, remotefile)[source]¶
Upload a file to the target. Will silently overwrite the remote file if it already exists.
- put(localfile, remotefile)[source]¶
Upload a file to the target. Will silently overwrite the remote file if it already exists.
- get_bytes(remotefile)[source]¶
Download a file from the target.
- Parameters:
remotefile (str) – source filename on the target
- Returns:
(bytes) file contents
- Raises:
ExecutionError – if something went wrong
- get(remotefile, localfile)[source]¶
Download a file from the target. Will silently overwrite the local file if it already exists.
- run_script_file(scriptfile, *args, timeout=60)[source]¶
Upload a script file to the target and run it.
- Parameters:
- Returns:
str, stderr: str, return_value: int)
- Return type:
Tuple of (stdout
- Raises:
ExecutionError – if something went wrong
IOError – if the provided localfile could not be found
- get_default_interface_device_name(version=4)[source]¶
Retrieve the default route’s interface device name.
- Parameters:
version (int) – IP version
- Returns:
Name of the device of the default route
- Raises:
ExecutionError – if no or multiple routes are set up
- get_ip_addresses(device=None)[source]¶
Retrieves IP addresses for given interface name.
Note that although the return type is named IPv4Interface/IPv6Interface, it contains an IP address with the corresponding network prefix.
- Parameters:
device (str) – Name of the interface to query, defaults to default route’s device name.
- Returns:
List of IPv4Interface or IPv6Interface objects
- get_status_uboot()[source]¶
Retrieve status of the UBootDriver. 0 means inactive, 1 means active.
- Returns:
status of the driver
- Return type:
- __init__(target, name, prompt, login_prompt, username, password=None, keyfile='', login_timeout=60, console_ready='', await_login_timeout=2, post_login_settle_time=0)¶
Method generated by attrs for class ADIShellDriver.
- Return type:
None
Storage Drivers¶
MassStorageDriver¶
- class adi_lg_plugins.drivers.massstoragedriver.MassStorageDriver(target, name)[source]¶
Bases:
DriverMassStorageDriver - Driver that manipulates a USB mass storage device. This can be used to copy/remove files from/to the device.
- unmount_partition()[source]¶
Unmount the mass storage device partition from the specified mount point.
- copy_file(src, dst)[source]¶
Copy a single file to the mass storage device.
- Parameters:
src – Source file path on the host system
dst – Destination path relative to the mass storage mount point
- __init__(target, name)¶
Method generated by attrs for class MassStorageDriver.
- Return type:
None
Kuiper Drivers¶
KuiperDLDriver¶
- class adi_lg_plugins.drivers.kuiperdldriver.KuiperDLDriver(target, name)[source]¶
Bases:
DriverKuiperDLDriver - Driver to download and manage Kuiper releases and provide files to the target device.
- sw_downloads_template = 'https://swdownloads.analog.com/cse/boot_partition_files/{release}/latest_boot_partition.tar.gz'¶
- cache_datafile = 'cache_info.json'¶
- check_cached(release_version=None)[source]¶
Check if the specified Kuiper release version is cached locally. :param release_version: Version of the Kuiper release to check. If None, uses the version from kuiper_resource. :type release_version: str
- Returns:
True if the release is cached, False otherwise.
- Return type:
- download_release(release_version=None, get_boot_files=False)[source]¶
Download the specified Kuiper release version if not already cached. :param release_version: Version of the Kuiper release to download. If None, uses the version from kuiper_resource. :type release_version: str
- add_files_to_target(filename)[source]¶
Add a file to the target device.
- Parameters:
filename (str) – Path to the file to add to the target.
- __init__(target, name)¶
Method generated by attrs for class KuiperDLDriver.
- Return type:
None
FPGA/JTAG Drivers¶
XilinxJTAGDriver¶
- class adi_lg_plugins.drivers.xilinxjtagdriver.XilinxJTAGDriver(target, name)[source]¶
Bases:
DriverXilinxJTAGDriver - Driver to program Xilinx FPGAs via JTAG using xsdb.
Supports Virtex, Artix, and Kintex FPGAs with Microblaze soft processors. Uses Xilinx xsdb (Xilinx Software Command-Line Tool) for JTAG operations.
This driver implements the boot sequence for logic-only FPGAs: 1. Flash bitstream to configure FPGA fabric and instantiate Microblaze 2. Download Linux kernel image to Microblaze memory 3. Start kernel execution 4. Disconnect from JTAG
- Bindings:
xilinxdevicejtag: XilinxDeviceJTAG resource for JTAG configuration xilinxvivado: XilinxVivadoTool resource for xsdb tool access
- bindings: Dict[str, Any] = {'xilinxdevicejtag': {'XilinxDeviceJTAG'}, 'xilinxvivado': {'XilinxVivadoTool'}}¶
- connect_jtag()[source]¶
Connect to JTAG interface.
- Raises:
ExecutionError – If JTAG connection fails.
- flash_bitstream()[source]¶
Flash the FPGA bitstream via JTAG.
Loads the bitstream file to configure the FPGA fabric and instantiate the Microblaze processor.
- Raises:
ExecutionError – If flashing fails or bitstream file not found.
- download_kernel()[source]¶
Download Linux kernel image to Microblaze processor.
Uses xsdb ‘dow’ (download) command to load the kernel into Microblaze memory. The bitstream must be flashed before calling this method.
- Raises:
ExecutionError – If download fails or kernel file not found.
- start_execution()[source]¶
Start kernel execution on Microblaze processor.
Uses xsdb ‘con’ (continue) command to begin kernel boot. The kernel must be downloaded before calling this method.
- Raises:
ExecutionError – If execution start fails.
- load_bitstream_and_kernel_and_start()[source]¶
Load bitstream and kernel in sequence and start execution.
This is a convenience method that performs the full sequence: 1. Flash bitstream 2. Download kernel 3. Start execution
- Raises:
ExecutionError – If any step in the sequence fails.
- __init__(target, name)¶
Method generated by attrs for class XilinxJTAGDriver.
- Return type:
None
Network Drivers¶
TFTPServerDriver¶
- class adi_lg_plugins.drivers.tftpserverdriver.TFTPServerDriver(target, name)[source]¶
Bases:
DriverTFTPServerDriver provides a pure Python TFTP server.
- bindings: Dict[str, Any] = {'resource': <class 'adi_lg_plugins.resources.tftpserver.TFTPServerResource'>}¶
- __init__(target, name)¶
Method generated by attrs for class TFTPServerDriver.
- Return type:
None
Utility Classes¶
- class adi_lg_plugins.drivers.kuiperdldriver.Downloader[source]¶
Utility class for downloading and verifying Kuiper Linux releases.
This class handles downloading release archives from ADI’s servers, verifying MD5 checksums, and extracting compressed archives. It supports both .xz and .zip compressed formats and displays progress bars using tqdm.
The Downloader is used internally by KuiperDLDriver but can also be used standalone via the kuiperdl CLI tool.
Example
>>> dl = Downloader() >>> rel = dl.releases("2023_R2_P1") >>> dl.download(rel["link"], rel["zipname"]) >>> dl.check(rel["zipname"], rel["zipmd5"]) >>> dl.extract(rel["zipname"], rel["imgname"])
- class adi_lg_plugins.drivers.imageextractor.IMGFileExtractor(img_path, logger=None)[source]¶
Extract files from disk image (.img) files using pytsk3.
This utility class provides methods to inspect partitions, list files, and extract individual files or directories from disk image files without mounting them. It’s primarily used by KuiperDLDriver to extract boot files from Kuiper Linux release images.
- Parameters:
img_path (str) – Path to the disk image file.
logger (Logger, optional) – Logger instance for debug output. If None, prints to stdout.
Example
>>> extractor = IMGFileExtractor("kuiper.img") >>> partitions = extractor.get_partitions() >>> fs = extractor.open_filesystem(partitions[0]["start"]) >>> extractor.extract_file(fs, "/Image", "./output/Image") >>> extractor.close()
Software Installer¶
SoftwareInstallerDriver¶
- class adi_lg_plugins.drivers.softwareinstaller.SoftwareInstallerDriver(target, name)[source]¶
Bases:
DriverSoftwareInstallerDriver - Driver to install software, clone repos, copy directories, and run builds/tests on a DUT.
- bindings: Dict[str, Any] = {'command': <class 'labgrid.protocol.commandprotocol.CommandProtocol'>, 'file_transfer': <class 'labgrid.protocol.filetransferprotocol.FileTransferProtocol'>}¶
- install_package(package_name, update=False)[source]¶
Installs a package using the detected package manager.
- __init__(target, name)¶
Method generated by attrs for class SoftwareInstallerDriver.
- Return type:
None