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 { chassis {
aggregated-devices { aggregated-devices {
ethernet { 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'] %} {% if device['config_context']['breakout_ports'] %}
@ -150,7 +150,7 @@ interfaces {
irb { irb {
{% endif %} {% endif %}
unit {{ interface['name'][4:] }} { unit {{ interface['name'][4:] }} {
description "{{ vlans[interface['name'][4:]|int] }}"; description "{{ interface['description'] }}";
family inet { family inet {
address {{ interface['ip_addresses'][0]['address'] }}; address {{ interface['ip_addresses'][0]['address'] }};
} }
@ -159,17 +159,17 @@ interfaces {
} }
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% for interface in device['interfaces'] if interface['name']=='lo0' %} {% for interface in device['interfaces'] if interface['name'].startswith('lo') %}
{{ interfaceconfig(interface) }} {{ interfaceconfig(interface) }}
{% endfor %} {% endfor %}
} }
{%- endmacro %} {%- endmacro %}
{% macro routingoptionssection(device) %} {% macro routingoptionssection(primary_ip4, config_context) %}
routing-options { routing-options {
router-id {{ device['primary_ip4']['address'][:-3] }}; router-id {{ primary_ip4['address'][:-3] }};
autonomous-system {{ device['config_context']['overlay_as'] }}; autonomous-system {{ config_context['overlay_as'] }};
forwarding-table { forwarding-table {
export PFE-ECMP; export PFE-ECMP;
chained-composite-next-hop { chained-composite-next-hop {
@ -182,7 +182,7 @@ routing-options {
{%- endmacro %} {%- endmacro %}
{% macro bgprrmeshgroup(name,devices) %} {% macro bgprrmeshgroup(device,spines) %}
group OVERLAY_RR_MESH { group OVERLAY_RR_MESH {
type internal; type internal;
family evpn { family evpn {
@ -193,20 +193,20 @@ routing-options {
multiplier 3; multiplier 3;
session-mode automatic; 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] }}; neighbor {{ dst_switch['primary_ip4']['address'][:-3] }};
{% endfor %} {% endfor %}
} }
{%- endmacro %} {%- endmacro %}
{% macro bgpoverlaygroup(device, devices, route_reflector, other_role) %} {% macro bgpoverlaygroup(device) %}
group OVERLAY { group OVERLAY {
type internal; type internal;
local-address {{ device['primary_ip4']['address'][:-3] }}; local-address {{ device['primary_ip4']['address'][:-3] }};
family evpn { family evpn {
signaling; signaling;
} }
{% if route_reflector %} {% if device['device_role']['name'] == 'Spine' %}
cluster {{ device['primary_ip4']['address'][:-3] }}; cluster {{ device['primary_ip4']['address'][:-3] }};
multipath; multipath;
{% endif %} {% endif %}
@ -215,15 +215,15 @@ routing-options {
multiplier 3; multiplier 3;
session-mode automatic; session-mode automatic;
} }
{% for dst_switch in devices if dst_switch['device_role']['name'] == other_role %} {% for dst_switch in device['peering_interfaces'] %}
neighbor {{ dst_switch['primary_ip4']['address'][:-3] }}; neighbor {{ dst_switch['cable_peer_interface']['device']['primary_ip4']['address'][:-3] }};
{% endfor %} {% endfor %}
} }
{%- endmacro %} {%- endmacro %}
{% macro bgpunderlaygroup(this_switch, devices, underlay_ips, underlay_as, other_role) %} {% macro bgpunderlaygroup(device) %}
group UNDERLAY { group UNDERLAY {
type external; type external;
hold-time 10; hold-time 10;
@ -231,13 +231,13 @@ routing-options {
unicast; unicast;
} }
export BGP_LOOPBACK0; export BGP_LOOPBACK0;
local-as {{ underlay_as[this_switch] }}; local-as {{ device['config_context']['underlay_as'] }};
multipath { multipath {
multiple-as; multiple-as;
} }
{% for dst_switch in devices if dst_switch['device_role']['name'] == other_role %} {% for dst_switch in device['peering_interfaces'] %}
neighbor {{ underlay_ips[dst_switch['name']][this_switch] }} { neighbor {{ dst_switch['cable_peer_interface']['ip_addresses'][0]['address'][:-3] }} {
peer-as {{ underlay_as[dst_switch['name']] }}; peer-as {{ dst_switch['cable_peer_interface']['device']['local_context_data']['underlay_as'] }};
} }
{% endfor %} {% 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'] %} {% if device['device_role']['name'] in ['Spine','Lab-Spine'] %}
{% set role='Spine' %} {% set role='Spine' %}
{% set other_role='Leaf' %} {% set other_role='Leaf' %}
@ -259,28 +259,28 @@ routing-options {
{% set name=device['name'] %} {% set name=device['name'] %}
{% endif %} {% endif %}
bgp { bgp {
{{ bgpoverlaygroup(device, devices, role=='Spine', other_role) }} {{ bgpoverlaygroup(device) }}
{% if role == 'Spine' %} {% if role == 'Spine' %}
{{ bgprrmeshgroup(name, devices) }} {{ bgprrmeshgroup(device,spines) }}
{% endif %} {% endif %}
{{ bgpunderlaygroup(name,devices, underlay_ips, underlay_as, other_role) }} {{ bgpunderlaygroup(device) }}
} }
{%- endmacro %} {%- endmacro %}
{% macro vlanssection(vlans,device) %} {% macro vlanssection(vlans,device) %}
vlans { vlans {
{% for vid,name in vlans.items() %} {% for vlan in vlans %}
vl{{ vid }} { vl{{ vlan['vid'] }} {
vlan-id {{ vid }}; vlan-id {{ vlan['vid'] }};
{% if name != '' %} {% if vlan['name'] != '' %}
description "{{ name }}"; description "{{ vlan['name'] }}";
{% endif %} {% endif %}
{% if device['interfaces']|selectattr('name', 'equalto', 'irb.'+vid|string)|list|count %} {% if device['interfaces']|selectattr('name', 'equalto', 'irb.'+vlan['vid']|string)|list|count %}
l3-interface irb.{{vid}}; l3-interface irb.{{vlan['vid']}};
{% endif %} {% endif %}
vxlan { vxlan {
vni {{ vid }}; vni {{ vlan['vid'] }};
} }
} }
{% endfor %} {% 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) }} {{ junos.systemsection(device) }}
{% if device['device_role']['name'] == 'Leaf' %} {% if device_role['name'] == 'Leaf' %}
{{ junos.chassissection(device) }} {{ junos.chassissection(device) }}
{% endif %} {% endif %}
{{ junos.interfacesection(device,vlans) }} {{ junos.interfacesection(device,tenant['vlans']) }}
{% if device['device_role']['name'] == 'Leaf' %} {% if device_role['name'] == 'Leaf' %}
forwarding-options { forwarding-options {
storm-control-profiles default { storm-control-profiles default {
all; all;
@ -16,7 +17,7 @@ policy-options {
term TERM1 { term TERM1 {
from { from {
protocol direct; protocol direct;
route-filter {{ device['primary_ip4']['address'] }} exact; route-filter {{ primary_ip4['address'] }} exact;
} }
then accept; then accept;
} }
@ -27,10 +28,10 @@ policy-options {
} }
} }
} }
{{ junos.routingoptionssection(device) }} {{ junos.routingoptionssection(primary_ip4, config_context) }}
protocols { protocols {
{{ junos.bgpsection(device, devices, underlay_ips, underlay_as) }} {{ junos.bgpsection(device,tenant['spines']) }}
{% if device['device_role']['name'] == 'Leaf' %} {% if device_role['name'] == 'Leaf' %}
evpn { evpn {
encapsulation vxlan; encapsulation vxlan;
extended-vni-list all; extended-vni-list all;
@ -40,14 +41,14 @@ protocols {
interface all; interface all;
} }
} }
{% if device['device_role']['name'] == 'Leaf' %} {% if device_role['name'] == 'Leaf' %}
switch-options { switch-options {
vtep-source-interface lo0.0; vtep-source-interface lo0.0;
route-distinguisher {{ device['primary_ip4']['address'][:-3] }}:1; route-distinguisher {{ primary_ip4['address'][:-3] }}:1;
vrf-target { vrf-target {
target:64512:1111; target:64512:1111;
auto; auto;
} }
} }
{{ junos.vlanssection(vlans, device) }} {{ junos.vlanssection(tenant['vlans'], device) }}
{% endif %} {% endif %}