Netbox Sync Device Prefixes Task¤
task api name:
sync_device_prefixes
The task derives IPv4 and IPv6 networks from live device interface addresses
and reconciles those prefixes with NetBox. It is independent from
sync_device_ip: it does not require NetBox interfaces and does not create or
update IP address records.
How It Works¤
- Resolve the selected devices and validate that they exist in NetBox.
- Run Nornir
parse_ttpwithget="interfaces"for the selected devices. - Apply interface, prefix, and ignore-range filters.
- Convert each address to its canonical network, for example
10.0.0.1/31to10.0.0.0/31. - Deduplicate observations, compare them with NetBox, and create missing or update out-of-sync prefixes.
NetBox interface presence is never checked. A prefix can therefore be synchronized before its source interface exists in NetBox.
Output¤
The result is global because the same prefix can be reported by several devices:
{
"created": ["10.0.0.0/31"],
"updated": ["10.0.1.0/31"],
"in_sync": ["2001:db8::1/128"]
}
Dry-run returns the same structure without writing to NetBox. With
with_approval=True, the prepared result is shown for approval before any
prefixes are written.
VRF Handling¤
ignore_vrf=True is the default:
- Prefixes are matched by canonical prefix alone.
- Existing VRF associations are preserved.
- New prefixes are created without a VRF.
With ignore_vrf=False:
- The live interface VRF is resolved by name; a missing VRF is created.
- Prefixes are matched by canonical prefix and VRF.
- If the same prefix exists in another VRF, that object is preserved and a new prefix is created in the live VRF.
globalanddefaultinterface VRFs are treated as the global table.
Site Handling¤
ignore_site=True is the default:
- Device sites are not written to prefixes.
- Existing prefix scope/site associations are preserved.
With ignore_site=False:
- New prefixes are associated with the reporting device's site.
- Existing matching prefixes are updated when their site differs.
- When several devices report the same prefix identity, the site from the alphabetically first device name is authoritative.
Prefix identity is the prefix alone when VRFs are ignored, otherwise it is the prefix and resolved VRF together.
Filtering¤
Interface filters are applied to live data before prefix derivation. Prefix filters are applied to the derived canonical prefixes:
filter_by_name— interface-name glob, such asLoopback*.filter_by_description— interface-description glob.filter_by_prefix— include prefixes contained within one IPv4 or IPv6 network.ignore_ranges— exclude derived prefixes fully contained within any supplied IPv4 or IPv6 network. A narrower ignored network does not exclude a broader live prefix containing it.
The default ignored ranges are:
127.0.0.0/8
224.0.0.0/24
fe80::/10
ff02::/16
::ffff:0:0/96
::1/128
Filters combine using intersection.
For example, ignore_ranges="10.3.15.33/32" does not exclude the live prefix
10.3.15.32/30, while ignore_ranges="10.3.15.0/24" does.
Deletion Behavior¤
The task never deletes prefixes. A prefix absent from the selected live device data is left unchanged in NetBox.
Branching Support¤
Pass branch=<name> to create or update prefixes in a NetBox Branching Plugin
branch. The task creates the branch when it does not already exist.
Examples¤
Synchronize prefixes from one device:
nf#netbox sync prefixes devices ceos-spine-1
Preview prefixes derived from loopbacks:
nf#netbox sync prefixes devices ceos-spine-1 filter-by-name "Loopback*" dry-run
Associate prefixes with live VRFs and device sites:
nf#netbox sync prefixes devices ceos-spine-1 ignore-vrf false ignore-site false
Select devices with a Nornir filter:
nf#netbox sync prefixes FC spine
result = client.run_job(
"netbox",
"sync_device_prefixes",
workers="any",
kwargs={
"devices": ["ceos-spine-1", "ceos-spine-2"],
"dry_run": True,
},
)
result = client.run_job(
"netbox",
"sync_device_prefixes",
workers="any",
kwargs={
"devices": ["ceos-spine-1"],
"ignore_vrf": False,
"ignore_site": False,
"filter_by_prefix": "10.0.0.0/8",
},
)
NORFAB Netbox Sync Device Prefixes Command Shell Reference¤
nf# man tree netbox.sync.prefixes
root
└── netbox
└── sync
└── prefixes
├── timeout
├── workers
├── verbose-result
├── progress
├── instance
├── dry-run
├── with-approval
├── devices
├── ignore-ranges
├── ignore-vrf
├── ignore-site
├── filter-by-name
├── filter-by-description
├── filter-by-prefix
├── branch
└── Nornir host filters
Python API Reference¤
Synchronize prefixes derived from live interface addresses into NetBox.
Prefixes are collected from the Nornir TTP interfaces getter without
requiring corresponding NetBox interfaces. Existing prefixes are matched
by prefix alone when ignore_vrf=True and by prefix plus VRF otherwise.
Site association is left unchanged by default. When ignore_site=False,
the site of the alphabetically first device reporting a prefix is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab Job object containing relevant metadata. |
required |
instance
|
Union[None, str]
|
NetBox instance name. |
None
|
dry_run
|
bool
|
Return the reconciliation plan without writing to NetBox. |
False
|
with_approval
|
bool
|
Preview changes and ask for review before applying them. |
False
|
timeout
|
int
|
Timeout in seconds for Nornir parsing and host resolution. |
600
|
devices
|
Union[None, list]
|
Explicit device names to collect prefixes from. |
None
|
branch
|
str
|
NetBox Branching plugin branch name. |
None
|
ignore_ranges
|
Union[None, str, list]
|
Exclude derived prefixes fully contained in these ranges. |
None
|
ignore_vrf
|
bool
|
Ignore live VRFs and preserve existing prefix VRFs. |
True
|
ignore_site
|
bool
|
Ignore device sites and preserve existing prefix scopes. |
True
|
filter_by_name
|
Union[None, str]
|
Interface-name glob filter. |
None
|
filter_by_description
|
Union[None, str]
|
Interface-description glob filter. |
None
|
filter_by_prefix
|
Union[None, str]
|
Include prefixes within this network only. |
None
|
**kwargs
|
Any
|
Nornir host filter arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Global |
Source code in norfab\workers\netbox_worker\ip_tasks.py
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 | |