|
@@ -9,6 +9,7 @@ from core.graphql.mixins import ChangelogMixin
|
|
|
from dcim import models
|
|
from dcim import models
|
|
|
from extras.graphql.mixins import ConfigContextMixin, ContactsMixin, ImageAttachmentsMixin
|
|
from extras.graphql.mixins import ConfigContextMixin, ContactsMixin, ImageAttachmentsMixin
|
|
|
from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
|
|
from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
|
|
|
|
|
+from netbox.graphql.optimization import build_gfk_prefetch
|
|
|
from netbox.graphql.scalars import BigInt
|
|
from netbox.graphql.scalars import BigInt
|
|
|
from netbox.graphql.types import (
|
|
from netbox.graphql.types import (
|
|
|
BaseObjectType,
|
|
BaseObjectType,
|
|
@@ -19,7 +20,7 @@ from netbox.graphql.types import (
|
|
|
)
|
|
)
|
|
|
from users.graphql.mixins import OwnerMixin
|
|
from users.graphql.mixins import OwnerMixin
|
|
|
from utilities.querysets import RestrictedPrefetch
|
|
from utilities.querysets import RestrictedPrefetch
|
|
|
-from virtualization.models import Cluster
|
|
|
|
|
|
|
+from virtualization.models import Cluster, VMInterface
|
|
|
|
|
|
|
|
from .filters import *
|
|
from .filters import *
|
|
|
from .mixins import CabledObjectMixin, PathEndpointMixin
|
|
from .mixins import CabledObjectMixin, PathEndpointMixin
|
|
@@ -150,7 +151,25 @@ class CableBundleType(PrimaryObjectType):
|
|
|
)
|
|
)
|
|
|
class CableTerminationType(NetBoxObjectType):
|
|
class CableTerminationType(NetBoxObjectType):
|
|
|
cable: Annotated['CableType', strawberry.lazy('dcim.graphql.types')] | None
|
|
cable: Annotated['CableType', strawberry.lazy('dcim.graphql.types')] | None
|
|
|
- termination: Annotated[
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @strawberry_django.field(
|
|
|
|
|
+ prefetch_related=build_gfk_prefetch(
|
|
|
|
|
+ 'termination',
|
|
|
|
|
+ [
|
|
|
|
|
+ CircuitTermination,
|
|
|
|
|
+ models.ConsolePort,
|
|
|
|
|
+ models.ConsoleServerPort,
|
|
|
|
|
+ models.FrontPort,
|
|
|
|
|
+ models.Interface,
|
|
|
|
|
+ models.PowerFeed,
|
|
|
|
|
+ models.PowerOutlet,
|
|
|
|
|
+ models.PowerPort,
|
|
|
|
|
+ models.RearPort,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ),
|
|
|
|
|
+ only=['termination_type', 'termination_id'],
|
|
|
|
|
+ )
|
|
|
|
|
+ def termination(self) -> Annotated[
|
|
|
Annotated['CircuitTerminationType', strawberry.lazy('circuits.graphql.types')]
|
|
Annotated['CircuitTerminationType', strawberry.lazy('circuits.graphql.types')]
|
|
|
| Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
|
|
| Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
| Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
| Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
@@ -161,7 +180,8 @@ class CableTerminationType(NetBoxObjectType):
|
|
|
| Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
| Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
| Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
|
|
| Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
|
|
|
strawberry.union('CableTerminationTerminationType'),
|
|
strawberry.union('CableTerminationTerminationType'),
|
|
|
- ] | None
|
|
|
|
|
|
|
+ ] | None:
|
|
|
|
|
+ return self.termination
|
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry_django.type(
|
|
@strawberry_django.type(
|
|
@@ -330,22 +350,38 @@ class InventoryItemTemplateType(ComponentTemplateType):
|
|
|
role: Annotated['InventoryItemRoleType', strawberry.lazy('dcim.graphql.types')] | None
|
|
role: Annotated['InventoryItemRoleType', strawberry.lazy('dcim.graphql.types')] | None
|
|
|
manufacturer: Annotated['ManufacturerType', strawberry.lazy('dcim.graphql.types')]
|
|
manufacturer: Annotated['ManufacturerType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
|
|
|
- @strawberry_django.field(prefetch_related='parent')
|
|
|
|
|
|
|
+ @strawberry_django.field(prefetch_related='parent', only=['parent_id'])
|
|
|
def parent(self) -> Annotated['InventoryItemTemplateType', strawberry.lazy('dcim.graphql.types')] | None:
|
|
def parent(self) -> Annotated['InventoryItemTemplateType', strawberry.lazy('dcim.graphql.types')] | None:
|
|
|
return self.parent
|
|
return self.parent
|
|
|
|
|
|
|
|
child_items: list[Annotated['InventoryItemTemplateType', strawberry.lazy('dcim.graphql.types')]]
|
|
child_items: list[Annotated['InventoryItemTemplateType', strawberry.lazy('dcim.graphql.types')]]
|
|
|
|
|
|
|
|
- component: Annotated[
|
|
|
|
|
- Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
- | Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
- | Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
- | Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
- | Annotated['PowerOutletType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
- | Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
- | Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
|
|
|
|
|
|
|
+ @strawberry_django.field(
|
|
|
|
|
+ prefetch_related=build_gfk_prefetch(
|
|
|
|
|
+ 'component',
|
|
|
|
|
+ [
|
|
|
|
|
+ models.ConsolePortTemplate,
|
|
|
|
|
+ models.ConsoleServerPortTemplate,
|
|
|
|
|
+ models.FrontPortTemplate,
|
|
|
|
|
+ models.InterfaceTemplate,
|
|
|
|
|
+ models.PowerOutletTemplate,
|
|
|
|
|
+ models.PowerPortTemplate,
|
|
|
|
|
+ models.RearPortTemplate,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ),
|
|
|
|
|
+ only=['component_type', 'component_id'],
|
|
|
|
|
+ )
|
|
|
|
|
+ def component(self) -> Annotated[
|
|
|
|
|
+ Annotated['ConsolePortTemplateType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
+ | Annotated['ConsoleServerPortTemplateType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
+ | Annotated['FrontPortTemplateType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
+ | Annotated['InterfaceTemplateType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
+ | Annotated['PowerOutletTemplateType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
+ | Annotated['PowerPortTemplateType', strawberry.lazy('dcim.graphql.types')]
|
|
|
|
|
+ | Annotated['RearPortTemplateType', strawberry.lazy('dcim.graphql.types')],
|
|
|
strawberry.union('InventoryItemTemplateComponentType'),
|
|
strawberry.union('InventoryItemTemplateComponentType'),
|
|
|
- ] | None
|
|
|
|
|
|
|
+ ] | None:
|
|
|
|
|
+ return self.component
|
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry_django.type(
|
|
@strawberry_django.type(
|
|
@@ -433,7 +469,16 @@ class FrontPortTemplateType(ModularComponentTemplateType):
|
|
|
class MACAddressType(PrimaryObjectType):
|
|
class MACAddressType(PrimaryObjectType):
|
|
|
mac_address: str
|
|
mac_address: str
|
|
|
|
|
|
|
|
- @strawberry_django.field(prefetch_related='assigned_object')
|
|
|
|
|
|
|
+ @strawberry_django.field(
|
|
|
|
|
+ prefetch_related=build_gfk_prefetch(
|
|
|
|
|
+ 'assigned_object',
|
|
|
|
|
+ [
|
|
|
|
|
+ models.Interface,
|
|
|
|
|
+ VMInterface,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ),
|
|
|
|
|
+ only=['assigned_object_type', 'assigned_object_id'],
|
|
|
|
|
+ )
|
|
|
def assigned_object(self) -> Annotated[
|
|
def assigned_object(self) -> Annotated[
|
|
|
Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
|
|
Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
|
|
|
| Annotated['VMInterfaceType', strawberry.lazy('virtualization.graphql.types')],
|
|
| Annotated['VMInterfaceType', strawberry.lazy('virtualization.graphql.types')],
|
|
@@ -497,11 +542,26 @@ class InventoryItemType(ComponentType):
|
|
|
|
|
|
|
|
child_items: list[Annotated['InventoryItemType', strawberry.lazy('dcim.graphql.types')]]
|
|
child_items: list[Annotated['InventoryItemType', strawberry.lazy('dcim.graphql.types')]]
|
|
|
|
|
|
|
|
- @strawberry_django.field(prefetch_related='parent')
|
|
|
|
|
|
|
+ @strawberry_django.field(prefetch_related='parent', only=['parent_id'])
|
|
|
def parent(self) -> Annotated['InventoryItemType', strawberry.lazy('dcim.graphql.types')] | None:
|
|
def parent(self) -> Annotated['InventoryItemType', strawberry.lazy('dcim.graphql.types')] | None:
|
|
|
return self.parent
|
|
return self.parent
|
|
|
|
|
|
|
|
- component: Annotated[
|
|
|
|
|
|
|
+ @strawberry_django.field(
|
|
|
|
|
+ prefetch_related=build_gfk_prefetch(
|
|
|
|
|
+ 'component',
|
|
|
|
|
+ [
|
|
|
|
|
+ models.ConsolePort,
|
|
|
|
|
+ models.ConsoleServerPort,
|
|
|
|
|
+ models.FrontPort,
|
|
|
|
|
+ models.Interface,
|
|
|
|
|
+ models.PowerOutlet,
|
|
|
|
|
+ models.PowerPort,
|
|
|
|
|
+ models.RearPort,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ),
|
|
|
|
|
+ only=['component_type', 'component_id'],
|
|
|
|
|
+ )
|
|
|
|
|
+ def component(self) -> Annotated[
|
|
|
Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
|
|
Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
| Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
| Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
| Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
|
|
| Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
|
|
@@ -510,7 +570,8 @@ class InventoryItemType(ComponentType):
|
|
|
| Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
| Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
|
|
|
| Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
|
|
| Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
|
|
|
strawberry.union('InventoryItemComponentType'),
|
|
strawberry.union('InventoryItemComponentType'),
|
|
|
- ] | None
|
|
|
|
|
|
|
+ ] | None:
|
|
|
|
|
+ return self.component
|
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry_django.type(
|
|
@strawberry_django.type(
|
|
@@ -611,7 +672,7 @@ class ModuleBayType(ModularComponentType):
|
|
|
installed_module: Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None
|
|
installed_module: Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None
|
|
|
children: list[Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')]]
|
|
children: list[Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')]]
|
|
|
|
|
|
|
|
- @strawberry_django.field(prefetch_related='parent')
|
|
|
|
|
|
|
+ @strawberry_django.field(prefetch_related='parent', only=['parent_id'])
|
|
|
def parent(self) -> Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')] | None:
|
|
def parent(self) -> Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')] | None:
|
|
|
return self.parent
|
|
return self.parent
|
|
|
|
|
|
|
@@ -888,7 +949,7 @@ class RegionType(VLANGroupsMixin, ContactsMixin, NestedGroupObjectType):
|
|
|
sites: list[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
|
|
sites: list[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
|
|
|
children: list[Annotated["RegionType", strawberry.lazy('dcim.graphql.types')]]
|
|
children: list[Annotated["RegionType", strawberry.lazy('dcim.graphql.types')]]
|
|
|
|
|
|
|
|
- @strawberry_django.field(prefetch_related='parent')
|
|
|
|
|
|
|
+ @strawberry_django.field(prefetch_related='parent', only=['parent_id'])
|
|
|
def parent(self) -> Annotated["RegionType", strawberry.lazy('dcim.graphql.types')] | None:
|
|
def parent(self) -> Annotated["RegionType", strawberry.lazy('dcim.graphql.types')] | None:
|
|
|
return self.parent
|
|
return self.parent
|
|
|
|
|
|
|
@@ -965,7 +1026,7 @@ class SiteGroupType(VLANGroupsMixin, ContactsMixin, NestedGroupObjectType):
|
|
|
sites: list[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
|
|
sites: list[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
|
|
|
children: list[Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')]]
|
|
children: list[Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')]]
|
|
|
|
|
|
|
|
- @strawberry_django.field(prefetch_related='parent')
|
|
|
|
|
|
|
+ @strawberry_django.field(prefetch_related='parent', only=['parent_id'])
|
|
|
def parent(self) -> Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')] | None:
|
|
def parent(self) -> Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')] | None:
|
|
|
return self.parent
|
|
return self.parent
|
|
|
|
|
|