Netbox Library
svc_netbox_lib.netbox
netbox_delete_interface(token, id)
Delete an interface from NetBox.
Parameters
token : str NetBox API token for authentication. id : int NetBox interface id to delete.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
netbox_delete_ip_address(token, ip_id)
Delete an IP address from NetBox.
Parameters
token : str NetBox API token for authentication. ip_id : int NetBox IP address object id to delete.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
netbox_delete_vlan(token, id)
Delete a VLAN object from NetBox.
Parameters
token : str NetBox API token for authentication. id : int NetBox VLAN object id to delete.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
netbox_delete_vrf(token, vrf_id)
Delete a VRF from NetBox.
Parameters
token : str NetBox API token for authentication. vrf_id : int NetBox VRF object id to delete.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
netbox_get_device_platform(token, device_id)
Get the current platform name and upgrade flag for a device in NetBox.
Parameters
token : str NetBox API token for authentication. device_id : int NetBox device id.
Returns
tuple[str, Any] (platform_name, upgrade_flag) where platform_name is the platform name string or 'none' and upgrade_flag is the device's custom_fields['upgrade'] value or None.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
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 | |
netbox_get_fqdn(token, site, device)
Query NetBox for a device and return its FQDN/name.
Parameters
token : str NetBox API token for authentication. site : str Site identifier to filter devices by. device : str Search string for the device (e.g. 'br1', 'csw1').
Returns
str Device FQDN/name if found, otherwise the string 'none'.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
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 | |
netbox_get_id(token, location, device)
Return the NetBox device id for a device matching location and name.
Parameters
token : str NetBox API token for authentication. location : str Site/location code to filter devices by. device : str Search string for the device.
Returns
int NetBox device id (raises if no results are found).
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
netbox_get_interfaces(token, id)
Fetch interfaces for a NetBox device and return a structured mapping.
Parameters
token : str NetBox API token for authentication. id : int NetBox device id to list interfaces for.
Returns
dict[str, dict] Mapping of interface name -> dict containing: - 'id' (int): NetBox interface id - 'description' (str) - 'type' (str): one of 'SMF', 'MMF', 'copper', 'lag', 'No SFP', etc. - 'speed' (str): human-readable speed tag
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
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 | |
netbox_get_ipv4_public_prefix(token, site)
Return the IPv4 public prefix role entry for a given site.
Parameters
token : str
NetBox API token for authentication.
site : str
Site identifier (used to construct the role filter: '
Returns
str The prefix string (e.g. '64.191.201.0/24'), or an empty string if none found.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
netbox_get_ipv4_public_routes(token, site)
Return IPv4 public addresses (children of the site's public prefix) from NetBox.
Parameters
token : str NetBox API token for authentication. site : str Site identifier to locate the parent public prefix.
Returns
dict[str, dict] Mapping of address (CIDR string) -> dict with keys 'id' and 'description'.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
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 | |
netbox_get_platforms(token)
Return a list of platform names (software versions) from NetBox.
Parameters
token : str NetBox API token for authentication.
Returns
list[str] List of platform names as strings.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
netbox_get_sites()
Return the list of supported SVC site identifiers.
Returns
list[str] A list of site codes (e.g. 'ld5', 'da6', 'ny5', ...).
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
4 5 6 7 8 9 10 11 12 13 14 | |
netbox_get_vlan_dictionary(token, site, device)
Return a mapping of VLAN tag to NetBox VLAN ID for a site and device filter.
Parameters
token : str NetBox API token for authentication. site : str Site identifier to filter VLANs by. device : str Search/filter term for VLANs (passed as 'q' to the API).
Returns
dict[int, int] or dict Mapping of VLAN VID (int) -> NetBox VLAN object id (int). If the request fails or no data is present, returns {'none': 'none'}.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
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 | |
netbox_get_vrfs(token, site)
Return VRFs for a given site from NetBox with selected metadata.
Parameters
token : str NetBox API token for authentication. site : str Site identifier to filter VRFs by (custom field 'Site').
Returns
dict[str, dict] Mapping of VRF name -> dict with keys: - 'id' : NetBox VRF id - 'instance_type' : custom field 'type' - 'route_distinguisher' : rd (string) - 'instance_interface' : tags list - 'site' : custom field 'Site'
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
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 | |
netbox_patch_device_platform(token, device_id, payload)
Patch/update the platform (software version) of a device in NetBox.
Parameters
token : str NetBox API token for authentication. device_id : int NetBox device id. payload : dict JSON payload with platform update fields.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
netbox_patch_interface(token, interface_id, payload)
Patch/update an interface object in NetBox.
Parameters
token : str NetBox API token for authentication. interface_id : int NetBox interface id to update. payload : dict JSON payload with fields to update.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
netbox_patch_ip_address(token, ip_id, payload)
Patch/update an IP address object in NetBox.
Parameters
token : str NetBox API token for authentication. ip_id : int NetBox IP address object id to update. payload : dict JSON payload with fields to update (e.g. {'description': '...'}).
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
netbox_patch_vrf(token, vrf_id, payload)
Patch/update a VRF object in NetBox.
Parameters
token : str NetBox API token for authentication. vrf_id : int NetBox VRF object id to update. payload : dict JSON payload with fields to update.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
netbox_post_interface(token, payload)
Create one or more interfaces in NetBox.
Parameters
token : str NetBox API token for authentication. payload : dict JSON payload for interface creation per NetBox API.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
netbox_post_ip_address(token, payload)
Create a new IP address in NetBox.
Parameters
token : str NetBox API token for authentication. payload : dict JSON payload for IP creation (e.g. {'address': 'x.x.x.x/yy', 'description': '...', 'vrf': {...}}).
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
netbox_post_platform(token, payload)
Create a new platform (software version) in NetBox.
Parameters
token : str NetBox API token for authentication. payload : dict JSON payload for platform creation (e.g. {'name': ..., 'slug': ...}).
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
netbox_post_vlan(token, payload)
Create a VLAN in NetBox.
Parameters
token : str NetBox API token for authentication. payload : dict JSON payload for VLAN creation following NetBox API schema.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
netbox_post_vrf(token, payload)
Create a new VRF in NetBox.
Parameters
token : str NetBox API token for authentication. payload : dict JSON payload for VRF creation per NetBox API.
Returns
int HTTP status code returned by the NetBox API.
Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |