Create Infrahub Transforms that generate YANG-structured payloads suitable for gNMI Set operations from Infrahub intent data, starting with VLANs and basic interfaces.
Context
With Infrahub as Source of Truth, we leverage its native Transform system (Jinja2 or Python) instead of custom Python mappers. Transforms query data via GraphQL and output structured YANG payloads ready for gNMI operations.
Architecture Decision
Option A: Jinja2 Transforms (Recommended for config generation)
Declarative templates for YANG structure
Easy to test and debug with infrahubctl render
Version-controlled in Git repository
Native Infrahub integration
Option B: Python Transforms (For complex logic)
Full Python flexibility when needed
Access to Infrahub SDK objects
Better for conditional logic or computed values
Tasks
Define GraphQL queries for intent data extraction
vlan_intent.gql - Fetch VLANs with VNI mappings
interface_intent.gql - Fetch interfaces with IP addresses
vxlan_intent.gql - Fetch L2VPN/VNI configurations
Create Jinja2 transforms for YANG generation
vlan_yang.j2 - VLAN → YANG config
interface_yang.j2 - Interface → YANG config
vxlan_yang.j2 - VXLAN → YANG config
Configure .infrahub.yml with transform definitions
Handle both OpenConfig and Arista-native YANG paths
{% for vlan in data.InfraVLAN.edges %}
{% set v = vlan.node %}
{
"path": "/network-instances/network-instance[name=default]/vlans/vlan[vlan-id={{ v.vlan_id.value }}]",
"value": {
"config": {
"vlan-id": {{ v.vlan_id.value }},
"name": "{{ v.name.value }}",
"status": "{{ v.status.value | upper }}"
}
}
}{% if not loop.last %},{% endif %}
{% endfor %}
.infrahub.yml Configuration
jinja2_transforms:- name:vlan_yang_transformdescription:"Generate YANG payload for VLANs"query:vlan_intenttemplate_path:transforms/vlan_yang.j2- name:interface_yang_transformdescription:"Generate YANG payload for interfaces"query:interface_intenttemplate_path:transforms/interface_yang.j2- name:vxlan_yang_transformdescription:"Generate YANG payload for VXLAN"query:vxlan_intenttemplate_path:transforms/vxlan_yang.j2queries:- name:vlan_intentfile_path:queries/vlan_intent.gql- name:interface_intentfile_path:queries/interface_intent.gql- name:vxlan_intentfile_path:queries/vxlan_intent.gql
API Usage
# Render VLAN YANG config for a device
curl "https://infrahub/api/transform/jinja2/vlan_yang_transform?device=leaf1"# Local debugging
infrahubctl render vlan_yang_transform device=leaf1
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
Create Infrahub Transforms that generate YANG-structured payloads suitable for gNMI Set operations from Infrahub intent data, starting with VLANs and basic interfaces.
Context
With Infrahub as Source of Truth, we leverage its native Transform system (Jinja2 or Python) instead of custom Python mappers. Transforms query data via GraphQL and output structured YANG payloads ready for gNMI operations.
Architecture Decision
Option A: Jinja2 Transforms (Recommended for config generation)
infrahubctl renderOption B: Python Transforms (For complex logic)
Tasks
vlan_intent.gql- Fetch VLANs with VNI mappingsinterface_intent.gql- Fetch interfaces with IP addressesvxlan_intent.gql- Fetch L2VPN/VNI configurationsvlan_yang.j2- VLAN → YANG configinterface_yang.j2- Interface → YANG configvxlan_yang.j2- VXLAN → YANG config.infrahub.ymlwith transform definitionsinfrahub-testsExample Implementation
GraphQL Query (
vlan_intent.gql)Jinja2 Transform (
vlan_yang.j2).infrahub.ymlConfigurationAPI Usage
Output Files
Acceptance Criteria
Migration Notes (from NetBox)
YangMapperclassto_yang()methodfrom_yang()reverse mappingRelated
src/yang/paths.py(documented YANG paths)Branch
feat/infrahub-transforms-vlan-interfaces-vxlancreated frommainfor this issue.