feat: Add Infrahub Jinja2 transform for BGP configuration (#23)
Single unified bgp_yang_transform covering the full BGP router stanza
(process config, peer groups, neighbors, address families) for all
10 fabric devices in a single query+template pass.
- Add GraphQL query bgp_intent.gql: queries InfraBGPRouterConfig by
device name, traversing local_asn, peer_groups (with remote_asn),
and sessions (with peer_group, remote_asn, vrf, peer_device);
separately queries InfraBGPAddressFamily for the same device,
including active_peer_groups, active_sessions, networks, and optional
vrf relationship
- Add Jinja2 template bgp_yang.j2: renders a JSON object with bgp.global
(ASN, router-id, distances, ECMP), bgp.peer_groups, bgp.neighbors,
bgp.address_families for global sessions, plus bgp.vrf_neighbors and
bgp.vrf_address_families for VRF-scoped entries (e.g. leaf7 VRF gold
border peering); returns [] for devices with no BGP config; all
optional relationships guarded with 'is defined and is not none' checks;
send_community "none" normalised to null in output
- Update .infrahub.yml: register bgp_intent query and bgp_yang_transform
- Add unit test fixtures for three representative devices:
leaf1 — 3 peer-groups, 5 global neighbors, 2 global AFs
spine1 — 1 peer-group (evpn/next-hop-unchanged), 16 neighbors
(8 direct underlay with remote_asn, 8 EVPN via peer-group),
IPv4 AF activates individual sessions
leaf7 — leaf1 pattern + VRF gold border session (AS 64999) and
VRF-scoped IPv4 unicast AF
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
180
infrahub/transforms/tests/bgp_yang/leaf1/input.json
Normal file
180
infrahub/transforms/tests/bgp_yang/leaf1/input.json
Normal file
@@ -0,0 +1,180 @@
|
||||
{
|
||||
"data": {
|
||||
"InfraBGPRouterConfig": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"router_id": { "value": "10.0.250.11" },
|
||||
"default_ipv4_unicast": { "value": false },
|
||||
"log_neighbor_changes": { "value": true },
|
||||
"ecmp_max_paths": { "value": 4 },
|
||||
"ecmp_max_ecmp": { "value": 64 },
|
||||
"ebgp_distance": { "value": 20 },
|
||||
"ibgp_distance": { "value": 200 },
|
||||
"local_distance": { "value": 200 },
|
||||
"local_asn": {
|
||||
"node": {
|
||||
"asn": { "value": 65001 }
|
||||
}
|
||||
},
|
||||
"peer_groups": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"name": { "value": "underlay" },
|
||||
"peer_group_type": { "value": "underlay" },
|
||||
"update_source": { "value": null },
|
||||
"ebgp_multihop": { "value": null },
|
||||
"send_community": { "value": "none" },
|
||||
"next_hop_self": { "value": false },
|
||||
"next_hop_unchanged": { "value": false },
|
||||
"maximum_routes": { "value": 12000 },
|
||||
"maximum_routes_warning_only": { "value": true },
|
||||
"remote_asn": {
|
||||
"node": {
|
||||
"asn": { "value": 65000 }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"name": { "value": "underlay_ibgp" },
|
||||
"peer_group_type": { "value": "underlay_ibgp" },
|
||||
"update_source": { "value": null },
|
||||
"ebgp_multihop": { "value": null },
|
||||
"send_community": { "value": "none" },
|
||||
"next_hop_self": { "value": true },
|
||||
"next_hop_unchanged": { "value": false },
|
||||
"maximum_routes": { "value": 12000 },
|
||||
"maximum_routes_warning_only": { "value": true },
|
||||
"remote_asn": {
|
||||
"node": {
|
||||
"asn": { "value": 65001 }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"name": { "value": "evpn" },
|
||||
"peer_group_type": { "value": "evpn" },
|
||||
"update_source": { "value": "Loopback0" },
|
||||
"ebgp_multihop": { "value": 3 },
|
||||
"send_community": { "value": "extended" },
|
||||
"next_hop_self": { "value": false },
|
||||
"next_hop_unchanged": { "value": false },
|
||||
"maximum_routes": { "value": 12000 },
|
||||
"maximum_routes_warning_only": { "value": true },
|
||||
"remote_asn": {
|
||||
"node": {
|
||||
"asn": { "value": 65000 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"sessions": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"peer_address": { "value": "10.0.1.0" },
|
||||
"description": { "value": "underlay to spine1" },
|
||||
"enabled": { "value": true },
|
||||
"peer_group": { "node": { "name": { "value": "underlay" }, "local_identifier": { "value": "leaf1__underlay" } } },
|
||||
"remote_asn": { "node": null },
|
||||
"vrf": { "node": null },
|
||||
"peer_device": { "node": { "name": { "value": "spine1" } } }
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"peer_address": { "value": "10.0.2.0" },
|
||||
"description": { "value": "underlay to spine2" },
|
||||
"enabled": { "value": true },
|
||||
"peer_group": { "node": { "name": { "value": "underlay" }, "local_identifier": { "value": "leaf1__underlay" } } },
|
||||
"remote_asn": { "node": null },
|
||||
"vrf": { "node": null },
|
||||
"peer_device": { "node": { "name": { "value": "spine2" } } }
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"peer_address": { "value": "10.0.3.1" },
|
||||
"description": { "value": "iBGP to leaf2" },
|
||||
"enabled": { "value": true },
|
||||
"peer_group": { "node": { "name": { "value": "underlay_ibgp" }, "local_identifier": { "value": "leaf1__underlay_ibgp" } } },
|
||||
"remote_asn": { "node": null },
|
||||
"vrf": { "node": null },
|
||||
"peer_device": { "node": { "name": { "value": "leaf2" } } }
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"peer_address": { "value": "10.0.250.1" },
|
||||
"description": { "value": "EVPN to spine1" },
|
||||
"enabled": { "value": true },
|
||||
"peer_group": { "node": { "name": { "value": "evpn" }, "local_identifier": { "value": "leaf1__evpn" } } },
|
||||
"remote_asn": { "node": null },
|
||||
"vrf": { "node": null },
|
||||
"peer_device": { "node": { "name": { "value": "spine1" } } }
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"peer_address": { "value": "10.0.250.2" },
|
||||
"description": { "value": "EVPN to spine2" },
|
||||
"enabled": { "value": true },
|
||||
"peer_group": { "node": { "name": { "value": "evpn" }, "local_identifier": { "value": "leaf1__evpn" } } },
|
||||
"remote_asn": { "node": null },
|
||||
"vrf": { "node": null },
|
||||
"peer_device": { "node": { "name": { "value": "spine2" } } }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"InfraBGPAddressFamily": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"afi": { "value": "ipv4" },
|
||||
"safi": { "value": "unicast" },
|
||||
"vrf": { "node": null },
|
||||
"active_peer_groups": {
|
||||
"edges": [
|
||||
{ "node": { "name": { "value": "underlay" } } },
|
||||
{ "node": { "name": { "value": "underlay_ibgp" } } }
|
||||
]
|
||||
},
|
||||
"active_sessions": { "edges": [] },
|
||||
"networks": {
|
||||
"edges": [
|
||||
{ "node": { "address": { "value": "10.0.250.11/32" } } },
|
||||
{ "node": { "address": { "value": "10.0.255.11/32" } } }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"afi": { "value": "evpn" },
|
||||
"safi": { "value": "unicast" },
|
||||
"vrf": { "node": null },
|
||||
"active_peer_groups": {
|
||||
"edges": [
|
||||
{ "node": { "name": { "value": "evpn" } } }
|
||||
]
|
||||
},
|
||||
"active_sessions": { "edges": [] },
|
||||
"networks": { "edges": [] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user