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>
68 lines
2.6 KiB
Django/Jinja
68 lines
2.6 KiB
Django/Jinja
{#
|
|
vlan_yang.j2 — Produce a JSON array of VLAN configuration objects.
|
|
|
|
Input: GraphQL response from vlan_intent query.
|
|
The query returns VLANs from two sources:
|
|
1. data.InfraVTEP[].vlan_vni_mappings[].vlan (L2/VXLAN VLANs)
|
|
2. data.InfraInterfaceVlan[].vlan (SVI/routing/MLAG VLANs)
|
|
|
|
We merge both sources, deduplicate by vlan_id, and emit one object per VLAN.
|
|
#}
|
|
{%- set vlans = {} -%}
|
|
|
|
{#— Collect VLANs from VTEP VLAN-VNI mappings —#}
|
|
{%- for vtep_edge in data.InfraVTEP.edges -%}
|
|
{%- for mapping_edge in vtep_edge.node.vlan_vni_mappings.edges -%}
|
|
{%- set vlan_node = mapping_edge.node.vlan.node -%}
|
|
{%- set vid = vlan_node.vlan_id.value | string -%}
|
|
{%- if vid not in vlans -%}
|
|
{%- set vni_val = null -%}
|
|
{%- set vni_type_val = null -%}
|
|
{%- if vlan_node.vni and vlan_node.vni.node -%}
|
|
{%- set vni_val = vlan_node.vni.node.vni.value -%}
|
|
{%- set vni_type_val = vlan_node.vni.node.vni_type.value -%}
|
|
{%- endif -%}
|
|
{%- set _ = vlans.update({vid: {
|
|
"vlan_id": vlan_node.vlan_id.value,
|
|
"name": vlan_node.name.value,
|
|
"status": vlan_node.status.value | upper,
|
|
"vlan_type": vlan_node.vlan_type.value,
|
|
"trunk_groups": vlan_node.trunk_groups.value if vlan_node.trunk_groups.value else [],
|
|
"stp_enabled": vlan_node.stp_enabled.value,
|
|
"vni": vni_val,
|
|
"vni_type": vni_type_val
|
|
}}) -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- endfor -%}
|
|
|
|
{#— Collect VLANs from SVI interfaces —#}
|
|
{%- for svi_edge in data.InfraInterfaceVlan.edges -%}
|
|
{%- if svi_edge.node.vlan and svi_edge.node.vlan.node -%}
|
|
{%- set vlan_node = svi_edge.node.vlan.node -%}
|
|
{%- set vid = vlan_node.vlan_id.value | string -%}
|
|
{%- if vid not in vlans -%}
|
|
{%- set vni_val = null -%}
|
|
{%- set vni_type_val = null -%}
|
|
{%- if vlan_node.vni and vlan_node.vni.node -%}
|
|
{%- set vni_val = vlan_node.vni.node.vni.value -%}
|
|
{%- set vni_type_val = vlan_node.vni.node.vni_type.value -%}
|
|
{%- endif -%}
|
|
{%- set _ = vlans.update({vid: {
|
|
"vlan_id": vlan_node.vlan_id.value,
|
|
"name": vlan_node.name.value,
|
|
"status": vlan_node.status.value | upper,
|
|
"vlan_type": vlan_node.vlan_type.value,
|
|
"trunk_groups": vlan_node.trunk_groups.value if vlan_node.trunk_groups.value else [],
|
|
"stp_enabled": vlan_node.stp_enabled.value,
|
|
"vni": vni_val,
|
|
"vni_type": vni_type_val
|
|
}}) -%}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
|
|
{#— Sort by vlan_id and emit JSON array —#}
|
|
{%- set sorted_vlans = vlans.values() | sort(attribute='vlan_id') -%}
|
|
{{ sorted_vlans | tojson(indent=2) }}
|