Netbox Get Containerlab Inventory Task¤
task api name:
get_containerlab_inventory
This task designed to provide Containerlab workers with inventory data sourced from Netbox to deploy lab topologies.
Get Containerlab Inventory Sample Usage¤
Below is an example of how to fetch Containerlab topology inventory data from Netbox for two devices named fceos4 and fceos5.
nf#netbox get containerlab-inventory devices fceos4 fceos5 lab-name foobar
--------------------------------------------- Job Events -----------------------------------------------
31-May-2025 13:10:14.477 7d434ed4e24c4a69af5d52797d7a187e job started
31-May-2025 13:10:14.525 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Fetching devices data from Netbox
31-May-2025 13:10:14.594 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Node added fceos4
31-May-2025 13:10:14.600 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Node added fceos5
31-May-2025 13:10:14.606 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Fetching connections data from Netbox
31-May-2025 13:10:15.211 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth1 - fceos4:eth1
31-May-2025 13:10:15.217 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth2 - fceos4:eth2
31-May-2025 13:10:15.225 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth3 - fceos4:eth3
31-May-2025 13:10:15.232 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth4 - fceos4:eth4
31-May-2025 13:10:15.238 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth6 - fceos4:eth6
31-May-2025 13:10:15.244 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth7 - fceos4:eth7
31-May-2025 13:10:15.250 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth8 - fceos4:eth101
31-May-2025 13:10:15.257 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Link added fceos5:eth11 - fceos4:eth11
31-May-2025 13:10:15.580 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Renaming fceos4 interfaces
31-May-2025 13:10:15.587 INFO netbox-worker-1.1 running netbox.get_containerlab_inventory - Renaming fceos5 interfaces
31-May-2025 13:10:15.808 7d434ed4e24c4a69af5d52797d7a187e job completed in 1.331 seconds
--------------------------------------------- Job Results --------------------------------------------
netbox-worker-1.1:
mgmt:
ipv4-subnet: 172.100.100.0/24
network: br-foobar
name: foobar
topology:
links:
- endpoints:
- interface: eth1
node: fceos5
- interface: eth1
node: fceos4
type: veth
- endpoints:
- interface: eth2
node: fceos5
- interface: eth2
node: fceos4
type: veth
- endpoints:
- interface: eth3
node: fceos5
- interface: eth3
node: fceos4
type: veth
- endpoints:
- interface: eth4
node: fceos5
- interface: eth4
node: fceos4
type: veth
- endpoints:
- interface: eth6
node: fceos5
- interface: eth6
node: fceos4
type: veth
- endpoints:
- interface: eth7
node: fceos5
- interface: eth7
node: fceos4
type: veth
- endpoints:
- interface: eth8
node: fceos5
- interface: eth101
node: fceos4
type: veth
- endpoints:
- interface: eth11
node: fceos5
- interface: eth11
node: fceos4
type: veth
nodes:
fceos4:
image: ceosimage:4.30.0F
kind: ceos
mgmt-ipv4: 172.100.100.2
ports:
- 12000:22/tcp
- 12001:23/tcp
- 12002:80/tcp
- 12003:161/udp
- 12005:830/tcp
- 12006:8080/tcp
fceos5:
image: ceosimage:4.30.0F
kind: ceos
mgmt-ipv4: 172.100.100.3
ports:
- 12007:22/tcp
- 12008:23/tcp
- 12009:80/tcp
- 12010:161/udp
- 12011:443/tcp
- 12012:830/tcp
- 12013:8080/tcp
nf#
NORFAB Netbox Get Containerlab Inventory Command Shell Reference¤
NorFab shell supports these command options for Netbox get_containerlab_inventory task:
nf#man tree netbox.get.containerlab-inventory
root
└── netbox: Netbox service
└── get: Query data from Netbox
└── containerlab-inventory: Query Netbox and construct Containerlab inventory
├── timeout: Job timeout
├── workers: Filter worker to target, default 'any'
├── verbose-result: Control output details, default 'False'
├── lab-name: Lab name to generate lab inventory for
├── tenant: Tenant name to generate lab inventory for
│ ├── tenant: Filter devices by tenants
│ ├── device-name-contains: Filter devices by name pattern
│ ├── model: Filter devices by models
│ ├── platform: Filter devices by platforms
│ ├── region: Filter devices by regions
│ ├── role: Filter devices by roles
│ ├── site: Filter devices by sites
│ ├── status: Filter devices by statuses
│ └── tag: Filter devices by tags
├── devices: List of devices to generate lab inventory for
├── progress: Display progress events, default 'True'
├── netbox-instance: Name of Netbox instance to pull inventory from
├── ipv4-subnet: IPv4 management subnet to use for lab, default '172.100.100.0/24'
├── image: Docker image to use for all nodes
└── ports: Range of TCP/UDP ports to use for nodes, default '[12000, 13000]'
nf#
Python API Reference¤
Retrieve and construct Containerlab inventory from NetBox data.
Containerlab node details must be defined under device configuration
context norfab.containerlab path, for example:
{
"norfab": {
"containerlab": {
"kind": "ceos",
"image": "ceos:latest",
"mgmt-ipv4": "172.100.100.10/24",
"ports": [
{10000: 22},
{10001: 830}
],
... any other node parameters ...
"interfaces_rename": [
{
"find": "eth",
"replace": "Eth",
"use_regex": false
}
]
}
}
}
For complete list of parameters refer to Containerlab nodes definition.
Special handling given to these parameters:
lab_name- if not provided usestenantargument value as a lab namekind- uses device platform field value by defaultimage- usesimagevalue if provided, otherwise uses{kind}:latestinterfaces_rename- a list of one or more interface renaming instructions, each item must havefindandreplacedefined, optionaluse_regexflag specifies whether to use regex based pattern substitution.
To retrieve topology data from Netbox at least one of these arguments must be provided to identify a set of devices to include into Containerlab topology:
tenant- topology constructed using all devices and links that belong to this tenantdevices- creates topology only using devices in the listsfilters- list of device filters to retrieve from Netbox and add to topology
If multiple of above arguments provided, resulting lab topology is a sum of all devices matched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab Job object containing relevant metadata |
required |
lab_name
|
(str, Mandatory)
|
Name of containerlab to construct inventory for. |
None
|
tenant
|
str
|
Construct topology using given tenant's devices |
None
|
filters
|
list
|
List of filters to apply when retrieving devices from NetBox. |
None
|
devices
|
list
|
List of specific devices to retrieve from NetBox. |
None
|
instance
|
str
|
NetBox instance to use. |
None
|
image
|
str
|
Default containerlab image to use, |
None
|
ipv4_subnet
|
(str, Optional)
|
Management subnet to use to IP number nodes starting with 2nd IP in the subnet, in assumption that 1st IP is a default gateway. |
'172.100.100.0/24'
|
ports
|
(tuple, Optional)
|
Ports range to use for nodes. |
(12000, 15000)
|
ports_map
|
(dict, Optional)
|
dictionary keyed by node name with list of ports maps to use, |
None
|
cache
|
Union[bool, str]
|
Cache usage options:
|
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Result
|
Containerlab inventory dictionary containing lab topology data |
Source code in norfab\workers\netbox_worker.py
3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 | |