fix: use 'device' instead of 'device_id' for interface creation

NetBox API requires 'device' field for creation, not 'device_id'.
Separated search and create logic for interfaces.
This commit is contained in:
2026-02-04 15:17:30 +00:00
parent 0de450211d
commit 52c9586667

View File

@@ -698,11 +698,18 @@ def create_interfaces(nb: pynetbox.api, devices: dict) -> dict:
continue
for intf_name, intf_type in interfaces:
intf, created = get_or_create(
nb.dcim.interfaces,
{"device_id": device.id, "name": intf_name},
{"type": intf_type},
)
# Search with device_id but create with device
existing = nb.dcim.interfaces.get(device_id=device.id, name=intf_name)
if existing:
intf = existing
created = False
else:
intf = nb.dcim.interfaces.create({
"device": device.id,
"name": intf_name,
"type": intf_type,
})
created = True
# Set custom fields for MLAG peer-link
if intf_name in ("Ethernet10", "Port-Channel10") and device_name.startswith("leaf"):