Nautobot NetBox Importer Package¶
nautobot_netbox_importer
¶
App declaration for nautobot_netbox_importer.
NautobotNetboxImporterConfig
¶
Bases: NautobotAppConfig
App configuration for the nautobot_netbox_importer app.
Source code in nautobot_netbox_importer/__init__.py
base
¶
Base types for the Nautobot Importer.
register_generator_setup(module)
¶
Register adapter setup function.
This function must be called before the adapter is used and containing module can't import anything from Nautobot.
Source code in nautobot_netbox_importer/base.py
command_utils
¶
Utility functions and classes for nautobot_netbox_importer.
LogRenderer
¶
Class for rendering structured logs to the console in a human-readable format.
Example
19:48:19 Apparent duplicate object encountered? duplicate_id: {'group': None, 'name': 'CR02.CHI_ORDMGMT', 'site': {'name': 'CHI01'}, 'vid': 1000} model: vlan pk_1: 3baf142d-dd90-4379-a048-3bbbcc9c799c pk_2: cba19791-4d59-4ddd-a5c9-d969ec3ed2ba
Source code in nautobot_netbox_importer/command_utils.py
__call__(logger, name, event_dict)
¶
Render the given event_dict to a string.
Source code in nautobot_netbox_importer/command_utils.py
enable_logging(verbosity=0, color=None)
¶
Set up structlog (as used by DiffSync) to log messages for this command.
Source code in nautobot_netbox_importer/command_utils.py
initialize_logger(options)
¶
Initialize logger instance.
Source code in nautobot_netbox_importer/command_utils.py
diffsync
¶
DiffSync adapter and model implementation for nautobot-netbox-importer.
This folder is an importer implementation specific to NetBox, in opposite to generator
folder, that is a generic Source => Nautobot importer.
adapters
¶
Adapter classes for loading DiffSyncModels with data from NetBox or Nautobot.
NautobotAdapter
¶
Bases: NautobotAdapter
DiffSync adapter for Nautobot.
Source code in nautobot_netbox_importer/diffsync/adapters/nautobot.py
__init__(*args, job=None, sync=None, **kwargs)
¶
Initialize Nautobot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
tuple
|
Arguments to be passed to the parent class. |
()
|
job
|
object
|
Nautobot job. Defaults to None. |
None
|
sync
|
object
|
Nautobot DiffSync. Defaults to None. |
None
|
**kwargs
|
dict
|
Additional arguments to be passed to the parent class. |
{}
|
Source code in nautobot_netbox_importer/diffsync/adapters/nautobot.py
NetBoxAdapter
¶
Bases: SourceAdapter
NetBox Source Adapter.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
__init__(input_ref, options, job=None, sync=None, *args, **kwargs)
¶
Initialize NetBox Source Adapter.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
import_to_nautobot()
¶
Import a NetBox export file into Nautobot.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
load()
¶
Load data from NetBox.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
NetBoxImporterOptions
¶
Bases: NamedTuple
NetBox importer options.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
nautobot
¶
Nautobot Adapter for NetBox Importer.
NautobotAdapter
¶
Bases: NautobotAdapter
DiffSync adapter for Nautobot.
Source code in nautobot_netbox_importer/diffsync/adapters/nautobot.py
__init__(*args, job=None, sync=None, **kwargs)
¶Initialize Nautobot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
tuple
|
Arguments to be passed to the parent class. |
()
|
job
|
object
|
Nautobot job. Defaults to None. |
None
|
sync
|
object
|
Nautobot DiffSync. Defaults to None. |
None
|
**kwargs
|
dict
|
Additional arguments to be passed to the parent class. |
{}
|
Source code in nautobot_netbox_importer/diffsync/adapters/nautobot.py
netbox
¶
NetBox to Nautobot Source Importer Definitions.
NetBoxAdapter
¶
Bases: SourceAdapter
NetBox Source Adapter.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
__init__(input_ref, options, job=None, sync=None, *args, **kwargs)
¶Initialize NetBox Source Adapter.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
import_to_nautobot()
¶Import a NetBox export file into Nautobot.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
load()
¶Load data from NetBox.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
NetBoxImporterOptions
¶
Bases: NamedTuple
NetBox importer options.
Source code in nautobot_netbox_importer/diffsync/adapters/netbox.py
models
¶
NetBox Importer DiffSync Models.
base
¶
NetBox to Nautobot Base Models Mapping.
setup(adapter)
¶
Map NetBox base models to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/base.py
cables
¶
DCIM data related functions.
create_missing_cable_terminations(adapter)
¶
Fix cables by ensuring proper terminations.
This function processes all cables from the source adapter and validates/fixes termination information for both sides of each cable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adapter
|
SourceAdapter
|
The source adapter containing cable data |
required |
Source code in nautobot_netbox_importer/diffsync/models/cables.py
setup(adapter)
¶
Map NetBox Cable related models to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/cables.py
circuits
¶
NetBox to Nautobot Circuits Models Mapping.
setup(adapter)
¶
Map NetBox circuits models to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/circuits.py
content_types
¶
NetBox to Nautobot Base Models Mapping.
setup(adapter)
¶
Map NetBox content types to Nautobot.
It's vital to map NetBox content types to Nautobot content types properly.
Automatically calculate NetBox content type IDs, if not provided, based on the order of the content types.
Source code in nautobot_netbox_importer/diffsync/models/content_types.py
custom_fields
¶
NetBox to Nautobot Custom Fields Models Mapping.
setup(adapter)
¶
Map NetBox custom fields to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/custom_fields.py
dcim
¶
NetBox to Nautobot DCIM Models Mapping.
fix_power_feed_locations(adapter)
¶
Fix panel location to match rack location based on powerfeed.
Source code in nautobot_netbox_importer/diffsync/models/dcim.py
setup(adapter)
¶
Map NetBox DCIM models to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/dcim.py
unrack_zero_uheight_devices(adapter)
¶
Unrack devices with 0U height.
Source code in nautobot_netbox_importer/diffsync/models/dcim.py
ipam
¶
NetBox to Nautobot IPAM Models Mapping.
setup(adapter)
¶
Map NetBox IPAM models to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/ipam.py
locations
¶
NetBox Specific Locations handling.
define_location(field)
¶
Define location field for NetBox importer.
Source code in nautobot_netbox_importer/diffsync/models/locations.py
define_locations(field)
¶
Define locations field for NetBox importer.
Source code in nautobot_netbox_importer/diffsync/models/locations.py
setup(adapter)
¶
Setup locations for NetBox importer.
Source code in nautobot_netbox_importer/diffsync/models/locations.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
object_change
¶
NetBox to Nautobot Object Change Model Mapping.
setup(adapter)
¶
Map NetBox object change to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/object_change.py
tags
¶
NetBox to Nautobot Tags related Models Mapping.
setup(adapter)
¶
Map NetBox tags related models to Nautobot.
virtualization
¶
NetBox to Nautobot Virtualization Models Mapping.
setup(adapter)
¶
Map NetBox virtualization models to Nautobot.
Source code in nautobot_netbox_importer/diffsync/models/virtualization.py
generator
¶
Generic Nautobot Import Library using DiffSync.
DiffSyncBaseModel
¶
Bases: DiffSyncModel
Base class for all DiffSync models.
Source code in nautobot_netbox_importer/generator/nautobot.py
create(adapter, ids, attrs)
classmethod
¶
Create this model instance, both in Nautobot and in DiffSync.
Source code in nautobot_netbox_importer/generator/nautobot.py
update(attrs)
¶
Update this model instance, both in Nautobot and in DiffSync.
Source code in nautobot_netbox_importer/generator/nautobot.py
ImporterPass
¶
InternalFieldType
¶
Bases: Enum
Internal field types.
Source code in nautobot_netbox_importer/generator/base.py
InvalidChoiceValueIssue
¶
Bases: SourceFieldIssue
Raised when an invalid choice value is encountered.
Source code in nautobot_netbox_importer/generator/source.py
__init__(field, value, replacement=NOTHING)
¶
Initialize the exception.
Source code in nautobot_netbox_importer/generator/source.py
NautobotAdapter
¶
Bases: BaseAdapter
Nautobot DiffSync Adapter.
Source code in nautobot_netbox_importer/generator/nautobot.py
__init__(*args, **kwargs)
¶
Initialize the adapter.
get_content_type_str(content_type_uid)
¶
Find Nautobot content type string for a given UID.
Source code in nautobot_netbox_importer/generator/nautobot.py
get_or_create_wrapper(content_type)
¶
Get or create a Nautobot model wrapper.
Source code in nautobot_netbox_importer/generator/nautobot.py
tag_issues(summary)
¶
Tag all records with any ImporterIssue.
Source code in nautobot_netbox_importer/generator/nautobot.py
PreImportRecordResult
¶
SourceAdapter
¶
Bases: BaseAdapter
Source DiffSync Adapter for importing data into Nautobot.
This adapter manages the entire import process from external data sources to Nautobot, including content type mapping, data transformation, and reference handling. It serves as the primary engine for the import process, maintaining relationships between source and target (Nautobot) models.
Attributes:
Name | Type | Description |
---|---|---|
get_source_data |
SourceDataGenerator
|
Function that generates source data records for import, returning an iterable of SourceRecord objects. |
wrappers |
OrderedDict
|
Ordered mapping of content type strings to SourceModelWrapper objects that handle the adaptation of source data to Nautobot models. |
nautobot |
NautobotAdapter
|
Adapter for interacting with Nautobot models and data. |
content_type_ids_mapping |
Dict[int, SourceModelWrapper]
|
Maps numeric content type IDs to their corresponding source model wrappers. |
summary |
ImportSummary
|
Collects statistics and information about the import process. |
logger |
Logger instance for reporting progress and issues. |
|
_content_types_back_mapping |
Dict[ContentTypeStr, Optional[ContentTypeStr]]
|
Maps from Nautobot content types back to source content types. When multiple source types map to a single Nautobot type, the mapping is set to None. |
The adapter works in phases:
- Model configuration - defining how source models map to Nautobot
- First pass - scanning source data to enhance defined structures
- Creation of importers - building functions to transform data
- Second pass - importing actual data
- Post-processing - handling references and finalizing imports
Source code in nautobot_netbox_importer/generator/source.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
__init__(*args, get_source_data, trace_issues=False, nautobot=None, logger=None, **kwargs)
¶
Initialize the SourceAdapter.
Source code in nautobot_netbox_importer/generator/source.py
configure_model(content_type, nautobot_content_type='', extend_content_type='', identifiers=None, fields=None, default_reference=None, flags=None, nautobot_flags=None, pre_import_record=None, post_import_record=None, disable_related_reference=None, forward_references=None, fill_placeholder=None, get_pk_from_data=None)
¶
Create or configure a wrapper for a source content type.
This method defines how a source data model maps to a Nautobot model during import, establishing field mappings, identifiers, processing behaviors, and reference handling. It serves as the primary configuration point for data adaptation between source and target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content_type
|
ContentTypeStr
|
String identifier for the source content type (e.g., "dcim.device"). Will be converted to lowercase. This is the primary identifier for the source model in the import process. |
required |
nautobot_content_type
|
ContentTypeStr
|
Target Nautobot content type to map to. If empty, defaults to the source content_type value. Will be converted to lowercase. Use this when the source model name differs from Nautobot's model. |
''
|
extend_content_type
|
ContentTypeStr
|
Name of an existing source content type to extend. When specified, the current model inherits the Nautobot content type and behaviors from the extended model. Cannot be used with nautobot_content_type. Useful for creating specialized versions of existing model mappings. |
''
|
identifiers
|
Optional[Iterable[FieldName]]
|
Collection of field names that uniquely identify records in this model. Used to match source records with existing Nautobot records. These fields serve as natural keys for record identification when primary keys don't match between systems. |
None
|
fields
|
Optional[Mapping[FieldName, SourceFieldDefinition]]
|
Dictionary mapping source field names to their definitions, which can be:
These mappings control exactly how each field is transformed during import. |
None
|
default_reference
|
Optional[RecordData]
|
Record data to use when this model is referenced but no specific record is provided. Creates a default instance for references that can be used as fallbacks for required relationships. |
None
|
flags
|
Optional[DiffSyncModelFlags]
|
DiffSync model flags controlling synchronization behavior for the source model. These flags affect how changes are detected and applied during the synchronization process. |
None
|
nautobot_flags
|
Optional[DiffSyncModelFlags]
|
DiffSync model flags for the target Nautobot model. Allows different sync behavior between source and target models. |
None
|
pre_import_record
|
Optional[PreImportRecord]
|
Function called before importing each record. Signature: (data: RecordData, pass: ImporterPass) -> PreImportRecordResult Can return SKIP_RECORD to exclude records from import. Useful for filtering or preprocessing data before import. |
None
|
post_import_record
|
Optional[PostImportRecord]
|
Function called after importing each record. Signature: (data: RecordData, model: DiffSyncBaseModel) -> None Enables custom post-processing of imported records, such as denormalization or triggering additional operations. |
None
|
disable_related_reference
|
Optional[bool]
|
When True, prevents automatic content_type field references from being created when this model is referenced by other models. Useful for models that should not participate in automatic reference tracking. |
None
|
forward_references
|
ForwardReferences
|
Custom function to allow forwarding references to another instance. Signature: (wrapper: SourceModelWrapper, references: SourceReferences) -> None |
None
|
fill_placeholder
|
Optional[FillPlaceholder]
|
Function to populate data when creating placeholder objects. Signature: (data: RecordData, suffix: str) -> None Used when creating placeholder objects to satisfy required relationships. |
None
|
get_pk_from_data
|
Optional[GetPkFromData]
|
Custom function to derive Nautobot's primary key from source record data. Signature: (data: RecordData) -> Uid Overrides default primary key generation logic when source data has complex or non-standard primary key representations. |
None
|
Returns:
Name | Type | Description |
---|---|---|
SourceModelWrapper |
SourceModelWrapper
|
The created or updated wrapper for the source content type, ready for use in the import process with all specified configurations applied. |
Raises:
Type | Description |
---|---|
ValueError
|
If both nautobot_content_type and extend_content_type are specified, or if a content type is already mapped to a different Nautobot content type. These configurations are mutually exclusive. |
Source code in nautobot_netbox_importer/generator/source.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
disable_model(content_type, disable_reason)
¶
get_imported_nautobot_wrappers()
¶
Get a list of Nautobot model wrappers in the order of import.
Source code in nautobot_netbox_importer/generator/source.py
get_nautobot_content_type_uid(content_type)
¶
Get the Django content type ID for a given content type.
Source code in nautobot_netbox_importer/generator/source.py
get_or_create_wrapper(value)
¶
Get a source Wrapper for a given content type.
Source code in nautobot_netbox_importer/generator/source.py
import_data()
¶
Import data from the source.
Source code in nautobot_netbox_importer/generator/source.py
load()
¶
post_load()
¶
Post import processing.
Source code in nautobot_netbox_importer/generator/source.py
summarize(diffsync_summary)
¶
Summarize the import.
Source code in nautobot_netbox_importer/generator/source.py
SourceField
¶
Represents a field in the source data model and manages its mapping to Nautobot.
This class handles field definition and reference between source data and Nautobot models. It provides mechanisms for customizing field mappings and setting importers for different field types.
Attributes:
Name | Type | Description |
---|---|---|
wrapper |
SourceModelWrapper
|
Reference to the parent wrapper that manages this field, providing context about the model it belongs to. |
name |
FieldName
|
The name of this field in the source data model. |
definition |
SourceFieldDefinition
|
How this field should be processed, can be: - None: Field should be ignored - str: Field should be renamed to this name in Nautobot - callable: Factory function to create field importer |
sources |
set
|
Set of SourceFieldSource enum values indicating the origin of this field (AUTO, CACHE, DATA, CUSTOM, SIBLING, IDENTIFIER). |
processed |
bool
|
Flag indicating whether this field has been processed during the import pipeline. |
_nautobot |
NautobotField
|
Reference to the corresponding Nautobot field wrapper that this source field maps to. |
importer |
SourceFieldImporter
|
Function that handles importing data from source to target for this field. The specific function depends on the field type. |
default_value |
Any
|
Default value to use when the field is missing in source data. Often derived from the Nautobot model's field default. |
disable_reason |
str
|
If non-empty, explains why this field is disabled for import. Disabled fields are skipped during the import process. |
Source code in nautobot_netbox_importer/generator/source.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 |
|
nautobot
property
¶
Get the Nautobot field wrapper.
__init__(wrapper, name, source)
¶
Initialize the SourceField.
Source code in nautobot_netbox_importer/generator/source.py
__str__()
¶
add_issue(issue_type, message, target=None)
¶
Add an importer issue to the Nautobot Model Wrapper.
Source code in nautobot_netbox_importer/generator/source.py
create_importer()
¶
Create importer for the field.
Source code in nautobot_netbox_importer/generator/source.py
disable(reason)
¶
get_source_value(source)
¶
Get a value from the source data, returning a default value if the value is empty.
Source code in nautobot_netbox_importer/generator/source.py
get_summary()
¶
Get a summary of the field.
Source code in nautobot_netbox_importer/generator/source.py
handle_sibling(sibling, nautobot_name='')
¶
Specify, that this field importer handles other field.
Source code in nautobot_netbox_importer/generator/source.py
set_choice_importer()
¶
Set a choice field importer.
Source code in nautobot_netbox_importer/generator/source.py
set_content_type_importer()
¶
Set a content type importer.
Source code in nautobot_netbox_importer/generator/source.py
set_content_types_importer()
¶
Set a content types importer.
Source code in nautobot_netbox_importer/generator/source.py
set_date_importer()
¶
Set a date importer.
Source code in nautobot_netbox_importer/generator/source.py
set_datetime_importer()
¶
Set a datetime importer.
Source code in nautobot_netbox_importer/generator/source.py
set_definition(definition)
¶
Customize field definition.
Source code in nautobot_netbox_importer/generator/source.py
set_importer(importer=None, nautobot_name='', override=False)
¶
Sets the importer and Nautobot field if not already specified.
If nautobot_name
is not provided, the field name is used.
Passing None to nautobot_name
indicates that there is custom mapping without a direct relationship to a Nautobot field.
Source code in nautobot_netbox_importer/generator/source.py
set_integer_importer()
¶
Set an integer field importer.
Source code in nautobot_netbox_importer/generator/source.py
set_json_importer()
¶
Set a JSON field importer.
Source code in nautobot_netbox_importer/generator/source.py
set_m2m_importer(related_source=None)
¶
Set a many to many importer.
Source code in nautobot_netbox_importer/generator/source.py
set_nautobot_field(nautobot_name='')
¶
Set a Nautobot field name for the field.
Source code in nautobot_netbox_importer/generator/source.py
set_nautobot_value(target, value)
¶
Set a value to the Nautobot model.
Source code in nautobot_netbox_importer/generator/source.py
set_relation_and_type_importer(type_field)
¶
Set a relation UUID importer based on the type field.
Source code in nautobot_netbox_importer/generator/source.py
set_relation_importer(related_source=None)
¶
Set a relation importer.
Source code in nautobot_netbox_importer/generator/source.py
set_status_importer()
¶
Set a status importer.
Source code in nautobot_netbox_importer/generator/source.py
set_timezone_importer()
¶
Set a timezone importer.
Source code in nautobot_netbox_importer/generator/source.py
set_uuid_importer()
¶
Set an UUID importer.
Source code in nautobot_netbox_importer/generator/source.py
set_value_importer()
¶
Set a value importer.
Source code in nautobot_netbox_importer/generator/source.py
SourceFieldIssue
¶
Bases: NetBoxImporterException
Raised when an error occurs during field import.
Source code in nautobot_netbox_importer/generator/source.py
__init__(message, field, issue_type='')
¶
Initialize the exception.
Source code in nautobot_netbox_importer/generator/source.py
SourceModelWrapper
¶
Definition of a source model mapping to Nautobot model.
This class maintains the mapping between a source data model and its corresponding Nautobot model. It handles field definitions, data transformations, importing records, and tracking references between models.
Attributes:
Name | Type | Description |
---|---|---|
adapter |
SourceAdapter
|
Parent adapter that manages this wrapper and coordinates the overall import process. |
content_type |
ContentTypeStr
|
String identifier for source content type (e.g., "dcim.device"). |
nautobot |
NautobotModelWrapper
|
Wrapper for the target Nautobot model, containing field definitions and handling interactions with Nautobot's data model. |
identifiers |
List[FieldName]
|
Field names used to uniquely identify records when primary keys don't match between systems. Acts as natural keys for record identification. |
disable_reason |
str
|
If non-empty, explains why this model is disabled for import. Disabled models are skipped during the import process. |
disable_related_reference |
bool
|
When True, prevents references processing. See |
extends_wrapper |
SourceModelWrapper
|
Another wrapper this one extends. When specified, this wrapper's data will be merged into the extended wrapper's instances. |
references |
SourceReferences
|
Cache all referencing content types for each imported instance of this model. Used to fill in Nautobot's |
forward_references |
ForwardReferences
|
Custom function to allow forwarding references to another instance. See |
fields |
OrderedDict[FieldName, SourceField]
|
Field definitions for this model, mapping source field names to their corresponding SourceField objects. |
importers |
Set[SourceFieldImporter]
|
Collection of functions that import fields from source to target. Each function handles the transformation of a specific field or set of related fields. |
flags |
DiffSyncModelFlags
|
Flags controlling DiffSync behavior for this model, affecting how changes are detected and applied during synchronization. |
default_reference_uid |
Uid
|
UID for the default record used when referencing this model but no specific record is provided. |
pre_import_record |
PreImportRecord
|
Function called before importing each record that can filter or preprocess records before import. |
post_import_record |
PostImportRecord
|
Function called after importing each record that can perform additional operations or validations. |
stats |
SourceModelStats
|
Statistics tracking for import operations on this model, including counts of created, imported, and cached records. |
_uid_to_pk_cache |
Dict[Uid, Uid]
|
Cache mapping source UIDs to primary keys for quick lookup during the import process. |
_cached_data |
Dict[Uid, RecordData]
|
Cache of data records by UID, used for storing records that might be referenced later but aren't directly imported. |
_fill_placeholder |
FillPlaceholder
|
Function to populate data when creating placeholder objects. |
_get_pk_from_data |
GetPkFromData
|
Custom function to derive Nautobot primary keys from source record data, allowing for custom key generation strategies. |
Source code in nautobot_netbox_importer/generator/source.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
__init__(adapter, content_type, nautobot_wrapper)
¶
Initialize the SourceModelWrapper.
Source code in nautobot_netbox_importer/generator/source.py
__str__()
¶
add_field(name, source)
¶
Add a field definition for a source field.
Source code in nautobot_netbox_importer/generator/source.py
add_reference(related_wrapper, uid)
¶
Add a reference from this content type to related record.
Source code in nautobot_netbox_importer/generator/source.py
cache_record(data)
¶
Cache data for optional later use.
If record is referenced by other models, it will be imported automatically; otherwise, it will be ignored.
Source code in nautobot_netbox_importer/generator/source.py
cache_record_uids(source, nautobot_uid=None)
¶
Cache record identifier mappings.
When nautobot_uid
is not provided, it is generated from the source data and caching is processed there.
Source code in nautobot_netbox_importer/generator/source.py
create_importers()
¶
Create importers for all fields.
Source code in nautobot_netbox_importer/generator/source.py
disable_field(field_name, reason)
¶
Disable field importing.
find_pk_from_uid(uid)
¶
Find a source primary key for a given source uid.
first_pass(data)
¶
Firts pass of data import.
Source code in nautobot_netbox_importer/generator/source.py
format_field_name(name)
¶
get_default_reference_uid()
¶
Get the default reference to this model.
get_or_create(uid, fail_missing=False)
¶
Get an existing DiffSync Model instance from the source or create a new one.
Use Nautobot data as defaults if available.
Source code in nautobot_netbox_importer/generator/source.py
get_pk_from_data(data)
¶
Get a source primary key for a given source data.
Source code in nautobot_netbox_importer/generator/source.py
get_pk_from_identifiers(data)
¶
Get a source primary key for a given source identifiers.
Source code in nautobot_netbox_importer/generator/source.py
get_pk_from_uid(uid)
¶
Get a source primary key for a given source uid.
Source code in nautobot_netbox_importer/generator/source.py
get_summary(content_type_id)
¶
Get a summary of the model.
Source code in nautobot_netbox_importer/generator/source.py
import_placeholder(suffix, data=None)
¶
Create a placeholder object for the given data.
Source code in nautobot_netbox_importer/generator/source.py
import_record(data, target=None)
¶
Import a single item from the source.
Source code in nautobot_netbox_importer/generator/source.py
is_pk_cached(uid)
¶
post_process_references()
¶
Post import processing.
Assigns referenced content_types to referencing instances.
Returns False if no post processing is needed, otherwise True to indicate that post processing is needed.
Source code in nautobot_netbox_importer/generator/source.py
second_pass(data)
¶
Second pass of data import.
Source code in nautobot_netbox_importer/generator/source.py
set_default_reference(data)
¶
set_identifiers(identifiers)
¶
Set identifiers for the model.
Source code in nautobot_netbox_importer/generator/source.py
SourceRecord
¶
base
¶
Generic DiffSync Importer base module.
BaseAdapter
¶
Bases: Adapter
Base class for Generator Adapters.
Source code in nautobot_netbox_importer/generator/base.py
InternalFieldType
¶
Bases: Enum
Internal field types.
Source code in nautobot_netbox_importer/generator/base.py
get_nautobot_field_and_type(model, field_name)
¶
Get Nautobot field and internal field type.
Source code in nautobot_netbox_importer/generator/base.py
normalize_datetime(value)
¶
Normalize datetime values to UTC to compare with DiffSync.
Source code in nautobot_netbox_importer/generator/base.py
source_pk_to_uuid(content_type, pk, namespace=uuid5(UUID('33c07af8-e425-43b2-b8d0-52289dfe7cf2'), settings.SECRET_KEY))
¶
Deterministically map source primary key to a UUID primary key.
One of the reasons Nautobot moved from sequential integers to UUIDs was to protect the application against key-enumeration attacks, so we don't use a hard-coded mapping from integer to UUID as that would defeat the purpose.
Source code in nautobot_netbox_importer/generator/base.py
exceptions
¶
Custom exceptions for the NetBox Importer.
NautobotModelNotFound
¶
Bases: NetBoxImporterException
Raised when a Nautobot model cannot be found.
fields
¶
Generic Field Importers definitions for Nautobot Importer.
auto_increment(prefix='', nautobot_name='')
¶
Auto increment field value, if the source value is empty.
Use to set the field value to a unique auto incremented value.
Supports string and integer fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
str
|
Optional prefix to be added to the auto incremented value. Valid for string fields only. |
''
|
nautobot_name
|
str
|
Optional name for the Nautobot field. |
''
|
Returns:
Type | Description |
---|---|
SourceFieldDefinition
|
A function that defines an auto increment field importer. |
Source code in nautobot_netbox_importer/generator/fields.py
constant(value, nautobot_name='', reference=None)
¶
Create a constant field definition for target record.
Map a constant value to a specific field in the target model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
Constant value to be set in the target field. |
required |
nautobot_name
|
FieldName
|
Optional name for the Nautobot field. |
''
|
reference
|
Optional[SourceModelWrapper]
|
Optional source model wrapper for reference tracking. |
None
|
Returns:
Type | Description |
---|---|
SourceFieldDefinition
|
A function that defines a constant field importer. |
Source code in nautobot_netbox_importer/generator/fields.py
default(default_value, nautobot_name='')
¶
Create a default field definition.
Use to set a default value for the field, if there is no value in the source data.
Source code in nautobot_netbox_importer/generator/fields.py
disable(reason)
¶
Disable the field.
Use to disable the field import with the given reason.
Source code in nautobot_netbox_importer/generator/fields.py
fallback(value=None, callback=None, nautobot_name='')
¶
Create a fallback field definition.
Use to set a fallback value or callback for the field, if there is an error during the default importer.
Source code in nautobot_netbox_importer/generator/fields.py
force(nautobot_name='')
¶
Mark Nautobot field as forced.
Use to force the field to be saved in Nautobot in the second save attempt after the initial save to override the default value set by Nautobot.
Source code in nautobot_netbox_importer/generator/fields.py
pass_through(nautobot_name='')
¶
Create a pass-through field definition.
Use to pass-through the value from source to target without changing it by the default importer.
Source code in nautobot_netbox_importer/generator/fields.py
relation(related_source, nautobot_name='')
¶
Create a relation field definition.
Use when there is a different source content type that should be mapped to Nautobot relation.
Source code in nautobot_netbox_importer/generator/fields.py
role(adapter, source_content_type, nautobot_name='role')
¶
Create a role field definition.
Use, when there is a different source role content type that should be mapped to the Nautobot "extras.Role".
It creates a new wrapper for the source_content_type
if it does not already exist.
It also handles the scenario where the same role names are used in different role models,
e.g., RackRole with name = "Network"
and DeviceRole with name = "Network"
to avoid duplicates.
Source code in nautobot_netbox_importer/generator/fields.py
source_constant(value, nautobot_name='')
¶
Create a source constant field definition.
Use, to pre-fill constant value for the field. Calls default importer after setting the value.
Source code in nautobot_netbox_importer/generator/fields.py
nautobot
¶
Nautobot DiffSync Importer.
DiffSyncBaseModel
¶
Bases: DiffSyncModel
Base class for all DiffSync models.
Source code in nautobot_netbox_importer/generator/nautobot.py
create(adapter, ids, attrs)
classmethod
¶
Create this model instance, both in Nautobot and in DiffSync.
Source code in nautobot_netbox_importer/generator/nautobot.py
update(attrs)
¶
Update this model instance, both in Nautobot and in DiffSync.
Source code in nautobot_netbox_importer/generator/nautobot.py
NautobotAdapter
¶
Bases: BaseAdapter
Nautobot DiffSync Adapter.
Source code in nautobot_netbox_importer/generator/nautobot.py
__init__(*args, **kwargs)
¶
Initialize the adapter.
get_content_type_str(content_type_uid)
¶
Find Nautobot content type string for a given UID.
Source code in nautobot_netbox_importer/generator/nautobot.py
get_or_create_wrapper(content_type)
¶
Get or create a Nautobot model wrapper.
Source code in nautobot_netbox_importer/generator/nautobot.py
tag_issues(summary)
¶
Tag all records with any ImporterIssue.
Source code in nautobot_netbox_importer/generator/nautobot.py
NautobotField
¶
Wrapper for a Nautobot field.
Source code in nautobot_netbox_importer/generator/nautobot.py
can_import
property
¶
Determine if this field can be imported.
is_auto_increment
property
¶
Check if the field is an integer.
is_content_type
property
¶
Check if the field is a content type.
is_integer
property
¶
Check if the field is an integer.
is_reference
property
¶
Check if the field is a reference.
related_meta
property
¶
Get the Nautobot model meta.
related_model
property
¶
Get the related model for a reference field.
__init__(name, internal_type, field=None)
¶
Initialize the wrapper.
Source code in nautobot_netbox_importer/generator/nautobot.py
NautobotModelWrapper
¶
Wrapper for a Nautobot model.
Source code in nautobot_netbox_importer/generator/nautobot.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
|
content_type_id
property
¶
Get the Nautobot content type ID.
content_type_instance
property
¶
Get the Nautobot content type instance for a given content type.
diffsync_class
property
¶
Get DiffSyncModel
class for this wrapper.
model
property
¶
Get the Nautobot model.
model_meta
property
¶
Get the Nautobot model meta.
pk_field
property
¶
Get the pk field.
__init__(adapter, content_type)
¶
Initialize the wrapper.
Source code in nautobot_netbox_importer/generator/nautobot.py
__str__()
¶
add_field(field_name)
¶
Add a field to the model.
Source code in nautobot_netbox_importer/generator/nautobot.py
add_issue(issue_type='', message='', uid='', data=None, diffsync_instance=None, nautobot_instance=None, error=None, nautobot_name='')
¶
Add a new importer issue.
This function register an issue and returns the issue object. All input arguments are optional, internal logic tries to fill in as much information as possible based on the arguments provided.
It can be called in any import stage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
issue_type
|
Optional[str]
|
The type of the issue, e.g. "SaveFailed". Can be determined from |
''
|
message
|
Optional[str]
|
A message to be included in the issue. Can be determined from |
''
|
uid
|
Optional[Uid]
|
The UID of the instance that caused the issue. Can be determined from instances. |
''
|
data
|
Optional[Mapping]
|
The data that caused the issue. |
None
|
diffsync_instance
|
Optional[DiffSyncModel]
|
The DiffSync instance that caused the issue. |
None
|
nautobot_instance
|
Optional[NautobotBaseModel]
|
The Nautobot instance that caused the issue. |
None
|
error
|
Optional[Exception]
|
The error that caused the issue. |
None
|
nautobot_name
|
Optional[str]
|
The name of the Nautobot instance that caused the issue. This is determined after the import, before creating summaries. |
''
|
Examples can be found by looking at calls to this function in the code.
Source code in nautobot_netbox_importer/generator/nautobot.py
find_or_create(identifiers_kwargs)
¶
Find a DiffSync instance based on filter kwargs or create a new instance from Nautobot if possible.
Source code in nautobot_netbox_importer/generator/nautobot.py
get_importer_issues()
¶
Get importer issues for this model.
This will also run clean
on all instances that failed clean()
after saving.
Source code in nautobot_netbox_importer/generator/nautobot.py
get_summary()
¶
Get the summary.
Source code in nautobot_netbox_importer/generator/nautobot.py
save_nautobot_instance(instance, values)
¶
Save a Nautobot instance.
When the first Nautobot save()
fails, importer calls super.save()
.
If that passes, FirstSaveFailed
issue is created.
This is to skip Nautobot checks/updates defined in save()
method.
If super.save() fails, it creates SaveFailed
issue, and the instance is not saved.
This can lead to integrity errors if the missing instance is referenced by other instances.
After the save, clean()
is called on the instance. If it fails, it creates a CleanFailed
issue.
It's possible to define force fields that are set after the initial save.
This is to override any values set by Nautobot save()
method.
To define field as forced, specify "<field name>": fields.force()
in configure_model(fields={ ... })
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
NautobotBaseModel
|
The Nautobot model instance to save |
required |
values
|
RecordData
|
Dictionary of field values to apply to the instance |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the instance was saved successfully, False otherwise |
Source code in nautobot_netbox_importer/generator/nautobot.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
|
set_instance_defaults(**defaults)
¶
tag_issues(issues)
¶
Tag all records with any ImporterIssue.
Source code in nautobot_netbox_importer/generator/nautobot.py
source
¶
Generic DiffSync Source Generator.
FallbackValueIssue
¶
Bases: SourceFieldIssue
Raised when a fallback value is used.
Source code in nautobot_netbox_importer/generator/source.py
__init__(field, target_value)
¶
ImporterPass
¶
InvalidChoiceValueIssue
¶
Bases: SourceFieldIssue
Raised when an invalid choice value is encountered.
Source code in nautobot_netbox_importer/generator/source.py
__init__(field, value, replacement=NOTHING)
¶
Initialize the exception.
Source code in nautobot_netbox_importer/generator/source.py
PreImportRecordResult
¶
SourceAdapter
¶
Bases: BaseAdapter
Source DiffSync Adapter for importing data into Nautobot.
This adapter manages the entire import process from external data sources to Nautobot, including content type mapping, data transformation, and reference handling. It serves as the primary engine for the import process, maintaining relationships between source and target (Nautobot) models.
Attributes:
Name | Type | Description |
---|---|---|
get_source_data |
SourceDataGenerator
|
Function that generates source data records for import, returning an iterable of SourceRecord objects. |
wrappers |
OrderedDict
|
Ordered mapping of content type strings to SourceModelWrapper objects that handle the adaptation of source data to Nautobot models. |
nautobot |
NautobotAdapter
|
Adapter for interacting with Nautobot models and data. |
content_type_ids_mapping |
Dict[int, SourceModelWrapper]
|
Maps numeric content type IDs to their corresponding source model wrappers. |
summary |
ImportSummary
|
Collects statistics and information about the import process. |
logger |
Logger instance for reporting progress and issues. |
|
_content_types_back_mapping |
Dict[ContentTypeStr, Optional[ContentTypeStr]]
|
Maps from Nautobot content types back to source content types. When multiple source types map to a single Nautobot type, the mapping is set to None. |
The adapter works in phases:
- Model configuration - defining how source models map to Nautobot
- First pass - scanning source data to enhance defined structures
- Creation of importers - building functions to transform data
- Second pass - importing actual data
- Post-processing - handling references and finalizing imports
Source code in nautobot_netbox_importer/generator/source.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
__init__(*args, get_source_data, trace_issues=False, nautobot=None, logger=None, **kwargs)
¶
Initialize the SourceAdapter.
Source code in nautobot_netbox_importer/generator/source.py
configure_model(content_type, nautobot_content_type='', extend_content_type='', identifiers=None, fields=None, default_reference=None, flags=None, nautobot_flags=None, pre_import_record=None, post_import_record=None, disable_related_reference=None, forward_references=None, fill_placeholder=None, get_pk_from_data=None)
¶
Create or configure a wrapper for a source content type.
This method defines how a source data model maps to a Nautobot model during import, establishing field mappings, identifiers, processing behaviors, and reference handling. It serves as the primary configuration point for data adaptation between source and target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content_type
|
ContentTypeStr
|
String identifier for the source content type (e.g., "dcim.device"). Will be converted to lowercase. This is the primary identifier for the source model in the import process. |
required |
nautobot_content_type
|
ContentTypeStr
|
Target Nautobot content type to map to. If empty, defaults to the source content_type value. Will be converted to lowercase. Use this when the source model name differs from Nautobot's model. |
''
|
extend_content_type
|
ContentTypeStr
|
Name of an existing source content type to extend. When specified, the current model inherits the Nautobot content type and behaviors from the extended model. Cannot be used with nautobot_content_type. Useful for creating specialized versions of existing model mappings. |
''
|
identifiers
|
Optional[Iterable[FieldName]]
|
Collection of field names that uniquely identify records in this model. Used to match source records with existing Nautobot records. These fields serve as natural keys for record identification when primary keys don't match between systems. |
None
|
fields
|
Optional[Mapping[FieldName, SourceFieldDefinition]]
|
Dictionary mapping source field names to their definitions, which can be:
These mappings control exactly how each field is transformed during import. |
None
|
default_reference
|
Optional[RecordData]
|
Record data to use when this model is referenced but no specific record is provided. Creates a default instance for references that can be used as fallbacks for required relationships. |
None
|
flags
|
Optional[DiffSyncModelFlags]
|
DiffSync model flags controlling synchronization behavior for the source model. These flags affect how changes are detected and applied during the synchronization process. |
None
|
nautobot_flags
|
Optional[DiffSyncModelFlags]
|
DiffSync model flags for the target Nautobot model. Allows different sync behavior between source and target models. |
None
|
pre_import_record
|
Optional[PreImportRecord]
|
Function called before importing each record. Signature: (data: RecordData, pass: ImporterPass) -> PreImportRecordResult Can return SKIP_RECORD to exclude records from import. Useful for filtering or preprocessing data before import. |
None
|
post_import_record
|
Optional[PostImportRecord]
|
Function called after importing each record. Signature: (data: RecordData, model: DiffSyncBaseModel) -> None Enables custom post-processing of imported records, such as denormalization or triggering additional operations. |
None
|
disable_related_reference
|
Optional[bool]
|
When True, prevents automatic content_type field references from being created when this model is referenced by other models. Useful for models that should not participate in automatic reference tracking. |
None
|
forward_references
|
ForwardReferences
|
Custom function to allow forwarding references to another instance. Signature: (wrapper: SourceModelWrapper, references: SourceReferences) -> None |
None
|
fill_placeholder
|
Optional[FillPlaceholder]
|
Function to populate data when creating placeholder objects. Signature: (data: RecordData, suffix: str) -> None Used when creating placeholder objects to satisfy required relationships. |
None
|
get_pk_from_data
|
Optional[GetPkFromData]
|
Custom function to derive Nautobot's primary key from source record data. Signature: (data: RecordData) -> Uid Overrides default primary key generation logic when source data has complex or non-standard primary key representations. |
None
|
Returns:
Name | Type | Description |
---|---|---|
SourceModelWrapper |
SourceModelWrapper
|
The created or updated wrapper for the source content type, ready for use in the import process with all specified configurations applied. |
Raises:
Type | Description |
---|---|
ValueError
|
If both nautobot_content_type and extend_content_type are specified, or if a content type is already mapped to a different Nautobot content type. These configurations are mutually exclusive. |
Source code in nautobot_netbox_importer/generator/source.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
disable_model(content_type, disable_reason)
¶
get_imported_nautobot_wrappers()
¶
Get a list of Nautobot model wrappers in the order of import.
Source code in nautobot_netbox_importer/generator/source.py
get_nautobot_content_type_uid(content_type)
¶
Get the Django content type ID for a given content type.
Source code in nautobot_netbox_importer/generator/source.py
get_or_create_wrapper(value)
¶
Get a source Wrapper for a given content type.
Source code in nautobot_netbox_importer/generator/source.py
import_data()
¶
Import data from the source.
Source code in nautobot_netbox_importer/generator/source.py
load()
¶
post_load()
¶
Post import processing.
Source code in nautobot_netbox_importer/generator/source.py
summarize(diffsync_summary)
¶
Summarize the import.
Source code in nautobot_netbox_importer/generator/source.py
SourceField
¶
Represents a field in the source data model and manages its mapping to Nautobot.
This class handles field definition and reference between source data and Nautobot models. It provides mechanisms for customizing field mappings and setting importers for different field types.
Attributes:
Name | Type | Description |
---|---|---|
wrapper |
SourceModelWrapper
|
Reference to the parent wrapper that manages this field, providing context about the model it belongs to. |
name |
FieldName
|
The name of this field in the source data model. |
definition |
SourceFieldDefinition
|
How this field should be processed, can be: - None: Field should be ignored - str: Field should be renamed to this name in Nautobot - callable: Factory function to create field importer |
sources |
set
|
Set of SourceFieldSource enum values indicating the origin of this field (AUTO, CACHE, DATA, CUSTOM, SIBLING, IDENTIFIER). |
processed |
bool
|
Flag indicating whether this field has been processed during the import pipeline. |
_nautobot |
NautobotField
|
Reference to the corresponding Nautobot field wrapper that this source field maps to. |
importer |
SourceFieldImporter
|
Function that handles importing data from source to target for this field. The specific function depends on the field type. |
default_value |
Any
|
Default value to use when the field is missing in source data. Often derived from the Nautobot model's field default. |
disable_reason |
str
|
If non-empty, explains why this field is disabled for import. Disabled fields are skipped during the import process. |
Source code in nautobot_netbox_importer/generator/source.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 |
|
nautobot
property
¶
Get the Nautobot field wrapper.
__init__(wrapper, name, source)
¶
Initialize the SourceField.
Source code in nautobot_netbox_importer/generator/source.py
__str__()
¶
add_issue(issue_type, message, target=None)
¶
Add an importer issue to the Nautobot Model Wrapper.
Source code in nautobot_netbox_importer/generator/source.py
create_importer()
¶
Create importer for the field.
Source code in nautobot_netbox_importer/generator/source.py
disable(reason)
¶
get_source_value(source)
¶
Get a value from the source data, returning a default value if the value is empty.
Source code in nautobot_netbox_importer/generator/source.py
get_summary()
¶
Get a summary of the field.
Source code in nautobot_netbox_importer/generator/source.py
handle_sibling(sibling, nautobot_name='')
¶
Specify, that this field importer handles other field.
Source code in nautobot_netbox_importer/generator/source.py
set_choice_importer()
¶
Set a choice field importer.
Source code in nautobot_netbox_importer/generator/source.py
set_content_type_importer()
¶
Set a content type importer.
Source code in nautobot_netbox_importer/generator/source.py
set_content_types_importer()
¶
Set a content types importer.
Source code in nautobot_netbox_importer/generator/source.py
set_date_importer()
¶
Set a date importer.
Source code in nautobot_netbox_importer/generator/source.py
set_datetime_importer()
¶
Set a datetime importer.
Source code in nautobot_netbox_importer/generator/source.py
set_definition(definition)
¶
Customize field definition.
Source code in nautobot_netbox_importer/generator/source.py
set_importer(importer=None, nautobot_name='', override=False)
¶
Sets the importer and Nautobot field if not already specified.
If nautobot_name
is not provided, the field name is used.
Passing None to nautobot_name
indicates that there is custom mapping without a direct relationship to a Nautobot field.
Source code in nautobot_netbox_importer/generator/source.py
set_integer_importer()
¶
Set an integer field importer.
Source code in nautobot_netbox_importer/generator/source.py
set_json_importer()
¶
Set a JSON field importer.
Source code in nautobot_netbox_importer/generator/source.py
set_m2m_importer(related_source=None)
¶
Set a many to many importer.
Source code in nautobot_netbox_importer/generator/source.py
set_nautobot_field(nautobot_name='')
¶
Set a Nautobot field name for the field.
Source code in nautobot_netbox_importer/generator/source.py
set_nautobot_value(target, value)
¶
Set a value to the Nautobot model.
Source code in nautobot_netbox_importer/generator/source.py
set_relation_and_type_importer(type_field)
¶
Set a relation UUID importer based on the type field.
Source code in nautobot_netbox_importer/generator/source.py
set_relation_importer(related_source=None)
¶
Set a relation importer.
Source code in nautobot_netbox_importer/generator/source.py
set_status_importer()
¶
Set a status importer.
Source code in nautobot_netbox_importer/generator/source.py
set_timezone_importer()
¶
Set a timezone importer.
Source code in nautobot_netbox_importer/generator/source.py
set_uuid_importer()
¶
Set an UUID importer.
Source code in nautobot_netbox_importer/generator/source.py
set_value_importer()
¶
Set a value importer.
Source code in nautobot_netbox_importer/generator/source.py
SourceFieldIssue
¶
Bases: NetBoxImporterException
Raised when an error occurs during field import.
Source code in nautobot_netbox_importer/generator/source.py
__init__(message, field, issue_type='')
¶
Initialize the exception.
Source code in nautobot_netbox_importer/generator/source.py
SourceFieldSource
¶
Bases: Enum
Defines the source of the SourceField.
Source code in nautobot_netbox_importer/generator/source.py
SourceModelWrapper
¶
Definition of a source model mapping to Nautobot model.
This class maintains the mapping between a source data model and its corresponding Nautobot model. It handles field definitions, data transformations, importing records, and tracking references between models.
Attributes:
Name | Type | Description |
---|---|---|
adapter |
SourceAdapter
|
Parent adapter that manages this wrapper and coordinates the overall import process. |
content_type |
ContentTypeStr
|
String identifier for source content type (e.g., "dcim.device"). |
nautobot |
NautobotModelWrapper
|
Wrapper for the target Nautobot model, containing field definitions and handling interactions with Nautobot's data model. |
identifiers |
List[FieldName]
|
Field names used to uniquely identify records when primary keys don't match between systems. Acts as natural keys for record identification. |
disable_reason |
str
|
If non-empty, explains why this model is disabled for import. Disabled models are skipped during the import process. |
disable_related_reference |
bool
|
When True, prevents references processing. See |
extends_wrapper |
SourceModelWrapper
|
Another wrapper this one extends. When specified, this wrapper's data will be merged into the extended wrapper's instances. |
references |
SourceReferences
|
Cache all referencing content types for each imported instance of this model. Used to fill in Nautobot's |
forward_references |
ForwardReferences
|
Custom function to allow forwarding references to another instance. See |
fields |
OrderedDict[FieldName, SourceField]
|
Field definitions for this model, mapping source field names to their corresponding SourceField objects. |
importers |
Set[SourceFieldImporter]
|
Collection of functions that import fields from source to target. Each function handles the transformation of a specific field or set of related fields. |
flags |
DiffSyncModelFlags
|
Flags controlling DiffSync behavior for this model, affecting how changes are detected and applied during synchronization. |
default_reference_uid |
Uid
|
UID for the default record used when referencing this model but no specific record is provided. |
pre_import_record |
PreImportRecord
|
Function called before importing each record that can filter or preprocess records before import. |
post_import_record |
PostImportRecord
|
Function called after importing each record that can perform additional operations or validations. |
stats |
SourceModelStats
|
Statistics tracking for import operations on this model, including counts of created, imported, and cached records. |
_uid_to_pk_cache |
Dict[Uid, Uid]
|
Cache mapping source UIDs to primary keys for quick lookup during the import process. |
_cached_data |
Dict[Uid, RecordData]
|
Cache of data records by UID, used for storing records that might be referenced later but aren't directly imported. |
_fill_placeholder |
FillPlaceholder
|
Function to populate data when creating placeholder objects. |
_get_pk_from_data |
GetPkFromData
|
Custom function to derive Nautobot primary keys from source record data, allowing for custom key generation strategies. |
Source code in nautobot_netbox_importer/generator/source.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
__init__(adapter, content_type, nautobot_wrapper)
¶
Initialize the SourceModelWrapper.
Source code in nautobot_netbox_importer/generator/source.py
__str__()
¶
add_field(name, source)
¶
Add a field definition for a source field.
Source code in nautobot_netbox_importer/generator/source.py
add_reference(related_wrapper, uid)
¶
Add a reference from this content type to related record.
Source code in nautobot_netbox_importer/generator/source.py
cache_record(data)
¶
Cache data for optional later use.
If record is referenced by other models, it will be imported automatically; otherwise, it will be ignored.
Source code in nautobot_netbox_importer/generator/source.py
cache_record_uids(source, nautobot_uid=None)
¶
Cache record identifier mappings.
When nautobot_uid
is not provided, it is generated from the source data and caching is processed there.
Source code in nautobot_netbox_importer/generator/source.py
create_importers()
¶
Create importers for all fields.
Source code in nautobot_netbox_importer/generator/source.py
disable_field(field_name, reason)
¶
Disable field importing.
find_pk_from_uid(uid)
¶
Find a source primary key for a given source uid.
first_pass(data)
¶
Firts pass of data import.
Source code in nautobot_netbox_importer/generator/source.py
format_field_name(name)
¶
get_default_reference_uid()
¶
Get the default reference to this model.
get_or_create(uid, fail_missing=False)
¶
Get an existing DiffSync Model instance from the source or create a new one.
Use Nautobot data as defaults if available.
Source code in nautobot_netbox_importer/generator/source.py
get_pk_from_data(data)
¶
Get a source primary key for a given source data.
Source code in nautobot_netbox_importer/generator/source.py
get_pk_from_identifiers(data)
¶
Get a source primary key for a given source identifiers.
Source code in nautobot_netbox_importer/generator/source.py
get_pk_from_uid(uid)
¶
Get a source primary key for a given source uid.
Source code in nautobot_netbox_importer/generator/source.py
get_summary(content_type_id)
¶
Get a summary of the model.
Source code in nautobot_netbox_importer/generator/source.py
import_placeholder(suffix, data=None)
¶
Create a placeholder object for the given data.
Source code in nautobot_netbox_importer/generator/source.py
import_record(data, target=None)
¶
Import a single item from the source.
Source code in nautobot_netbox_importer/generator/source.py
is_pk_cached(uid)
¶
post_process_references()
¶
Post import processing.
Assigns referenced content_types to referencing instances.
Returns False if no post processing is needed, otherwise True to indicate that post processing is needed.
Source code in nautobot_netbox_importer/generator/source.py
second_pass(data)
¶
Second pass of data import.
Source code in nautobot_netbox_importer/generator/source.py
set_default_reference(data)
¶
set_identifiers(identifiers)
¶
Set identifiers for the model.
Source code in nautobot_netbox_importer/generator/source.py
SourceRecord
¶
TruncatedValueIssue
¶
Bases: SourceFieldIssue
Raised when a value is truncated.
Source code in nautobot_netbox_importer/generator/source.py
__init__(field, source_value, target_value)
¶
Initialize the exception.
summary
¶
Importer summary module.
FieldSummary
¶
Bases: NamedTuple
Summarizes a field's mapping between source and target systems.
Fields
name: Source field name in the source system nautobot_name: Corresponding field name in Nautobot (if any) nautobot_internal_type: Nautobot's internal data type for this field nautobot_can_import: Whether this field can be imported into Nautobot importer: Name of the importer function/method handling this field definition: Original field definition/value from source sources: List of sources where this field appears default_value: Default value used when source value is missing disable_reason: Reason why this field is disabled for import (if applicable) required: Whether this field is required in Nautobot
Source code in nautobot_netbox_importer/summary.py
ImportSummary
¶
Container class for import operation summary data.
Stores, processes and formats information about source models, target Nautobot models, and DiffSync operations during an import process.
Source code in nautobot_netbox_importer/summary.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
data_nautobot_models
property
¶
Get Nautobot models that correspond to data sources.
Yields:
Name | Type | Description |
---|---|---|
NautobotModelSummary |
NautobotModelSummary
|
Objects that have corresponding entries in data_sources. |
data_sources
property
¶
Get source models originating from data.
Yields:
Name | Type | Description |
---|---|---|
SourceModelSummary |
SourceModelSummary
|
Objects that originates from source data. |
__init__()
¶
Initialize the import summary with empty collections.
dump(path, output_format='json', indent=4)
¶
Save the import summary to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Pathable
|
Path-like object where to save the summary |
required |
output_format
|
str
|
Format to save in ('json' or 'text') |
'json'
|
indent
|
int
|
Number of spaces for JSON indentation (if output_format is 'json') |
4
|
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported output format is specified |
Examples:
>>> summary.dump("/tmp/import_results.json")
>>> summary.dump("/tmp/import_results.txt", output_format="text")
Source code in nautobot_netbox_importer/summary.py
get_back_mapping()
¶
Generate formatted information about reverse content type mapping.
Shows how Nautobot content types map back to source content types, identifying ambiguous mappings where multiple source types map to the same Nautobot type.
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted lines describing back mapping from Nautobot to source content types |
Source code in nautobot_netbox_importer/summary.py
get_content_types_deviations()
¶
Generate formatted information about content type mapping deviations.
Shows how source content types map to Nautobot content types, highlighting extensions and non-standard mappings.
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted lines describing content type mapping deviations |
Source code in nautobot_netbox_importer/summary.py
get_fields_mapping()
¶
Generate formatted information about field mappings between source and Nautobot.
Shows how fields from source models map to fields in Nautobot models, including import methods and data types.
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted lines describing field mappings |
Source code in nautobot_netbox_importer/summary.py
get_issues()
¶
Generate formatted information about issues encountered during import.
Groups issues by Nautobot content type and formats them for readability.
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted lines describing import issues |
Source code in nautobot_netbox_importer/summary.py
get_stats(caption, objects)
¶
Generate formatted statistics for a collection of objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
caption
|
str
|
Caption for the statistics section |
required |
objects
|
Iterable[object]
|
Collection of objects to summarize |
required |
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted lines of statistics information |
Source code in nautobot_netbox_importer/summary.py
get_summary()
¶
Generate a formatted text representation of the import summary.
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted lines with the import summary |
Source code in nautobot_netbox_importer/summary.py
load(path)
¶
Load import summary from a JSON file.
Loads the serialized summary information from a JSON file into the current instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Pathable
|
Path-like object pointing to a JSON summary file |
required |
Examples:
Source code in nautobot_netbox_importer/summary.py
ImporterIssue
¶
Bases: NamedTuple
Represents an issue encountered during the import process.
Fields
uid: Unique identifier for the issue name: Name of the affected object or field issue_type: Type of issue (e.g., 'validation', 'import_error') message: Descriptive error message data: Additional contextual data for debugging source_reference: Reference to the source data (mostly ID field) that caused the issue
Source code in nautobot_netbox_importer/summary.py
NautobotModelStats
¶
Nautobot Model Statistics.
Source code in nautobot_netbox_importer/summary.py
NautobotModelSummary
¶
Bases: NamedTuple
Summarizes a Nautobot model's import results and any issues.
Fields
content_type: Nautobot content type string identifier content_type_id: Numeric ID of the Nautobot content type (if available) flags: Feature flags applied to this model disabled: Whether this model is disabled for import stats: Statistics about the Nautobot model's import process issues: List of issues encountered during import for this model
Source code in nautobot_netbox_importer/summary.py
SourceModelStats
¶
Source Model Statistics.
Source code in nautobot_netbox_importer/summary.py
SourceModelSummary
¶
Bases: NamedTuple
Summarizes a source model's mapping to Nautobot and import statistics.
Fields
content_type: Source content type string identifier content_type_id: Numeric ID of the source content type extends_content_type: Parent content type that this model extends (if any) nautobot_content_type: Target Nautobot content type disable_reason: Reason why this model is disabled for import (if applicable) identifiers: List of fields used to uniquely identify instances disable_related_reference: Whether related references are disabled forward_references: Configuration for forward references handling pre_import: Pre-import processing function/method name post_import: Post-import processing function/method name fields: List of field summaries for this model flags: Feature flags applied to this model default_reference_uid: Default UID used for reference when actual reference is missing stats: Statistics about the source model's import process
Source code in nautobot_netbox_importer/summary.py
get_issue_tag(issue)
¶
Get a tag for an issue.
Source code in nautobot_netbox_importer/summary.py
serialize_to_summary(value)
¶
Serialize a value to a summary-compatible format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
NullablePrimitives
|
The value to serialize |
required |
Returns:
Name | Type | Description |
---|---|---|
NullablePrimitives |
NullablePrimitives
|
A summary-compatible representation of the value |
NullablePrimitives
|
|
|
NullablePrimitives
|
|
|
NullablePrimitives
|
|
|
NullablePrimitives
|
|
Examples:
>>> serialize_to_summary(None)
None
>>> serialize_to_summary("string")
"string"
>>> serialize_to_summary(42)
42
Source code in nautobot_netbox_importer/summary.py
tests
¶
Unit tests for nautobot_netbox_importer app.
test_basic
¶
Basic tests that do not require Django.
TestDocsPackaging
¶
Bases: TestCase
Test Version in doc requirements is the same pyproject.
Source code in nautobot_netbox_importer/tests/test_basic.py
test_version()
¶
Verify that pyproject.toml dev dependencies have the same versions as in the docs requirements.txt.
Source code in nautobot_netbox_importer/tests/test_basic.py
test_import
¶
Test cases for the NetBox adapter.
Tests use stored fixtures to verify that the import process works as expected.
Check the fixtures README for more details.
TestImport
¶
Bases: TestCase
Unittest for NetBox adapter.
Test cases are dynamically created based on the fixtures available for the current Nautobot version.
Source code in nautobot_netbox_importer/tests/test_import.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
setUp()
¶
Set up test environment.
Source code in nautobot_netbox_importer/tests/test_import.py
warn_if_building_fixtures()
¶
Context manager to catch exceptions when building fixtures and issue a warning instead.
Source code in nautobot_netbox_importer/tests/test_import.py
urls
¶
Django urlpatterns declaration for nautobot_netbox_importer app.