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 usestenant
argument value as a lab namekind
- uses device platform field value by defaultimage
- usesimage
value if provided, otherwise uses{kind}:latest
interfaces_rename
- a list of one or more interface renaming instructions, each item must havefind
andreplace
defined, optionaluse_regex
flag 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 |
---|---|---|---|
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
|
progress
|
bool
|
If True, emits progress events. |
False
|
cache
|
Union[bool, str]
|
Cache usage options:
|
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Containerlab inventory dictionary containing lab topology data |
Source code in norfab\workers\netbox_worker.py
2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 |
|