From 7e6bb0e6bc628d0972378dfbf0f5487a15c5e434 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Wed, 23 Oct 2024 13:16:39 -0700 Subject: [PATCH] 7699 graphql, tables --- netbox/virtualization/graphql/types.py | 15 +++++++++++---- netbox/virtualization/tables/clusters.py | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/netbox/virtualization/graphql/types.py b/netbox/virtualization/graphql/types.py index 2d872322b..4af31fc2e 100644 --- a/netbox/virtualization/graphql/types.py +++ b/netbox/virtualization/graphql/types.py @@ -1,4 +1,4 @@ -from typing import Annotated, List +from typing import Annotated, List, Union import strawberry import strawberry_django @@ -31,18 +31,25 @@ class ComponentType(NetBoxObjectType): @strawberry_django.type( models.Cluster, - fields='__all__', + exclude=('scope_type', 'scope_id', '_location', '_region', '_site', '_sitegroup'), filters=ClusterFilter ) class ClusterType(VLANGroupsMixin, NetBoxObjectType): type: Annotated["ClusterTypeType", strawberry.lazy('virtualization.graphql.types')] | None group: Annotated["ClusterGroupType", strawberry.lazy('virtualization.graphql.types')] | None tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None - site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')] | None - virtual_machines: List[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]] devices: List[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]] + @strawberry_django.field + def scope(self) -> Annotated[Union[ + Annotated["LocationType", strawberry.lazy('dcim.graphql.types')], + Annotated["RegionType", strawberry.lazy('dcim.graphql.types')], + Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')], + Annotated["SiteType", strawberry.lazy('dcim.graphql.types')], + ], strawberry.union("ClusterScopeType")] | None: + return self.scope + @strawberry_django.type( models.ClusterGroup, diff --git a/netbox/virtualization/tables/clusters.py b/netbox/virtualization/tables/clusters.py index d3c799fb9..28a2b00dc 100644 --- a/netbox/virtualization/tables/clusters.py +++ b/netbox/virtualization/tables/clusters.py @@ -75,7 +75,8 @@ class ClusterTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable): ) site = tables.Column( verbose_name=_('Site'), - linkify=True + linkify=True, + accessor='_site' ) device_count = columns.LinkedCountColumn( viewname='dcim:device_list',