Note
One of the main concept of Ockle’s design is that everything that could be a plugin, should be.
Ockle allows to add major features by the use of plugins. Each plugin is python class instance that gets executed in its own thread, allowing the developer to add new logic and behavior. You should be able to write a plugin without modifying Ockle’s core. But should be able to access any method within it. Many core functions in Ockle are plugins themselves including the Automatic server control and the communication to the web-based GUI.
In order to write a plugin, you should know that there are many pre-built tools that would help you in building one. Including a way to place your configuration variables in the GUI via simple Plugin ini template files
A general description of the tools available for the plugin would look like this:
Every plugin is supplied with a pointer to the Main Daemon singletron, allowing access to services such as the server tree data-structure (to change the state of the servers) and the communication handler (which lets you add more commands to the communication with the webserver or any other external client). The plugin also gets access to all the functions defined in the plugin template class, such as special functions that arrange the configuration variable storage.
To use this plugin framework simple extend the plugins.ModuleTemplate.ModuleTemplate . You may either extend the __init__ function to do things with Ockle starts, or the run method that will run your code in a seprate thread with access to Ockle’s functionality. You can also use the __init__ function to register new commends to send to Ockle as done in plugins.CoreCommunicationCommands.CoreCommunicationCommands.
The basic plugin that that all other plugins must extend
Get a value from the config ini for a plugin
Parameters: | value – The value you want to load |
---|---|
Returns: | the value from config.ini |
Get a value from the config ini for a plugin
:param value - the value you want :return: the value from config.ini
Here is a simple plugin example, this plugin simply sends to debug “I am a test plugin” message every X seconds, as defined in its config var.
If you want the configuration variable to be changeable at the webserver GUI, you must provide a template ini file in the src/config/plugins folder. The files should have the name of the plugin class proceeded with the .ini ending.
The section should be named plugins.<plugin name> .
These template files follow Ockle’s INI Template file format .
Lets look at our TimerPluginExample example from before. We will need it to have a src/config/plugins/TimerPluginExample.ini. This file should contain the following text:
With those two files in place Ockle takes it from here and the plugin would be available to the user in the config sections.