Files
Netbox-Utilities/netbox_utilities/graphql.py
T
MrBlakeandClaude Opus 5.5 d45afa5e54 feat: several slot areas per device, e.g. front bays and a PCIe card
Disks that are not in the front bays, such as NVMe SSDs on a PCIe card or
M.2 SSDs on a boot card, can now be documented in their own slot area.

- A device can have several areas, each with name, order, slot count,
  rows, first slot, numbering and form factor; the tab shows one grid per
  area with its own fill, select and edit actions.
- Add area, edit area and delete empty areas on the Disks tab.
- Slot numbers are unique per area; drag and drop also moves or swaps
  disks between areas.
- Device type templates store all areas; Apply template creates the
  missing ones.
- Disks get a bay field in forms, CSV import (bay column, optional when
  the device has one area), REST API, GraphQL, filters and tables.
- Migration 0010 turns every existing layout into the area "Front" and
  assigns the existing disks to it.
- The grouped disk overview shows the area in its own column and centres
  the slot number.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 14:46:48 +02:00

86 lines
3.2 KiB
Python

from typing import TYPE_CHECKING, Annotated
import strawberry
import strawberry_django
from netbox.graphql.types import NetBoxObjectType
from .models import Disk, DiskBayLayout, DiskBayTemplate, RAIDGroup
if TYPE_CHECKING:
from dcim.graphql.types import DeviceType, DeviceTypeType
from tenancy.graphql.types import TenantType
LAYOUT_FIELDS = ["id", "name", "weight", "slot_count", "rows", "first_slot", "numbering", "form_factor"]
@strawberry_django.type(RAIDGroup, fields=["id", "name", "level", "spans", "description"])
class NetBoxUtilitiesRAIDGroupType(NetBoxObjectType):
device: Annotated["DeviceType", strawberry.lazy("dcim.graphql.types")]
disks: list[Annotated["NetBoxUtilitiesDiskType", strawberry.lazy("netbox_utilities.graphql")]]
@strawberry_django.field
def usable_capacity_gb(self) -> int | None:
return self.usable_capacity_gb
@strawberry_django.field
def is_degraded(self) -> bool:
return self.is_degraded
@strawberry_django.type(
Disk,
fields=[
"id",
"slot",
"status",
"disk_type",
"interface",
"form_factor",
"manufacturer",
"model",
"capacity_gb",
"serial",
"firmware",
"manufacture_date",
"install_date",
"removal_date",
"warranty_end",
"description",
"comments",
],
)
class NetBoxUtilitiesDiskType(NetBoxObjectType):
device: Annotated["DeviceType", strawberry.lazy("dcim.graphql.types")]
tenant: Annotated["TenantType", strawberry.lazy("tenancy.graphql.types")] | None
raid_group: Annotated["NetBoxUtilitiesRAIDGroupType", strawberry.lazy("netbox_utilities.graphql")] | None
bay: Annotated["NetBoxUtilitiesDiskBayLayoutType", strawberry.lazy("netbox_utilities.graphql")] | None
@strawberry_django.field
def warnings(self) -> list[str]:
return [text for _, text in self.warnings]
@strawberry_django.type(DiskBayLayout, fields=LAYOUT_FIELDS)
class NetBoxUtilitiesDiskBayLayoutType(NetBoxObjectType):
device: Annotated["DeviceType", strawberry.lazy("dcim.graphql.types")]
@strawberry_django.type(DiskBayTemplate, fields=LAYOUT_FIELDS)
class NetBoxUtilitiesDiskBayTemplateType(NetBoxObjectType):
device_type: Annotated["DeviceTypeType", strawberry.lazy("dcim.graphql.types")]
@strawberry.type(name="Query")
class NetBoxUtilitiesDiskQuery:
netbox_utilities_disk: NetBoxUtilitiesDiskType = strawberry_django.field()
netbox_utilities_disk_list: list[NetBoxUtilitiesDiskType] = strawberry_django.field()
netbox_utilities_raid_group: NetBoxUtilitiesRAIDGroupType = strawberry_django.field()
netbox_utilities_raid_group_list: list[NetBoxUtilitiesRAIDGroupType] = strawberry_django.field()
netbox_utilities_disk_bay_layout: NetBoxUtilitiesDiskBayLayoutType = strawberry_django.field()
netbox_utilities_disk_bay_layout_list: list[NetBoxUtilitiesDiskBayLayoutType] = strawberry_django.field()
netbox_utilities_disk_bay_template: NetBoxUtilitiesDiskBayTemplateType = strawberry_django.field()
netbox_utilities_disk_bay_template_list: list[NetBoxUtilitiesDiskBayTemplateType] = strawberry_django.field()
schema = [NetBoxUtilitiesDiskQuery]