feat(infrahub): add Infrahub client for fabric intent (#42) #54
Reference in New Issue
Block a user
Delete Branch "feature/42-infrahub-client"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
pynetboxwithinfrahub-sdk>=0.16.0+pydantic>=2.0as runtime dependencies; addpytest/pytest-asyncioto dev dependenciesFabricInfrahubClient— an async client wrappinginfrahub-sdkthat queries a remote Infrahub instance and returns typed, immutable Pydantic modelsChanges
pyproject.tomlpynetbox>=7.5.0→infrahub-sdk>=0.16.0+pydantic>=2.0pytest>=8.0.0,pytest-asyncio>=0.23.0src/infrahub/exceptions.pyCustom exception hierarchy:
InfrahubClientError(base)InfrahubConnectionError,InfrahubQueryError,InfrahubNotFoundErrorsrc/infrahub/models.pyPydantic v2 frozen models for all fabric intent types:
DeviceIntent,VlanIntent,VniIntent,BgpRouterConfigIntent,BgpPeerGroupIntent,BgpSessionIntent,VrfIntent,VtepIntent,MlagDomainIntent,MlagPeerConfigIntent,EvpnInstanceIntentsrc/infrahub/client.py—FabricInfrahubClientAll methods fetch from Infrahub and convert SDK nodes → Pydantic models:
get_device— device attrs + resolved ASN/platform/siteget_device_vlans— via VTEP vlan_vni_mappings, fallback to SVI interfacesget_device_bgp_config/get_device_bgp_peer_groups/get_device_bgp_sessionsget_device_vrfs— viaVRFDeviceAssignmentwith route targetsget_device_vtep— with all vlan/vni mappingsget_device_evpn_instancesget_mlag_domain/get_mlag_peer_configasync with FabricInfrahubClient(...) as client)tests/test_infrahub_client.pyunittest.mock.AsyncMock/MagicMockInfrahubNotFoundErroron missing device, branch selection forwarded toConfig, cache hit (second call skips SDK), VTEP/MLAG/BGP/VRF/EVPN pathsTest plan
uvx pytest tests/test_infrahub_client.py -v— all tests passuvx ruff check src/infrahub/ tests/— no lint errorsuvx ruff format --check src/infrahub/ tests/— no formatting issuesCloses #42
🤖 Generated with Claude Code