Data Flow¶
This document illustrates the data flow from NetBox to Nautobot.
Data Flow Diagram¶
A detailed description of the individual steps can be found in the developer Generator Documentation or the user Using the App documentation.
flowchart LR
subgraph user[User Actions]
direction TB
A[Export Data from NetBox] --> |User exports JSON file| B[Execute 'import_netbox' Command]
end
subgraph importer[Importer Process]
direction TB
C[Configure Deviations] --> transaction
subgraph transaction[Transaction Block]
direction TB
subgraph firstiter[First Input Iteration]
direction TB
FI1[Read SourceRecord]
FI2[Create SourceModelWrappers and Field definitions]
FI1 --> FI2
FI2 --> FI1
end
E[First Iteration Over Data] --> firstiter
firstiter --> F[Create Importers]
F --> seconditer
subgraph seconditer[Second Input Iteration]
direction TB
SI1[Read SourceRecord]
SI2[Attempt to read Nautobot DiffSyncModel instance]
SI3[Create NetBox DiffSyncModel instance]
SI1 --> SI2
SI2 --> SI3
SI3 --> SI1
end
seconditer --> G[Assing content_types fields]
G --> H[Evaluate Differences with DiffSync]
H --> I[Synchronization into Nautobot]
end
transaction --> K[Print summary]
end
user --> | JSON file reference | importer
%% Add legend
style A fill:#f9f,stroke:#333,stroke-width:2px
style K fill:#bbf,stroke:#333,stroke-width:2px
Data Export¶
The user exports data from NetBox into a JSON file, described here.
Import Execution¶
The user executes the nautobot-server import_netbox command to initiate the import process by passing the JSON file reference as an argument, described here.
Initial Setup¶
The importer initializes by setting up the following objects:
NetBoxAdapterandNautobotAdapterinstances to interact with the respective systems.configure_model()is used to define deviations between NetBox and Nautobot data models, resulting in aSourceModelWrapperinstance for each content type.- It generates
SourceFieldinstances based on the provided configuration.- Field definitions are stored for the later creation of importers.
- Creates a
NautobotModelWrapperfor each mapped Nautobot content type.
- It generates
Transaction Processing¶
A database transaction begins, encompassing the steps below:
- The
NetBoxAdapteremploysget_source_data()to retrieve and iterate over NetBox data:- Each piece of data is represented as a
SourceRecordcontaining acontent_typestring and adatadictionary. - The importer constructs its internal hierarchy by establishing
SourceModelWrapperinstances for each content type, which includeSourceFieldinstances for each key found in thedatadictionary.
- Each piece of data is represented as a
- The importer generates field importers for each
SourceModelWrapper, mapping each field to a correspondingNautobotFieldusingfield.set_importer(<source importer>, <nautobot field name>).- It may disable field import based on specific conditions, such as defining a field as
Noneor in case of absent Nautobot fields. - Then it establishes an importer according to the Nautobot field type or using a custom field definition.
- It may disable field import based on specific conditions, such as defining a field as
- The importer goes through the JSON file a second time, processing each
SourceRecordto enact the relevant import actions for each content type.- This can involve creating
DiffSyncModelinstances and storing them usingNetBoxAdapter. - For each
DiffSyncModelinstance created, it attempts to load the Nautobot object from the database as anotherDiffSyncModelinstance and store it usingNautobotAdapter.
- This can involve creating
- Post-import actions are invoked for each
SourceModelWrapper, wherecontent_typesfields values are assigned based on the references cached during data import. - The importer evaluates the differences (a "diff") between NetBox and Nautobot data sets.
- DiffSync, an internal mechanism, is used to synchronize data into Nautobot's database following the comparison.
- Any Nautobot objects that faced validation issues during synchronization are checked using
clean(), which captures the issues withinImporterIssueinstances.
Finalization¶
A summary of the import operation is presented at the end.