9856 update types

This commit is contained in:
Arthur 2024-02-26 14:13:44 -08:00
parent 44f4d60f5d
commit 497de46ad9
4 changed files with 123 additions and 21 deletions

View File

@ -311,7 +311,7 @@ class InventoryItemTemplateType(ComponentTemplateObjectType):
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')], Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
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("InventoryItemTemplateComponentType")]]:
return self.component return self.component

View File

@ -234,8 +234,7 @@ class RouteTargetType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Service, models.Service,
# fields='__all__', fields='__all__',
exclude=('ports',), # bug - temp
filters=ServiceFilter filters=ServiceFilter
) )
class ServiceType(NetBoxObjectType): class ServiceType(NetBoxObjectType):
@ -248,8 +247,7 @@ class ServiceType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.ServiceTemplate, models.ServiceTemplate,
# fields='__all__', fields='__all__',
exclude=('ports',), # bug - temp
filters=ServiceTemplateFilter filters=ServiceTemplateFilter
) )
class ServiceTemplateType(NetBoxObjectType): class ServiceTemplateType(NetBoxObjectType):
@ -262,7 +260,30 @@ class ServiceTemplateType(NetBoxObjectType):
filters=VLANFilter filters=VLANFilter
) )
class VLANType(NetBoxObjectType): class VLANType(NetBoxObjectType):
pass
@strawberry_django.field
def interfaces_as_untagged(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.interfaces_as_untagged.all()
@strawberry_django.field
def vminterfaces_as_untagged(self) -> List[Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vminterfaces_as_untagged.all()
@strawberry_django.field
def wirelesslan_set(self) -> List[Annotated["WirelessLANType", strawberry.lazy('wireless.graphql.types')]]:
return self.wirelesslan_set.all()
@strawberry_django.field
def prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
return self.prefixes.all()
@strawberry_django.field
def interfaces_as_tagged(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.interfaces_as_tagged.all()
@strawberry_django.field
def vminterfaces_as_tagged(self) -> List[Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vminterfaces_as_tagged.all()
@strawberry_django.type( @strawberry_django.type(
@ -271,8 +292,22 @@ class VLANType(NetBoxObjectType):
filters=VLANGroupFilter filters=VLANGroupFilter
) )
class VLANGroupType(OrganizationalObjectType): class VLANGroupType(OrganizationalObjectType):
# scope = graphene.Field('ipam.graphql.gfk_mixins.VLANGroupScopeType')
pass @strawberry_django.field
def vlans(self) -> List[VLANType]:
return self.vlans.all()
@strawberry_django.field
def scope(self) -> Annotated[Union[
Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')],
Annotated["ClusterGroupType", strawberry.lazy('virtualization.graphql.types')],
Annotated["LocationType", strawberry.lazy('dcim.graphql.types')],
Annotated["RackType", strawberry.lazy('dcim.graphql.types')],
Annotated["RegionType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("VLANGroupScopeType")]:
return self.scope
@strawberry_django.type( @strawberry_django.type(
@ -281,4 +316,31 @@ class VLANGroupType(OrganizationalObjectType):
filters=VRFFilter filters=VRFFilter
) )
class VRFType(NetBoxObjectType): class VRFType(NetBoxObjectType):
pass
@strawberry_django.field
def interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.interfaces.all()
@strawberry_django.field
def ip_addresses(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]:
return self.ip_addresses.all()
@strawberry_django.field
def vminterfaces(self) -> List[Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vminterfaces.all()
@strawberry_django.field
def ip_ranges(self) -> List[Annotated["IPRangeType", strawberry.lazy('ipam.graphql.types')]]:
return self.ip_ranges.all()
@strawberry_django.field
def export_targets(self) -> List[Annotated["RouteTargetType", strawberry.lazy('ipam.graphql.types')]]:
return self.export_targets.all()
@strawberry_django.field
def import_targets(self) -> List[Annotated["RouteTargetType", strawberry.lazy('ipam.graphql.types')]]:
return self.import_targets.all()
@strawberry_django.field
def prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
return self.prefixes.all()

View File

@ -6,6 +6,7 @@ import strawberry_django
from dcim.graphql.types import ComponentObjectType from dcim.graphql.types import ComponentObjectType
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.types import OrganizationalObjectType, NetBoxObjectType from netbox.graphql.types import OrganizationalObjectType, NetBoxObjectType
from virtualization import models from virtualization import models
from .filters import * from .filters import *
@ -70,33 +71,61 @@ class ClusterTypeType(OrganizationalObjectType):
@strawberry_django.type( @strawberry_django.type(
models.VirtualMachine, models.VirtualMachine,
# fields='__all__', fields='__all__',
exclude=('_name', 'interface_count', 'virtual_disk_count',), # bug - temp
filters=VirtualMachineFilter filters=VirtualMachineFilter
) )
class VirtualMachineType(ConfigContextMixin, NetBoxObjectType): class VirtualMachineType(ConfigContextMixin, NetBoxObjectType):
_name: str _name: str
interface_count: BigInt
virtual_disk_count: BigInt
@strawberry_django.field
def interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.interfaces.all()
@strawberry_django.field
def services(self) -> List[Annotated["ServiceType", strawberry.lazy('ipam.graphql.types')]]:
return self.services.all()
@strawberry_django.field
def virtualdisks(self) -> List[Annotated["VirtualDiskType", strawberry.lazy('virtualization.graphql.types')]]:
return self.virtualdisks.all()
@strawberry_django.type( @strawberry_django.type(
models.VMInterface, models.VMInterface,
# fields='__all__', fields='__all__',
exclude=('mac_address', '_name',), # bug - temp
filters=VMInterfaceFilter filters=VMInterfaceFilter
) )
class VMInterfaceType(IPAddressesMixin, ComponentObjectType): class VMInterfaceType(IPAddressesMixin, ComponentObjectType):
_name: str
mac_address: str
def resolve_mode(self, info): @strawberry_django.field
return self.mode or None def ip_addresses(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]:
return self.ip_addresses.all()
@strawberry_django.field
def tagged_vlans(self) -> List[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]:
return self.tagged_vlans.all()
@strawberry_django.field
def mac_address(self) -> List[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
return self.mac_address.all()
@strawberry_django.field
def bridge_interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.bridge_interfaces.all()
@strawberry_django.field
def child_interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.child_interfaces.all()
@strawberry_django.type( @strawberry_django.type(
models.VirtualDisk, models.VirtualDisk,
# fields='__all__', fields='__all__',
exclude=('_name',), # bug - temp
filters=VirtualDiskFilter filters=VirtualDiskFilter
) )
class VirtualDiskType(ComponentObjectType): class VirtualDiskType(ComponentObjectType):
_name: str
def resolve_mode(self, info):
return self.mode or None

View File

@ -21,7 +21,18 @@ __all__ = (
filters=WirelessLANGroupFilter filters=WirelessLANGroupFilter
) )
class WirelessLANGroupType(OrganizationalObjectType): class WirelessLANGroupType(OrganizationalObjectType):
pass
@strawberry_django.field
def parent(self) -> Annotated["WirelessLANGroupType", strawberry.lazy('wireless.graphql.types')]:
return self.parent
@strawberry_django.field
def wireless_lans(self) -> List[Annotated["WirelessLANType", strawberry.lazy('wireless.graphql.types')]]:
return self.wireless_lans.all()
@strawberry_django.field
def children(self) -> List[Annotated["WirelessLANGroupType", strawberry.lazy('wireless.graphql.types')]]:
return self.children.all()
@strawberry_django.type( @strawberry_django.type(