From 9fd3e01cdfd537ec7f1973319e4df58dc6076c91 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 29 Oct 2026 12:50:05 +0100 Subject: [PATCH] feat: clearer cluster capacity panel Key figures (hosts, vCPU:core, RAM allocation, N+1) as tiles with colours, warnings in one compact box and the host table across the full width with RAM bars, coloured ratios and one-line VM figures. Co-Authored-By: Claude Opus 5.5 --- netbox_utilities/hardware_views.py | 30 +++- .../cluster_capacity_panel.html | 145 +++++++++++++----- 2 files changed, 138 insertions(+), 37 deletions(-) diff --git a/netbox_utilities/hardware_views.py b/netbox_utilities/hardware_views.py index b82b4f4..f922c1f 100644 --- a/netbox_utilities/hardware_views.py +++ b/netbox_utilities/hardware_views.py @@ -117,11 +117,29 @@ def build_cluster_capacity(request, cluster_id, extra_host=None): return hardware.build_capacity([host_entry(device) for device in hosts], vm_rows(vms)), hosts +def ratio_level(ratio, limit): + """Bootstrap colour for a vCPU:core ratio.""" + if ratio is None: + return "secondary" + if limit and ratio > limit: + return "danger" if ratio > limit * 1.5 else "warning" + return "success" + + +def memory_level(value): + if value is None: + return "secondary" + return "danger" if value > 100 else "warning" if value > 85 else "success" + + def cluster_capacity_context(request, cluster): capacity, hosts = build_cluster_capacity(request, cluster.pk) + limit = hardware.vcpu_ratio_warning() rows = [] for device, host in zip(hosts, capacity.hosts, strict=True): record = getattr(device, "netbox_utilities_hardware", None) + ratio = host.total_vcpus / host.cores if host.cores else None + memory_percent = hardware.percent(host.total_vm_memory_gb, host.memory_gb) rows.append( { "device": device, @@ -129,12 +147,20 @@ def cluster_capacity_context(request, cluster): "host": host, "memory": hardware.format_memory(host.memory_gb), "vm_memory": hardware.format_memory(round(host.total_vm_memory_gb, 1)), - "memory_percent": hardware.percent(host.total_vm_memory_gb, host.memory_gb), - "vcpu_per_core": hardware.format_ratio(host.total_vcpus / host.cores if host.cores else None), + "memory_percent": memory_percent, + "memory_bar": min(memory_percent or 0, 100), + "memory_level": memory_level(memory_percent), + "vcpu_per_core": hardware.format_ratio(ratio), + "ratio_level": ratio_level(ratio, limit), } ) + memory_percent = capacity.memory_percent return { **capacity_context(capacity), + "ratio_limit": limit, + "cluster_ratio_level": ratio_level(capacity.vcpu_per_core, limit), + "cluster_memory_bar": min(memory_percent or 0, 100), + "cluster_memory_level": memory_level(memory_percent), "rows": rows, "hardware_list_url": f"{reverse('plugins:netbox_utilities:devicehardware_list')}?cluster_id={cluster.pk}", "can_add": request.user.has_perm("netbox_utilities.add_devicehardware"), diff --git a/netbox_utilities/templates/netbox_utilities/cluster_capacity_panel.html b/netbox_utilities/templates/netbox_utilities/cluster_capacity_panel.html index 730f138..f22f0bf 100644 --- a/netbox_utilities/templates/netbox_utilities/cluster_capacity_panel.html +++ b/netbox_utilities/templates/netbox_utilities/cluster_capacity_panel.html @@ -6,44 +6,119 @@ {% if not rows %}
Dem Cluster sind keine Hosts (Geräte) zugeordnet.
{% else %} -
-
- {% include 'netbox_utilities/inc/hardware_capacity.html' %} -
-
-
- - - - - - {% for row in rows %} - - - - - - - - - - {% endfor %} - -
HostCPUKerne / ThreadsRAMVMsvCPU : KernRAM belegt
{{ row.device }} - {% if row.record and row.record.cpu %}{{ row.record.cpu_display }} - {% elif can_add %}erfassen - {% else %}fehlt{% endif %} - {% if row.host.cores %}{{ row.host.cores }} / {{ row.host.threads }}{% else %}—{% endif %}{{ row.memory }} - {{ row.host.vm_count }}{% if row.host.shared_vcpus or row.host.shared_memory_gb %} + anteilig{% endif %} -
{{ row.host.total_vcpus|floatformat:"-1" }} vCPU, {{ row.vm_memory }}
-
{{ row.vcpu_per_core }} - {% if row.memory_percent is not None %} - {{ row.memory_percent }} % - {% else %}—{% endif %} -
+
+
+ {# Hosts #} +
+
+
Hosts
+
{{ rows|length }}
+
+ {% if capacity.cores %}{{ capacity.cores }} Kerne · {{ capacity.threads }} Threads · {{ memory }}{% else %}keine CPU erfasst{% endif %} +
+
+
+ {# vCPU ratio #} +
+
+
vCPU : Kern
+
{{ vcpu_per_core }}
+
+ {{ capacity.vcpus|floatformat:"-1" }} vCPUs in {{ capacity.vm_count }} VM{{ capacity.vm_count|pluralize:",s" }} + {% if ratio_limit %}· Grenze {{ ratio_limit }} : 1{% endif %} +
+
+
+ {# RAM #} +
+
+
RAM belegt
+
+ {% if capacity.memory_percent is not None %}{{ capacity.memory_percent }} %{% else %}—{% endif %} +
+
+
+
+
{{ vm_memory }} von {{ memory }}
+
+
+ {# N+1 #} +
+
+
Ausfall größter Host (N+1)
+ {% if capacity.failover_memory_gb is None %} +
—
+
braucht mindestens 2 Hosts mit erfasstem RAM
+ {% else %} +
+ {% if capacity.failover_ok %}OK{% else %}Nicht erfüllt{% endif %} +
+
{{ failover_memory }} verbleiben · {{ vm_memory }} benötigt
+ {% endif %} +
+ + {% if capacity_warnings %} +
+
    + {% for level, text in capacity_warnings %}
  • {{ text }}
  • {% endfor %} +
+
+ {% endif %}
+ +
+ + + + + + + + + + + + + + {% for row in rows %} + + + + + + + + + + {% endfor %} + +
HostCPUKerne / ThreadsRAMVMsvCPU : KernRAM belegt
{{ row.device }} + {% if row.record and row.record.cpu %}{{ row.record.cpu_display }} + {% elif can_add %} erfassen + {% else %}fehlt{% endif %} + {% if row.host.cores %}{{ row.host.cores }} / {{ row.host.threads }}{% else %}—{% endif %}{{ row.memory }} + {% if row.host.vm_count or row.host.total_vcpus %} + {{ row.host.vm_count }} VM{{ row.host.vm_count|pluralize:",s" }}{% if row.host.shared_vcpus or row.host.shared_memory_gb %} + anteilig{% endif %} + · {{ row.host.total_vcpus|floatformat:"-1" }} vCPU · {{ row.vm_memory }} + {% else %} + keine VMs + {% endif %} + + {% if row.host.cores %}{{ row.vcpu_per_core }}{% else %}—{% endif %} + + {% if row.memory_percent is not None %} +
+
+
+
+ {{ row.memory_percent }} % +
+ {% else %}—{% endif %} +
+
+