Adding Extensions to LAVA Server¶
LAVA Server can be used as the base for further extensions. Extensions currently exist for things like adding scheduler support, a dashboard interface, and additional views of test data. Extensions can add further data models, menus, and views, and even APIs to the existing LAVA Server framework.
Extensions are essentially just a django app. They hook into LAVA Server using an pkg_resources entry points machinery. For a simple example of adding an extension, see the ‘demo’ subdirectory in the lava-server source repository.
setup.py¶
Your setup.py will need to add entry points for lava_server.extensions for the extension you wish to add
entry_points="""
[lava_server.extensions]
demo = demo_app.extension:DemoExtension
""",
The DemoExtension class will be defined below.
The extension class¶
The other thing your django extension to LAVA Server will need is a class that
implements the IExtension
interface. This class
defines the properties and methods that are needed for LAVA Server to include
your extension.
You may find a small demo extension in the source tree. You can use that as a base for your own code.
# Copyright (C) 2010, 2011 Linaro Limited
#
# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
#
# This file is part of LAVA Server.
#
# LAVA Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3
# as published by the Free Software Foundation
#
# LAVA Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with LAVA Server. If not, see <http://www.gnu.org/licenses/>.
import versiontools
from lava_server.extension import LavaServerExtension
import demo_app
class DemoExtension(LavaServerExtension):
"""
Demo extension that shows how to integrate third party
components into LAVA server.
"""
@property
def app_name(self):
return "demo_app"
@property
def name(self):
return "Demo"
@property
def api_class(self):
from demo_app.models import DemoAPI
return DemoAPI
@property
def main_view_name(self):
return "demo_app.views.hello"
@property
def description(self):
return "Demo extension for LAVA server"
@property
def version(self):
return versiontools.format_version(demo_app.__version__)
Adding new XML-RPC methods¶
As previously mentioned, the LAVA Server XML-RPC API can be extended with new methods using LAVA Server extensions. In the demo_app example we have been looking at, a new method called demoMethod() is added to the API and is automatically added under a namespace called demo. It uses ExposedAPI from linaro_django_xmlrpc.models to do this.
from django.db import models
from linaro_django_xmlrpc.models import ExposedAPI
class Message(models.Model):
text = models.TextField()
class DemoAPI(ExposedAPI):
def demoMethod(self):
"""
This is a demo method.
"""
return 42