Files
arista-evpn-vxlan-clab/infrahub/transforms/tests/interface_yang/input.json
Damien Arnodo 668e9cbada feat: Add Infrahub Jinja2 transforms for VLANs, interfaces, and VXLAN (#20) (#24)
## Summary

Closes #20

Adds Infrahub Jinja2 transforms that query device intent from Infrahub via GraphQL and produce structured JSON payloads (YANG-style) suitable for gNMI Set operations on Arista EOS devices.

- **3 GraphQL queries** — `vlan_intent`, `interface_intent`, `vxlan_intent` — each parameterized by `$device_name`
- **3 Jinja2 templates** — `vlan_yang.j2`, `interface_yang.j2`, `vxlan_yang.j2` — producing JSON arrays/objects from the GraphQL response
- **Integration test fixtures** — one directory per transform with `input.json`, `output.json`, and `test.yml`, using leaf1 from the lab topology as sample device
- **`.infrahub.yml` updated** with `queries` and `jinja2_transforms` sections

## Files added

```
transforms/
├── queries/
│   ├── vlan_intent.gql       # VLANs via VTEP mappings + SVI interfaces
│   ├── interface_intent.gql  # All interface types with IPs
│   └── vxlan_intent.gql      # VTEP config + VLAN/VNI/VRF mappings
├── templates/
│   ├── vlan_yang.j2          # JSON array of VLANs (merged, deduplicated, sorted)
│   ├── interface_yang.j2     # JSON array of interfaces with type discriminator
│   └── vxlan_yang.j2         # JSON object: vtep + vlan_vni + vrf_vni mappings
└── tests/
    ├── vlan_yang/{input,output,test}.{json,yml}
    ├── interface_yang/{input,output,test}.{json,yml}
    └── vxlan_yang/{input,output,test}.{json,yml}
```

## Transform usage

```bash
# Render locally
infrahubctl render vlan_yang_transform device_name=leaf1
infrahubctl render interface_yang_transform device_name=leaf1
infrahubctl render vxlan_yang_transform device_name=leaf1

# Via API
GET /api/transform/jinja2/vlan_yang_transform?device_name=leaf1
GET /api/transform/jinja2/interface_yang_transform?device_name=leaf1
GET /api/transform/jinja2/vxlan_yang_transform?device_name=leaf1
```

## Test plan

- [x] Load branch into Infrahub (`infrahubctl schema load` + `infrahubctl object load`)
- [x] Run `infrahubctl render vlan_yang_transform device_name=leaf1` and verify JSON output matches expected VLANs (40, 4090, 4091)
- [x] Run `infrahubctl render interface_yang_transform device_name=leaf1` and verify all interface types are present with correct attributes
- [x] Run `infrahubctl render vxlan_yang_transform device_name=leaf1` and verify VTEP source address, UDP port, and VLAN-VNI mapping for VLAN 40 / VNI 110040
- [x] Run `infrahubctl render vxlan_yang_transform device_name=leaf3` and verify VRF gold / L3VNI 100001 appears in `vrf_vni_mappings`
- ~~[ ] Verify `infrahubctl test` passes for all three test fixtures~~

Reviewed-on: #24
2026-02-28 17:42:08 +00:00

351 lines
7.5 KiB
JSON

{
"data": {
"InfraInterfaceLoopback": {
"edges": [
{
"node": {
"name": {
"value": "Loopback0"
},
"description": {
"value": "Router-ID"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"ip_addresses": {
"edges": [
{
"node": {
"address": {
"value": "10.0.250.11/32"
}
}
}
]
}
}
},
{
"node": {
"name": {
"value": "Loopback1"
},
"description": {
"value": "VTEP"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"ip_addresses": {
"edges": []
}
}
}
]
},
"InfraInterfaceEthernet": {
"edges": [
{
"node": {
"name": {
"value": "Ethernet1"
},
"description": {
"value": "host1"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"speed": {
"value": null
},
"mode": {
"value": "trunk"
},
"lag": {
"node": {
"name": {
"value": "Port-Channel1"
}
}
},
"ip_addresses": {
"edges": []
}
}
},
{
"node": {
"name": {
"value": "Ethernet10"
},
"description": {
"value": "mlag peer link"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"speed": {
"value": null
},
"mode": {
"value": "trunk"
},
"lag": {
"node": {
"name": {
"value": "Port-Channel999"
}
}
},
"ip_addresses": {
"edges": []
}
}
},
{
"node": {
"name": {
"value": "Ethernet11"
},
"description": {
"value": "spine1"
},
"enabled": {
"value": true
},
"mtu": {
"value": 9214
},
"speed": {
"value": null
},
"mode": {
"value": "routed"
},
"lag": null,
"ip_addresses": {
"edges": [
{
"node": {
"address": {
"value": "10.0.1.1/31"
}
}
}
]
}
}
},
{
"node": {
"name": {
"value": "Ethernet12"
},
"description": {
"value": "spine2"
},
"enabled": {
"value": true
},
"mtu": {
"value": 9214
},
"speed": {
"value": null
},
"mode": {
"value": "routed"
},
"lag": null,
"ip_addresses": {
"edges": [
{
"node": {
"address": {
"value": "10.0.2.1/31"
}
}
}
]
}
}
}
]
},
"InfraInterfaceVlan": {
"edges": [
{
"node": {
"name": {
"value": "Vlan4090"
},
"description": {
"value": "MLAG Peer-Link"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"virtual_router_address": {
"value": null
},
"autostate": {
"value": false
},
"vlan": {
"node": {
"vlan_id": {
"value": 4090
}
}
},
"ip_addresses": {
"edges": [
{
"node": {
"address": {
"value": "10.0.199.254/31"
}
}
}
]
}
}
},
{
"node": {
"name": {
"value": "Vlan4091"
},
"description": {
"value": "MLAG iBGP Peering"
},
"enabled": {
"value": true
},
"mtu": {
"value": 9214
},
"virtual_router_address": {
"value": null
},
"autostate": {
"value": true
},
"vlan": {
"node": {
"vlan_id": {
"value": 4091
}
}
},
"ip_addresses": {
"edges": [
{
"node": {
"address": {
"value": "10.0.3.0/31"
}
}
}
]
}
}
}
]
},
"InfraInterfaceLag": {
"edges": [
{
"node": {
"name": {
"value": "Port-Channel1"
},
"description": {
"value": "host1"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"lacp_mode": {
"value": "active"
},
"mlag_id": {
"value": 1
},
"members": {
"edges": [
{
"node": {
"name": {
"value": "Ethernet1"
}
}
}
]
},
"ip_addresses": {
"edges": []
}
}
},
{
"node": {
"name": {
"value": "Port-Channel999"
},
"description": {
"value": "MLAG Peer"
},
"enabled": {
"value": true
},
"mtu": {
"value": null
},
"lacp_mode": {
"value": "active"
},
"mlag_id": {
"value": null
},
"members": {
"edges": [
{
"node": {
"name": {
"value": "Ethernet10"
}
}
}
]
},
"ip_addresses": {
"edges": []
}
}
}
]
}
}
}