NetBox Create VLAN Task¤
task API name:
create_vlan
The create_vlan task creates or updates one VLAN in an existing VLAN group. Supply vid for an explicit VLAN ID, or omit it to allocate the next available ID from the group's configured ranges.
Inputs¤
| Parameter | Required | Default | Description |
|---|---|---|---|
vlan_group |
Yes | — | Existing VLAN group name |
name |
Yes | — | VLAN name |
vid |
No | None |
Explicit VLAN ID from 1 through 4094; omit to allocate |
status |
No | active |
VLAN status |
description |
No | None |
VLAN description |
tenant |
No | None |
Tenant name |
role |
No | None |
IPAM role name |
tags |
No | None |
Tag names |
custom_fields |
No | None |
NetBox custom-field values |
instance |
No | Worker default | NetBox instance to target |
dry_run |
No | False |
Return the selected VID without writing |
branch |
No | None |
NetBox Branching plugin branch name |
Output¤
{
"vid": 1000,
"name": "USERS",
"vlan_group": "CAMPUS",
"status": "created",
}
status is create or update during dry-run and created or updated after an applied operation.
Examples¤
A dedicated NFCLI command is not currently registered for create_vlan.
# Use the Python API, REST API, MCP task interface, or design filter.
from norfab.core.nfapi import NorFab
with NorFab(inventory="./inventory.yaml") as nf:
client = nf.make_client()
allocated = client.run_job(
"netbox",
"create_vlan",
workers="any",
kwargs={"vlan_group": "CAMPUS", "name": "USERS"},
)
explicit = client.run_job(
"netbox",
"create_vlan",
workers="any",
kwargs={
"vlan_group": "CAMPUS",
"name": "SERVERS",
"vid": 1100,
},
)
In a NetBox design:
{% set users_vid = "CAMPUS" | netbox.create_vlan("USERS") %}
vlans:
- group: CAMPUS
vid: {{ users_vid }}
name: USERS
Notes / Gotchas¤
- The VLAN group must already exist and have available VID ranges for allocation.
- With an explicit
vid, identity is VLAN group plus VID. - Without
vid, an existing VLAN with the same group and name is reused. - When updating a VLAN, new tags and new items in list-valued custom fields are added without removing existing ones. Supplying
[]leaves an existing list unchanged. For custom fields,nullclears the value, and a new scalar value replaces the old one. - Object and multiobject custom fields accept related object names or IDs. The task resolves names using each field's NetBox definition; missing or ambiguous names fail.
- Branch writes require the NetBox Branching plugin.
Troubleshooting¤
- VLAN group not found: verify the exact group name in NetBox.
- No available VLAN IDs: add or expand the group's VID ranges.
- Ambiguous identity: remove duplicate VLANs with the same group and identity fields.
Task Command Shell Reference¤
create_vlan does not currently have a dedicated NFCLI command model.
Python API Reference¤
Create, update, or allocate a VLAN in an existing group.
A supplied VID identifies the VLAN within its group. Without a VID, an existing VLAN is matched by group and name, or the first available VID is allocated. Repeated calls without a VID and with the same name reuse that VLAN. Tags and array custom fields add values on updates; scalar custom fields replace their values. Existing VLANs are patched without a local diff check. Dry-run reports the selected VID but does not write attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
Current NorFab job for events and branch provisioning. |
required |
vlan_group
|
str
|
Name of the existing VLAN group. |
required |
name
|
str
|
VLAN name to create or assign to the matched VLAN. |
required |
vid
|
Union[None, int]
|
Explicit VLAN ID; omit to allocate from the group. |
None
|
status
|
str
|
NetBox VLAN status, defaulting to active. |
'active'
|
description
|
Union[None, str]
|
Optional VLAN description. |
None
|
tenant
|
Union[None, str]
|
Optional tenant name. |
None
|
role
|
Union[None, str]
|
Optional IPAM role name. |
None
|
tags
|
Union[None, list]
|
Optional tag names to add without removing existing tags. |
None
|
custom_fields
|
Union[None, dict]
|
Optional NetBox custom-field values. Arrays add missing values; empty arrays preserve existing arrays. Null and scalar values replace existing values. Object and multiobject fields accept related object names or IDs. |
None
|
instance
|
Union[None, str]
|
NetBox instance name, or the worker default when omitted. |
None
|
dry_run
|
bool
|
Select a VLAN without creating or updating it. |
False
|
branch
|
Union[None, str]
|
Optional NetBox Branching plugin branch name. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Selected VLAN ID, name, group, and action. Applied results |
Result
|
also include the NetBox object ID. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The group is missing, the match is ambiguous, or no VLAN IDs remain available for allocation. |
Source code in norfab\workers\netbox_worker\vlan_tasks.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |