feat: own Disks main menu and disk list grouped by device
The disk entries move from the Plugins menu into a top-level Disks menu with Disks, RAID groups and Disk templates. The Disks entry opens a new page that groups all disks by device in collapsible sections with per-device summary, search, warning and removed-disk switches and expand/collapse all. The flat table with filters, export and bulk actions remains available. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e6be0ed294
commit
14cb5d5829
6 files changed
+264
-31
No files matched your search
@@ -231,7 +231,7 @@ the device front, the number of the first slot (0 or 1, as printed by the
|
||||
vendor), row- or column-wise numbering and the default form factor. With
|
||||
**Save as template for the device type** the layout is stored for the device
|
||||
type; the next device of the same type offers **Apply template** and needs
|
||||
a single click. Templates are managed under **Plugins > NetBox Utilities > Disk templates**.
|
||||
a single click. Templates are managed under **Disks > Disk templates** in the main menu.
|
||||
The layout can be changed later with **Change layout**; slots that still hold a
|
||||
disk cannot be removed.
|
||||
|
||||
@@ -276,17 +276,28 @@ capacity, the usable RAID capacity, spares and failed disks. The warnings panel
|
||||
lists failed disks, expired warranties, warranties ending within
|
||||
`disk_warranty_warning_days` and disks older than `disk_age_warning_years`.
|
||||
|
||||
**Lists, search and export.** **Plugins > NetBox Utilities > Disks** lists all disks of all
|
||||
devices with filters for device, tenant, RAID group, status, type, interface,
|
||||
form factor, manufacturer, warranty (expired / expiring / valid), *older than
|
||||
N years* and *with warnings*. The global tenant filter applies to this list.
|
||||
Export works through NetBox' standard **Export** button. The NetBox global search
|
||||
**Main menu.** The plugin adds its own **Disks** menu with the entries
|
||||
**Disks**, **RAID groups** and **Disk templates**.
|
||||
|
||||
**Disks grouped by device.** **Disks > Disks** shows all disks grouped by device.
|
||||
Each device is a collapsible section whose header shows the device, role, site,
|
||||
tenant, number of disks, raw capacity, failed disks and warnings, plus a link to
|
||||
the device's **Disks** tab. The page offers a search (serial number, model,
|
||||
manufacturer, device), **Only with warnings**, **Show removed** and **Expand
|
||||
all** / **Collapse all**; the global tenant filter applies here as well.
|
||||
|
||||
**Lists, search and export.** **Table view & export** on that page opens the flat
|
||||
list of all disks with filters for device, tenant, RAID group, status, type,
|
||||
interface, form factor, manufacturer, warranty (expired / expiring / valid),
|
||||
*older than N years* and *with warnings*. The global tenant filter applies to
|
||||
this list. Export, bulk edit and bulk delete work through NetBox' standard
|
||||
buttons. The NetBox global search
|
||||
finds disks by serial number, model, manufacturer and firmware and shows the
|
||||
device and slot. The device list offers an optional **Disks** column
|
||||
(used/total, linked to the tab) under **Configure Table**; it runs two queries
|
||||
per row, so enable it only where needed.
|
||||
|
||||
**CSV import.** **Plugins > NetBox Utilities > Disks > Import** accepts CSV, JSON or YAML
|
||||
**CSV import.** **Disks > Disks > Import** accepts CSV, JSON or YAML
|
||||
with these columns: `device` (device name), `slot`, `status`, `disk_type`,
|
||||
`interface`, `form_factor`, `manufacturer`, `model`, `capacity` (e.g. `4 TB`),
|
||||
`serial`, `firmware`, `manufacture_date`, `install_date`, `removal_date`,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from itertools import groupby
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from dcim.models import Device
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.paginator import Paginator
|
||||
from django.db import transaction
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
@@ -294,6 +296,64 @@ class DiskReplaceView(ContentTypePermissionRequiredMixin, View):
|
||||
#
|
||||
|
||||
|
||||
class DiskByDeviceView(ContentTypePermissionRequiredMixin, View):
|
||||
"""All disks grouped by device in collapsible sections; the flat list stays available."""
|
||||
|
||||
template_name = "netbox_utilities/disk_by_device.html"
|
||||
# Read by the global tenant filter middleware, which injects tenant_id for this filterset.
|
||||
filterset = disk_filtersets.DiskFilterSet
|
||||
devices_per_page = 50
|
||||
|
||||
def get_required_permission(self):
|
||||
return "netbox_utilities.view_disk"
|
||||
|
||||
def get(self, request):
|
||||
queryset = Disk.objects.restrict(request.user, "view").select_related(
|
||||
"device", "device__role", "device__tenant", "device__site", "raid_group"
|
||||
)
|
||||
params = request.GET.copy()
|
||||
params.pop("page", None)
|
||||
show_removed = params.get("removed") == "1"
|
||||
if not show_removed and not params.getlist("status"):
|
||||
queryset = queryset.filter(status__in=disks.SLOT_OCCUPYING_STATUSES)
|
||||
filterset = self.filterset(params, queryset)
|
||||
queryset = filterset.qs.order_by("device__name", "device_id", "slot", "pk")
|
||||
|
||||
groups = []
|
||||
for device, device_disks in groupby(queryset, key=lambda disk: disk.device):
|
||||
device_disks = list(device_disks)
|
||||
installed = [disk for disk in device_disks if disk.occupies_slot]
|
||||
summary = disks.disk_summary(installed, 0)
|
||||
groups.append(
|
||||
{
|
||||
"device": device,
|
||||
"disks": device_disks,
|
||||
"count": len(installed),
|
||||
"raw_capacity": disks.format_capacity(summary["raw_capacity_gb"]),
|
||||
"failed": summary["failed"],
|
||||
"warning_count": sum(1 for disk in installed if disk.warnings),
|
||||
}
|
||||
)
|
||||
|
||||
page = Paginator(groups, self.devices_per_page).get_page(request.GET.get("page"))
|
||||
query = params.urlencode()
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
{
|
||||
"page": page,
|
||||
"groups": page.object_list,
|
||||
"device_count": len(groups),
|
||||
"disk_count": sum(group["count"] for group in groups),
|
||||
"q": params.get("q", ""),
|
||||
"show_removed": show_removed,
|
||||
"warnings_only": params.get("has_warnings") == "true",
|
||||
"query": query,
|
||||
"expand_all": len(page.object_list) == 1,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@register_model_view(Disk, "list", path="", detail=False)
|
||||
class DiskListView(generic.ObjectListView):
|
||||
queryset = Disk.objects.select_related("device", "raid_group", "tenant")
|
||||
|
||||
@@ -1,29 +1,6 @@
|
||||
from netbox.plugins import PluginMenuButton, PluginMenuItem
|
||||
from netbox.plugins import PluginMenu, PluginMenuButton, PluginMenuItem
|
||||
|
||||
menu_items = (
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:disk_list",
|
||||
link_text="Datenträger",
|
||||
permissions=("netbox_utilities.view_disk",),
|
||||
buttons=(
|
||||
PluginMenuButton(
|
||||
link="plugins:netbox_utilities:disk_bulk_import",
|
||||
title="Importieren",
|
||||
icon_class="mdi mdi-upload",
|
||||
permissions=("netbox_utilities.add_disk",),
|
||||
),
|
||||
),
|
||||
),
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:raidgroup_list",
|
||||
link_text="RAID-Gruppen",
|
||||
permissions=("netbox_utilities.view_raidgroup",),
|
||||
),
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:diskbaytemplate_list",
|
||||
link_text="Datenträger-Vorlagen",
|
||||
permissions=("netbox_utilities.view_diskbaytemplate",),
|
||||
),
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:bulk_module_install",
|
||||
link_text="Module mehrfach einbauen",
|
||||
@@ -41,3 +18,39 @@ menu_items = (
|
||||
staff_only=True,
|
||||
),
|
||||
)
|
||||
|
||||
# Own top-level menu for disks; the disk entry opens the list grouped by device.
|
||||
menu = PluginMenu(
|
||||
label="Datenträger",
|
||||
icon_class="mdi mdi-harddisk",
|
||||
groups=(
|
||||
(
|
||||
"Datenträger",
|
||||
(
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:disk_by_device",
|
||||
link_text="Datenträger",
|
||||
permissions=("netbox_utilities.view_disk",),
|
||||
buttons=(
|
||||
PluginMenuButton(
|
||||
link="plugins:netbox_utilities:disk_bulk_import",
|
||||
title="Importieren",
|
||||
icon_class="mdi mdi-upload",
|
||||
permissions=("netbox_utilities.add_disk",),
|
||||
),
|
||||
),
|
||||
),
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:raidgroup_list",
|
||||
link_text="RAID-Gruppen",
|
||||
permissions=("netbox_utilities.view_raidgroup",),
|
||||
),
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_utilities:diskbaytemplate_list",
|
||||
link_text="Datenträger-Vorlagen",
|
||||
permissions=("netbox_utilities.view_diskbaytemplate",),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -381,3 +381,22 @@ a.nbu-disk-slot[draggable="true"] {
|
||||
pointer-events: none;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* Datenträger grouped by device */
|
||||
.nbu-disk-group-header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.nbu-disk-group-chevron {
|
||||
margin-right: 0.25rem;
|
||||
transition: transform 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
.nbu-disk-group-header[aria-expanded="true"] .nbu-disk-group-chevron {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
{% extends 'base/layout.html' %}
|
||||
{% load helpers %}
|
||||
|
||||
{% block title %}Datenträger{% endblock %}
|
||||
|
||||
{% block controls %}
|
||||
<div class="btn-list">
|
||||
<a href="{% url 'plugins:netbox_utilities:disk_list' %}{% if query %}?{{ query }}{% endif %}" class="btn btn-outline-secondary">
|
||||
<i class="mdi mdi-table" aria-hidden="true"></i> Tabellenansicht & Export
|
||||
</a>
|
||||
{% if perms.netbox_utilities.add_disk %}
|
||||
<a href="{% url 'plugins:netbox_utilities:disk_bulk_import' %}" class="btn btn-cyan">
|
||||
<i class="mdi mdi-upload" aria-hidden="true"></i> Importieren
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock controls %}
|
||||
|
||||
{% block content %}
|
||||
<form method="get" class="card mb-3">
|
||||
<div class="card-body d-flex flex-wrap gap-2 align-items-center">
|
||||
<input type="search" name="q" value="{{ q }}" class="form-control w-auto flex-grow-1"
|
||||
placeholder="Seriennummer, Modell, Hersteller oder Gerät" aria-label="Suche">
|
||||
<label class="form-check form-switch mb-0">
|
||||
<input type="checkbox" class="form-check-input" name="has_warnings" value="true"{% if warnings_only %} checked{% endif %}>
|
||||
<span class="form-check-label">Nur mit Warnungen</span>
|
||||
</label>
|
||||
<label class="form-check form-switch mb-0">
|
||||
<input type="checkbox" class="form-check-input" name="removed" value="1"{% if show_removed %} checked{% endif %}>
|
||||
<span class="form-check-label">Ausgebaute anzeigen</span>
|
||||
</label>
|
||||
<button type="submit" class="btn btn-primary"><i class="mdi mdi-magnify" aria-hidden="true"></i> Suchen</button>
|
||||
{% if query %}<a href="{% url 'plugins:netbox_utilities:disk_by_device' %}" class="btn btn-outline-secondary">Zurücksetzen</a>{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 mb-2">
|
||||
<span class="text-muted me-auto">{{ disk_count }} Datenträger in {{ device_count }} Gerät{{ device_count|pluralize:"en" }}</span>
|
||||
{% if groups %}
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-nbu-collapse="show">
|
||||
<i class="mdi mdi-unfold-more-horizontal" aria-hidden="true"></i> Alle aufklappen
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-nbu-collapse="hide">
|
||||
<i class="mdi mdi-unfold-less-horizontal" aria-hidden="true"></i> Alle zuklappen
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% for group in groups %}
|
||||
{% with device=group.device %}
|
||||
<div class="card mb-2">
|
||||
<div class="card-header nbu-disk-group-header" role="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#nbu-disk-group-{{ device.pk }}" aria-expanded="{{ expand_all|yesno:'true,false' }}"
|
||||
aria-controls="nbu-disk-group-{{ device.pk }}">
|
||||
<i class="mdi mdi-chevron-right nbu-disk-group-chevron" aria-hidden="true"></i>
|
||||
<span class="fw-bold me-2">{{ device }}</span>
|
||||
{% if device.role %}<span class="badge text-bg-secondary me-2">{{ device.role }}</span>{% endif %}
|
||||
<span class="text-muted small me-auto">{% if device.site %}{{ device.site }}{% endif %}{% if device.tenant %} · {{ device.tenant }}{% endif %}</span>
|
||||
<span class="badge text-bg-blue me-1">{{ group.count }} Datenträger</span>
|
||||
<span class="badge text-bg-secondary me-1">{{ group.raw_capacity }}</span>
|
||||
{% if group.failed %}<span class="badge text-bg-danger me-1">{{ group.failed }} defekt</span>{% endif %}
|
||||
{% if group.warning_count %}<span class="badge text-bg-warning me-1"><i class="mdi mdi-alert" aria-hidden="true"></i> {{ group.warning_count }}</span>{% endif %}
|
||||
<a href="{% url 'dcim:device_disks' pk=device.pk %}" class="btn btn-sm btn-outline-primary ms-2" title="Datenträger-Tab des Geräts öffnen">
|
||||
<i class="mdi mdi-open-in-app" aria-hidden="true"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div id="nbu-disk-group-{{ device.pk }}" class="collapse{% if expand_all %} show{% endif %}">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-sm mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Slot</th><th>Status</th><th>Typ</th><th>Hersteller / Modell</th><th>Größe</th>
|
||||
<th>Seriennummer</th><th>RAID-Gruppe</th><th>Garantie bis</th><th>Warnungen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for disk in group.disks %}
|
||||
<tr>
|
||||
<td><a href="{{ disk.get_absolute_url }}">{{ disk.slot }}</a></td>
|
||||
<td>{% badge disk.get_status_display bg_color=disk.get_status_color %}</td>
|
||||
<td>{{ disk.get_disk_type_display|placeholder }}{% if disk.interface %} <span class="text-muted">{{ disk.get_interface_display }}</span>{% endif %}</td>
|
||||
<td>{{ disk.manufacturer }} {{ disk.model }}</td>
|
||||
<td>{{ disk.capacity_display }}</td>
|
||||
<td><a href="{{ disk.get_absolute_url }}" class="font-monospace">{{ disk.serial|placeholder }}</a></td>
|
||||
<td>{{ disk.raid_group|linkify:"name"|placeholder }}</td>
|
||||
<td>{{ disk.warranty_end|isodate|placeholder }}</td>
|
||||
<td>{% for level, text in disk.warnings %}<span class="badge text-bg-{{ level }} me-1">{{ text }}</span>{% empty %}{{ ""|placeholder }}{% endfor %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% empty %}
|
||||
<div class="card"><div class="card-body text-muted">Keine Datenträger gefunden.</div></div>
|
||||
{% endfor %}
|
||||
|
||||
{% if page.has_other_pages %}
|
||||
<nav class="mt-3" aria-label="Seiten">
|
||||
<ul class="pagination">
|
||||
{% if page.has_previous %}
|
||||
<li class="page-item"><a class="page-link" href="?{% if query %}{{ query }}&{% endif %}page={{ page.previous_page_number }}">Zurück</a></li>
|
||||
{% endif %}
|
||||
<li class="page-item disabled"><span class="page-link">Seite {{ page.number }} von {{ page.paginator.num_pages }}</span></li>
|
||||
{% if page.has_next %}
|
||||
<li class="page-item"><a class="page-link" href="?{% if query %}{{ query }}&{% endif %}page={{ page.next_page_number }}">Weiter</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
for (const button of document.querySelectorAll("[data-nbu-collapse]")) {
|
||||
button.addEventListener("click", () => {
|
||||
for (const element of document.querySelectorAll("[id^='nbu-disk-group-']")) {
|
||||
const collapse = window.bootstrap?.Collapse?.getOrCreateInstance(element, { toggle: false });
|
||||
if (collapse) collapse[button.dataset.nbuCollapse]();
|
||||
else element.classList.toggle("show", button.dataset.nbuCollapse === "show");
|
||||
const header = document.querySelector(`[data-bs-target="#${element.id}"]`);
|
||||
if (header) header.setAttribute("aria-expanded", String(button.dataset.nbuCollapse === "show"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock content %}
|
||||
@@ -18,6 +18,7 @@ urlpatterns = [
|
||||
path("settings/", views.UtilitiesSettingsView.as_view(), name="settings"),
|
||||
path("tenant/select/", views.SelectTenantView.as_view(), name="select_tenant"),
|
||||
# Datenträger
|
||||
path("disks/by-device/", disk_views.DiskByDeviceView.as_view(), name="disk_by_device"),
|
||||
path("disks/", include(get_model_urls("netbox_utilities", "disk", detail=False))),
|
||||
path("disks/<int:pk>/", include(get_model_urls("netbox_utilities", "disk"))),
|
||||
path("disks/<int:pk>/replace/", disk_views.DiskReplaceView.as_view(), name="disk_replace"),
|
||||
|
||||
Reference in new issue
Block a user