feat: support NetBox Utilities disk management

- Use conditional unique constraints as import identity only when the
  record matches the condition, and filter target candidates by it.
  Replaced disks no longer overwrite active disks in the same slot.
- Export disk bay templates together with their device type dependency.
- Skip records of the optional NetBox Utilities plugin with a warning
  when it is not installed on the target instead of aborting the import.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-19 13:46:27 +02:00
1 parent 47e9192fda
commit ab4a6c8958
5 files changed
+233 -10

No files matched your search

+10 -3
View File
@@ -9,6 +9,13 @@ from django.db import models
AUTO_IMPORT_TENANT_NAME = "Auto-Import"
AUTO_IMPORT_TENANT_SLUG = "auto-import"
MISSING_TENANT_MESSAGE = "Für dieses Objekt muss ein Mandant angegeben werden."
# Apps of optional plugins whose data is exported when installed on the source
# and skipped (instead of failing the import) when missing on the target.
OPTIONAL_PLUGIN_APP_LABELS = frozenset({"netbox_utilities"})
def is_optional_plugin_model(label: str) -> bool:
return label.split(".", 1)[0] in OPTIONAL_PLUGIN_APP_LABELS
def netbox_utilities_tenant_required() -> bool:
@@ -34,12 +41,12 @@ def is_module_relation(field) -> bool:
return getattr(getattr(related_model, "_meta", None), "label_lower", None) == "dcim.module"
def _condition_field_names(condition):
def condition_field_names(condition):
for child in getattr(condition, "children", ()):
if isinstance(child, tuple):
yield child[0].split("__", 1)[0]
else:
yield from _condition_field_names(child)
yield from condition_field_names(child)
@cache
@@ -49,7 +56,7 @@ def check_constraint_field_names(model) -> frozenset[str]:
names = set()
for constraint in model._meta.constraints:
if isinstance(constraint, models.CheckConstraint):
names.update(_condition_field_names(constraint.condition))
names.update(condition_field_names(constraint.condition))
return frozenset(names)