Skip to content

Templating

Peering Manager comes with a built-in templating feature. This feature can be used to generate configuration for routers as well as e-mails.

Jinja2

The templating feature is based on Jinja2; therefore templates must follow Jinja2's syntax. To help you writing your templates, Peering Manager will expose variables and filters.

You can also use Jinja2 extensions by installing them in the Python environment and asking Peering Manager to load them using the JINJA2_TEMPLATE_EXTENSIONS setting.

CLI

Tests can be performed via a terminal and the render_configuration command. This command must be run from Peering Manager's virtual environment and can take up to five arguments:

  • --limit [LIMIT]: limit the configuration to the given set of routers (comma separated)
  • --input [INPUT]: file to read the template from (default to stdin)
  • --output [OUTPUT]: file to write the configuration to (default to stdout)
  • --trim: remove new line after tag (keep them by default)
  • --lstrip: strip whitespaces before block (keep them by default)

For example, to generate the configuration for a device called router1 from the standard input and printing it to the standard output, the command to run will be:

(venv) # echo '{{ router.hostname }} | python manage.py render_configuration --limit router1
...

Examples

If you need some guidance before writing a template, you can take a look at the following example templates. Please note these may not be ready to use for you as they are maintained by the community. However, feel free to use them and to change them at your convenience.