{# 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.applies_to_device_interfaces }}
{{ form.module_type_is_regex }}
{{ form.module_type }}
{{ form.module_type.help_text }}
{% if form.module_type.errors %}
{{ form.module_type.errors }}
{% endif %}
{% with module_label=form.module_type_pattern.label module_help=form.module_type_pattern.help_text device_label=form.device_pattern_label device_help=form.device_pattern_help_text %}
{{ form.module_type_pattern }}
{% if form.applies_to_device_interfaces.value %}{{ device_help }}{% else %}{{ module_help }}{% endif %}
{% if form.module_type_pattern.errors %}
{{ form.module_type_pattern.errors }}
{% endif %}
{% endwith %}

Optional scoping — leave blank to match any:

{{ form.parent_module_type }}
{{ form.parent_module_type.help_text }}
{% if form.parent_module_type.errors %}
{{ form.parent_module_type.errors }}
{% endif %}
{{ form.device_type }}
{{ form.device_type.help_text }}
{% if form.device_type.errors %}
{{ form.device_type.errors }}
{% endif %}
{{ form.platform }}
{{ form.platform.help_text }}
{% if form.platform.errors %}
{{ form.platform.errors }}
{% endif %}

{{ form.breakout_mode }}
{{ form.breakout_mode.help_text }}
{% if form.breakout_mode.errors %}
{{ form.breakout_mode.errors }}
{% endif %}
{{ form.parent_name_template }}
{{ form.parent_name_template.help_text }}
{% if form.parent_name_template.errors %}
{{ form.parent_name_template.errors }}
{% endif %}
{{ form.channel_count }}
{{ form.channel_count.help_text }}
{% if form.channel_count.errors %}
{{ form.channel_count.errors }}
{% endif %}
{{ form.channel_start }}
{{ form.channel_start.help_text }}
{% if form.channel_start.errors %}
{{ form.channel_start.errors }}
{% endif %}
{# ── Right column: variable values ────────────────────────────────────────── #}
Variable Values

Set the template variable values used for the manual preview. These supply the naming context for the selected rule kind.

{% for field in form %} {% if field.name|slice:":4" == "var_" %}
{{ field }}{% if field.errors %}
{{ field.errors }}
{% endif %}
{{ field.help_text }}
{% endif %} {% endfor %}
Variable reference {% for row in module_variable_rows %} {% endfor %}
VariableDescriptionExample
{{ row.token }}{{ row.description }}{{ row.example }}
{% for row in device_variable_rows %} {% endfor %}
VariableDescriptionExample
{{ row.token }}{{ row.description }}{{ row.example }}

Arithmetic: expressions inside {} are evaluated safely, e.g. {8 + ({parent_bay_position_num} - 1) * 2 + {sfp_slot}}. Use the _num variables in arithmetic: a bay position may be a path such as TenGigabitEthernet3/2/1.

{# /row #}
{# ── Results ─────────────────────────────────────────────────────────────────── #} {% if error %}
Template error: {{ error }}
{% endif %} {% if form.applies_to_device_interfaces.value %}

The database preview covers module rules only.

{% endif %} {% if preview_results and not error %}
Manual Variable Preview
{% if preview_results.0.channel is not None or preview_results.0.role == "parent" %}{% endif %} {% if form.applies_to_device_interfaces.value %}{% endif %} {% for entry in preview_results %} {% if entry.channel is not None %} {% elif entry.role == "parent" %}{% endif %} {% if form.applies_to_device_interfaces.value %}{% endif %} {% endfor %}
#ChannelSource (base name)Derived port Result
{{ forloop.counter }}{{ entry.channel }}parent{{ entry.source }}{{ entry.port }} {{ 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 detail in entry.name_details %} {{ detail.name }}{% if detail.channel_id %}ch {{ detail.channel_id }}{% endif %}{% if not forloop.last %}, {% endif %} {% endfor %}
{% else %}
No installed interfaces would be affected.
{% endif %}
{% endif %} {% endblock %}