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) }}interface_role_get(interface)
Section titled “interface_role_get(interface)”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 %}Python
Section titled “Python”The same matching is available in Python, for example in custom scripts:
from interface_profiles.models import ProfileConfigTemplate
# Applicable config templates, highest weight firsttemplates = ProfileConfigTemplate.objects.for_interface(interface)
# Config templates in scope of the interface, for any roletemplates = 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 Noneresult.interface_template # InterfaceTemplate or Noneresult.config_template # ProfileConfigTemplate or Noneresult.config # rendered configuration, or Noneresult.config_error # rendering error, or None