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:
140
infrahub/transforms/tests/bgp_yang/leaf7/output.json
Normal file
140
infrahub/transforms/tests/bgp_yang/leaf7/output.json
Normal file
@@ -0,0 +1,140 @@
|
||||
{
|
||||
"bgp": {
|
||||
"global": {
|
||||
"asn": 65004,
|
||||
"router_id": "10.0.250.17",
|
||||
"default_ipv4_unicast": false,
|
||||
"log_neighbor_changes": true,
|
||||
"distance": {
|
||||
"ebgp": 20,
|
||||
"ibgp": 200,
|
||||
"local": 200
|
||||
},
|
||||
"ecmp": {
|
||||
"max_paths": 4,
|
||||
"max_ecmp": 64
|
||||
}
|
||||
},
|
||||
"peer_groups": [
|
||||
{
|
||||
"name": "underlay",
|
||||
"type": "underlay",
|
||||
"remote_asn": 65000,
|
||||
"update_source": null,
|
||||
"ebgp_multihop": null,
|
||||
"send_community": null,
|
||||
"next_hop_self": false,
|
||||
"next_hop_unchanged": false,
|
||||
"maximum_routes": 12000,
|
||||
"maximum_routes_warning_only": true
|
||||
},
|
||||
{
|
||||
"name": "underlay_ibgp",
|
||||
"type": "underlay_ibgp",
|
||||
"remote_asn": 65004,
|
||||
"update_source": null,
|
||||
"ebgp_multihop": null,
|
||||
"send_community": null,
|
||||
"next_hop_self": true,
|
||||
"next_hop_unchanged": false,
|
||||
"maximum_routes": 12000,
|
||||
"maximum_routes_warning_only": true
|
||||
},
|
||||
{
|
||||
"name": "evpn",
|
||||
"type": "evpn",
|
||||
"remote_asn": 65000,
|
||||
"update_source": "Loopback0",
|
||||
"ebgp_multihop": 3,
|
||||
"send_community": "extended",
|
||||
"next_hop_self": false,
|
||||
"next_hop_unchanged": false,
|
||||
"maximum_routes": 12000,
|
||||
"maximum_routes_warning_only": true
|
||||
}
|
||||
],
|
||||
"neighbors": [
|
||||
{
|
||||
"peer_address": "10.0.1.12",
|
||||
"description": "underlay to spine1",
|
||||
"enabled": true,
|
||||
"peer_group": "underlay",
|
||||
"remote_asn": null
|
||||
},
|
||||
{
|
||||
"peer_address": "10.0.2.12",
|
||||
"description": "underlay to spine2",
|
||||
"enabled": true,
|
||||
"peer_group": "underlay",
|
||||
"remote_asn": null
|
||||
},
|
||||
{
|
||||
"peer_address": "10.0.3.7",
|
||||
"description": "iBGP to leaf8",
|
||||
"enabled": true,
|
||||
"peer_group": "underlay_ibgp",
|
||||
"remote_asn": null
|
||||
},
|
||||
{
|
||||
"peer_address": "10.0.250.1",
|
||||
"description": "EVPN to spine1",
|
||||
"enabled": true,
|
||||
"peer_group": "evpn",
|
||||
"remote_asn": null
|
||||
},
|
||||
{
|
||||
"peer_address": "10.0.250.2",
|
||||
"description": "EVPN to spine2",
|
||||
"enabled": true,
|
||||
"peer_group": "evpn",
|
||||
"remote_asn": null
|
||||
}
|
||||
],
|
||||
"address_families": [
|
||||
{
|
||||
"afi": "ipv4",
|
||||
"safi": "unicast",
|
||||
"active_peer_groups": [
|
||||
"underlay",
|
||||
"underlay_ibgp"
|
||||
],
|
||||
"active_sessions": [],
|
||||
"networks": [
|
||||
"10.0.250.17/32",
|
||||
"10.0.255.14/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"afi": "evpn",
|
||||
"safi": "unicast",
|
||||
"active_peer_groups": [
|
||||
"evpn"
|
||||
],
|
||||
"active_sessions": [],
|
||||
"networks": []
|
||||
}
|
||||
],
|
||||
"vrf_neighbors": [
|
||||
{
|
||||
"peer_address": "10.90.90.1",
|
||||
"description": "border peering to AS 64999 in VRF gold",
|
||||
"enabled": true,
|
||||
"peer_group": null,
|
||||
"remote_asn": 64999,
|
||||
"vrf": "gold"
|
||||
}
|
||||
],
|
||||
"vrf_address_families": [
|
||||
{
|
||||
"afi": "ipv4",
|
||||
"safi": "unicast",
|
||||
"vrf": "gold",
|
||||
"active_peer_groups": [],
|
||||
"active_sessions": [
|
||||
"10.90.90.1"
|
||||
],
|
||||
"networks": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user