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:
@@ -698,11 +698,18 @@ def create_interfaces(nb: pynetbox.api, devices: dict) -> dict:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
for intf_name, intf_type in interfaces:
|
for intf_name, intf_type in interfaces:
|
||||||
intf, created = get_or_create(
|
# Search with device_id but create with device
|
||||||
nb.dcim.interfaces,
|
existing = nb.dcim.interfaces.get(device_id=device.id, name=intf_name)
|
||||||
{"device_id": device.id, "name": intf_name},
|
if existing:
|
||||||
{"type": intf_type},
|
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
|
# Set custom fields for MLAG peer-link
|
||||||
if intf_name in ("Ethernet10", "Port-Channel10") and device_name.startswith("leaf"):
|
if intf_name in ("Ethernet10", "Port-Channel10") and device_name.startswith("leaf"):
|
||||||
|
|||||||
Reference in New Issue
Block a user