Netbox Create IP Bulk Task¤
task api name:
create_ip_bulk
Allocates IP addresses for multiple device interfaces. The task first retrieves matching interfaces with get_interfaces, then calls create_ip for each device/interface pair.
Inputs¤
| Parameter | Required | Description |
|---|---|---|
prefix |
Yes | Parent prefix as a network string, prefix description, or pynetbox filter dictionary |
devices |
Yes | Device names to assign IP addresses to |
interface_list |
No | Exact interface names to target |
interface_regex |
No | Regex pattern to match interface names |
description |
No | Description for allocated IP addresses |
vrf |
No | VRF name for allocated IP addresses |
tags |
No | Tags to associate with allocated IP addresses |
dns_name |
No | DNS name for allocated IP addresses |
tenant |
No | Tenant name to associate with allocated IP addresses |
comments |
No | IP address comments |
role |
No | IP address role |
status |
No | IP address status |
is_primary |
No | Set each IP as the primary IP for its device |
mask_len |
No | Allocate child subnets of this length before creating IPs |
create_peer_ip |
No | Create IP addresses for connected peer interfaces, default True |
instance |
No | NetBox instance name to target |
branch |
No | NetBox Branching plugin branch name to write to |
dry_run |
No | Preview allocations without writing |
Output¤
Returns allocation results keyed by device and interface:
{
"ceos-leaf-1": {
"Ethernet1": {
"address": "10.0.0.1/31",
"...": "...",
},
},
}
Notes / Gotchas¤
interface_listtakes precedence overinterface_regexwhen both are provided.- Dry-run mode passes through to
create_ip; the samemask_lendry-run limitation applies. mask_len=32ormask_len=128is invalid withcreate_peer_ip=True.- Branch writes require the NetBox Branching Plugin.
Examples¤
Allocate IPs for selected interfaces:
nf#netbox create ip-bulk prefix 10.0.0.0/24 devices ceos-leaf-1 ceos-leaf-2 interface-list Ethernet1 Ethernet2
Allocate IPs for interfaces matching a regex:
nf#netbox create ip-bulk prefix 10.0.0.0/24 devices ceos-leaf-1 interface-regex "Ethernet[1-4]" mask-len 31
Preview allocations:
nf#netbox create ip-bulk prefix 10.0.0.0/24 devices ceos-leaf-1 interface-list Ethernet1 dry-run
from norfab.core.nfapi import NorFab
nf = NorFab(inventory="./inventory.yaml")
nf.start()
client = nf.make_client()
# allocate IPs for selected interfaces
result = client.run_job(
"netbox",
"create_ip_bulk",
workers="any",
kwargs={
"prefix": "10.0.0.0/24",
"devices": ["ceos-leaf-1", "ceos-leaf-2"],
"interface_list": ["Ethernet1", "Ethernet2"],
},
)
# allocate /31 link subnets for matching interfaces
result = client.run_job(
"netbox",
"create_ip_bulk",
workers="any",
kwargs={
"prefix": {"prefix": "10.0.0.0/24", "site": "lab"},
"devices": ["ceos-leaf-1"],
"interface_regex": "Ethernet[1-4]",
"mask_len": 31,
"description": "fabric uplink",
},
)
nf.destroy()
NORFAB Netbox Create IP Bulk Command Shell Reference¤
NorFab shell supports these command options for Netbox create_ip_bulk task:
nf# man tree netbox.create.ip-bulk
root
└── netbox: Netbox service
└── create: Create objects in Netbox
└── ip-bulk: Allocate next available IP address from prefix for multiple devices and interfaces
├── timeout: Job timeout
├── workers: Filter worker to target, default 'any'
├── verbose-result: Control output details, default 'False'
├── progress: Display progress events, default 'True'
├── nowait: Do not wait for job to complete, default 'False'
├── instance: Netbox instance name to target
├── dry-run: Do not commit to database
├── branch: Branching plugin branch name to use
├── prefix: Prefix to allocate IP address from, can also provide prefix name or filters
├── devices: List of device names to create IP address for
├── interface-regex: Regular expression of device interface names to create IP address for
├── interface-list: List of interface names to create IP address for
├── description: IP address description
├── vrf: VRF to associate with IP address
├── tags: Tags to add to IP address
├── dns-name: IP address DNS name
├── tenant: Tenant name to associate with IP address
├── comments: IP address comments field
├── role: IP address functional role
├── mask-len: Mask length to use for IP address
├── create-peer-ip: Create link peer IP address as well
└── status: IP address status
nf#
Python API Reference¤
Bulk assigns IP addresses to interfaces of specified devices.
.. warning::
**Dry-run limitation**: when ``dry_run=True``, ``mask_len`` is ignored and
the same candidate IP address (taken directly from the parent prefix using
the parent prefix mask length) is returned for every interface — no child
subnets are created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
The job instance used for logging and tracking the task. |
required |
prefix
|
Union[str, dict]
|
The prefix to allocate IPs from; IPv4/IPv6 network string, prefix description, or dict with pynetbox filter keys. |
required |
devices
|
list[str]
|
List of device names to assign IP addresses to. |
None
|
interface_list
|
list[str]
|
List of specific interface names to target.
Takes precedence over |
None
|
interface_regex
|
str
|
Regex pattern to match interface names. |
None
|
instance
|
str
|
The NetBox instance name to use. |
None
|
dry_run
|
bool
|
If True, preview changes without committing to NetBox. |
False
|
branch
|
str
|
NetBox branching plugin branch name to use. |
None
|
description
|
str
|
Description for the allocated IP addresses. |
None
|
vrf
|
str
|
VRF name for the IP addresses. |
None
|
tags
|
list
|
List of tags to associate with the IP addresses. |
None
|
dns_name
|
str
|
DNS name for the IP addresses. |
None
|
tenant
|
str
|
Tenant name to associate with the IP addresses. |
None
|
comments
|
str
|
Additional comments for the IP addresses. |
None
|
role
|
str
|
Role for the IP addresses, e.g. 'loopback', 'anycast'. |
None
|
status
|
str
|
Status for the IP addresses, e.g. 'active', 'reserved', 'deprecated'. |
None
|
is_primary
|
bool
|
If True, set each IP as the primary IP for its device. |
None
|
mask_len
|
int
|
Mask length for the IP addresses; creates a child subnet
of this length within the parent prefix. Ignored when |
None
|
create_peer_ip
|
bool
|
If True, creates an IP address for the link peer interface. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object containing per-device, per-interface IP allocation results. |
Source code in norfab\workers\netbox_worker\ip_tasks.py
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 510 511 512 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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |