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
DeviceFactory is the central registry for all Moler device objects. It creates devices from configuration or explicit class references, caches them by name, and provides lifecycle operations such as removal and bulk teardown.
DeviceFactory directly.
Devices are singletons within a
DeviceFactory. Requesting the same name twice returns the same object.Factory methods
get_device
name, the cached instance is returned. Otherwise a new device is created and cached.
Provide either name or device_class, not both.
Name of a device pre-defined in Moler’s configuration. Moler looks up the class and connection parameters from that configuration entry.
Fully-qualified Python class name, e.g.
'moler.device.unixlocal.UnixLocal'. Used when creating a device without a named configuration entry.Dict describing the I/O connection, with at minimum an
'io_type' key (e.g., {'io_type': 'terminal', 'variant': 'threaded'}). Ignored if the device is already created or io_connection is provided.State machine hop configuration used to define multi-step state transitions (e.g., reaching a nested SSH session).
Name of the state the device should enter after creation, e.g.
'UNIX_REMOTE'. If None the device’s own default initial state is used.If
True, open the connection and transition to initial_state immediately. Set False to create the device object without connecting.If
True, load command and event classes on first use rather than at device initialization. Useful to reduce startup time when many devices are created.Supply an already-open connection object directly. Ignored if the device is already cached.
Extra keyword arguments forwarded to the device constructor for device-specific options.
WrongUsage— if neithernamenordevice_classis given, or if both are given.KeyError— ifnameis not found in the configuration.
create_all_devices
If
False, the first failure raises and stops creation of subsequent devices. If True, failures are logged as warnings and creation continues.remove_device
Name of the device to remove.
Device object to remove. Use this when you hold a reference but not the name.
name or device. Raises WrongUsage if neither is given.
remove_all_devices
If
True, completely resets the factory’s internal name registry so the same names can be reused. Use with caution — existing log files may be overwritten if devices with the same names are recreated.was_any_device_deleted
True if any device has been removed since the factory was last cleared. Useful in test frameworks to detect unexpected device teardown.
get_cloned_device
Reference to the device to clone — either a device object or a name string.
Name for the cloned device.
Initial state for the clone. Defaults to the source device’s current state.
get_devices_by_type
device_type.
A device class to filter by. Pass
None to return all devices.Device instance methods
The following methods are defined on the device objects returned byget_device().
get_cmd
Command instance bound to this device’s connection.
Class name (without package path) of the command, e.g.
'ls', 'ping'.Parameters forwarded to the command constructor.
If
True, the device state is verified before executing the command.Return a command appropriate for this state rather than the current state.
get_event
Event instance bound to this device’s connection.
Class name of the event (without package path).
Parameters forwarded to the event constructor.
Verify device state before creating the event.
Return an event for this state rather than the current state.
goto_state
Target state name, e.g.
'UNIX_LOCAL', 'UNIX_REMOTE'.Seconds before the transition is aborted.
-1 uses the default timeout.Number of retries if the state transition fails.
If
True and the device leaves the target state unexpectedly, it attempts to return to it automatically.enable_logging / disable_logging
set_logging_suffix
Suffix string to append. Pass
None to remove any existing suffix.