rPath Appliance Platform Agent:Reusable Code
From rPath Wiki
|
rPath Appliance Platform Agent plugins can reuse code provided by rAPA and can call functions from other rAPA plugins. Use the following sections as a guide when reusing code and functions.
Reusable Code in Python Classes
The following Python classes in the appliance agent can be used as needed to add a feature to the web interface for a plugin. Read the Python code in each corresponding .py file to see how arguments are processed:
| Class | Appliance Platform Files | Description |
|---|---|---|
| CallbackDisplayWidget | raa/widgets/callbackdisplay.py | Progress bar for showing the status of a process Read more |
| DateTimePicker | raa/widgets/datetimepicker.py | Entry fields for date and time data |
| RepeatScheduleWidget | raa/widgets/repeatschedule.py | Entry fields for repeating schedule data |
| StatusBoxWidget | raa/widgets/statusbox.py | Message box for reporting errors or other status messages |
| TabbedPageWidget | raa/widgets/tabbedpage.py | Present different parts of the plugin using a tabbed navigation |
Reusable Code in Kid Templates
To use the reusable code in a plugin, write the kid template for the plugin to import the Python classes, and call methods from those classes where appropriate:
- Use an import line for each class in the Python code section:
from raa.widgets.<module_name> import <class_name> - Call the Python methods within the kid template where appropriate:
${<method_call>}
Examples of reusable code are in the UpdateTroves plugin file raaplugins/updatetroves/trovelist.kid. The following two lines show the importing of the tabbed page and callback display classes:
from raa.widgets.tabbedpage import TabbedPageWidget from raa.widgets.callbackdisplay import CallbackDisplayWidget
These lines show calls to methods in those classes:
${TabbedPageWidget(value=pageList)} ${CallbackDisplayWidget(schedId=schedId, optype=optype, statusmsg=statusmsg, status=status)}
Reusing Functions Across Plugins
rAPA plugins can make use of the functions in other plugins. Server sides of plugins can only call server-side functions, and web sides of plugins can only call web-side functions. Use the following syntax from the class definition of one plugin to call the Python method as provided in another plugin:
self.plugins['/<plugindir>/<PluginClass>'].<method>(<variables>).
Replace the <plugindir> and <PluginClass> as appropriate to match the URL that corresponds to the plugin, and replace <method> and <variables> to complete the method call as defined in that plugin. This code goes through rAPA's core code to identify the other plugin and to call the method. This is applicable both for the standard rAPA plugins as well as any custom plugins.
For example, suppose the web side of your custom plugin needs to call the function that gets information about the last update check performed from the Updates plugin. First, note the following:
- The plugin resides in the updatetroves subdirectory of raaplugins and is accessible with the URL https//<hostname>/updatetroves/UpdateTroves.
- The UpdateTroves class on the web side of the plugin includes getLastCheck which does not require any variables to be passed.
With this information, add the following to the web side of your custom plugin to perform this same function:
self.plugins['/updatetroves/UpdateTroves'].getLastCheck().
