.. _plugin_dev: Developing Plugins ================== To understand the basic concept of plugins and how to use them, refer to the :ref:`usage documentation ` This document describes the process and APIs required to develop your own plugins. .. _plugin_dev_arch: Plugin Architecture Overview ---------------------------- GRU Plugins are Python classes that subclass abstract plugin classes. For example, to write your own *Host Widget*, you'll need to subclass the :any:`gru.plugins.base.hostwidget.HostWidgetPlugin` class. On startup, the server will do the following: 1. Add the directories listed under :ref:`plugin-directories` to Python's ``sys.path`` 2. It will then iterate over the module names listed in ``plugins.modules`` and import them 3. For each imported module, the server will iterate over all classes, looking for ones that subclass any of GRU's internal abstract plugin types 4. An object will be instantiated out of each class found. The default ``on_load()`` method will be called. This is where plugin startup code should live. Things like setting up database connections should be done there 5. For modules that expose views_, a Flask Blueprint_ will be registered and used when serving these views All plugins subclass the following abstract class: .. py:class:: gru.plugins.base.BasePlugin .. py:method:: on_load(self): Defaults to doing nothing. If you have any startup logic, this is the place to put it. .. _plugin_dev_widgets: Host Widgets ------------ To write your own Host widget you'll need to provide the following: 1. A subclass of ``gru.plugins.base.hostwidget.HostWidgetPlugin`` 2. A template file that extends ``plugins/host_widget.html``. This Jinja_ template defines 3 parts that you'll be able to overide. They will later be merged into the host info page. These parts are: - ``plugincss`` - will be loaded at the head of the host info page. This is where ``