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 %}
| Host | CPU | Kerne / Threads | RAM | VMs | vCPU : Kern | RAM 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 %} - | -
| Host | +CPU | +Kerne / Threads | +RAM | +VMs | +vCPU : Kern | +RAM 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 %}
+
+
+ {% else %}—{% endif %}
+
+
+
+ {{ row.memory_percent }} %
+ |
+