A Command in Moler is a subclass ofDocumentation 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.
ConnectionObserver that actively sends a command string over a connection and parses the resulting output. Unlike a plain ConnectionObserver (which passively watches), a Command is the active counterpart: it triggers output on the device by writing to the connection, then collects and parses whatever comes back.
Each Command encapsulates three concerns in a single object:
- Triggering — sends the command string via
connection.sendline(self.command_string) - Parsing — implements
data_received()to extract structured data from the device output - Storing the result — calls
set_result()when parsing is complete
The Future/Promise pattern
Commands implement the Futures and promises pattern. Running a command and parsing its output takes time, so the result is not available immediately after calling the command. Moler exposes this explicitly through two execution modes.- Blocking (callable)
- Non-blocking (start + await_done)
Call the command object directly like a function. It runs in the foreground and blocks until the command finishes, then returns the result.This is the simplest usage: create, call, process the result.
Command lifecycle
Start (or call)
Either call the command directly (blocking) or call
start() to run it in the background. On start, Moler sends command_string over the connection.Data received and parsed
As data arrives from the connection,
data_received(data, recv_time) is called. The command parses each chunk and accumulates the result internally.Results are dicts (or lists of dicts)
Commands return structured Python objects — almost alwaysdict or list[dict] — making results easy to process in test code.
Running commands in parallel
Because commands implement the Future pattern, multiple commands can run concurrently. Start them all in the background, then await each result:A command object cannot be reused after it is done. Create a new instance for each invocation.
Command vs. ConnectionObserver
ConnectionObserver | Command | |
|---|---|---|
| Sends data? | No (passive) | Yes — writes command_string to connection |
| Triggers device output? | No | Yes |
| Typical use | Watching for alarms, reboots | Running ping, ls, ssh, etc. |
is_command() | False | True |
Command is simply the “active” version of a ConnectionObserver. It inherits the same lifecycle (start, await_done, cancel, result) but additionally sends a string that causes the device to produce the output it will parse.
Events
Passive observers that watch for patterns and fire callbacks
Devices
State machines that manufacture commands for the current state