types.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from typing import Annotated, List, TYPE_CHECKING
  2. import strawberry
  3. import strawberry_django
  4. from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
  5. from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType
  6. from tenancy import models
  7. from .filters import *
  8. from .mixins import ContactAssignmentsMixin
  9. if TYPE_CHECKING:
  10. from circuits.graphql.types import CircuitType
  11. from dcim.graphql.types import (
  12. CableType,
  13. DeviceType,
  14. LocationType,
  15. PowerFeedType,
  16. RackType,
  17. RackReservationType,
  18. SiteType,
  19. VirtualDeviceContextType,
  20. )
  21. from ipam.graphql.types import (
  22. AggregateType,
  23. ASNType,
  24. ASNRangeType,
  25. IPAddressType,
  26. IPRangeType,
  27. PrefixType,
  28. RouteTargetType,
  29. VLANType,
  30. VRFType,
  31. )
  32. from netbox.graphql.types import ContentTypeType
  33. from wireless.graphql.types import WirelessLANType, WirelessLinkType
  34. from virtualization.graphql.types import ClusterType, VirtualMachineType
  35. from vpn.graphql.types import L2VPNType, TunnelType
  36. __all__ = (
  37. 'ContactAssignmentType',
  38. 'ContactGroupType',
  39. 'ContactRoleType',
  40. 'ContactType',
  41. 'TenantType',
  42. 'TenantGroupType',
  43. )
  44. #
  45. # Tenants
  46. #
  47. @strawberry_django.type(models.Tenant, fields='__all__', filters=TenantFilter)
  48. class TenantType(NetBoxObjectType):
  49. group: Annotated['TenantGroupType', strawberry.lazy('tenancy.graphql.types')] | None
  50. contacts: List[Annotated['ContactType', strawberry.lazy('tenancy.graphql.types')]]
  51. asns: List[Annotated['ASNType', strawberry.lazy('ipam.graphql.types')]]
  52. circuits: List[Annotated['CircuitType', strawberry.lazy('circuits.graphql.types')]]
  53. sites: List[Annotated['SiteType', strawberry.lazy('dcim.graphql.types')]]
  54. vlans: List[Annotated['VLANType', strawberry.lazy('ipam.graphql.types')]]
  55. wireless_lans: List[Annotated['WirelessLANType', strawberry.lazy('wireless.graphql.types')]]
  56. route_targets: List[Annotated['RouteTargetType', strawberry.lazy('ipam.graphql.types')]]
  57. locations: List[Annotated['LocationType', strawberry.lazy('dcim.graphql.types')]]
  58. ip_ranges: List[Annotated['IPRangeType', strawberry.lazy('ipam.graphql.types')]]
  59. rackreservations: List[Annotated['RackReservationType', strawberry.lazy('dcim.graphql.types')]]
  60. racks: List[Annotated['RackType', strawberry.lazy('dcim.graphql.types')]]
  61. vdcs: List[Annotated['VirtualDeviceContextType', strawberry.lazy('dcim.graphql.types')]]
  62. prefixes: List[Annotated['PrefixType', strawberry.lazy('ipam.graphql.types')]]
  63. cables: List[Annotated['CableType', strawberry.lazy('dcim.graphql.types')]]
  64. virtual_machines: List[Annotated['VirtualMachineType', strawberry.lazy('virtualization.graphql.types')]]
  65. vrfs: List[Annotated['VRFType', strawberry.lazy('ipam.graphql.types')]]
  66. asn_ranges: List[Annotated['ASNRangeType', strawberry.lazy('ipam.graphql.types')]]
  67. wireless_links: List[Annotated['WirelessLinkType', strawberry.lazy('wireless.graphql.types')]]
  68. aggregates: List[Annotated['AggregateType', strawberry.lazy('ipam.graphql.types')]]
  69. power_feeds: List[Annotated['PowerFeedType', strawberry.lazy('dcim.graphql.types')]]
  70. devices: List[Annotated['DeviceType', strawberry.lazy('dcim.graphql.types')]]
  71. tunnels: List[Annotated['TunnelType', strawberry.lazy('vpn.graphql.types')]]
  72. ip_addresses: List[Annotated['IPAddressType', strawberry.lazy('ipam.graphql.types')]]
  73. clusters: List[Annotated['ClusterType', strawberry.lazy('virtualization.graphql.types')]]
  74. l2vpns: List[Annotated['L2VPNType', strawberry.lazy('vpn.graphql.types')]]
  75. @strawberry_django.type(models.TenantGroup, fields='__all__', filters=TenantGroupFilter)
  76. class TenantGroupType(OrganizationalObjectType):
  77. parent: Annotated['TenantGroupType', strawberry.lazy('tenancy.graphql.types')] | None
  78. tenants: List[TenantType]
  79. children: List[Annotated['TenantGroupType', strawberry.lazy('tenancy.graphql.types')]]
  80. #
  81. # Contacts
  82. #
  83. @strawberry_django.type(models.Contact, fields='__all__', filters=ContactFilter)
  84. class ContactType(ContactAssignmentsMixin, NetBoxObjectType):
  85. groups: List[Annotated['ContactGroupType', strawberry.lazy('tenancy.graphql.types')]]
  86. @strawberry_django.type(models.ContactRole, fields='__all__', filters=ContactRoleFilter)
  87. class ContactRoleType(ContactAssignmentsMixin, OrganizationalObjectType):
  88. pass
  89. @strawberry_django.type(models.ContactGroup, fields='__all__', filters=ContactGroupFilter)
  90. class ContactGroupType(OrganizationalObjectType):
  91. parent: Annotated['ContactGroupType', strawberry.lazy('tenancy.graphql.types')] | None
  92. contacts: List[ContactType]
  93. children: List[Annotated['ContactGroupType', strawberry.lazy('tenancy.graphql.types')]]
  94. @strawberry_django.type(models.ContactAssignment, fields='__all__', filters=ContactAssignmentFilter)
  95. class ContactAssignmentType(CustomFieldsMixin, TagsMixin, BaseObjectType):
  96. object_type: Annotated['ContentTypeType', strawberry.lazy('netbox.graphql.types')] | None
  97. contact: Annotated['ContactType', strawberry.lazy('tenancy.graphql.types')] | None
  98. role: Annotated['ContactRoleType', strawberry.lazy('tenancy.graphql.types')] | None