A Device in Moler serves two roles simultaneously:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nokia/moler/llms.txt
Use this file to discover all available pages before exploring further.
- State machine — tracks which shell/environment the connection is currently in (e.g. local shell, remote SSH, root prompt) and can automatically navigate between states.
- Factory — produces
CommandandEventobjects pre-configured for the connection and current state.
goto_state("UNIX_REMOTE") and get_cmd("ls") without knowing anything about how SSH is invoked or which prompt regex to match.
Getting a device
Devices are retrieved viaDeviceFactory.get_device(). The first call creates the device and opens its connection; subsequent calls with the same name return the cached instance.
YAML configuration
Device definitions live in a YAML config file. TheDEVICE_CLASS key names the Python class; CONNECTION_HOPS describes how to move between states.
States and transitions
Every device starts life in theNOT_CONNECTED state. When a connection is opened the device moves to its initial state (e.g. UNIX_LOCAL). Call goto_state() to move to any reachable state — the device works out the intermediate hops automatically.
Standard states
| State | Description |
|---|---|
NOT_CONNECTED | No connection open. All devices start here. |
UNIX_LOCAL | Local shell on the machine running the test. |
UNIX_LOCAL_ROOT | Root shell on the local machine (via su). |
UNIX_REMOTE | Remote Unix shell (reached via SSH or telnet). |
PROXY_PC | Intermediate jump host. |
ADB_SHELL, AT_REMOTE, SCPI) are defined by their respective device classes.
goto_state() parameters
Getting commands and events
Useget_cmd() and get_event() to obtain objects bound to the device’s connection and current state.
cmd_name is the class name (without package), e.g. "ps", "ls", "ssh", "ping". Commands are resolved from the packages associated with the current state.
You can also use the shorthand run() which creates, runs, and returns the result in one call:
Available device types
| Class | Module | Description |
|---|---|---|
UnixLocal | moler.device.unixlocal | Local Unix shell |
UnixRemote | moler.device.unixremote | Remote Unix shell (via SSH) |
AdbRemote | moler.device.adbremote | Android Debug Bridge shell |
JuniperGeneric | moler.device.junipergeneric | Juniper network device |
AtRemote | moler.device.atremote | AT command interface |
Scpi | moler.device.scpi | SCPI instrument interface |
PduAten | moler.device.pdu_aten | ATEN PDU power device |
ProxyPc | moler.device.proxy_pc | Jump-host / proxy PC |
Logging
Each device automatically creates two log files when theLOGGER section is present in the config:
moler.log— high-level activity across all devicesmoler.<DeviceName>.log— all raw I/O and command activity for that device
Removing devices
When a device is no longer needed, remove it to close the connection and finish any running commands or events:Commands
What get_cmd() returns and how to run it
Connections
The underlying IO layer devices use