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
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |