NetBox Sync BGP ASNs¤
task API name:
sync_bgp_asn
The sync_bgp_asn task collects globally unique BGP ASNs from live devices
using the Nornir TTP bgp_asn getter and reconciles them with NetBox IPAM.
It updates descriptions and optionally records the devices on which each ASN
was observed. It never deletes ASNs or device associations.
Inputs¤
| Parameter | Required | Default | Description |
|---|---|---|---|
devices |
Conditional | None |
NetBox and Nornir device names; a device or Nornir filter is required |
rir |
For creation | None |
Existing NetBox RIR name used to create missing ASNs |
device_custom_field |
No | devices |
Multi-object ASN custom field related to dcim.device |
ignore_asn_by_range |
No | None |
ASN values or numerical ranges to exclude, such as 65000 or 65100-65200 |
instance |
No | Worker default | NetBox instance to target |
branch |
No | None |
NetBox Branching plugin branch |
dry_run |
No | False |
Return the calculated diff without writing |
with_approval |
No | False |
Request approval before writing |
timeout |
No | 600 |
Host-resolution and parsing timeout in seconds |
| Nornir filters | Conditional | — | Select devices using FB, FC, FG, FL, and other FFun filters |
Existing ASNs can be updated without rir. If missing ASNs are discovered and
rir is omitted or does not exist, the task reports the issue, skips their
creation, and continues updating existing ASNs.
The device custom field must be assigned to ipam.asn, use the multi-object
type, and relate to dcim.device. A missing field is ignored.
Output¤
Results are grouped under global and contain created, updated, deleted,
and in_sync ASN lists. Dry-run output uses create, update, delete, and
in_sync. The delete list is always empty.
Examples¤
nf# netbox sync bgp-asn devices edge-1 edge-2 rir Private
Ignore individual ASNs and ranges:
nf# netbox sync bgp-asn devices edge-1 rir Private ignore-asn-by-range 65000 65100-65200
Preview updates without supplying an RIR:
nf# netbox sync bgp-asn devices edge-1 dry-run
from norfab.core.nfapi import NorFab
with NorFab(inventory="./inventory.yaml") as nf:
result = nf.make_client().run_job(
"netbox",
"sync_bgp_asn",
workers="any",
kwargs={
"devices": ["edge-1", "edge-2"],
"rir": "Private",
},
)
print(result)
Notes and Gotchas¤
- When several devices report the same ASN, the first non-empty description in device-name order is used.
- Existing device associations are preserved and newly observed devices are appended.
with_approvalcannot be combined with the NFCLInowaitoption.
Python API Reference¤
Synchronize globally unique live BGP ASNs with NetBox.
Existing ASNs are updated without requiring an RIR. Missing ASNs are
created only when rir identifies an existing NetBox RIR. The
selected ASN custom field records devices on which each ASN was
observed. ASNs and device associations are never deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job object. |
required |
instance
|
Union[None, str]
|
NetBox instance name. Uses the default instance when omitted. |
None
|
dry_run
|
bool
|
Return the calculated diff without writing to NetBox. |
False
|
with_approval
|
bool
|
Ask for approval before applying the prepared diff. |
False
|
timeout
|
int
|
Timeout in seconds for Nornir host resolution and parsing. |
600
|
devices
|
Union[None, list]
|
Explicit NetBox and Nornir device names. |
None
|
branch
|
Union[None, str]
|
NetBox Branching plugin branch name. |
None
|
rir
|
Union[None, str]
|
NetBox RIR name required when creating missing ASNs. |
None
|
device_custom_field
|
str
|
ASN custom field containing associated devices. |
'devices'
|
ignore_asn_by_range
|
Union[None, list]
|
ASN values or numerical ranges to ignore. |
None
|
**kwargs
|
Any
|
Nornir FFun host filters. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Global ASN synchronization actions. |
Source code in norfab\workers\netbox_worker\bgp_asn_tasks.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 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 | |