fix: drop unsupported user argument from disk tables and show disk count in tab badge
NetBox 4.7 tables no longer accept a user keyword argument, which broke the Datenträger tab with a TypeError. The tab badge now shows the number of installed disks instead of used/total slots or "neu". Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
adbd697c0a
commit
a296c57536
2 files changed
+11
-15
No files matched your search
@@ -223,9 +223,8 @@ case-insensitive and only matches the first word: `DC01` matches
|
|||||||
### Disks (Datenträger)
|
### Disks (Datenträger)
|
||||||
|
|
||||||
Devices whose role is one of `disk_device_roles` (default `Server`, `NAS`,
|
Devices whose role is one of `disk_device_roles` (default `Server`, `NAS`,
|
||||||
`SAN`, `MSA`) get a **Datenträger** tab. The tab badge shows used/total slots,
|
`SAN`, `MSA`) get a **Datenträger** tab. The tab badge shows the number of
|
||||||
or `neu` while nothing has been set up yet. Devices with other roles do not
|
installed disks. Devices with other roles do not show the tab.
|
||||||
show the tab.
|
|
||||||
|
|
||||||
**First visit.** A wizard asks for the number of slots, the number of rows on
|
**First visit.** A wizard asks for the number of slots, the number of rows on
|
||||||
the device front, the number of the first slot (0 or 1, as printed by the
|
the device front, the number of the first slot (0 or 1, as printed by the
|
||||||
|
|||||||
@@ -18,17 +18,16 @@ LAYOUT_FIELDS = disk_forms.LAYOUT_FIELDS
|
|||||||
|
|
||||||
|
|
||||||
def disk_tab_badge(device):
|
def disk_tab_badge(device):
|
||||||
"""Badge for the device tab; None hides the tab for roles without disks."""
|
"""Number of installed disks; None hides the tab for roles without disks.
|
||||||
|
|
||||||
|
The count is returned as a string so that "0" still shows the tab (hide_if_empty).
|
||||||
|
"""
|
||||||
if not get_plugin_config("netbox_utilities", "disks_enabled") or not disks.supports_disks(device):
|
if not get_plugin_config("netbox_utilities", "disks_enabled") or not disks.supports_disks(device):
|
||||||
return None
|
return None
|
||||||
layout = DiskBayLayout.objects.filter(device=device).only("slot_count").first()
|
return str(Disk.objects.filter(device=device, status__in=disks.SLOT_OCCUPYING_STATUSES).count())
|
||||||
if layout is None:
|
|
||||||
return "neu"
|
|
||||||
used = Disk.objects.filter(device=device, status__in=disks.SLOT_OCCUPYING_STATUSES).count()
|
|
||||||
return f"{used}/{layout.slot_count}"
|
|
||||||
|
|
||||||
|
|
||||||
def device_disk_context(device, user=None):
|
def device_disk_context(device):
|
||||||
layout = DiskBayLayout.objects.filter(device=device).first()
|
layout = DiskBayLayout.objects.filter(device=device).first()
|
||||||
device_disks = list(
|
device_disks = list(
|
||||||
Disk.objects.filter(device=device).select_related("raid_group").order_by("slot", "-removal_date", "pk")
|
Disk.objects.filter(device=device).select_related("raid_group").order_by("slot", "-removal_date", "pk")
|
||||||
@@ -40,7 +39,7 @@ def device_disk_context(device, user=None):
|
|||||||
"supported": disks.supports_disks(device),
|
"supported": disks.supports_disks(device),
|
||||||
"layout": layout,
|
"layout": layout,
|
||||||
"raid_groups": raid_groups,
|
"raid_groups": raid_groups,
|
||||||
"history_table": disk_tables.DeviceDiskHistoryTable(history, user=user, orderable=False),
|
"history_table": disk_tables.DeviceDiskHistoryTable(history, orderable=False),
|
||||||
"history_count": len(history),
|
"history_count": len(history),
|
||||||
"disk_warnings": [(disk, disk.warnings) for disk in installed if disk.warnings],
|
"disk_warnings": [(disk, disk.warnings) for disk in installed if disk.warnings],
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,7 @@ class DeviceDisksView(generic.ObjectView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
def get_extra_context(self, request, instance):
|
||||||
return device_disk_context(instance, request.user)
|
return device_disk_context(instance)
|
||||||
|
|
||||||
|
|
||||||
class _DeviceDiskActionView(ContentTypePermissionRequiredMixin, View):
|
class _DeviceDiskActionView(ContentTypePermissionRequiredMixin, View):
|
||||||
@@ -317,9 +316,7 @@ class RAIDGroupView(generic.ObjectView):
|
|||||||
def get_extra_context(self, request, instance):
|
def get_extra_context(self, request, instance):
|
||||||
usable, tolerated, error = instance.capacity
|
usable, tolerated, error = instance.capacity
|
||||||
return {
|
return {
|
||||||
"members_table": disk_tables.DiskTable(
|
"members_table": disk_tables.DiskTable(instance.disks.select_related("device", "tenant"), orderable=False),
|
||||||
instance.disks.select_related("device", "tenant"), user=request.user, orderable=False
|
|
||||||
),
|
|
||||||
"usable_capacity": disks.format_capacity(usable) if usable else None,
|
"usable_capacity": disks.format_capacity(usable) if usable else None,
|
||||||
"tolerated_failures": tolerated,
|
"tolerated_failures": tolerated,
|
||||||
"capacity_error": error,
|
"capacity_error": error,
|
||||||
|
|||||||
Reference in new issue
Block a user