IP Fabric Adapter
Relevant source files
The following files were used as context for generating this wiki page:
The IP Fabric Adapter enables data synchronization from IP Fabric to Infrahub. It retrieves network inventory data—including devices, interfaces, VLANs, and addressing—using the IP Fabric Python SDK and maps it into the Infrahub data model via a declarative YAML configuration.
This adapter functions primarily as a source, populating Infrahub with real-world state discovered by IP Fabric. It uses the diffsync framework to compare discovered inventory against existing Infrahub records, allowing for idempotent updates.
Sources: README.md:10-14, infrahub_sync/adapters/ipfabricsync.py:44-53, dev/knowledge/sync-architecture.md:8-14
Architecture and Components
The adapter consists of two primary classes that interface with the infrahub-sync core and the IP Fabric API.
Core Classes
IpfabricsyncAdapter: Inherits fromDiffSyncMixinandAdapter. It manages theIPFClientsession, handles authentication, and orchestrates the loading of records from IP Fabric tables.IpfabricsyncModel: Inherits fromDiffSyncModelMixinandDiffSyncModel. It provides the structure for individual records and defines how they are created or updated in the destination system.
Sources: infrahub_sync/adapters/ipfabricsync.py:44-48, infrahub_sync/adapters/ipfabricsync.py:127-128, dev/knowledge/adapter-anatomy.md:12-25
Component Diagram
The following diagram illustrates the relationship between the Adapter, the IP Fabric SDK, and the core sync engine.
The diagram shows the flow from the configuration file through the adapter to the external IP Fabric API.
Sources: dev/knowledge/sync-architecture.md:21-33, infrahub_sync/adapters/ipfabricsync.py:53-56
Data Loading Logic
The model_loader method retrieves and processes data from IP Fabric based on the schema_mapping defined in the configuration.
- Table Fetching: The adapter uses
self.client.fetch_all()to retrieve data from specific IP Fabric table endpoints (e.g.,tables/inventory/devices). - Filtering: The adapter applies
model.filter_records()to drop entries that do not match criteria defined in theconfig.yml. - Transformation: The adapter applies
model.transform_records()to modify fields using Jinja2 expressions before they enter theDiffSyncstore. - Model Addition: Each processed record is converted to a DiffSync-compatible dictionary and added to the adapter's internal store.
Sources: infrahub_sync/adapters/ipfabricsync.py:76-101, dev/knowledge/schema-mapping.md:57-68
Sequence Diagram: Data Loading
This diagram outlines the synchronous steps taken to load and process data from the source.
Sources: infrahub_sync/adapters/ipfabricsync.py:76-103, dev/knowledge/sync-architecture.md:21-25
Configuration
The adapter requires specific settings and environment variables to establish a connection to IP Fabric.
Connection Settings
| Parameter | Type | Default | Description |
|---|---|---|---|
base_url | String | None | The URL of the IP Fabric instance. Falls back to IPF_URL env var. |
auth | String | None | API Token for IP Fabric. Falls back to IPF_TOKEN env var. |
Sources: infrahub_sync/adapters/ipfabricsync.py:58-74, examples/ipfabric_to_infrahub/config.yml:4-8
Schema Mapping Example
The configuration maps IP Fabric tables to Infrahub node types.
schema_mapping:
- name: InfraDevice
mapping: tables/inventory/devices
identifiers: ["hostname"]
fields:
- name: hostname
mapping: hostname
- name: serial_number
mapping: sn
- name: location
mapping: siteName
reference: LocationGeneric
Sources: examples/ipfabric_to_infrahub/config.yml:76-96
Field Transformation and References
The adapter handles complex field mappings, including static values, direct attribute mapping, and reference resolution.
- Reference Resolution: If a field defines a
reference, the adapter looks up theunique_idof the related object in the store. This allows linking a device to its site or an interface to its parent device. - List Handling: The adapter automatically handles list-based attributes (e.g., NTP servers). It attempts to parse strings as JSON or comma-separated values to ensure a Python list is returned.
- Custom Transforms: The adapter includes specific logic for unit conversion, such as converting interface speed by dividing by 1000.
Sources: infrahub_sync/adapters/ipfabricsync.py:105-125, dev/knowledge/schema-mapping.md:27-37
Summary
The IP Fabric Adapter provides a bridge between IP Fabric's discovery capabilities and Infrahub's versioned source of truth. By leveraging the ipfabric SDK and the diffsync framework, it ensures that network state is accurately reflected in Infrahub. The adapter relies on a declarative schema mapping to transform raw table data into structured network models, supporting complex relationships and data filtering.
Sources: README.md:14-18, infrahub_sync/adapters/ipfabricsync.py:44-50