Peering Manager Adapter
Relevant source files
The following files were used as context for generating this wiki page:
The Peering Manager Adapter enables bidirectional data synchronization between Peering Manager and Infrahub. It extends the GenericrestapiAdapter to provide specialized handling for Peering Manager's REST API structure, authentication, and relationship mapping. This adapter allows users to manage autonomous systems, BGP communities, routing policies, and Internet Exchange Point (IXP) connections across both platforms.
Within the infrahub-sync ecosystem, the Peering Manager Adapter acts as a connector that translates Peering Manager's API responses into the internal DiffSync model format. It supports both source and destination roles, meaning it can either extract data from Peering Manager or apply changes to it based on the config.yml definition.
Architecture and Class Structure
The adapter implementation consists of two primary classes that inherit from the project's base mixins and the generic REST API classes.
The diagram shows the inheritance relationship between the Peering Manager specialized classes and the Generic REST API base classes.
Sources: infrahub_sync/adapters/peeringmanager.py:20-39, dev/knowledge/adapter-anatomy.md:7-24
PeeringmanagerAdapter
This class initializes the connection to Peering Manager. It overrides the default GenericrestapiAdapter settings to match Peering Manager's API conventions, such as using /api as the endpoint and results as the key for paginated responses.
Sources: infrahub_sync/adapters/peeringmanager.py:20-39
PeeringmanagerModel
This class handles individual data records. It implements the update method to translate DiffSync attribute changes back into REST PATCH requests that Peering Manager understands, including resolving references to other models.
Sources: infrahub_sync/adapters/peeringmanager.py:42-105
Configuration and Environment Variables
The adapter requires specific environment variables or configuration settings to authenticate and locate the Peering Manager instance.
| Setting | Environment Variables | Default Value | Description |
|---|---|---|---|
url | PEERING_MANAGER_ADDRESS, PEERING_MANAGER_URL | N/A | The base URL of the Peering Manager instance. |
token | PEERING_MANAGER_TOKEN | N/A | The API token for authentication. |
api_endpoint | N/A | /api | The base path for API requests. |
auth_method | N/A | token | The method used to authenticate requests. |
response_key_pattern | N/A | results | The JSON key containing the list of objects in API responses. |
Sources: infrahub_sync/adapters/peeringmanager.py:27-36, examples/peering-manager_to_infrahub/config.yml:7-12
Data Flow: Update Process
When the adapter acts as a destination, it reconciles differences by updating existing objects. The PeeringmanagerModel.update method performs complex mapping of local attributes to Peering Manager API fields.
The flow shows how the model translates high-level DiffSync attributes into specific REST API payloads during a synchronization update.
Sources: infrahub_sync/adapters/peeringmanager.py:53-105
Relationship Handling
During the update process, the adapter specifically handles reference fields. If a field in the schema_mapping is marked as a reference, the adapter looks up the associated node in the DiffSync store to retrieve its local_id (the Peering Manager internal ID), ensuring that foreign key relationships remain valid.
Sources: infrahub_sync/adapters/peeringmanager.py:76-92
Schema Mapping Example
Synchronization is governed by the schema_mapping in config.yml. This mapping defines how source API paths (like peering/autonomous-systems) map to destination Infrahub models (like InfraAutonomousSystem).
- name: InfraAutonomousSystem
mapping: peering/autonomous-systems
identifiers: ["asn"]
fields:
- name: name
mapping: name
- name: asn
mapping: asn
- name: organization
mapping: name
reference: OrganizationProvider
Sources: examples/peering-manager_to_infrahub/config.yml:50-65
Supported Resource Mappings
The Peering Manager Adapter commonly handles the following resource types as evidenced in the example configuration:
| Infrahub Model | Peering Manager API Path | Identifiers |
|---|---|---|
OrganizationProvider | peering/autonomous-systems | name |
InfraAutonomousSystem | peering/autonomous-systems | asn |
InfraBGPCommunity | peering/communities | name (slug) |
InfraIXP | peering/internet-exchanges | name |
IpamIPAddress | net/connections | address |
InfraIXPConnection | net/connections | name |
Sources: examples/peering-manager_to_infrahub/config.yml:45-160
The Peering Manager Adapter provides a robust bridge for network peering data. By leveraging the GenericrestapiAdapter base, it focuses on the specific nuances of Peering Manager's data model and API behavior, ensuring consistent synchronization of ASN, BGP, and IXP resources within the Infrahub ecosystem.