9856 fix partial dcim FK

This commit is contained in:
Arthur 2024-03-07 10:48:50 -08:00
parent e53475a63f
commit 676764a661
3 changed files with 48 additions and 33 deletions

View File

@ -25,7 +25,7 @@ from .mixins import CabledObjectMixin, PathEndpointMixin
__all__ = ( __all__ = (
'CableType', 'CableType',
'ComponentObjectType', 'ComponentType',
'ConsolePortType', 'ConsolePortType',
'ConsolePortTemplateType', 'ConsolePortTemplateType',
'ConsoleServerPortType', 'ConsoleServerPortType',
@ -44,6 +44,7 @@ __all__ = (
'InventoryItemTemplateType', 'InventoryItemTemplateType',
'LocationType', 'LocationType',
'ManufacturerType', 'ManufacturerType',
'ModularComponentType',
'ModuleType', 'ModuleType',
'ModuleBayType', 'ModuleBayType',
'ModuleBayTemplateType', 'ModuleBayTemplateType',
@ -74,7 +75,7 @@ __all__ = (
@strawberry.type @strawberry.type
class ComponentObjectType( class ComponentType(
ChangelogMixin, ChangelogMixin,
CustomFieldsMixin, CustomFieldsMixin,
TagsMixin, TagsMixin,
@ -84,9 +85,16 @@ class ComponentObjectType(
Base type for device/VM components Base type for device/VM components
""" """
_name: str _name: str
device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]
class ComponentTemplateObjectType( @strawberry.type
class ModularComponentType(ComponentType):
module: Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None
@strawberry.type
class ComponentTemplateType(
ChangelogMixin, ChangelogMixin,
BaseObjectType BaseObjectType
): ):
@ -94,12 +102,22 @@ class ComponentTemplateObjectType(
Base type for device/VM components Base type for device/VM components
""" """
_name: str _name: str
device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]
@strawberry.type
class ModularComponentTemplateType(ComponentTemplateType):
"""
Base type for ComponentTemplateModel which supports optional assignment to a ModuleType.
"""
device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None
module_type: Annotated["ModuleTypeType", strawberry.lazy('dcim.graphql.types')] | None
# #
# Model types # Model types
# #
@strawberry_django.type( @strawberry_django.type(
models.CableTermination, models.CableTermination,
exclude=('termination_type', 'termination_id'), exclude=('termination_type', 'termination_id'),
@ -169,7 +187,7 @@ class CableType(NetBoxObjectType):
exclude=('_path',), exclude=('_path',),
filters=ConsolePortFilter filters=ConsolePortFilter
) )
class ConsolePortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin): class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
pass pass
@ -178,7 +196,7 @@ class ConsolePortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin)
fields='__all__', fields='__all__',
filters=ConsolePortTemplateFilter filters=ConsolePortTemplateFilter
) )
class ConsolePortTemplateType(ComponentTemplateObjectType): class ConsolePortTemplateType(ModularComponentTemplateType):
_name: str _name: str
@ -187,7 +205,7 @@ class ConsolePortTemplateType(ComponentTemplateObjectType):
exclude=('_path',), exclude=('_path',),
filters=ConsoleServerPortFilter filters=ConsoleServerPortFilter
) )
class ConsoleServerPortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin): class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
pass pass
@ -196,7 +214,7 @@ class ConsoleServerPortType(ComponentObjectType, CabledObjectMixin, PathEndpoint
fields='__all__', fields='__all__',
filters=ConsoleServerPortTemplateFilter filters=ConsoleServerPortTemplateFilter
) )
class ConsoleServerPortTemplateType(ComponentTemplateObjectType): class ConsoleServerPortTemplateType(ModularComponentTemplateType):
_name: str _name: str
@ -288,8 +306,8 @@ class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, ContactsMixin, NetBo
fields='__all__', fields='__all__',
filters=DeviceBayFilter filters=DeviceBayFilter
) )
class DeviceBayType(ComponentObjectType): class DeviceBayType(ComponentType):
pass installed_device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None
@strawberry_django.type( @strawberry_django.type(
@ -297,7 +315,7 @@ class DeviceBayType(ComponentObjectType):
fields='__all__', fields='__all__',
filters=DeviceBayTemplateFilter filters=DeviceBayTemplateFilter
) )
class DeviceBayTemplateType(ComponentTemplateObjectType): class DeviceBayTemplateType(ComponentTemplateType):
_name: str _name: str
@ -306,7 +324,7 @@ class DeviceBayTemplateType(ComponentTemplateObjectType):
exclude=('component_type', 'component_id', 'parent'), exclude=('component_type', 'component_id', 'parent'),
filters=InventoryItemTemplateFilter filters=InventoryItemTemplateFilter
) )
class InventoryItemTemplateType(ComponentTemplateObjectType): class InventoryItemTemplateType(ComponentTemplateType):
_name: str _name: str
@strawberry_django.field @strawberry_django.field
@ -337,6 +355,7 @@ class InventoryItemTemplateType(ComponentTemplateObjectType):
) )
class DeviceRoleType(OrganizationalObjectType): class DeviceRoleType(OrganizationalObjectType):
color: str color: str
config_template: Annotated["ConfigTemplateType", strawberry.lazy('extras.graphql.types')] | None
@strawberry_django.field @strawberry_django.field
def virtual_machines(self) -> List[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]: def virtual_machines(self) -> List[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]:
@ -416,7 +435,7 @@ class DeviceTypeType(NetBoxObjectType):
fields='__all__', fields='__all__',
filters=FrontPortFilter filters=FrontPortFilter
) )
class FrontPortType(ComponentObjectType, CabledObjectMixin): class FrontPortType(ModularComponentType, CabledObjectMixin):
color: str color: str
@ -425,7 +444,7 @@ class FrontPortType(ComponentObjectType, CabledObjectMixin):
fields='__all__', fields='__all__',
filters=FrontPortTemplateFilter filters=FrontPortTemplateFilter
) )
class FrontPortTemplateType(ComponentTemplateObjectType): class FrontPortTemplateType(ModularComponentTemplateType):
_name: str _name: str
color: str color: str
@ -435,7 +454,7 @@ class FrontPortTemplateType(ComponentTemplateObjectType):
fields='__all__', fields='__all__',
filters=InterfaceFilter filters=InterfaceFilter
) )
class InterfaceType(IPAddressesMixin, ComponentObjectType, CabledObjectMixin, PathEndpointMixin): class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, PathEndpointMixin):
mac_address: str | None mac_address: str | None
wwn: str | None wwn: str | None
@ -473,7 +492,7 @@ class InterfaceType(IPAddressesMixin, ComponentObjectType, CabledObjectMixin, Pa
fields='__all__', fields='__all__',
filters=InterfaceTemplateFilter filters=InterfaceTemplateFilter
) )
class InterfaceTemplateType(ComponentTemplateObjectType): class InterfaceTemplateType(ModularComponentTemplateType):
_name: str _name: str
@strawberry_django.field @strawberry_django.field
@ -486,7 +505,7 @@ class InterfaceTemplateType(ComponentTemplateObjectType):
exclude=('component_type', 'component_id', 'parent'), exclude=('component_type', 'component_id', 'parent'),
filters=InventoryItemFilter filters=InventoryItemFilter
) )
class InventoryItemType(ComponentObjectType): class InventoryItemType(ComponentType):
@strawberry_django.field @strawberry_django.field
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
@ -631,7 +650,7 @@ class ModuleType(NetBoxObjectType):
fields='__all__', fields='__all__',
filters=ModuleBayFilter filters=ModuleBayFilter
) )
class ModuleBayType(ComponentObjectType): class ModuleBayType(ComponentType):
@strawberry_django.field @strawberry_django.field
def installed_module(self) -> Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None: def installed_module(self) -> Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None:
@ -643,7 +662,7 @@ class ModuleBayType(ComponentObjectType):
fields='__all__', fields='__all__',
filters=ModuleBayTemplateFilter filters=ModuleBayTemplateFilter
) )
class ModuleBayTemplateType(ComponentTemplateObjectType): class ModuleBayTemplateType(ComponentTemplateType):
_name: str _name: str
@ -717,7 +736,7 @@ class PowerFeedType(NetBoxObjectType, CabledObjectMixin, PathEndpointMixin):
fields='__all__', fields='__all__',
filters=PowerOutletFilter filters=PowerOutletFilter
) )
class PowerOutletType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin): class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
pass pass
@ -726,7 +745,7 @@ class PowerOutletType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin)
fields='__all__', fields='__all__',
filters=PowerOutletTemplateFilter filters=PowerOutletTemplateFilter
) )
class PowerOutletTemplateType(ComponentTemplateObjectType): class PowerOutletTemplateType(ModularComponentTemplateType):
_name: str _name: str
@ -747,7 +766,7 @@ class PowerPanelType(NetBoxObjectType, ContactsMixin):
exclude=('_path',), exclude=('_path',),
filters=PowerPortFilter filters=PowerPortFilter
) )
class PowerPortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin): class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
@strawberry_django.field @strawberry_django.field
def poweroutlets(self) -> List[Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')]]: def poweroutlets(self) -> List[Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')]]:
@ -759,7 +778,7 @@ class PowerPortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin):
fields='__all__', fields='__all__',
filters=PowerPortTemplateFilter filters=PowerPortTemplateFilter
) )
class PowerPortTemplateType(ComponentTemplateObjectType): class PowerPortTemplateType(ModularComponentTemplateType):
_name: str _name: str
@strawberry_django.field @strawberry_django.field
@ -823,7 +842,7 @@ class RackRoleType(OrganizationalObjectType):
fields='__all__', fields='__all__',
filters=RearPortFilter filters=RearPortFilter
) )
class RearPortType(ComponentObjectType, CabledObjectMixin): class RearPortType(ModularComponentType, CabledObjectMixin):
color: str color: str
@strawberry_django.field @strawberry_django.field
@ -836,7 +855,7 @@ class RearPortType(ComponentObjectType, CabledObjectMixin):
fields='__all__', fields='__all__',
filters=RearPortTemplateFilter filters=RearPortTemplateFilter
) )
class RearPortTemplateType(ComponentTemplateObjectType): class RearPortTemplateType(ModularComponentTemplateType):
_name: str _name: str
color: str color: str

View File

@ -158,8 +158,7 @@ class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType):
@strawberry_django.type( @strawberry_django.type(
models.IPRange, models.IPRange,
# fields='__all__', fields='__all__',
exclude=('start_address', 'end_address',), # bug - temp
filters=IPRangeFilter filters=IPRangeFilter
) )
class IPRangeType(NetBoxObjectType): class IPRangeType(NetBoxObjectType):
@ -172,8 +171,7 @@ class IPRangeType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Prefix, models.Prefix,
# fields='__all__', fields='__all__',
exclude=('prefix',), # bug - temp
filters=PrefixFilter filters=PrefixFilter
) )
class PrefixType(NetBoxObjectType, BaseIPAddressFamilyType): class PrefixType(NetBoxObjectType, BaseIPAddressFamilyType):

View File

@ -3,7 +3,7 @@ from typing import Annotated, List
import strawberry import strawberry
import strawberry_django import strawberry_django
from dcim.graphql.types import ComponentObjectType from dcim.graphql.types import ComponentType
from extras.graphql.mixins import ConfigContextMixin from extras.graphql.mixins import ConfigContextMixin
from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
from netbox.graphql.scalars import BigInt from netbox.graphql.scalars import BigInt
@ -110,8 +110,7 @@ class VirtualMachineType(ConfigContextMixin, NetBoxObjectType):
fields='__all__', fields='__all__',
filters=VMInterfaceFilter filters=VMInterfaceFilter
) )
class VMInterfaceType(IPAddressesMixin, ComponentObjectType): class VMInterfaceType(IPAddressesMixin, ComponentType):
_name: str
mac_address: str | None mac_address: str | None
parent: Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')] | None parent: Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')] | None
bridge: Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')] | None bridge: Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')] | None
@ -141,6 +140,5 @@ class VMInterfaceType(IPAddressesMixin, ComponentObjectType):
fields='__all__', fields='__all__',
filters=VirtualDiskFilter filters=VirtualDiskFilter
) )
class VirtualDiskType(ComponentObjectType): class VirtualDiskType(ComponentType):
_name: str
virtual_machine: Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')] virtual_machine: Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]