1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

96 lines
2.5 KiB
Python
Raw Normal View History

import graphene
from dcim.graphql.types import (
InterfaceType,
LocationType,
RackType,
RegionType,
SiteGroupType,
SiteType,
)
from dcim.models import Interface, Location, Rack, Region, Site, SiteGroup
from ipam.graphql.types import FHRPGroupType, VLANType
from ipam.models import VLAN, FHRPGroup
from virtualization.graphql.types import ClusterGroupType, ClusterType, VMInterfaceType
from virtualization.models import Cluster, ClusterGroup, VMInterface
class IPAddressAssignmentType(graphene.Union):
class Meta:
types = (
InterfaceType,
FHRPGroupType,
VMInterfaceType,
)
@classmethod
def resolve_type(cls, instance, info):
2023-07-30 13:34:08 -04:00
if type(instance) is Interface:
return InterfaceType
2023-07-30 13:34:08 -04:00
if type(instance) is FHRPGroup:
return FHRPGroupType
2023-07-30 13:34:08 -04:00
if type(instance) is VMInterface:
return VMInterfaceType
class L2VPNAssignmentType(graphene.Union):
class Meta:
types = (
InterfaceType,
VLANType,
VMInterfaceType,
)
@classmethod
def resolve_type(cls, instance, info):
2023-07-30 13:34:08 -04:00
if type(instance) is Interface:
return InterfaceType
2023-07-30 13:34:08 -04:00
if type(instance) is VLAN:
return VLANType
2023-07-30 13:34:08 -04:00
if type(instance) is VMInterface:
return VMInterfaceType
class FHRPGroupInterfaceType(graphene.Union):
class Meta:
types = (
InterfaceType,
VMInterfaceType,
)
@classmethod
def resolve_type(cls, instance, info):
2023-07-30 13:34:08 -04:00
if type(instance) is Interface:
return InterfaceType
2023-07-30 13:34:08 -04:00
if type(instance) is VMInterface:
return VMInterfaceType
class VLANGroupScopeType(graphene.Union):
class Meta:
types = (
ClusterType,
ClusterGroupType,
LocationType,
RackType,
RegionType,
SiteType,
SiteGroupType,
)
@classmethod
def resolve_type(cls, instance, info):
2023-07-30 13:34:08 -04:00
if type(instance) is Cluster:
return ClusterType
2023-07-30 13:34:08 -04:00
if type(instance) is ClusterGroup:
return ClusterGroupType
2023-07-30 13:34:08 -04:00
if type(instance) is Location:
return LocationType
2023-07-30 13:34:08 -04:00
if type(instance) is Rack:
return RackType
2023-07-30 13:34:08 -04:00
if type(instance) is Region:
return RegionType
2023-07-30 13:34:08 -04:00
if type(instance) is Site:
return SiteType
2023-07-30 13:34:08 -04:00
if type(instance) is SiteGroup:
return SiteGroupType