Creating a new server extension#
Inmanta server extensions are separate Python packages with their own release cycle that can add additional server slices and Inmanta environment settings to the orchestrator. Server slices are components in the service orchestrator. A slice can be responsible for API endpoints or provide internal services to other slices. The core server extension provides all slices of the core service orchestrator.
The package layout of a server extension#
Each Inmanta server extension is defined as a subpackage of the
inmanta_ext is a namespace package
used by the service orchestrator to discover new extensions. The following directory structure is
required for a new extension called
inmanta_ext | |__ new_extension | |__ __init__.py | |__ extension.py
__init__.pyfile can be left empty. This file is only required to indicate that
new_extensionis a python package.
extension.pyfile must contain a
setupfunction that registers the necessary server slices to the application context. An example
extension.pyfile is shown below. The parameter
<server-slice-instance>should be replaced with an instance of the server slice that belongs to the extension. Multiple server slices can be registered.
extension.pyfile can contain an optional
register_environment_settingsfunction that allows an extension to register extension-specific settings that can be used to customize an Inmanta environment.
# File: extension.py from inmanta.server.extensions import ApplicationContext from inmanta import data def setup(application: ApplicationContext) -> None: application.register_slice(<server-slice-instance>) def register_environment_settings(application: ApplicationContext) -> None: application.register_environment_setting( data.Setting( name="my_environment_setting", default=False, typ="bool", validator=data.convert_boolean, doc="Explain what the setting does.", ) )
Indicate which version of the Inmanta core is compatible with the developed extension by constraining the version of the
Inmanta core package to a valid range in the
setup.py file of the extension.
Adding server slices to the extension#
A server slice is defined by creating a class that extends from
- class inmanta.server.protocol.ServerSlice(name: str)[source]#
Base class for server extensions offering zero or more api endpoints
Extensions developers should override the lifecycle methods:
To register endpoints that server static content, either use :func:’add_static_handler’ or :func:’add_static_content’ To create endpoints, use the annotation based mechanism
To schedule recurring tasks, use
schedule()or self._sched To schedule background tasks, use
- get_dependencies() List[str] [source]#
List of names of slices that must be started before this one.
- async prestart(server: Server) None [source]#
Called by the RestServer host prior to start, can be used to collect references to other server slices Dependencies are not up yet.
- async prestop() None [source]#
Always called before stop
Stop producing new work: - stop timers - stop listeners - notify shutdown to systems depending on us (like agents)
sets is_stopping to true
But remain functional
All dependencies are up (if present)
- async start() None [source]#
Start the server slice.
This method blocks until the slice is ready to receive calls
Dependencies are up (if present) prior to invocation of this call
The constructor of the ServerSlice class expects the name of the slice as an argument. This name should have the format
<extension-name>is the name of the package that contains the
<server-slice-name>can be chosen by the developer.
get_depended_by()methods can be overridden when required.
Enable the extension#
By default, no extensions are enabled on the Inmanta server. Extensions can be enabled by specifying them in the
server.enabled-extensions option of the Inmanta configuration file. This option accepts a
comma-separated list of extensions that should be enabled.
# File: /etc/inmanta/inmanta.d/0-extensions.cfg [server] enabled_extensions=new_extension
The Inmanta extension template#
A new Inmanta extension can be created via the Inmanta extension template. This is a cookiecutter template to generate the initial Python project for a new Inmanta extension. The documentation regarding this template is available on https://github.com/inmanta/inmanta-extension-template.