Changes for Netbox

netbox
Daniel Ankers 2024-06-28 09:53:02 +01:00
parent 38a07f013e
commit 21b228b71b
2 changed files with 32 additions and 33 deletions

View File

@ -1,14 +1,14 @@
{% macro systemsection(device) %}
{% macro systemsection(device,root_pw,users,syslog_servers,ntp_servers) %}
system {
host-name {{ device['hostname'] }};
root-authentication {
encrypted-password "{{ device['config_context']['root_pw'] }}"; ## Client Higher
encrypted-password "{{ root_pw }}"; ## Client Higher
}
login {
class sysadmin {
permissions [ admin clear configure control firewall-control interface interface-control network reset rollback routing routing-control snmp snmp-control trace-control view view-configuration ];
}
{% for user, details in device['config_context']['users']|dictsort %}
{% for user, details in users|dictsort %}
user {{ user }} {
uid 200{{ loop.index }};
class {{ details['role'] }};
@ -22,7 +22,7 @@ system {
ssh;
}
syslog {
{% for server in device['config_context']['syslog_servers'] %}
{% for server in syslog_servers %}
host {{ server }} {
any notice;
authorization info;
@ -40,9 +40,9 @@ system {
authorization info;
}
}
{% if device['config_context']['ntp_servers']|length > 0 %}
{% if ntp_servers|length > 0 %}
ntp {
{% for server in device['config_context']['ntp_servers'] %}
{% for server in ntp_servers %}
server {{ server }};
{% endfor %}
}
@ -51,15 +51,15 @@ system {
{%- endmacro %}
{% macro chassissection(device) %}
{% macro chassissection(device,breakout_ports) %}
chassis {
aggregated-devices {
ethernet {
device-count {{ device['interfaces']|selectattr('type','eq','LAG')|list|count }};
}
}
{% if device['config_context']['breakout_ports'] %}
{% for fpc, fpcdata in device['config_context']['breakout_ports'].items() %}
{% if breakout_ports %}
{% for fpc, fpcdata in breakout_ports.items() %}
fpc {{ fpc }} {
{% for pic, picdata in fpcdata.items() %}
pic {{ pic }} {
@ -102,9 +102,9 @@ chassis {
aggregated-ether-options {
lacp {
periodic fast;
{% if interface['_custom_field_data']['system_id'] %}
system-id {{ interface['_custom_field_data']['system_id'] }};
{% elif interface['_custom_field_data']['esi_lag'] %}
{% if interface['custom_field_data']['system_id'] %}
system-id {{ interface['custom_field_data']['system_id'] }};
{% elif interface['custom_field_data']['esi_lag'] %}
system-id 00:00:{{ '%02d' % rack|int }}:{% if interface['name'][2:]|int < 99 %}{{ '%02d' % interface['name'][2:]|int }}{% else %}{{ '%02x' % interface['name'][2:]|int }}{% endif %}:00:01;
{% endif %}
}
@ -178,13 +178,13 @@ interfaces {
}
{%- endmacro %}
{% macro snmpsection(rack, config_context) %}
{% macro snmpsection(rack, snmp) %}
snmp {
location "Domicilium Datacentre {{ rack['name'] }}";
contact "{{ config_context['snmp']['contact'] }}";
community {{ config_context['snmp']['community'] }} {
contact "{{ snmp['contact'] }}";
community {{ snmp['community'] }} {
authorization read-only;
{% for client in config_context['snmp']['clients'] %}
{% for client in snmp['clients'] %}
{% if loop.first %}
clients {
{% endif %}
@ -197,13 +197,13 @@ snmp {
}
{%- endmacro %}
{% macro routingoptionssection(primary_ip4, config_context) %}
{% macro routingoptionssection(primary_ip4, overlay_as, gateway) %}
routing-options {
router-id {{ primary_ip4['address'][:-3] }};
autonomous-system {{ config_context['overlay_as'] }};
{% if config_context['gateway'] %}
autonomous-system {{ overlay_as }};
{% if gateway %}
static {
route 0.0.0.0/0 next-hop {{ config_context['gateway'] }};
route 0.0.0.0/0 next-hop {{ gateway }};
}
{% endif %}
forwarding-table {
@ -267,7 +267,7 @@ routing-options {
unicast;
}
export BGP_LOOPBACK0;
local-as {{ device['config_context']['underlay_as'] }};
local-as {{ device['local_context_data']['underlay_as'] }};
multipath {
multiple-as;
}
@ -305,17 +305,15 @@ routing-options {
{%- endmacro %}
{% macro sflowsection(device) %}
{% if device['config_context']['sflow'] %}
{% macro sflowsection(sflow) %}
sflow {
{% for collector in device['config_context']['sflow']['collectors'] %}
{% for collector in sflow['collectors'] %}
collector {{ collector }};
{% endfor %}
{% for interface in device['config_context']['sflow']['interfaces'] %}
{% for interface in sflow['interfaces'] %}
interfaces {{ interface }}.0;
{% endfor %}
}
{% endif %}
{%- endmacro %}

View File

@ -1,11 +1,10 @@
{% set device=({'hostname':hostname,'device_role':device_role,'primary_ip4':primary_ip4,'rack':rack,'interfaces':interfaces,'peering_interfaces':peering_interfaces,'config_context':config_context}) %}
{% import "juniper-macros.j2" as junos %}
{{ junos.systemsection(device) }}
{% if device_role['name'] == 'Leaf' %}
{{ junos.chassissection(device) }}
{{ junos.systemsection(device,root_pw,users,syslog_servers,ntp_servers) }}
{% if device.role['name'] == 'Leaf' %}
{{ junos.chassissection(device,breakout_ports) }}
{% endif %}
{{ junos.interfacesection(device,tenant['vlans']) }}
{{ junos.snmpsection(rack, config_context) }}
{{ junos.snmpsection(rack, snmp) }}
{% if device_role['name'] == 'Leaf' %}
forwarding-options {
storm-control-profiles default {
@ -29,7 +28,7 @@ policy-options {
}
}
}
{{ junos.routingoptionssection(primary_ip4, config_context) }}
{{ junos.routingoptionssection(primary_ip4, overlay_as, gateway) }}
protocols {
{{ junos.bgpsection(device,tenant['spines']) }}
{% if device_role['name'] == 'Leaf' %}
@ -41,7 +40,9 @@ protocols {
lldp {
interface all;
}
{{ junos.sflowsection(device) }}
{% if sflow %}
{{ junos.sflowsection(sflow) }}
{% endif %}
}
{% if device_role['name'] == 'Leaf' %}
switch-options {