Updates for Golden Config GraphQL query

main
Daniel Ankers 2023-10-26 21:49:47 +01:00
parent 56d97768bb
commit 4ec3e90bb9
4 changed files with 41 additions and 42 deletions

View File

@ -1 +0,0 @@
juniper-vxlan.j2

View File

@ -51,7 +51,7 @@ system {
chassis {
aggregated-devices {
ethernet {
device-count {{ device['interfaces']|selectattr('type','eq','LAG')|list|count }}; {# Change this to be dynamically generated +#}
device-count {{ device['interfaces']|selectattr('type','eq','LAG')|list|count }};
}
}
{% if device['config_context']['breakout_ports'] %}
@ -150,7 +150,7 @@ interfaces {
irb {
{% endif %}
unit {{ interface['name'][4:] }} {
description "{{ vlans[interface['name'][4:]|int] }}";
description "{{ interface['description'] }}";
family inet {
address {{ interface['ip_addresses'][0]['address'] }};
}
@ -159,17 +159,17 @@ interfaces {
}
{% endif %}
{% endfor %}
{% for interface in device['interfaces'] if interface['name']=='lo0' %}
{% for interface in device['interfaces'] if interface['name'].startswith('lo') %}
{{ interfaceconfig(interface) }}
{% endfor %}
}
{%- endmacro %}
{% macro routingoptionssection(device) %}
{% macro routingoptionssection(primary_ip4, config_context) %}
routing-options {
router-id {{ device['primary_ip4']['address'][:-3] }};
autonomous-system {{ device['config_context']['overlay_as'] }};
router-id {{ primary_ip4['address'][:-3] }};
autonomous-system {{ config_context['overlay_as'] }};
forwarding-table {
export PFE-ECMP;
chained-composite-next-hop {
@ -182,7 +182,7 @@ routing-options {
{%- endmacro %}
{% macro bgprrmeshgroup(name,devices) %}
{% macro bgprrmeshgroup(device,spines) %}
group OVERLAY_RR_MESH {
type internal;
family evpn {
@ -193,20 +193,20 @@ routing-options {
multiplier 3;
session-mode automatic;
}
{% for dst_switch in devices if dst_switch['device_role']['name'] == 'Spine' and dst_switch['name'] != name %}
{% for dst_switch in spines if dst_switch['primary_ip4']['address'] != device['primary_ip4']['address'] %}
neighbor {{ dst_switch['primary_ip4']['address'][:-3] }};
{% endfor %}
}
{%- endmacro %}
{% macro bgpoverlaygroup(device, devices, route_reflector, other_role) %}
{% macro bgpoverlaygroup(device) %}
group OVERLAY {
type internal;
local-address {{ device['primary_ip4']['address'][:-3] }};
family evpn {
signaling;
}
{% if route_reflector %}
{% if device['device_role']['name'] == 'Spine' %}
cluster {{ device['primary_ip4']['address'][:-3] }};
multipath;
{% endif %}
@ -215,15 +215,15 @@ routing-options {
multiplier 3;
session-mode automatic;
}
{% for dst_switch in devices if dst_switch['device_role']['name'] == other_role %}
neighbor {{ dst_switch['primary_ip4']['address'][:-3] }};
{% for dst_switch in device['peering_interfaces'] %}
neighbor {{ dst_switch['cable_peer_interface']['device']['primary_ip4']['address'][:-3] }};
{% endfor %}
}
{%- endmacro %}
{% macro bgpunderlaygroup(this_switch, devices, underlay_ips, underlay_as, other_role) %}
{% macro bgpunderlaygroup(device) %}
group UNDERLAY {
type external;
hold-time 10;
@ -231,13 +231,13 @@ routing-options {
unicast;
}
export BGP_LOOPBACK0;
local-as {{ underlay_as[this_switch] }};
local-as {{ device['config_context']['underlay_as'] }};
multipath {
multiple-as;
}
{% for dst_switch in devices if dst_switch['device_role']['name'] == other_role %}
neighbor {{ underlay_ips[dst_switch['name']][this_switch] }} {
peer-as {{ underlay_as[dst_switch['name']] }};
{% for dst_switch in device['peering_interfaces'] %}
neighbor {{ dst_switch['cable_peer_interface']['ip_addresses'][0]['address'][:-3] }} {
peer-as {{ dst_switch['cable_peer_interface']['device']['local_context_data']['underlay_as'] }};
}
{% endfor %}
}
@ -245,7 +245,7 @@ routing-options {
{% macro bgpsection(device, devices, underlay_ips, underlay_as) %}
{% macro bgpsection(device,spines) %}
{% if device['device_role']['name'] in ['Spine','Lab-Spine'] %}
{% set role='Spine' %}
{% set other_role='Leaf' %}
@ -259,28 +259,28 @@ routing-options {
{% set name=device['name'] %}
{% endif %}
bgp {
{{ bgpoverlaygroup(device, devices, role=='Spine', other_role) }}
{{ bgpoverlaygroup(device) }}
{% if role == 'Spine' %}
{{ bgprrmeshgroup(name, devices) }}
{{ bgprrmeshgroup(device,spines) }}
{% endif %}
{{ bgpunderlaygroup(name,devices, underlay_ips, underlay_as, other_role) }}
{{ bgpunderlaygroup(device) }}
}
{%- endmacro %}
{% macro vlanssection(vlans,device) %}
vlans {
{% for vid,name in vlans.items() %}
vl{{ vid }} {
vlan-id {{ vid }};
{% if name != '' %}
description "{{ name }}";
{% for vlan in vlans %}
vl{{ vlan['vid'] }} {
vlan-id {{ vlan['vid'] }};
{% if vlan['name'] != '' %}
description "{{ vlan['name'] }}";
{% endif %}
{% if device['interfaces']|selectattr('name', 'equalto', 'irb.'+vid|string)|list|count %}
l3-interface irb.{{vid}};
{% if device['interfaces']|selectattr('name', 'equalto', 'irb.'+vlan['vid']|string)|list|count %}
l3-interface irb.{{vlan['vid']}};
{% endif %}
vxlan {
vni {{ vid }};
vni {{ vlan['vid'] }};
}
}
{% endfor %}

View File

@ -1 +0,0 @@
juniper-vxlan.j2

View File

@ -1,10 +1,11 @@
{% import "juniper-macros.j2" as junos %}
{% set device=({'name':name,'device_role':device_role,'primary_ip4':primary_ip4,'rack':rack,'interfaces':interfaces,'peering_interfaces':peering_interfaces,'config_context':config_context}) %}
{% import "juniper-macros-gc.j2" as junos %}
{{ junos.systemsection(device) }}
{% if device['device_role']['name'] == 'Leaf' %}
{% if device_role['name'] == 'Leaf' %}
{{ junos.chassissection(device) }}
{% endif %}
{{ junos.interfacesection(device,vlans) }}
{% if device['device_role']['name'] == 'Leaf' %}
{{ junos.interfacesection(device,tenant['vlans']) }}
{% if device_role['name'] == 'Leaf' %}
forwarding-options {
storm-control-profiles default {
all;
@ -16,7 +17,7 @@ policy-options {
term TERM1 {
from {
protocol direct;
route-filter {{ device['primary_ip4']['address'] }} exact;
route-filter {{ primary_ip4['address'] }} exact;
}
then accept;
}
@ -27,10 +28,10 @@ policy-options {
}
}
}
{{ junos.routingoptionssection(device) }}
{{ junos.routingoptionssection(primary_ip4, config_context) }}
protocols {
{{ junos.bgpsection(device, devices, underlay_ips, underlay_as) }}
{% if device['device_role']['name'] == 'Leaf' %}
{{ junos.bgpsection(device,tenant['spines']) }}
{% if device_role['name'] == 'Leaf' %}
evpn {
encapsulation vxlan;
extended-vni-list all;
@ -40,14 +41,14 @@ protocols {
interface all;
}
}
{% if device['device_role']['name'] == 'Leaf' %}
{% if device_role['name'] == 'Leaf' %}
switch-options {
vtep-source-interface lo0.0;
route-distinguisher {{ device['primary_ip4']['address'][:-3] }}:1;
route-distinguisher {{ primary_ip4['address'][:-3] }}:1;
vrf-target {
target:64512:1111;
auto;
}
}
{{ junos.vlanssection(vlans, device) }}
{{ junos.vlanssection(tenant['vlans'], device) }}
{% endif %}