Files
NetBox-Customer-Export/netbox_customer_export/hardware_utilities.py
T
MrBlakeandClaude Opus 5.5 55c70814c3 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]>
2026-10-29 11:29:37 +01:00

51 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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)