Skip to content
Interface Profiles

Jinja helpers

The plugin adds these functions to the Jinja2 environment of NetBox, so they are available in device config templates, export templates and any other template NetBox renders.

interface_config_render(interface, **kwargs)

Section titled “interface_config_render(interface, **kwargs)”

Renders the config template that applies to interface with the highest weight, and returns the output as a string. Returns an empty string when the interface has no role or no config template applies.

The config template receives the context of the calling template, such as device and the device’s config context, plus interface and the keyword arguments:

{{ interface_config_render(interface, uplink_vlan=10) }}

Returns the interface role of the applicable config template with the highest weight, or None when no config template applies. Because a config template’s role is the interface’s role, this is the interface’s role whenever it has a config template.

{% set role = interface_role_get(interface) %}
{% if role and role.group and role.group.slug == "trunk" %}
spanning-tree portfast trunk
{% endif %}

The same matching is available in Python, for example in custom scripts:

from interface_profiles.models import ProfileConfigTemplate
# Applicable config templates, highest weight first
templates = ProfileConfigTemplate.objects.for_interface(interface)
# Config templates in scope of the interface, for any role
templates = ProfileConfigTemplate.objects.in_scope(interface)

resolve_interface_config() returns what the interface-configs/ REST endpoint returns: the role, the interface template and config template that apply, and the rendered configuration.

from interface_profiles.services import resolve_interface_config
result = resolve_interface_config(interface)
result.interface_role # InterfaceRole or None
result.interface_template # InterfaceTemplate or None
result.config_template # ProfileConfigTemplate or None
result.config # rendered configuration, or None
result.config_error # rendering error, or None