Fix importing IP ranges
IPRange.save() computes its size from start_address.ip, but the importer assigned the archived addresses as plain strings, so every archive containing IP ranges failed with "'str' object has no attribute 'ip'". Convert values of NetBox IP fields with the field's to_python(). This also affects NetBox 4.6. IP ranges also had no natural key, so importing into an instance that already contained the range created a duplicate. Match them by (vrf, start_address, end_address). Verified with a real export and repeated imports on NetBox 4.7.2; the version stays 0.3.14 because Netbox-Utilities only enables its integration for known versions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
0fdde044e1
commit
44149acf16
2 files changed
+32
No files matched your search
@@ -54,6 +54,7 @@ EXPLICIT_IDENTITIES = {
|
||||
"dcim.inventoryitem": ("device", "parent", "name"),
|
||||
"ipam.prefix": ("vrf", "prefix"),
|
||||
"ipam.ipaddress": ("vrf", "address"),
|
||||
"ipam.iprange": ("vrf", "start_address", "end_address"),
|
||||
"ipam.vlan": ("group", "vid"),
|
||||
"circuits.circuit": ("provider", "cid"),
|
||||
"virtualization.virtualmachine": ("cluster", "tenant", "name"),
|
||||
@@ -169,9 +170,16 @@ def _coerce_model_field_value(field, value):
|
||||
and hasattr(base_field, "base_field")
|
||||
):
|
||||
return [_coerce_range_value(base_field, item) for item in value]
|
||||
if isinstance(value, str) and _is_netbox_ip_field(field):
|
||||
# IPRange.save() computes its size from start_address.ip, so plain strings are not enough.
|
||||
return field.to_python(value)
|
||||
return value
|
||||
|
||||
|
||||
def _is_netbox_ip_field(field):
|
||||
return any(cls.__name__ == "BaseIPField" for cls in type(field).__mro__)
|
||||
|
||||
|
||||
def _identity_candidates(model):
|
||||
explicit = EXPLICIT_IDENTITIES.get(model._meta.label_lower)
|
||||
if explicit:
|
||||
|
||||
Reference in new issue
Block a user