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
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |