<class 'KeyError'> 'interface_name' when attempting an ip-address import with csv

286 views
Skip to first unread message

Cameron Rake

unread,
Apr 20, 2021, 2:49:32 AM4/20/21
to NetBox
I have successfully imported Devices and Prefixes, however when I attempt to import an ip-address i receive the above error (once all the formatting errors have been corrected and the duplicate entries have been addressed).  The import attempts to install the first row but always errors out on this message "<class 'KeyError'>  'interface_name'".

Thanks for any help you can provide.

CR

Cameron Rake

unread,
Apr 20, 2021, 3:03:43 AM4/20/21
to NetBox
Found workaround

The CSV format I am trying to use is:
address,vrf,tenant,status,device,description

The import works if I remove 'device' from the import.  I still need to fix that error, but at least have a workaround.

Brian Candler

unread,
Apr 20, 2021, 3:22:57 AM4/20/21
to NetBox
IP addresses are not directly linked to devices (*).  The relationship goes like this:

device -----< interface -----< IPAddress

Therefore you need to:
1. import the devices;
2. import the interfaces (if they are not already created as part of the device template);
3. import the IP Addresses linked to *interface*.

In order to identify an interface, you need to specify both the *device* and *interface* columns in the CSV (since interface names are only unique to a device).

For VMs, you would use virtualmachine+interface instead of device+interface.


(*) That's not entirely true, as there is also a direct link on device pointing to primary_ip4 and primary_ip6.  Therefore it looks like this:

device ----------< interface -----< IPAddress
 primary_ip4 -+---------------------' '
 primary_ip6 -+-----------------------'

However, you can only point primary_ip4 or primary_ip6 to an IPAddress which is also linked to an interface on the same device.  This means you have to import the IPAddress first *before* setting the device primary_ip4/ip6.  Since CSV upload doesn't support modifying existing objects (nor uploading device+interface+IPAddress in the same transaction), you cannot do this via CSV.

Cameron Rake

unread,
Apr 20, 2021, 12:38:02 PM4/20/21
to Brian Candler, NetBox
Thanks Brian, for the detailed explanation and follow up!  That makes perfect sense.

--
You received this message because you are subscribed to a topic in the Google Groups "NetBox" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/netbox-discuss/NhEeJ2VHKlQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/6d3cb1a1-2ab6-42de-ac81-b298ba18a110n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages