types.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. from typing import TYPE_CHECKING, Annotated
  2. import strawberry
  3. import strawberry_django
  4. from core.graphql.mixins import ChangelogMixin
  5. from dcim import models
  6. from extras.graphql.mixins import ConfigContextMixin, ContactsMixin, ImageAttachmentsMixin
  7. from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
  8. from netbox.graphql.scalars import BigInt
  9. from netbox.graphql.types import (
  10. BaseObjectType,
  11. NestedGroupObjectType,
  12. NetBoxObjectType,
  13. OrganizationalObjectType,
  14. PrimaryObjectType,
  15. )
  16. from users.graphql.mixins import OwnerMixin
  17. from .filters import *
  18. from .mixins import CabledObjectMixin, PathEndpointMixin
  19. if TYPE_CHECKING:
  20. from circuits.graphql.types import CircuitTerminationType
  21. from extras.graphql.types import ConfigTemplateType
  22. from ipam.graphql.types import (
  23. ASNType,
  24. IPAddressType,
  25. PrefixType,
  26. ServiceType,
  27. VLANTranslationPolicyType,
  28. VLANType,
  29. VRFType,
  30. )
  31. from tenancy.graphql.types import TenantType
  32. from users.graphql.types import UserType
  33. from virtualization.graphql.types import ClusterType, VirtualMachineType, VMInterfaceType
  34. from vpn.graphql.types import L2VPNTerminationType
  35. from wireless.graphql.types import WirelessLANType, WirelessLinkType
  36. __all__ = (
  37. 'CableType',
  38. 'ComponentType',
  39. 'ConsolePortTemplateType',
  40. 'ConsolePortType',
  41. 'ConsoleServerPortTemplateType',
  42. 'ConsoleServerPortType',
  43. 'DeviceBayTemplateType',
  44. 'DeviceBayType',
  45. 'DeviceRoleType',
  46. 'DeviceType',
  47. 'DeviceTypeType',
  48. 'FrontPortTemplateType',
  49. 'FrontPortType',
  50. 'InterfaceTemplateType',
  51. 'InterfaceType',
  52. 'InventoryItemRoleType',
  53. 'InventoryItemTemplateType',
  54. 'InventoryItemType',
  55. 'LocationType',
  56. 'MACAddressType',
  57. 'ManufacturerType',
  58. 'ModularComponentType',
  59. 'ModuleBayTemplateType',
  60. 'ModuleBayType',
  61. 'ModuleType',
  62. 'ModuleTypeProfileType',
  63. 'ModuleTypeType',
  64. 'PlatformType',
  65. 'PowerFeedType',
  66. 'PowerOutletTemplateType',
  67. 'PowerOutletType',
  68. 'PowerPanelType',
  69. 'PowerPortTemplateType',
  70. 'PowerPortType',
  71. 'RackReservationType',
  72. 'RackRoleType',
  73. 'RackType',
  74. 'RackTypeType',
  75. 'RearPortTemplateType',
  76. 'RearPortType',
  77. 'RegionType',
  78. 'SiteGroupType',
  79. 'SiteType',
  80. 'VirtualChassisType',
  81. 'VirtualDeviceContextType',
  82. )
  83. #
  84. # Base types
  85. #
  86. @strawberry.type
  87. class ComponentType(OwnerMixin, NetBoxObjectType):
  88. """
  89. Base type for device/VM components
  90. """
  91. device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]
  92. @strawberry.type
  93. class ModularComponentType(ComponentType):
  94. module: Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None
  95. @strawberry.type
  96. class ComponentTemplateType(ChangelogMixin, BaseObjectType):
  97. """
  98. Base type for device/VM components
  99. """
  100. device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]
  101. @strawberry.type
  102. class ModularComponentTemplateType(ComponentTemplateType):
  103. """
  104. Base type for ComponentTemplateModel which supports optional assignment to a ModuleType.
  105. """
  106. device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')] | None
  107. module_type: Annotated["ModuleTypeType", strawberry.lazy('dcim.graphql.types')] | None
  108. #
  109. # Model types
  110. #
  111. @strawberry_django.type(
  112. models.CableTermination,
  113. exclude=['termination_type', 'termination_id', '_device', '_rack', '_location', '_site'],
  114. filters=CableTerminationFilter,
  115. pagination=True
  116. )
  117. class CableTerminationType(NetBoxObjectType):
  118. cable: Annotated['CableType', strawberry.lazy('dcim.graphql.types')] | None
  119. termination: Annotated[
  120. Annotated['CircuitTerminationType', strawberry.lazy('circuits.graphql.types')]
  121. | Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
  122. | Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
  123. | Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
  124. | Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
  125. | Annotated['PowerFeedType', strawberry.lazy('dcim.graphql.types')]
  126. | Annotated['PowerOutletType', strawberry.lazy('dcim.graphql.types')]
  127. | Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
  128. | Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
  129. strawberry.union('CableTerminationTerminationType'),
  130. ] | None
  131. @strawberry_django.type(
  132. models.Cable,
  133. fields='__all__',
  134. filters=CableFilter,
  135. pagination=True
  136. )
  137. class CableType(PrimaryObjectType):
  138. color: str
  139. tenant: Annotated['TenantType', strawberry.lazy('tenancy.graphql.types')] | None
  140. terminations: list[CableTerminationType]
  141. a_terminations: list[Annotated[
  142. Annotated['CircuitTerminationType', strawberry.lazy('circuits.graphql.types')]
  143. | Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
  144. | Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
  145. | Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
  146. | Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
  147. | Annotated['PowerFeedType', strawberry.lazy('dcim.graphql.types')]
  148. | Annotated['PowerOutletType', strawberry.lazy('dcim.graphql.types')]
  149. | Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
  150. | Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
  151. strawberry.union('CableTerminationTerminationType'),
  152. ]]
  153. b_terminations: list[Annotated[
  154. Annotated['CircuitTerminationType', strawberry.lazy('circuits.graphql.types')]
  155. | Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
  156. | Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
  157. | Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
  158. | Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
  159. | Annotated['PowerFeedType', strawberry.lazy('dcim.graphql.types')]
  160. | Annotated['PowerOutletType', strawberry.lazy('dcim.graphql.types')]
  161. | Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
  162. | Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
  163. strawberry.union('CableTerminationTerminationType'),
  164. ]]
  165. @strawberry_django.type(
  166. models.ConsolePort,
  167. exclude=['_path'],
  168. filters=ConsolePortFilter,
  169. pagination=True
  170. )
  171. class ConsolePortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
  172. pass
  173. @strawberry_django.type(
  174. models.ConsolePortTemplate,
  175. fields='__all__',
  176. filters=ConsolePortTemplateFilter,
  177. pagination=True
  178. )
  179. class ConsolePortTemplateType(ModularComponentTemplateType):
  180. pass
  181. @strawberry_django.type(
  182. models.ConsoleServerPort,
  183. exclude=['_path'],
  184. filters=ConsoleServerPortFilter,
  185. pagination=True
  186. )
  187. class ConsoleServerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
  188. pass
  189. @strawberry_django.type(
  190. models.ConsoleServerPortTemplate,
  191. fields='__all__',
  192. filters=ConsoleServerPortTemplateFilter,
  193. pagination=True
  194. )
  195. class ConsoleServerPortTemplateType(ModularComponentTemplateType):
  196. pass
  197. @strawberry_django.type(
  198. models.Device,
  199. fields='__all__',
  200. filters=DeviceFilter,
  201. pagination=True
  202. )
  203. class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, ContactsMixin, PrimaryObjectType):
  204. console_port_count: BigInt
  205. console_server_port_count: BigInt
  206. power_port_count: BigInt
  207. power_outlet_count: BigInt
  208. interface_count: BigInt
  209. front_port_count: BigInt
  210. rear_port_count: BigInt
  211. device_bay_count: BigInt
  212. module_bay_count: BigInt
  213. inventory_item_count: BigInt
  214. config_template: Annotated["ConfigTemplateType", strawberry.lazy('extras.graphql.types')] | None
  215. device_type: Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]
  216. role: Annotated["DeviceRoleType", strawberry.lazy('dcim.graphql.types')]
  217. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  218. platform: Annotated["PlatformType", strawberry.lazy('dcim.graphql.types')] | None
  219. site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
  220. location: Annotated["LocationType", strawberry.lazy('dcim.graphql.types')] | None
  221. rack: Annotated["RackType", strawberry.lazy('dcim.graphql.types')] | None
  222. primary_ip4: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
  223. primary_ip6: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
  224. oob_ip: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
  225. cluster: Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')] | None
  226. virtual_chassis: Annotated["VirtualChassisType", strawberry.lazy('dcim.graphql.types')] | None
  227. virtual_machines: list[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]
  228. modules: list[Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')]]
  229. interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
  230. rearports: list[Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')]]
  231. consoleports: list[Annotated["ConsolePortType", strawberry.lazy('dcim.graphql.types')]]
  232. powerports: list[Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')]]
  233. cabletermination_set: list[Annotated["CableTerminationType", strawberry.lazy('dcim.graphql.types')]]
  234. consoleserverports: list[Annotated["ConsoleServerPortType", strawberry.lazy('dcim.graphql.types')]]
  235. poweroutlets: list[Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')]]
  236. frontports: list[Annotated["FrontPortType", strawberry.lazy('dcim.graphql.types')]]
  237. devicebays: list[Annotated["DeviceBayType", strawberry.lazy('dcim.graphql.types')]]
  238. modulebays: list[Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')]]
  239. services: list[Annotated["ServiceType", strawberry.lazy('ipam.graphql.types')]]
  240. inventoryitems: list[Annotated["InventoryItemType", strawberry.lazy('dcim.graphql.types')]]
  241. vdcs: list[Annotated["VirtualDeviceContextType", strawberry.lazy('dcim.graphql.types')]]
  242. @strawberry_django.field
  243. def vc_master_for(self) -> Annotated["VirtualChassisType", strawberry.lazy('dcim.graphql.types')] | None:
  244. return self.vc_master_for if hasattr(self, 'vc_master_for') else None
  245. @strawberry_django.field
  246. def parent_bay(self) -> Annotated["DeviceBayType", strawberry.lazy('dcim.graphql.types')] | None:
  247. return self.parent_bay if hasattr(self, 'parent_bay') else None
  248. @strawberry_django.type(
  249. models.DeviceBay,
  250. fields='__all__',
  251. filters=DeviceBayFilter,
  252. pagination=True
  253. )
  254. class DeviceBayType(ComponentType):
  255. installed_device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None
  256. @strawberry_django.type(
  257. models.DeviceBayTemplate,
  258. fields='__all__',
  259. filters=DeviceBayTemplateFilter,
  260. pagination=True
  261. )
  262. class DeviceBayTemplateType(ComponentTemplateType):
  263. pass
  264. @strawberry_django.type(
  265. models.InventoryItemTemplate,
  266. exclude=['component_type', 'component_id', 'parent'],
  267. filters=InventoryItemTemplateFilter,
  268. pagination=True
  269. )
  270. class InventoryItemTemplateType(ComponentTemplateType):
  271. role: Annotated['InventoryItemRoleType', strawberry.lazy('dcim.graphql.types')] | None
  272. manufacturer: Annotated['ManufacturerType', strawberry.lazy('dcim.graphql.types')]
  273. @strawberry_django.field
  274. def parent(self) -> Annotated['InventoryItemTemplateType', strawberry.lazy('dcim.graphql.types')] | None:
  275. return self.parent
  276. child_items: list[Annotated['InventoryItemTemplateType', strawberry.lazy('dcim.graphql.types')]]
  277. component: Annotated[
  278. Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
  279. | Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
  280. | Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
  281. | Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
  282. | Annotated['PowerOutletType', strawberry.lazy('dcim.graphql.types')]
  283. | Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
  284. | Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
  285. strawberry.union('InventoryItemTemplateComponentType'),
  286. ] | None
  287. @strawberry_django.type(
  288. models.DeviceRole,
  289. fields='__all__',
  290. filters=DeviceRoleFilter,
  291. pagination=True
  292. )
  293. class DeviceRoleType(NestedGroupObjectType):
  294. parent: Annotated['DeviceRoleType', strawberry.lazy('dcim.graphql.types')] | None
  295. children: list[Annotated['DeviceRoleType', strawberry.lazy('dcim.graphql.types')]]
  296. color: str
  297. config_template: Annotated["ConfigTemplateType", strawberry.lazy('extras.graphql.types')] | None
  298. virtual_machines: list[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]
  299. devices: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  300. @strawberry_django.type(
  301. models.DeviceType,
  302. fields='__all__',
  303. filters=DeviceTypeFilter,
  304. pagination=True
  305. )
  306. class DeviceTypeType(PrimaryObjectType):
  307. console_port_template_count: BigInt
  308. console_server_port_template_count: BigInt
  309. power_port_template_count: BigInt
  310. power_outlet_template_count: BigInt
  311. interface_template_count: BigInt
  312. front_port_template_count: BigInt
  313. rear_port_template_count: BigInt
  314. device_bay_template_count: BigInt
  315. module_bay_template_count: BigInt
  316. inventory_item_template_count: BigInt
  317. device_count: BigInt
  318. front_image: strawberry_django.fields.types.DjangoImageType | None
  319. rear_image: strawberry_django.fields.types.DjangoImageType | None
  320. manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')]
  321. default_platform: Annotated["PlatformType", strawberry.lazy('dcim.graphql.types')] | None
  322. frontporttemplates: list[Annotated["FrontPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  323. modulebaytemplates: list[Annotated["ModuleBayTemplateType", strawberry.lazy('dcim.graphql.types')]]
  324. instances: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  325. poweroutlettemplates: list[Annotated["PowerOutletTemplateType", strawberry.lazy('dcim.graphql.types')]]
  326. powerporttemplates: list[Annotated["PowerPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  327. inventoryitemtemplates: list[Annotated["InventoryItemTemplateType", strawberry.lazy('dcim.graphql.types')]]
  328. rearporttemplates: list[Annotated["RearPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  329. consoleserverporttemplates: list[Annotated["ConsoleServerPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  330. interfacetemplates: list[Annotated["InterfaceTemplateType", strawberry.lazy('dcim.graphql.types')]]
  331. devicebaytemplates: list[Annotated["DeviceBayTemplateType", strawberry.lazy('dcim.graphql.types')]]
  332. consoleporttemplates: list[Annotated["ConsolePortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  333. @strawberry_django.type(
  334. models.FrontPort,
  335. fields='__all__',
  336. filters=FrontPortFilter,
  337. pagination=True
  338. )
  339. class FrontPortType(ModularComponentType, CabledObjectMixin):
  340. color: str
  341. mappings: list[Annotated["PortMappingType", strawberry.lazy('dcim.graphql.types')]]
  342. @strawberry_django.type(
  343. models.FrontPortTemplate,
  344. fields='__all__',
  345. filters=FrontPortTemplateFilter,
  346. pagination=True
  347. )
  348. class FrontPortTemplateType(ModularComponentTemplateType):
  349. color: str
  350. mappings: list[Annotated["PortMappingTemplateType", strawberry.lazy('dcim.graphql.types')]]
  351. @strawberry_django.type(
  352. models.MACAddress,
  353. exclude=['assigned_object_type', 'assigned_object_id'],
  354. filters=MACAddressFilter,
  355. pagination=True
  356. )
  357. class MACAddressType(PrimaryObjectType):
  358. mac_address: str
  359. @strawberry_django.field
  360. def assigned_object(self) -> Annotated[
  361. Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
  362. | Annotated['VMInterfaceType', strawberry.lazy('virtualization.graphql.types')],
  363. strawberry.union('MACAddressAssignmentType'),
  364. ] | None:
  365. return self.assigned_object
  366. @strawberry_django.type(
  367. models.Interface,
  368. exclude=['_path'],
  369. filters=InterfaceFilter,
  370. pagination=True
  371. )
  372. class InterfaceType(IPAddressesMixin, ModularComponentType, CabledObjectMixin, PathEndpointMixin):
  373. _name: str
  374. wwn: str | None
  375. parent: Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')] | None
  376. bridge: Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')] | None
  377. lag: Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')] | None
  378. wireless_link: Annotated["WirelessLinkType", strawberry.lazy('wireless.graphql.types')] | None
  379. untagged_vlan: Annotated["VLANType", strawberry.lazy('ipam.graphql.types')] | None
  380. vrf: Annotated["VRFType", strawberry.lazy('ipam.graphql.types')] | None
  381. primary_mac_address: Annotated["MACAddressType", strawberry.lazy('dcim.graphql.types')] | None
  382. qinq_svlan: Annotated["VLANType", strawberry.lazy('ipam.graphql.types')] | None
  383. vlan_translation_policy: Annotated["VLANTranslationPolicyType", strawberry.lazy('ipam.graphql.types')] | None
  384. l2vpn_termination: Annotated["L2VPNTerminationType", strawberry.lazy('vpn.graphql.types')] | None
  385. vdcs: list[Annotated["VirtualDeviceContextType", strawberry.lazy('dcim.graphql.types')]]
  386. tagged_vlans: list[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]
  387. bridge_interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
  388. wireless_lans: list[Annotated["WirelessLANType", strawberry.lazy('wireless.graphql.types')]]
  389. member_interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
  390. child_interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
  391. mac_addresses: list[Annotated["MACAddressType", strawberry.lazy('dcim.graphql.types')]]
  392. @strawberry_django.type(
  393. models.InterfaceTemplate,
  394. fields='__all__',
  395. filters=InterfaceTemplateFilter,
  396. pagination=True
  397. )
  398. class InterfaceTemplateType(ModularComponentTemplateType):
  399. _name: str
  400. bridge: Annotated["InterfaceTemplateType", strawberry.lazy('dcim.graphql.types')] | None
  401. bridge_interfaces: list[Annotated["InterfaceTemplateType", strawberry.lazy('dcim.graphql.types')]]
  402. @strawberry_django.type(
  403. models.InventoryItem,
  404. exclude=['component_type', 'component_id', 'parent'],
  405. filters=InventoryItemFilter,
  406. pagination=True
  407. )
  408. class InventoryItemType(ComponentType):
  409. role: Annotated['InventoryItemRoleType', strawberry.lazy('dcim.graphql.types')] | None
  410. manufacturer: Annotated['ManufacturerType', strawberry.lazy('dcim.graphql.types')] | None
  411. child_items: list[Annotated['InventoryItemType', strawberry.lazy('dcim.graphql.types')]]
  412. @strawberry_django.field
  413. def parent(self) -> Annotated['InventoryItemType', strawberry.lazy('dcim.graphql.types')] | None:
  414. return self.parent
  415. component: Annotated[
  416. Annotated['ConsolePortType', strawberry.lazy('dcim.graphql.types')]
  417. | Annotated['ConsoleServerPortType', strawberry.lazy('dcim.graphql.types')]
  418. | Annotated['FrontPortType', strawberry.lazy('dcim.graphql.types')]
  419. | Annotated['InterfaceType', strawberry.lazy('dcim.graphql.types')]
  420. | Annotated['PowerOutletType', strawberry.lazy('dcim.graphql.types')]
  421. | Annotated['PowerPortType', strawberry.lazy('dcim.graphql.types')]
  422. | Annotated['RearPortType', strawberry.lazy('dcim.graphql.types')],
  423. strawberry.union('InventoryItemComponentType'),
  424. ] | None
  425. @strawberry_django.type(
  426. models.InventoryItemRole,
  427. fields='__all__',
  428. filters=InventoryItemRoleFilter,
  429. pagination=True
  430. )
  431. class InventoryItemRoleType(OrganizationalObjectType):
  432. color: str
  433. inventory_items: list[Annotated["InventoryItemType", strawberry.lazy('dcim.graphql.types')]]
  434. inventory_item_templates: list[Annotated["InventoryItemTemplateType", strawberry.lazy('dcim.graphql.types')]]
  435. @strawberry_django.type(
  436. models.Location,
  437. # fields='__all__',
  438. exclude=['parent'], # bug - temp
  439. filters=LocationFilter,
  440. pagination=True
  441. )
  442. class LocationType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, NestedGroupObjectType):
  443. site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
  444. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  445. parent: Annotated["LocationType", strawberry.lazy('dcim.graphql.types')] | None
  446. powerpanel_set: list[Annotated["PowerPanelType", strawberry.lazy('dcim.graphql.types')]]
  447. cabletermination_set: list[Annotated["CableTerminationType", strawberry.lazy('dcim.graphql.types')]]
  448. racks: list[Annotated["RackType", strawberry.lazy('dcim.graphql.types')]]
  449. devices: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  450. children: list[Annotated["LocationType", strawberry.lazy('dcim.graphql.types')]]
  451. @strawberry_django.field
  452. def clusters(self) -> list[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
  453. return self.cluster_set.all()
  454. @strawberry_django.field
  455. def circuit_terminations(self) -> list[
  456. Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]
  457. ]:
  458. return self.circuit_terminations.all()
  459. @strawberry_django.type(
  460. models.Manufacturer,
  461. fields='__all__',
  462. filters=ManufacturerFilter,
  463. pagination=True
  464. )
  465. class ManufacturerType(OrganizationalObjectType, ContactsMixin):
  466. platforms: list[Annotated["PlatformType", strawberry.lazy('dcim.graphql.types')]]
  467. device_types: list[Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]]
  468. inventory_item_templates: list[Annotated["InventoryItemTemplateType", strawberry.lazy('dcim.graphql.types')]]
  469. inventory_items: list[Annotated["InventoryItemType", strawberry.lazy('dcim.graphql.types')]]
  470. module_types: list[Annotated["ModuleTypeType", strawberry.lazy('dcim.graphql.types')]]
  471. @strawberry_django.type(
  472. models.Module,
  473. fields='__all__',
  474. filters=ModuleFilter,
  475. pagination=True
  476. )
  477. class ModuleType(PrimaryObjectType):
  478. device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]
  479. module_bay: Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')]
  480. module_type: Annotated["ModuleTypeType", strawberry.lazy('dcim.graphql.types')]
  481. interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
  482. powerports: list[Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')]]
  483. consoleserverports: list[Annotated["ConsoleServerPortType", strawberry.lazy('dcim.graphql.types')]]
  484. consoleports: list[Annotated["ConsolePortType", strawberry.lazy('dcim.graphql.types')]]
  485. poweroutlets: list[Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')]]
  486. rearports: list[Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')]]
  487. frontports: list[Annotated["FrontPortType", strawberry.lazy('dcim.graphql.types')]]
  488. @strawberry_django.type(
  489. models.ModuleBay,
  490. # fields='__all__',
  491. exclude=['parent'],
  492. filters=ModuleBayFilter,
  493. pagination=True
  494. )
  495. class ModuleBayType(ModularComponentType):
  496. installed_module: Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')] | None
  497. children: list[Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')]]
  498. @strawberry_django.field
  499. def parent(self) -> Annotated["ModuleBayType", strawberry.lazy('dcim.graphql.types')] | None:
  500. return self.parent
  501. @strawberry_django.type(
  502. models.ModuleBayTemplate,
  503. fields='__all__',
  504. filters=ModuleBayTemplateFilter,
  505. pagination=True
  506. )
  507. class ModuleBayTemplateType(ModularComponentTemplateType):
  508. pass
  509. @strawberry_django.type(
  510. models.ModuleTypeProfile,
  511. fields='__all__',
  512. filters=ModuleTypeProfileFilter,
  513. pagination=True
  514. )
  515. class ModuleTypeProfileType(PrimaryObjectType):
  516. module_types: list[Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')]]
  517. @strawberry_django.type(
  518. models.ModuleType,
  519. fields='__all__',
  520. filters=ModuleTypeFilter,
  521. pagination=True
  522. )
  523. class ModuleTypeType(PrimaryObjectType):
  524. module_count: BigInt
  525. profile: Annotated["ModuleTypeProfileType", strawberry.lazy('dcim.graphql.types')] | None
  526. manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')]
  527. frontporttemplates: list[Annotated["FrontPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  528. consoleserverporttemplates: list[Annotated["ConsoleServerPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  529. interfacetemplates: list[Annotated["InterfaceTemplateType", strawberry.lazy('dcim.graphql.types')]]
  530. powerporttemplates: list[Annotated["PowerPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  531. poweroutlettemplates: list[Annotated["PowerOutletTemplateType", strawberry.lazy('dcim.graphql.types')]]
  532. rearporttemplates: list[Annotated["RearPortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  533. instances: list[Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')]]
  534. consoleporttemplates: list[Annotated["ConsolePortTemplateType", strawberry.lazy('dcim.graphql.types')]]
  535. @strawberry_django.type(
  536. models.Platform,
  537. fields='__all__',
  538. filters=PlatformFilter,
  539. pagination=True
  540. )
  541. class PlatformType(NestedGroupObjectType):
  542. parent: Annotated['PlatformType', strawberry.lazy('dcim.graphql.types')] | None
  543. children: list[Annotated['PlatformType', strawberry.lazy('dcim.graphql.types')]]
  544. manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')] | None
  545. config_template: Annotated["ConfigTemplateType", strawberry.lazy('extras.graphql.types')] | None
  546. virtual_machines: list[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]
  547. devices: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  548. @strawberry_django.type(
  549. models.PortMapping,
  550. fields='__all__',
  551. filters=PortMappingFilter,
  552. pagination=True
  553. )
  554. class PortMappingType(ModularComponentTemplateType):
  555. front_port: Annotated["FrontPortType", strawberry.lazy('dcim.graphql.types')]
  556. rear_port: Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')]
  557. @strawberry_django.type(
  558. models.PortTemplateMapping,
  559. fields='__all__',
  560. filters=PortTemplateMappingFilter,
  561. pagination=True
  562. )
  563. class PortMappingTemplateType(ModularComponentTemplateType):
  564. front_port: Annotated["FrontPortTemplateType", strawberry.lazy('dcim.graphql.types')]
  565. rear_port: Annotated["RearPortTemplateType", strawberry.lazy('dcim.graphql.types')]
  566. @strawberry_django.type(
  567. models.PowerFeed,
  568. exclude=['_path'],
  569. filters=PowerFeedFilter,
  570. pagination=True
  571. )
  572. class PowerFeedType(CabledObjectMixin, PathEndpointMixin, PrimaryObjectType):
  573. power_panel: Annotated["PowerPanelType", strawberry.lazy('dcim.graphql.types')]
  574. rack: Annotated["RackType", strawberry.lazy('dcim.graphql.types')] | None
  575. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  576. @strawberry_django.type(
  577. models.PowerOutlet,
  578. exclude=['_path'],
  579. filters=PowerOutletFilter,
  580. pagination=True
  581. )
  582. class PowerOutletType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
  583. power_port: Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')] | None
  584. color: str
  585. @strawberry_django.type(
  586. models.PowerOutletTemplate,
  587. fields='__all__',
  588. filters=PowerOutletTemplateFilter,
  589. pagination=True
  590. )
  591. class PowerOutletTemplateType(ModularComponentTemplateType):
  592. power_port: Annotated["PowerPortTemplateType", strawberry.lazy('dcim.graphql.types')] | None
  593. color: str
  594. @strawberry_django.type(
  595. models.PowerPanel,
  596. fields='__all__',
  597. filters=PowerPanelFilter,
  598. pagination=True
  599. )
  600. class PowerPanelType(ContactsMixin, PrimaryObjectType):
  601. site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
  602. location: Annotated["LocationType", strawberry.lazy('dcim.graphql.types')] | None
  603. powerfeeds: list[Annotated["PowerFeedType", strawberry.lazy('dcim.graphql.types')]]
  604. @strawberry_django.type(
  605. models.PowerPort,
  606. exclude=['_path'],
  607. filters=PowerPortFilter,
  608. pagination=True
  609. )
  610. class PowerPortType(ModularComponentType, CabledObjectMixin, PathEndpointMixin):
  611. poweroutlets: list[Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')]]
  612. @strawberry_django.type(
  613. models.PowerPortTemplate,
  614. fields='__all__',
  615. filters=PowerPortTemplateFilter,
  616. pagination=True
  617. )
  618. class PowerPortTemplateType(ModularComponentTemplateType):
  619. poweroutlet_templates: list[Annotated["PowerOutletTemplateType", strawberry.lazy('dcim.graphql.types')]]
  620. @strawberry_django.type(
  621. models.RackType,
  622. fields='__all__',
  623. filters=RackTypeFilter,
  624. pagination=True
  625. )
  626. class RackTypeType(ImageAttachmentsMixin, PrimaryObjectType):
  627. rack_count: BigInt
  628. manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')]
  629. @strawberry_django.type(
  630. models.Rack,
  631. fields='__all__',
  632. filters=RackFilter,
  633. pagination=True
  634. )
  635. class RackType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, PrimaryObjectType):
  636. site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]
  637. location: Annotated["LocationType", strawberry.lazy('dcim.graphql.types')] | None
  638. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  639. role: Annotated["RackRoleType", strawberry.lazy('dcim.graphql.types')] | None
  640. rack_type: Annotated["RackTypeType", strawberry.lazy('dcim.graphql.types')] | None
  641. reservations: list[Annotated["RackReservationType", strawberry.lazy('dcim.graphql.types')]]
  642. devices: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  643. powerfeeds: list[Annotated["PowerFeedType", strawberry.lazy('dcim.graphql.types')]]
  644. cabletermination_set: list[Annotated["CableTerminationType", strawberry.lazy('dcim.graphql.types')]]
  645. @strawberry_django.type(
  646. models.RackReservation,
  647. fields='__all__',
  648. filters=RackReservationFilter,
  649. pagination=True
  650. )
  651. class RackReservationType(PrimaryObjectType):
  652. units: list[int]
  653. rack: Annotated["RackType", strawberry.lazy('dcim.graphql.types')]
  654. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  655. user: Annotated["UserType", strawberry.lazy('users.graphql.types')]
  656. @strawberry_django.type(
  657. models.RackRole,
  658. fields='__all__',
  659. filters=RackRoleFilter,
  660. pagination=True
  661. )
  662. class RackRoleType(OrganizationalObjectType):
  663. color: str
  664. racks: list[Annotated["RackType", strawberry.lazy('dcim.graphql.types')]]
  665. @strawberry_django.type(
  666. models.RearPort,
  667. fields='__all__',
  668. filters=RearPortFilter,
  669. pagination=True
  670. )
  671. class RearPortType(ModularComponentType, CabledObjectMixin):
  672. color: str
  673. mappings: list[Annotated["PortMappingType", strawberry.lazy('dcim.graphql.types')]]
  674. @strawberry_django.type(
  675. models.RearPortTemplate,
  676. fields='__all__',
  677. filters=RearPortTemplateFilter,
  678. pagination=True
  679. )
  680. class RearPortTemplateType(ModularComponentTemplateType):
  681. color: str
  682. mappings: list[Annotated["PortMappingTemplateType", strawberry.lazy('dcim.graphql.types')]]
  683. @strawberry_django.type(
  684. models.Region,
  685. exclude=['parent'],
  686. filters=RegionFilter,
  687. pagination=True
  688. )
  689. class RegionType(VLANGroupsMixin, ContactsMixin, NestedGroupObjectType):
  690. sites: list[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
  691. children: list[Annotated["RegionType", strawberry.lazy('dcim.graphql.types')]]
  692. @strawberry_django.field
  693. def parent(self) -> Annotated["RegionType", strawberry.lazy('dcim.graphql.types')] | None:
  694. return self.parent
  695. @strawberry_django.field
  696. def clusters(self) -> list[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
  697. return self.cluster_set.all()
  698. @strawberry_django.field
  699. def circuit_terminations(self) -> list[
  700. Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]
  701. ]:
  702. return self.circuit_terminations.all()
  703. @strawberry_django.type(
  704. models.Site,
  705. fields='__all__',
  706. filters=SiteFilter,
  707. pagination=True
  708. )
  709. class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, ContactsMixin, PrimaryObjectType):
  710. time_zone: str | None
  711. region: Annotated["RegionType", strawberry.lazy('dcim.graphql.types')] | None
  712. group: Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')] | None
  713. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  714. prefixes: list[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]
  715. virtual_machines: list[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]
  716. racks: list[Annotated["RackType", strawberry.lazy('dcim.graphql.types')]]
  717. cabletermination_set: list[Annotated["CableTerminationType", strawberry.lazy('dcim.graphql.types')]]
  718. powerpanel_set: list[Annotated["PowerPanelType", strawberry.lazy('dcim.graphql.types')]]
  719. devices: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  720. locations: list[Annotated["LocationType", strawberry.lazy('dcim.graphql.types')]]
  721. asns: list[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]
  722. circuit_terminations: list[Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]]
  723. clusters: list[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]
  724. vlans: list[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]
  725. @strawberry_django.field
  726. def clusters(self) -> list[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
  727. return self.cluster_set.all()
  728. @strawberry_django.field
  729. def circuit_terminations(self) -> list[
  730. Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]
  731. ]:
  732. return self.circuit_terminations.all()
  733. @strawberry_django.type(
  734. models.SiteGroup,
  735. exclude=['parent'], # bug - temp
  736. filters=SiteGroupFilter,
  737. pagination=True
  738. )
  739. class SiteGroupType(VLANGroupsMixin, ContactsMixin, NestedGroupObjectType):
  740. sites: list[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]
  741. children: list[Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')]]
  742. @strawberry_django.field
  743. def parent(self) -> Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')] | None:
  744. return self.parent
  745. @strawberry_django.field
  746. def clusters(self) -> list[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
  747. return self.cluster_set.all()
  748. @strawberry_django.field
  749. def circuit_terminations(self) -> list[
  750. Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]
  751. ]:
  752. return self.circuit_terminations.all()
  753. @strawberry_django.type(
  754. models.VirtualChassis,
  755. fields='__all__',
  756. filters=VirtualChassisFilter,
  757. pagination=True
  758. )
  759. class VirtualChassisType(PrimaryObjectType):
  760. member_count: BigInt
  761. master: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None
  762. members: list[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]
  763. @strawberry_django.type(
  764. models.VirtualDeviceContext,
  765. fields='__all__',
  766. filters=VirtualDeviceContextFilter,
  767. pagination=True
  768. )
  769. class VirtualDeviceContextType(PrimaryObjectType):
  770. device: Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')] | None
  771. primary_ip4: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
  772. primary_ip6: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
  773. tenant: Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')] | None
  774. interfaces: list[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]