feat: Add Infrahub Jinja2 transforms for VLANs, interfaces, and VXLAN (#20)
Add three GraphQL queries, Jinja2 templates, and integration tests for generating YANG-style JSON configuration payloads from Infrahub intent data, suitable for gNMI Set operations on Arista EOS devices. Queries (transforms/queries/): - vlan_intent.gql: Fetches VLANs for a device via VTEP mappings and SVI interfaces, including VNI associations. - interface_intent.gql: Fetches all interface types (loopback, ethernet, vlan, lag) with IP addresses and type-specific attributes. - vxlan_intent.gql: Fetches VTEP config, VLAN-to-VNI mappings, and VRF-to-VNI mappings (L3VNI) via VRF device assignments. Templates (transforms/templates/): - vlan_yang.j2: Merges VLANs from both VTEP and SVI sources, deduplicates by vlan_id, and emits a sorted JSON array. - interface_yang.j2: Emits a JSON array of interfaces sorted by name, with a "type" discriminator field for each interface kind. - vxlan_yang.j2: Emits a JSON object with vtep config, vlan_vni_mappings, and vrf_vni_mappings sections. Integration tests (transforms/tests/): - One test directory per transform with input.json (sample GraphQL response for leaf1), output.json (expected result), and test.yml config. - Test data reflects the lab topology: leaf1 VTEP 10.0.255.11, VLAN 40 / VNI 110040, MLAG VLANs 4090/4091, underlay Ethernet11/12. .infrahub.yml updated with queries and jinja2_transforms sections. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
62
transforms/tests/vxlan_yang/input.json
Normal file
62
transforms/tests/vxlan_yang/input.json
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"data": {
|
||||
"InfraVTEP": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"source_address": {
|
||||
"value": "10.0.255.11"
|
||||
},
|
||||
"udp_port": {
|
||||
"value": 4789
|
||||
},
|
||||
"learn_restrict": {
|
||||
"value": "any"
|
||||
},
|
||||
"source_interface": {
|
||||
"node": {
|
||||
"name": {
|
||||
"value": "Loopback1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"vlan_vni_mappings": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"description": {
|
||||
"value": "VLAN 40 <-> VNI 110040"
|
||||
},
|
||||
"vlan": {
|
||||
"node": {
|
||||
"vlan_id": {
|
||||
"value": 40
|
||||
},
|
||||
"name": {
|
||||
"value": "test-l2-vxlan"
|
||||
}
|
||||
}
|
||||
},
|
||||
"vni": {
|
||||
"node": {
|
||||
"vni": {
|
||||
"value": 110040
|
||||
},
|
||||
"vni_type": {
|
||||
"value": "l2vni"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"InfraVRFDeviceAssignment": {
|
||||
"edges": []
|
||||
}
|
||||
}
|
||||
}
|
||||
17
transforms/tests/vxlan_yang/output.json
Normal file
17
transforms/tests/vxlan_yang/output.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"vtep": {
|
||||
"source_address": "10.0.255.11",
|
||||
"source_interface": "Loopback1",
|
||||
"udp_port": 4789,
|
||||
"learn_restrict": "any",
|
||||
"vlan_vni_mappings": [
|
||||
{
|
||||
"vlan_id": 40,
|
||||
"vlan_name": "test-l2-vxlan",
|
||||
"vni": 110040,
|
||||
"vni_type": "l2vni"
|
||||
}
|
||||
],
|
||||
"vrf_vni_mappings": []
|
||||
}
|
||||
}
|
||||
13
transforms/tests/vxlan_yang/test.yml
Normal file
13
transforms/tests/vxlan_yang/test.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
# Integration test for vxlan_yang_transform
|
||||
# Usage: infrahubctl test transforms/tests/vxlan_yang/test.yml
|
||||
apiVersion: infrahub.app/v1
|
||||
kind: IntegrationTest
|
||||
spec:
|
||||
kind: jinja2-transform-integration
|
||||
name: vxlan_yang_transform_leaf1
|
||||
transform: vxlan_yang_transform
|
||||
params:
|
||||
device_name: leaf1
|
||||
input: input.json
|
||||
output: output.json
|
||||
Reference in New Issue
Block a user