types.py 36 KB

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