types.py 32 KB

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