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.

165 lines
6.7 KiB

{%- macro interface_description(interface, interface_context) %}
description "{% if interface.label %}{{ interface.label|replace('"','\\"') or "-" }}: {% endif %}{{ interface.description|replace('"','\\"') or "-" }}{% if interface.connected_endpoint %} ({{ interface.connected_endpoint.name|replace('"','\\"')|replace('.voneus.net','') }}{% if interface.connected_endpoint.device.name %} @ {{ interface.connected_endpoint.device.name|replace('.voneus.net','')|replace('"','\\"') }}{% 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]|replace('"','\\"')|replace('.voneus.net','') }}]{% endif %}{% endif %}"
{%- endmacro %}
{%- macro interface_common(interface, interface_context, mtu=True) %}
{%- if mtu and interface.mtu %}
mtu {{ interface.mtu }};
{%- endif %}
{%- endmacro %}
{%- macro interface_addresses(device, interface, interface_context, interface_tags, mtu=False) %}
family inet {
{%- if mtu and interface.mtu %}
mtu {{ interface.mtu }};
{%- endif %}
{%- for address in interface|get_addresses %}{% if address|ipv4 %}
address {{ address.address }}{% if address.address == device.primary_ip4.address %}{
primary;
preferred;
}{% else %};{% endif %}
{%- endif %}{%- endfor %}
filter {
input control-plane-protection-IPv4;
{%- if 'transit-link' in interface_tags or 'ix-link' in interface_tags or 'pni-link' in interface_tags %}
output BCP38-edge-IPv4;
{%- endif %}
}
}
family inet6 {
{%- if mtu and interface.mtu %}
mtu {{ interface.mtu }};
{%- endif %}
{%- for address in interface|get_addresses %}{% if address|ipv6 %}
address {{ address.address }}{% if address.address == device.primary_ip6.address %}{
primary;
preferred;
}{% else %};{% endif %}
{%- endif %}{%- endfor %}
filter {
input control-plane-protection-IPv6;
{%- if 'transit-link' in interface_tags or 'ix-link' in interface_tags or 'pni-link' in interface_tags %}
output BCP38-edge-IPv6;
{%- endif %}
}
}
{%- set tags = interface.tags|tags_to_map %}
{%- if 'core-isis-link' in tags %}
family iso;
family mpls;
{%- elif 'isis-loopback' in tags %}
family iso {
address {{ device.primary_ip4.address|ipv4_to_iso }};
}
{%- endif %}
{%- endmacro %}
{{ "interfaces"|progress }} {
{%- for interface, subinterfaces in device_interfaces|subinterfaces(".") %}
{%- set interface_context = interface.tags|get_netbox_tags_contexts|contexts_merge_last %}
{%- set interface_tags = [] %}
{%- for tag in interface.tags %}
{%- do interface_tags.append(tag.slug) %}
{%- endfor %}
{%- if '@' in interface.name %}
/* do not configure groups interface: {{ interface.name }} */
{%- elif interface.mgmt_only %}
/* do not configure management-only interface: {{ interface.name }} */
{%- elif 'no-automation' in interface_tags %}
/* do not configure no-automation interface: {{ interface.name }} */
{% elif interface.lag %}
{{ interface.name }} {
{{ interface_description(interface, interface_context) }}
{{ interface_common(interface, interface_context, mtu=False) }}
gigether-options {
802.3ad {{ interface.lag.name }};
}
{%- elif interface.name.startswith( 'lo' ) %}
{{ interface.name }} {
{{ interface_description(interface, interface_context) }}
{{ interface_common(interface, interface_context) }}
{%- for unit, subinterface in subinterfaces %}
{%- set subinterface_tags = [] %}
{%- for tag in subinterface.tags %}
{%- do subinterface_tags.append(tag.slug) %}
{%- endfor %}
unit {{ unit }} {
{%- if subinterface.untagged_vlan %}
vlan-id {{ subinterface.untagged_vlan.vid }};
{%- elif unit|int %}
vlan-id {{ unit }};
{%- endif %}
{%- set subinterface_context = subinterface.tags|get_netbox_tags_contexts|contexts_merge_last %}
{{ interface_description(subinterface, subinterface_context) }}
{{ interface_common(subinterface, subinterface_context, mtu=False) }}
{{ interface_addresses(device, subinterface, subinterface_context, subinterface_tags, mtu=False) }}
}
{%- endfor %}
{%- elif interface.type.value == 'lag' %}
{{ interface.name }} {
vlan-tagging;
aggregated-ether-options {
minimum-links 1;
link-speed 100g;
}
{{ interface_description(interface, interface_context) }}
{{ interface_common(interface, interface_context, mtu=True) }}
{%- elif interface.type.value != 'virtual' %}
{{ interface.name }} {
{{ interface_description(interface) }}
{%- if not interface.mode or ( interface.mode.value == 'access' ) %}
unit 0 {
{{ interface_description(interface, interface_context) }}
{{ interface_common(interface, interface_context, mtu=False) }}
{{ interface_addresses(device, interface, interface_context, interface_tags, mtu=True) }}
}
{%- elif interface.mode.value == 'tagged' %}
vlan-tagging;
{%- endif %}
{%- endif %}
{%- if ( not interface.mgmt_only ) and ( 'no-automation' not in interface_tags ) and ( '@' not in interface.name ) %}
{%- for tagged_vlan in interface.tagged_vlans %}{%- endfor %}
{%- if interface.mode.value == 'tagged' %}
{%- for unit, subinterface in subinterfaces %}
{%- set subinterface_tags = [] %}
{%- for tag in subinterface.tags %}
{%- do subinterface_tags.append(tag.slug) %}
{%- endfor %}
unit {{ unit }} {
{%- if subinterface.untagged_vlan %}
vlan-id {{ subinterface.untagged_vlan.vid }};
{%- elif unit|int %}
vlan-id {{ unit }};
{%- endif %}
{%- set subinterface_context = subinterface.tags|get_netbox_tags_contexts|contexts_merge_last %}
{{ interface_description(subinterface, subinterface_context) }}
{{ interface_common(subinterface, subinterface_context, mtu=False) }}
{{ interface_addresses(device, subinterface, subinterface_context, subinterface_tags, mtu=True) }}
}
{%- endfor %}
{%- endif %}
}
{%- endif %}
{%- endfor %}
fxp0 {
unit 0;
}
}