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\netbox_worker.py
3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 | |