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.
Overview
Command extends ConnectionObserver to model device commands — operations like ls, ping, or show version that are initiated by sending a string to the device and conclude when the device’s output matches an expected pattern.
Command object:
- Sends
command_stringover the connection when started. - Parses the subsequent output in
data_received(). - Calls
set_result()once parsing is complete.
Command is an abstract class. You must subclass it, set self.command_string, and implement data_received().Constructor
The connection used to send the command string and receive its output.
The runner managing background execution. Resolved from the connection or the global default if
None.| Attribute | Type | Description |
|---|---|---|
command_string | str | None | The string to be sent to the device. Must be set before start() is called. |
cmd_name | str | Derived class name in lower-case underscore form (from Command.observer_name). |
Public methods
send_command
self.command_string over the connection using connection.sendline(). This is called automatically by the runner when the command is submitted for execution. You generally do not need to call it manually.
Raises AttributeError if connection is None.
is_command
True. This distinguishes Command instances from plain ConnectionObserver instances at runtime, for example when the CommandScheduler serializes commands on a shared connection.
get_long_desc
"Command <module>.<ClassName>(\"<command_string>\", id:...)".
get_short_desc
"Command <module>.<ClassName>(id:...)".
Inherited API
All methods fromConnectionObserver are available. The most commonly used ones:
| Method | Description |
|---|---|
start(timeout) | Begin sending and parsing. Raises NoCommandStringProvided if command_string is None. |
await_done(timeout) | Block until the command completes and return its result. |
result() | Retrieve the parsed result. |
cancel() | Cancel the running command. |
set_result(result) | Call from data_received() when parsing is done. |
set_exception(exc) | Call from data_received() to signal a failure. |
on_timeout() | Override for custom timeout behavior. |
Subclassing guide
To implement a command:- Subclass
Command. - Set
self.command_stringin__init__(or accept it as a parameter). - Implement
data_received(data, recv_time)to parse lines and callset_result()when done.