types.py 32 KB

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