Netbox Create Device Interfaces Task¤
task api name:
create_device_interfaces
Task to create network interfaces on one or more devices in NetBox. This task creates interfaces in bulk and only if the interfaces do not already exist in NetBox, making it idempotent and safe to run multiple times.
The task supports alphanumeric range expansion, allowing you to create multiple interfaces with a single pattern. This is particularly useful for creating large numbers of similar interfaces efficiently.
Tip
The create_device_interfaces task automatically skips interfaces that already exist, preventing duplicate creation attempts and allowing for safe re-runs of automation tasks.
Interface Name Range Expansion¤
The task supports powerful range expansion patterns for creating multiple interfaces:
Numeric Ranges¤
Use [start-end] syntax to expand numeric ranges:
interface_name: "Ethernet[1-5]"
# Expands to: Ethernet1, Ethernet2, Ethernet3, Ethernet4, Ethernet5
interface_name: "Loopback[10-12]"
# Expands to: Loopback10, Loopback11, Loopback12
Comma-Separated Lists¤
Use [option1,option2,...] syntax to expand lists:
interface_name: "[ge,xe,fe]-0/0/0"
# Expands to: ge-0/0/0, xe-0/0/0, fe-0/0/0
interface_name: "Port-[A,B,C]"
# Expands to: Port-A, Port-B, Port-C
Multiple Range Patterns¤
Combine multiple range patterns in a single interface name:
interface_name: "[ge,xe]-0/0/[0-3]"
# Expands to: ge-0/0/0, ge-0/0/1, ge-0/0/2, ge-0/0/3,
# xe-0/0/0, xe-0/0/1, xe-0/0/2, xe-0/0/3
Multiple Interface Names¤
Pass a list of interface names (with or without ranges):
interface_name:
- "Loopback[1-3]"
- "Management1"
- "[ge,xe]-0/1/0"
# Expands to: Loopback1, Loopback2, Loopback3, Management1, ge-0/1/0, xe-0/1/0
Branching Support¤
Create Device Interfaces task is branch aware and can create interfaces within a branch. Netbox Branching Plugin needs to be installed on the Netbox instance.
When using branches, interfaces are created in the specified branch and can be reviewed before merging into the main database.
NORFAB Netbox Create Device Interfaces Command Shell Reference¤
NorFab shell supports these command options for Netbox create_device_interfaces task:
nf#man tree netbox.create.device-interfaces
root
└── netbox: Netbox service
└── create: Create objects in Netbox
└── device-interfaces: Create devices interfaces
├── instance: Netbox instance name to target
├── dry-run: Do not commit to database
├── branch: Branching plugin branch name to use
├── *devices: List of device names or device objects to create interfaces for
├── *interface_name: Name(s) of the interface(s) to create
├── interface-type: Name(s) of the interface(s) to create, default 'other'
├── description: Interface description
├── speed: Interface speed in Kbps
├── mtu: Maximum transmission unit size in bytes
├── timeout: Job timeout
├── workers: Filter worker to target, default 'any'
├── verbose-result: Control output details, default 'False'
└── progress: Display progress events, default 'True'
nf#
Usage Examples¤
Basic Interface Creation¤
Create a single interface on one device:
from norfab.core.nfapi import NorFab
nf = NorFab()
result = nf.run_job(
service="netbox",
task="create_device_interfaces",
workers="any",
kwargs={
"devices": ["switch-01", "switch-02"],
"interface_name": "Loopbback[0-5]",
"interface_type": "virtual",
"description": "Test interfaces"
}
)
Interface Types¤
Common interface types supported by NetBox:
virtual- Virtual interfaces (loopbacks, tunnel interfaces)lag- Link Aggregation Group (Port-Channel, bond)1000base-t- 1G copper Ethernet10gbase-x-sfpp- 10G SFP+ Ethernet25gbase-x-sfp28- 25G SFP28 Ethernet40gbase-x-qsfpp- 40G QSFP+ Ethernet100gbase-x-qsfp28- 100G QSFP28 Ethernetother- Generic interface type (default)
Refer to your NetBox instance for the complete list of available interface types.
Error Handling¤
Task handles several error conditions gracefully:
- Non-existent Device: If a device doesn't exist in NetBox, an error is logged but processing continues for other devices
- Duplicate Interfaces: Existing interfaces are automatically skipped and listed in the
skippedarray - Invalid Interface Type: NetBox will reject invalid interface types with an error message
- Branch Not Found: If a specified branch doesn't exist and the branching plugin is not available, the task will fail
Best Practices¤
- Use Dry Run First: Always test with
dry_run: Truebefore creating interfaces in production - Meaningful Names: Use descriptive interface names that match your device's actual interface naming
- Consistent Types: Use appropriate interface types that match the physical/virtual nature of the interfaces
- Batch Operations: Create multiple interfaces in a single call for efficiency
- Branch Usage: Use branches for testing bulk operations before committing to the main database
- Idempotency: The task is idempotent - running it multiple times with the same parameters is safe
Python API Reference¤
Create interfaces for one or more devices in NetBox. This task creates interfaces in bulk and only if interfaces does not exist in Netbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
The job object containing execution context and metadata. |
required |
devices
|
list
|
List of device names or device objects to create interfaces for. |
required |
interface_name
|
Union[list, str]
|
Name(s) of the interface(s) to create. Can be a single interface name as a string or multiple names as a list. Alphanumeric ranges are supported for bulk creation:
|
required |
interface_type
|
str
|
Type of interface (e.g., "other", "virtual", "lag", "1000base-t"). Defaults to "other". |
'other'
|
instance
|
Union[None, str]
|
NetBox instance identifier to use. If None, uses the default instance. Defaults to None. |
None
|
dry_run
|
bool
|
If True, simulates the operation without making actual changes. Defaults to False. |
False
|
branch
|
str
|
NetBox branch to use for the operation. Defaults to None. |
None
|
kwargs
|
dict
|
Any additional interface attributes |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Result object containing the task name, execution results, and affected resources. The result dictionary contains status and details of interface creation operations. |
Source code in norfab\workers\netbox_worker\netbox_worker.py
4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 | |