BGP Router Manager templates for Voneus core and aggregation infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
3.9 KiB

{%- macro physical_interface_comment(interface) %}{% if interface.label %}{{ interface.label|safe_string or "-" }}: {% endif %}{{ interface.description|safe_string or "-" }}{% if interface.connected_endpoint %} ({{ interface.connected_endpoint.name|safe_string|replace('.voneus.net','') }}{% if interface.connected_endpoint.device.name %} @ {{ interface.connected_endpoint.device.name|replace('.voneus.net','')|safe_string }}{% endif %}){% endif %}{% if interface.cable %} via [{{ interface.cable.label.split("/")[-1] }}]{% endif %}{% if interface.link_peer %} to [{{ interface.link_peer.label or interface.link_peer.name }}{% if interface.link_peer.device %} @ {{ interface.link_peer.device.name.split("/")[-1]|safe_string|replace('.voneus.net','') }}]{% endif %}{% endif %}{%- endmacro %}
{%- macro virtual_interface_comment(interface) %}{% if interface.label %}{{ interface.label|safe_string or "-" }}: {% endif %}{{ interface.description|safe_string or "-" }}{%- endmacro %}
{%- macro interface_addresses(device, interface, interface_context, interface_tags, mtu=False) %}
{%- for address in interface|get_addresses %}
{%- if address|ipv4 %}
/ip address add interface="{{ interface.name }}" address={{ address.address }} comment="{{ address.description }}"
{%- elif address|ipv6 %}
/ipv6 address add interface="{{ interface.name }}" address={{ address.address }} comment="{{ address.description }}"
{%- endif %}
{%- endfor %}
{%- endmacro %}
{%- for interface, subinterfaces in device_interfaces|subinterfaces(".") %}
{%- set interface_context = interface.tags|get_netbox_tags_contexts|contexts_merge_last %}
{%- if interface.type.value == "25gbase-x-sfp28"%}
/interface ethernet
set [ find default-name=sfp28-{{ interface.name.split("/")[-1]|int }} ] name="{{ interface.name|safe_string }}" comment="{{ physical_interface_comment( interface ) }}"
{%- elif interface.type.value == "10gbase-x-sfpp"%}
/interface ethernet
set [ find default-name=sfp-sfpplus{{ interface.name.split("/")[-1]|int }} ] name="{{ interface.name|safe_string }}" comment="{{ physical_interface_comment( interface ) }}"
{%- elif interface.type.value == "1000base-t"%}
/interface ethernet
set [ find default-name=ether{{ interface.name.split("/")[-1]|int }} ] name="{{ interface.name|safe_string }}" comment="{{ physical_interface_comment( interface ) }}"
{%- elif interface.type.value == "virtual" %}
/interface bridge
add name="{{ interface.name|safe_string }}" protocol-mode=none vlan-filtering=no comment="{{ virtual_interface_comment( interface ) }}"
{%- elif interface.type.value == "bridge" %}
/interface bridge
add name="{{ interface.name|safe_string }}" protocol-mode=none vlan-filtering=yes comment="{{ virtual_interface_comment( interface ) }}"
{%- endif %}
{%- set interface_tags = [] %}
{%- for tag in interface.tags %}
{%- do interface_tags.append(tag.slug) %}
{%- endfor %}
{%- set interface_context = interface.tags|get_netbox_tags_contexts|contexts_merge_last %}
{{ interface_addresses(device, interface, interface_context, interface_tags) }}
{%- for unit, subinterface in subinterfaces %}
{%- set subinterface_tags = [] %}
{%- for tag in subinterface.tags %}
{%- do subinterface_tags.append(tag.slug) %}
{%- endfor %}
{%- set subinterface_context = subinterface.tags|get_netbox_tags_contexts|contexts_merge_last %}
/interface vlan
add name="{{ subinterface.name }}" interface="{{ interface.name }}" vlan-id={% if subinterface.untagged_vlan %}{{ subinterface.untagged_vlan.vid }}{% elif unit|int %}{{ unit }}{% else %}0{% endif %} comment="{{ subinterface.description|safe_string }}"
{{ interface_addresses(device, subinterface, subinterface_context, subinterface_tags) }}
{%- endfor %}
{%- endfor %}