{# SPDX-License-Identifier: Apache-2.0 #} {# Copyright (C) 2025 Marcin Zieba #} {% extends 'generic/_base.html' %} {% block title %}Build Rule — Live Tester{% endblock %} {% block content %} {% if loaded_rule %}
Testing existing rule #{{ loaded_rule.pk }} (view / edit). Modify the fields below and click Check to preview, or Save as Rule to update or create a rule.
{% endif %}

Fill in the rule fields and variable values below, then click Check to preview the resulting interface name(s). If a module type is specified, the database is also queried for any matching installed interfaces and their computed names are shown.
Scope fields (Parent Module Type, Device Type, Platform) are optional filters — leave them blank to test the rule without scoping.

{% csrf_token %} {{ form.non_field_errors }}
{# ── Left column: rule definition ─────────────────────────────────────────── #}
Rule Definition
{{ form.name_template }}
{{ form.name_template.help_text }}
{% if form.name_template.errors %}
{{ form.name_template.errors }}
{% endif %}
{{ form.module_type_is_regex }}
{{ form.module_type }}
{{ form.module_type.help_text }}

Optional scoping — leave blank to match any:

{{ form.parent_module_type }}
{{ form.parent_module_type.help_text }}
{{ form.device_type }}
{{ form.device_type.help_text }}
{{ form.platform }}
{{ form.platform.help_text }}

{{ form.channel_count }}
{{ form.channel_count.help_text }}
{{ form.channel_start }}
{{ form.channel_start.help_text }}
{# ── Right column: variable values ────────────────────────────────────────── #}
Variable Values

Set the template variable values used for the manual preview. These simulate what NetBox extracts from the module bay context at install time.

{% for field in form %} {% if field.name|slice:":4" == "var_" %}
{{ field }}
{% endif %} {% endfor %}
Variable reference
VariableDescriptionExample
{slot}Top-level slot from parent bay position0, 2
{bay_position}Bay position string from NetBox0, swp1
{bay_position_num}Numeric suffix of bay position1 (from swp1)
{parent_bay_position}Parent module bay's position0, 2
{sfp_slot}Sub-bay index within parent module0, 1
{base}Current interface name from NetBoxEthernet1, et-0/0/0
{channel}Channel number (auto-set for breakout)0, 1, 2

Arithmetic: expressions inside {} are evaluated safely, e.g. {8 + ({parent_bay_position} - 1) * 2 + {sfp_slot}}.

{# /row #}
{# ── Results ─────────────────────────────────────────────────────────────────── #} {% if error %}
Template error: {{ error }}
{% endif %} {% if preview_results and not error %}
Manual Variable Preview
{% if preview_results.0.channel is not None %}{% endif %} {% for entry in preview_results %} {% if entry.channel is not None %}{% endif %} {% endfor %}
#ChannelSource (base name) Result
{{ forloop.counter }}{{ entry.channel }}{{ entry.source }} {{ entry.result }}
{% endif %} {% if db_preview is not None and not error %}
Matching Installed Interfaces
{% if db_total > db_preview|length %} Showing {{ db_preview|length }} of {{ db_total }} affected {% else %} {{ db_preview|length }} affected {% endif %}
{% if db_preview %}
{% for entry in db_preview %} {% endfor %}
Device Module Type Current Name New Name(s)
{% if entry.module.device %} {{ entry.module.device }} {% else %}{% endif %} {% if entry.module.module_type %} {{ entry.module.module_type.model }} {% else %} {% endif %} {{ entry.current_name }} {% for new_name in entry.new_names %} {{ new_name }}{% if not forloop.last %}, {% endif %} {% endfor %}
{% else %}
No installed interfaces would be affected.
{% endif %}
{% endif %} {% endblock %}