feat: CPU & RAM from Netbox-Utilities in device tables and clusters

Device tables get optional CPU and RAM columns. Clusters show physical
cores/threads and host RAM with vCPU-per-core ratio and RAM allocation.
Also fixes decimal formatting of vCPU and rack units (245.00, HE 40.0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-29 11:29:37 +01:00
1 parent 4ec96bf65d
commit 55c70814c3
5 files changed
+110 -13

No files matched your search

@@ -0,0 +1,50 @@
"""CPU & RAM aus dem Plugin Netbox-Utilities (netbox_utilities.DeviceHardware)."""
from django.apps import apps
def is_installed():
if not apps.is_installed("netbox_utilities"):
return False
try:
apps.get_model("netbox_utilities", "DeviceHardware")
except LookupError: # ältere Version ohne CPU & RAM
return False
return True
def hardware(device):
"""DeviceHardware des Geräts oder None (nicht installiert / nicht gepflegt)."""
if not is_installed():
return None
return getattr(device, "netbox_utilities_hardware", None) # RelatedObjectDoesNotExist ist ein AttributeError
def cores_threads(hw):
"""(Kerne, Threads) gesamt oder (None, None)."""
if not hw or not hw.cpu_id:
return None, None
return hw.total_cores, hw.total_threads
def format_memory(gigabytes):
from netbox_utilities import hardware as helpers
return helpers.format_memory(gigabytes)
def cpu_text(device):
"""„2 × Intel Xeon Gold 6130“ + Zeile „32 Kerne / 64 Threads“."""
hw = hardware(device)
if not hw or not hw.cpu_id:
return None
cores, threads = cores_threads(hw)
return f"{hw.cpu_display}\n{cores} Kerne / {threads} Threads"
def ram_text(device):
"""„384 GB“ + Zeile „12 × 32 GB · DDR4-2666“."""
hw = hardware(device)
if not hw or not hw.memory_gb:
return None
detail = hw.memory_detail
return f"{format_memory(hw.memory_gb)}\n{detail}" if detail else format_memory(hw.memory_gb)