Code snippets

Some code examples to ease the life of module developers

Hostname FQDN

Retrieve the fully qualified domain name of the server by using the agent Python library. In case of exception the function outputs the default FQDN

Python example code:

import agent

fqdn = agent.get_hostname()

output example:

Port validation

Check if the TCP port is already used by a service. Exit with an error if the port is used.

import sys
import agent

if agent.tcp_port_in_use(port):

Web route validation

Check if HTTP routes are handled by Traefik. The function issues an HTTP request to port 80, setting the Host header in the HTTP request and/or the URL path. Any HTTP non-404 response assumes the HTTP route exists.

Test if a domain-based route is used (

import sys
import agent

hostname = ''
if agent.http_route_in_use(domain=hostname):

Test if a path-based route is used (/path)

import sys
import agent
path ='/path' # path fragment of the URL to check
if agent.http_route_in_use(domain=none, path=path):

Extra python libraries

If the module requires extra Python libraries, you can install them inside the create-module action.

Here’s an example of a create-module action step named 20initialize:


pip install bcrypt==4.1.2

You can then use the imported bcrypt library in all your action steps. A similar script can be added under update-module.d/.