Python Plugins
Linux and Windows WSL
Configuration
Warning
- To install the plugin, you need the Cellframe Node to be installed
Enable plugin subsystem in cellframe-node Cellframe Node Configuration|configuration
[plugins]
py_path=/opt/cellframe-node/var/lib/plugins
enabled=true
py_load=true
Plugin structure
To use plugins with Cellframe Node, follow these steps:
- Create Plugin Directory:
- Navigate to
/opt/cellframe-node/var/lib
directory. - Create a folder named
plugins
.
- Navigate to
- Organize Plugin Files by following:
plugins
├── plugin_1
│ ├── plugin_1.py
│ └── manifest.json
└── plugin_2
├── plugin_2.py
└── manifest.json
Important
- Each plugin directory should contain at least two files: manifest.json and the Python script implementing the plugin’s functionality.
- The name of each entrypoint should match the name of the corresponding plugin and the name in manifest file.
Python script
The plugin folder can contain several python scripts. Each plugin must contain init and possibly deinit functions. The init and deinit functions must return integer value and should not accept any arguments.
The init function is called by the plugin sybsystem after downloading the chain files, but before the Cellframe Node goes online.
The deinit function is called when the Cellframe Node shut down. Finalize all work with open resourse here, if there where any.
Note
In Cellframe Node, each plugin is treated as a separate Python module, herewith, they all work in a common scope.
# testplugin.py
from DAP.Core import logIT
def init():
"""
Initialization function for the plugin.
This function is called when the plugin is loaded.
It should perform any necessary setup.
Returns:
int: A status code indicating the success of initialization. Zero indicates success,
while non-zero values indicate errors.
"""
logIt.notice('Hello world!')
return 0
def deinit():
"""
Deinitialization function for the plugin.
This function is called when the plugin is unloaded.
It should perform any necessary cleanup.
Returns:
int: A status code indicating the success of deinitialization. Zero indicates success,
while non-zero values indicate errors.
"""
# Perform cleanup here
return 0
Launchig the plugin
- To run plugins, restart the Cellframe Node.
- To check the plugin has started and is working properly, view the log by following:
tail -f /opt/cellframe-node/var/log/cellframe-node.log
it is also possible to restart your plugins without restarting the node
Note
It is also possible to restart your plugins without restart the node. To do this, use the restart or reload CLI (Command Line Interface) commands: To restart all plugins in
/opt/cellframe-node/var/lib/plugins
directory:cellframe-node-cli plugin restart
To reload a spesific plugin:
cellframe-node-cli plugin reload <plugin-name>
Installing third-party modules
To install third-party modules, you need to contact the pip utility directly:
sudo /opt/cellframe-node/python/bin/pip3 install <name-of-the-package>
Afterward, the downloaded files will be stored in the following directory: /opt/cellframe-node/python/lib/python3.10.