netbox-spatial-lens 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. netbox_spatial_lens-0.4.0/LICENSE +21 -0
  2. netbox_spatial_lens-0.4.0/PKG-INFO +129 -0
  3. netbox_spatial_lens-0.4.0/README.md +102 -0
  4. netbox_spatial_lens-0.4.0/netbox_spatial_lens/__init__.py +87 -0
  5. netbox_spatial_lens-0.4.0/netbox_spatial_lens/api/__init__.py +0 -0
  6. netbox_spatial_lens-0.4.0/netbox_spatial_lens/api/serializers.py +98 -0
  7. netbox_spatial_lens-0.4.0/netbox_spatial_lens/api/urls.py +12 -0
  8. netbox_spatial_lens-0.4.0/netbox_spatial_lens/api/views.py +164 -0
  9. netbox_spatial_lens-0.4.0/netbox_spatial_lens/cabling.py +329 -0
  10. netbox_spatial_lens-0.4.0/netbox_spatial_lens/choices.py +18 -0
  11. netbox_spatial_lens-0.4.0/netbox_spatial_lens/device_overlays.py +195 -0
  12. netbox_spatial_lens-0.4.0/netbox_spatial_lens/elevation.py +383 -0
  13. netbox_spatial_lens-0.4.0/netbox_spatial_lens/field_filters.py +152 -0
  14. netbox_spatial_lens-0.4.0/netbox_spatial_lens/filtersets.py +92 -0
  15. netbox_spatial_lens-0.4.0/netbox_spatial_lens/floor_cabling.py +404 -0
  16. netbox_spatial_lens-0.4.0/netbox_spatial_lens/floor_scene.py +293 -0
  17. netbox_spatial_lens-0.4.0/netbox_spatial_lens/forms.py +187 -0
  18. netbox_spatial_lens-0.4.0/netbox_spatial_lens/geometry.py +347 -0
  19. netbox_spatial_lens-0.4.0/netbox_spatial_lens/integrations/__init__.py +0 -0
  20. netbox_spatial_lens-0.4.0/netbox_spatial_lens/integrations/floorplan.py +90 -0
  21. netbox_spatial_lens-0.4.0/netbox_spatial_lens/layout.py +305 -0
  22. netbox_spatial_lens-0.4.0/netbox_spatial_lens/management/__init__.py +0 -0
  23. netbox_spatial_lens-0.4.0/netbox_spatial_lens/management/commands/__init__.py +0 -0
  24. netbox_spatial_lens-0.4.0/netbox_spatial_lens/management/commands/lens_autoplace.py +160 -0
  25. netbox_spatial_lens-0.4.0/netbox_spatial_lens/management/commands/lens_enrich.py +684 -0
  26. netbox_spatial_lens-0.4.0/netbox_spatial_lens/migrations/0001_initial.py +74 -0
  27. netbox_spatial_lens-0.4.0/netbox_spatial_lens/migrations/0002_floorlayer.py +48 -0
  28. netbox_spatial_lens-0.4.0/netbox_spatial_lens/migrations/0003_alter_floorlayer_file_alter_floorlayer_opacity.py +26 -0
  29. netbox_spatial_lens-0.4.0/netbox_spatial_lens/migrations/__init__.py +0 -0
  30. netbox_spatial_lens-0.4.0/netbox_spatial_lens/models.py +397 -0
  31. netbox_spatial_lens-0.4.0/netbox_spatial_lens/navigation.py +50 -0
  32. netbox_spatial_lens-0.4.0/netbox_spatial_lens/overlays.py +608 -0
  33. netbox_spatial_lens-0.4.0/netbox_spatial_lens/palette.py +286 -0
  34. netbox_spatial_lens-0.4.0/netbox_spatial_lens/ports.py +131 -0
  35. netbox_spatial_lens-0.4.0/netbox_spatial_lens/power.py +218 -0
  36. netbox_spatial_lens-0.4.0/netbox_spatial_lens/scene.py +483 -0
  37. netbox_spatial_lens-0.4.0/netbox_spatial_lens/search.py +14 -0
  38. netbox_spatial_lens-0.4.0/netbox_spatial_lens/signals.py +44 -0
  39. netbox_spatial_lens-0.4.0/netbox_spatial_lens/site_overlays.py +131 -0
  40. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/cabinet3d.js +232 -0
  41. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/editor.js +399 -0
  42. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/finder.js +196 -0
  43. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/floor.js +285 -0
  44. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/floor3d.js +466 -0
  45. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/legend.js +129 -0
  46. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/lens.css +1507 -0
  47. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/rack3d.js +513 -0
  48. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/rack_panel.js +305 -0
  49. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/stage3d.js +592 -0
  50. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/state.js +32 -0
  51. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/world.js +654 -0
  52. netbox_spatial_lens-0.4.0/netbox_spatial_lens/static/netbox_spatial_lens/zoom.js +146 -0
  53. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tables.py +86 -0
  54. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tags.py +36 -0
  55. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/floor.html +284 -0
  56. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/floor_layout.html +84 -0
  57. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/alloc_row.html +16 -0
  58. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/cable_row.html +22 -0
  59. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/device_cabling.html +37 -0
  60. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/field_finders.html +9 -0
  61. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/finder.html +43 -0
  62. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/finder_cable.html +23 -0
  63. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/finder_circuit.html +16 -0
  64. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/finder_field.html +11 -0
  65. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/finder_site.html +16 -0
  66. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/finder_tag.html +10 -0
  67. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/floor_svg.html +187 -0
  68. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/help.html +10 -0
  69. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/legend.html +65 -0
  70. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/levels.html +39 -0
  71. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/palette.html +8 -0
  72. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/stats.html +20 -0
  73. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/inc/zoom.html +15 -0
  74. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/rack.html +288 -0
  75. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/site.html +88 -0
  76. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templates/netbox_spatial_lens/world.html +146 -0
  77. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templatetags/__init__.py +0 -0
  78. netbox_spatial_lens-0.4.0/netbox_spatial_lens/templatetags/lens.py +85 -0
  79. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/__init__.py +0 -0
  80. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/base.py +143 -0
  81. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_autoplace.py +53 -0
  82. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_branching.py +142 -0
  83. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_device_overlays.py +140 -0
  84. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_docs.py +148 -0
  85. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_elevation.py +337 -0
  86. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_field_filters.py +130 -0
  87. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_floor_cabling.py +212 -0
  88. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_floor_scene.py +306 -0
  89. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_floorplan_import.py +64 -0
  90. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_geometry.py +100 -0
  91. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_layers.py +183 -0
  92. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_legend_bands.py +53 -0
  93. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_models.py +54 -0
  94. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_overlays.py +295 -0
  95. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_placement_rules.py +119 -0
  96. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_plan.py +283 -0
  97. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_rear_devices.py +52 -0
  98. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_scene.py +269 -0
  99. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_site_overlays.py +186 -0
  100. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_tracing.py +80 -0
  101. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_ui.py +210 -0
  102. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_views.py +768 -0
  103. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tests/test_visibility.py +85 -0
  104. netbox_spatial_lens-0.4.0/netbox_spatial_lens/tracing.py +276 -0
  105. netbox_spatial_lens-0.4.0/netbox_spatial_lens/urls.py +37 -0
  106. netbox_spatial_lens-0.4.0/netbox_spatial_lens/views.py +597 -0
  107. netbox_spatial_lens-0.4.0/netbox_spatial_lens/world.py +472 -0
  108. netbox_spatial_lens-0.4.0/netbox_spatial_lens.egg-info/PKG-INFO +129 -0
  109. netbox_spatial_lens-0.4.0/netbox_spatial_lens.egg-info/SOURCES.txt +111 -0
  110. netbox_spatial_lens-0.4.0/netbox_spatial_lens.egg-info/dependency_links.txt +1 -0
  111. netbox_spatial_lens-0.4.0/netbox_spatial_lens.egg-info/top_level.txt +1 -0
  112. netbox_spatial_lens-0.4.0/pyproject.toml +58 -0
  113. netbox_spatial_lens-0.4.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Antoine Keranflec'h
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,129 @@
1
+ Metadata-Version: 2.4
2
+ Name: netbox-spatial-lens
3
+ Version: 0.4.0
4
+ Summary: World map, floor plans and rack elevations for NetBox, recoloured by power, cooling and space
5
+ Author-email: Antoine Keranflech <antoine.keranflech@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/antoinekh/netbox-spatial-lens
8
+ Project-URL: Documentation, https://github.com/antoinekh/netbox-spatial-lens/tree/master/docs
9
+ Project-URL: Source, https://github.com/antoinekh/netbox-spatial-lens
10
+ Project-URL: Changelog, https://github.com/antoinekh/netbox-spatial-lens/blob/master/CHANGELOG.md
11
+ Project-URL: Issues, https://github.com/antoinekh/netbox-spatial-lens/issues
12
+ Keywords: netbox,netbox-plugin,floorplan,datacenter,dcim,visualization,capacity,power,cooling,rack-elevation
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Framework :: Django
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Intended Audience :: System Administrators
20
+ Classifier: Environment :: Web Environment
21
+ Classifier: Topic :: System :: Networking
22
+ Classifier: Topic :: System :: Systems Administration
23
+ Requires-Python: >=3.12
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Dynamic: license-file
27
+
28
+ <div align="center">
29
+ <picture>
30
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/logo-dark.svg?sanitize=true" />
31
+ <img src="https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/logo.svg?sanitize=true" width="460" alt="netbox spatial lens" />
32
+ </picture>
33
+ <p><strong>Your estate through one lens: world, floor and rack, drawn from NetBox and recoloured by what you need to see</strong></p>
34
+ <p>world &bull; site &bull; floor &bull; rack</p>
35
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
36
+ <img src="https://img.shields.io/badge/NetBox-%3E%3D%204.7.0%2C%20%3C%204.8-00857d" alt="NetBox compatibility" />
37
+ <img src="https://img.shields.io/badge/python-%3E%3D%203.12-blue" alt="Python version" />
38
+ <p>
39
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/tree/v0.4.0/docs/">Documentation</a></strong> |
40
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/COMPATIBILITY.md">Compatibility</a></strong> |
41
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/configuration.md">Configuration</a></strong> |
42
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/permissions.md">Permissions</a></strong> |
43
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/extending.md">Extending</a></strong> |
44
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/CHANGELOG.md">Changelog</a></strong>
45
+ </p>
46
+ </div>
47
+
48
+ A lens does two things to what you point it at: it brings one place into focus, and it filters what you see there. That is what this is for a network. The world map, the floor plan and the rack in 3D are the same estate at three focal lengths, one click apart, and every one of them recolours on demand by whatever you came to find out.
49
+
50
+ A NetBox plugin. NetBox knows a rack's height, footprint, power feeds and cooling capability. It does not know where the rack stands in the room, and it will not colour a room by any of those values. This draws the room and colours it.
51
+
52
+ > [!WARNING]
53
+ > **Not stable yet.** The version is below 1.0. Models, settings and APIs can still change between releases. Read the [changelog](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/CHANGELOG.md) before you upgrade.
54
+
55
+ <p align="center">
56
+ <a href="#what-it-does">What it does</a> |
57
+ <a href="#getting-started">Getting started</a> |
58
+ <a href="#where-the-ideas-come-from">Where the ideas come from</a> |
59
+ <a href="#documentation">Documentation</a>
60
+ </p>
61
+
62
+ ## What it does
63
+
64
+ **World → site → floor → rack**, one click each way. Every drawing has a stat strip above it and a legend that filters it.
65
+
66
+ ### The world map
67
+
68
+ Sites on a globe, sized by rack count and coloured by **group**, **status**, **tenant** or **region**, with the circuits between them coloured by **provider**. The two legends and the **Sites** and **Circuits** finders narrow the map. It needs WebGL and MapLibre, which loads from a CDN by default or from your own copy; tiles are optional.
69
+
70
+ ![A globe with sites in North America and Europe, circuits drawn as great circles across the Atlantic, and two legends naming the site groups and the circuit providers](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/world.png)
71
+
72
+ ### The site
73
+
74
+ Every room in the site as a small plan with its own figures, on a tab of NetBox's site page.
75
+
76
+ ![The MDF site drawn as four rooms side by side, each with its rack, device, space and power figures above a thumbnail of its real floor plan](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/site.png)
77
+
78
+ ### The floor
79
+
80
+ The room in 3D, every rack a cabinet at its real position, rotation and height, coloured by **power**, **cooling**, **space** or **role**, with the reading rising up its doors and the cable runs arcing over the tops. Look from the top, at three quarters or from the side, and switch from **Cabinets** to **Devices** to see every rack open with its real devices and their front and rear images. Switch to **2D** for the plan over a scanned drawing, with zoom. Both views share a sortable rack table. Find racks by name or asset tag, narrow them by tag or custom field, and place them in the layout editor.
81
+
82
+ ![A 20.7 by 13.2 metre data hall of 80 cabinets in eight rows of ten, two blocks of four rows either side of a central aisle, their roofs and doors coloured by how full they are, the leaf to spine uplinks arcing from every rack to the two spines in row A, and the hover card of rack G04](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/floor-3d.png)
83
+
84
+ ![The same hall of 80 racks in the Devices view: every cabinet open with its real devices, roofs coloured by rack role, and the hover card of one switch naming its rack, type and unit](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/floor-devices.png)
85
+
86
+ ![The hall in the Devices view with "c" in the find box: the ten racks of row C stand out with their devices and every other rack fades, and the hover card of one router in C08](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/floor-devices-find.png)
87
+
88
+ ### The rack
89
+
90
+ The cabinet in 3D, with the real front and rear images of each device type, every cable run through the cable managers, and reserved and free units. Turn it, move it and zoom, or jump to the front, the rear or the side. Devices are coloured by **role**, **status**, **tenant**, **cabling** or **power**. Find devices by name or asset tag, and narrow them by tag or custom field. It needs WebGL and Three.js, which loads from a CDN by default or from your own copy.
91
+
92
+ ![Rack C04, a 48U cabinet of 49 devices seen from behind and to the side, the switches wearing their real rear panels, the data cables dressed up one cable manager and the power leads up the other, and the two uplinks leaving through the roof, beside the port allocation and cabling panels](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/rack.png)
93
+
94
+ ### On every level
95
+
96
+ In the rack, click a cable, or a row of the cabling list, to trace it end to end, through patch panels and out to a provider, or along a power chain from socket to feed. On the floor, a cable leaving the room opens the cable, or the circuit it reaches.
97
+
98
+ ## Getting started
99
+
100
+ Install it like any NetBox plugin: `pip install netbox-spatial-lens`, add `netbox_spatial_lens` to `PLUGINS`, and migrate. It also works inside [netbox-branching](https://github.com/netboxlabs/netbox-branching) branches.
101
+
102
+ ### Your first floor
103
+
104
+ 1. **Draw the room:** **Spatial Lens > Floors > Add**. Give its width and depth, and bind it to a **site** (one room) or a **location** (several rooms).
105
+ 2. **Place the racks:** open the floor, choose **Edit layout**, then drag each rack from the list onto the plan and rotate it. Rack sizes come from NetBox.
106
+ 3. **Look at it:** colour by power, cooling, space or role, and click a rack to open it.
107
+
108
+ Optional: add a background plan, and set site coordinates for the world map.
109
+
110
+ For the development stack, the demo database, and the commands that populate it, see [docs/development.md](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/development.md).
111
+
112
+ ## Where the ideas come from
113
+
114
+ - **[net3d](https://github.com/hervehildenbrand/net3d)**: the zoom-through navigation, cable tracing and power chains. Not its architecture, which is a standalone Node app reading the REST API from outside.
115
+ - **[NetBox Labs Visual Explorer](https://netboxlabs.com/docs/visual-explorer/floorplans/)**: the geometry model, one queryable row per placement. It has no overlays, which is our reason to exist.
116
+ - **[netbox-floorplan-plugin](https://github.com/netbox-community/netbox-floorplan-plugin)**: read as a one-shot importer. Its plan is a Fabric.js blob with no coordinate columns, so an overlay over it would be a JSON walk per rack.
117
+ - **[netbox-demo-data](https://github.com/netbox-community/netbox-demo-data)**: what everything is tested against.
118
+
119
+ ## Documentation
120
+
121
+ | | |
122
+ |---|---|
123
+ | [Compatibility](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/COMPATIBILITY.md) | Which NetBox versions each release supports |
124
+ | [Configuration](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/configuration.md) | Every setting, and a site with no internet access |
125
+ | [Extending](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/extending.md) | Colouring from another plugin, filtering by custom fields, and the floor layout API |
126
+ | [Modules](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/modules.md) | What each module and script holds |
127
+ | [Permissions](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/permissions.md) | What to grant, and what each page reads |
128
+ | [Development](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/development.md) | The dev stack, the demo database, and the commands that fill it |
129
+ | [Gotchas](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/gotchas.md) | What NetBox and this stack do that is not obvious |
@@ -0,0 +1,102 @@
1
+ <div align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/logo-dark.svg?sanitize=true" />
4
+ <img src="https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/logo.svg?sanitize=true" width="460" alt="netbox spatial lens" />
5
+ </picture>
6
+ <p><strong>Your estate through one lens: world, floor and rack, drawn from NetBox and recoloured by what you need to see</strong></p>
7
+ <p>world &bull; site &bull; floor &bull; rack</p>
8
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
9
+ <img src="https://img.shields.io/badge/NetBox-%3E%3D%204.7.0%2C%20%3C%204.8-00857d" alt="NetBox compatibility" />
10
+ <img src="https://img.shields.io/badge/python-%3E%3D%203.12-blue" alt="Python version" />
11
+ <p>
12
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/tree/v0.4.0/docs/">Documentation</a></strong> |
13
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/COMPATIBILITY.md">Compatibility</a></strong> |
14
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/configuration.md">Configuration</a></strong> |
15
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/permissions.md">Permissions</a></strong> |
16
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/extending.md">Extending</a></strong> |
17
+ <strong><a href="https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/CHANGELOG.md">Changelog</a></strong>
18
+ </p>
19
+ </div>
20
+
21
+ A lens does two things to what you point it at: it brings one place into focus, and it filters what you see there. That is what this is for a network. The world map, the floor plan and the rack in 3D are the same estate at three focal lengths, one click apart, and every one of them recolours on demand by whatever you came to find out.
22
+
23
+ A NetBox plugin. NetBox knows a rack's height, footprint, power feeds and cooling capability. It does not know where the rack stands in the room, and it will not colour a room by any of those values. This draws the room and colours it.
24
+
25
+ > [!WARNING]
26
+ > **Not stable yet.** The version is below 1.0. Models, settings and APIs can still change between releases. Read the [changelog](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/CHANGELOG.md) before you upgrade.
27
+
28
+ <p align="center">
29
+ <a href="#what-it-does">What it does</a> |
30
+ <a href="#getting-started">Getting started</a> |
31
+ <a href="#where-the-ideas-come-from">Where the ideas come from</a> |
32
+ <a href="#documentation">Documentation</a>
33
+ </p>
34
+
35
+ ## What it does
36
+
37
+ **World → site → floor → rack**, one click each way. Every drawing has a stat strip above it and a legend that filters it.
38
+
39
+ ### The world map
40
+
41
+ Sites on a globe, sized by rack count and coloured by **group**, **status**, **tenant** or **region**, with the circuits between them coloured by **provider**. The two legends and the **Sites** and **Circuits** finders narrow the map. It needs WebGL and MapLibre, which loads from a CDN by default or from your own copy; tiles are optional.
42
+
43
+ ![A globe with sites in North America and Europe, circuits drawn as great circles across the Atlantic, and two legends naming the site groups and the circuit providers](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/world.png)
44
+
45
+ ### The site
46
+
47
+ Every room in the site as a small plan with its own figures, on a tab of NetBox's site page.
48
+
49
+ ![The MDF site drawn as four rooms side by side, each with its rack, device, space and power figures above a thumbnail of its real floor plan](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/site.png)
50
+
51
+ ### The floor
52
+
53
+ The room in 3D, every rack a cabinet at its real position, rotation and height, coloured by **power**, **cooling**, **space** or **role**, with the reading rising up its doors and the cable runs arcing over the tops. Look from the top, at three quarters or from the side, and switch from **Cabinets** to **Devices** to see every rack open with its real devices and their front and rear images. Switch to **2D** for the plan over a scanned drawing, with zoom. Both views share a sortable rack table. Find racks by name or asset tag, narrow them by tag or custom field, and place them in the layout editor.
54
+
55
+ ![A 20.7 by 13.2 metre data hall of 80 cabinets in eight rows of ten, two blocks of four rows either side of a central aisle, their roofs and doors coloured by how full they are, the leaf to spine uplinks arcing from every rack to the two spines in row A, and the hover card of rack G04](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/floor-3d.png)
56
+
57
+ ![The same hall of 80 racks in the Devices view: every cabinet open with its real devices, roofs coloured by rack role, and the hover card of one switch naming its rack, type and unit](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/floor-devices.png)
58
+
59
+ ![The hall in the Devices view with "c" in the find box: the ten racks of row C stand out with their devices and every other rack fades, and the hover card of one router in C08](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/floor-devices-find.png)
60
+
61
+ ### The rack
62
+
63
+ The cabinet in 3D, with the real front and rear images of each device type, every cable run through the cable managers, and reserved and free units. Turn it, move it and zoom, or jump to the front, the rear or the side. Devices are coloured by **role**, **status**, **tenant**, **cabling** or **power**. Find devices by name or asset tag, and narrow them by tag or custom field. It needs WebGL and Three.js, which loads from a CDN by default or from your own copy.
64
+
65
+ ![Rack C04, a 48U cabinet of 49 devices seen from behind and to the side, the switches wearing their real rear panels, the data cables dressed up one cable manager and the power leads up the other, and the two uplinks leaving through the roof, beside the port allocation and cabling panels](https://raw.githubusercontent.com/antoinekh/netbox-spatial-lens/v0.4.0/docs/images/rack.png)
66
+
67
+ ### On every level
68
+
69
+ In the rack, click a cable, or a row of the cabling list, to trace it end to end, through patch panels and out to a provider, or along a power chain from socket to feed. On the floor, a cable leaving the room opens the cable, or the circuit it reaches.
70
+
71
+ ## Getting started
72
+
73
+ Install it like any NetBox plugin: `pip install netbox-spatial-lens`, add `netbox_spatial_lens` to `PLUGINS`, and migrate. It also works inside [netbox-branching](https://github.com/netboxlabs/netbox-branching) branches.
74
+
75
+ ### Your first floor
76
+
77
+ 1. **Draw the room:** **Spatial Lens > Floors > Add**. Give its width and depth, and bind it to a **site** (one room) or a **location** (several rooms).
78
+ 2. **Place the racks:** open the floor, choose **Edit layout**, then drag each rack from the list onto the plan and rotate it. Rack sizes come from NetBox.
79
+ 3. **Look at it:** colour by power, cooling, space or role, and click a rack to open it.
80
+
81
+ Optional: add a background plan, and set site coordinates for the world map.
82
+
83
+ For the development stack, the demo database, and the commands that populate it, see [docs/development.md](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/development.md).
84
+
85
+ ## Where the ideas come from
86
+
87
+ - **[net3d](https://github.com/hervehildenbrand/net3d)**: the zoom-through navigation, cable tracing and power chains. Not its architecture, which is a standalone Node app reading the REST API from outside.
88
+ - **[NetBox Labs Visual Explorer](https://netboxlabs.com/docs/visual-explorer/floorplans/)**: the geometry model, one queryable row per placement. It has no overlays, which is our reason to exist.
89
+ - **[netbox-floorplan-plugin](https://github.com/netbox-community/netbox-floorplan-plugin)**: read as a one-shot importer. Its plan is a Fabric.js blob with no coordinate columns, so an overlay over it would be a JSON walk per rack.
90
+ - **[netbox-demo-data](https://github.com/netbox-community/netbox-demo-data)**: what everything is tested against.
91
+
92
+ ## Documentation
93
+
94
+ | | |
95
+ |---|---|
96
+ | [Compatibility](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/COMPATIBILITY.md) | Which NetBox versions each release supports |
97
+ | [Configuration](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/configuration.md) | Every setting, and a site with no internet access |
98
+ | [Extending](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/extending.md) | Colouring from another plugin, filtering by custom fields, and the floor layout API |
99
+ | [Modules](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/modules.md) | What each module and script holds |
100
+ | [Permissions](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/permissions.md) | What to grant, and what each page reads |
101
+ | [Development](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/development.md) | The dev stack, the demo database, and the commands that fill it |
102
+ | [Gotchas](https://github.com/antoinekh/netbox-spatial-lens/blob/v0.4.0/docs/gotchas.md) | What NetBox and this stack do that is not obvious |
@@ -0,0 +1,87 @@
1
+ from netbox.plugins import PluginConfig
2
+
3
+ __version__ = '0.4.0'
4
+
5
+
6
+ class SpatialLensConfig(PluginConfig):
7
+ name = 'netbox_spatial_lens'
8
+ verbose_name = 'NetBox Spatial Lens'
9
+ description = 'World map, floor plans and rack elevations for NetBox, recoloured by power, cooling and space'
10
+ version = __version__
11
+ base_url = 'spatial-lens'
12
+ # The rack cooling fields this plugin colours by (cooling_capability, cooling_capacity)
13
+ # arrived in NetBox 4.7, so there is no earlier release to support.
14
+ min_version = '4.7.0'
15
+ max_version = '4.7.99'
16
+ default_settings = { # noqa: RUF012
17
+ # Footprint used when a rack declares no outer_width or outer_depth, in millimetres.
18
+ # 600x1070 is a standard 19-inch cabinet. A rack drawn at this size is reported as
19
+ # estimated rather than silently passed off as measured.
20
+ 'default_rack_width': 600,
21
+ 'default_rack_depth': 1070,
22
+ # Grid the editor snaps to, in centimetres. 0 disables snapping.
23
+ 'grid_size': 10,
24
+ # Custom fields offered as filters, the way tags are, on the floor (racks) and in the rack
25
+ # view (devices): a list of field names. Only select and multiselect fields are used.
26
+ 'filter_custom_fields': [],
27
+ # Which built-in overlays to register. True for all, False for none, or a list of
28
+ # names from 'power', 'cooling', 'space' and 'role'.
29
+ 'enable_builtin_overlays': True,
30
+ # Overlay selected when a floor is opened without one named.
31
+ 'default_overlay': 'power',
32
+ # Which built-in device colourings a rack offers. True for all, False for none, or a
33
+ # list from 'role', 'status', 'tenant', 'cabling' and 'power'.
34
+ 'enable_builtin_device_overlays': True,
35
+ # Colouring selected when a rack is opened without one named.
36
+ 'default_device_overlay': 'role',
37
+ # Which built-in site colourings the world map offers. True for all, False for none, or
38
+ # a list from 'group', 'status', 'tenant' and 'region'.
39
+ 'enable_builtin_site_overlays': True,
40
+ # Colouring selected when the map is opened without one named.
41
+ 'default_site_overlay': 'group',
42
+ # Tiles for the world map. OpenStreetMap's own tiles are the default because they
43
+ # need no API key; CARTO's basemaps now watermark every tile without one. Point this
44
+ # at your own tile server, or set it to None, on a site with no egress. Without tiles
45
+ # the globe is drawn on a plain ground, with the same sites and circuits on it.
46
+ #
47
+ # A URL containing {theme} gets 'light' or 'dark' substituted, so a basemap offering
48
+ # both follows the NetBox theme.
49
+ 'map_tile_url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
50
+ 'map_attribution': '&copy; OpenStreetMap contributors',
51
+ # Where MapLibre is served from. Bundling it would put a minified library in a Python
52
+ # package; naming it here lets a deployment host its own copy instead.
53
+ #
54
+ # MapLibre rather than Leaflet because it draws a globe: zoomed out, an estate on two
55
+ # continents reads as one earth rather than as a strip of repeating flat maps with the
56
+ # same site on it three times, and there is no antimeridian to fall off. It needs WebGL:
57
+ # a browser without it, or one that cannot load these two files, is told so on the page,
58
+ # and the figures, legends and lists there still work.
59
+ 'map_css': 'https://cdnjs.cloudflare.com/ajax/libs/maplibre-gl/5.6.1/maplibre-gl.min.css',
60
+ 'map_js': 'https://cdnjs.cloudflare.com/ajax/libs/maplibre-gl/5.6.1/maplibre-gl.min.js',
61
+ # Where the map's letters come from. A raster basemap carries no fonts of its own, and a
62
+ # renderer that draws its own labels needs them. Point this at your own glyph server on
63
+ # a site with no egress; without it the markers are drawn and the names are not.
64
+ 'map_glyphs': 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf',
65
+ # Where the 3D rack and floor drawings load Three.js from: a copy of the `three` npm
66
+ # package, laid out as published, so `build/three.module.js` and `examples/jsm/` sit under
67
+ # it. Pinned, because the addons under `examples/jsm/` must come from the same release as
68
+ # the core. Empty turns both drawings off: the rack page keeps its panels and figures, and
69
+ # the floor opens on its 2D plan.
70
+ 'three_base': 'https://cdn.jsdelivr.net/npm/three@0.186.0/',
71
+ }
72
+
73
+ def ready(self) -> None:
74
+ super().ready()
75
+
76
+ from . import (
77
+ device_overlays,
78
+ overlays,
79
+ signals, # noqa: F401 (connects the receivers)
80
+ site_overlays,
81
+ )
82
+
83
+ for level in (overlays, device_overlays, site_overlays):
84
+ level.registry.register_configured_builtins()
85
+
86
+
87
+ config = SpatialLensConfig
@@ -0,0 +1,98 @@
1
+ from dcim.api.serializers import LocationSerializer, RackSerializer, SiteSerializer
2
+ from netbox.api.serializers import NetBoxModelSerializer
3
+ from rest_framework import serializers
4
+
5
+ from netbox_spatial_lens.models import Floor, FloorLayer, RackPlacement
6
+
7
+ __all__ = (
8
+ 'FloorLayerSerializer',
9
+ 'FloorSerializer',
10
+ 'RackPlacementSerializer',
11
+ )
12
+
13
+
14
+ class FloorSerializer(NetBoxModelSerializer):
15
+ url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_spatial_lens-api:floor-detail')
16
+ site = SiteSerializer(nested=True, required=False, allow_null=True)
17
+ location = LocationSerializer(nested=True, required=False, allow_null=True)
18
+ placement_count = serializers.IntegerField(read_only=True)
19
+
20
+ class Meta:
21
+ model = Floor
22
+ fields = (
23
+ 'id',
24
+ 'url',
25
+ 'display',
26
+ 'name',
27
+ 'site',
28
+ 'location',
29
+ 'width',
30
+ 'depth',
31
+ 'unit',
32
+ 'placement_count',
33
+ 'description',
34
+ 'comments',
35
+ 'tags',
36
+ 'custom_fields',
37
+ 'created',
38
+ 'last_updated',
39
+ )
40
+ brief_fields = ('id', 'url', 'display', 'name')
41
+
42
+
43
+ class RackPlacementSerializer(NetBoxModelSerializer):
44
+ url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_spatial_lens-api:rackplacement-detail')
45
+ floor = FloorSerializer(nested=True)
46
+ rack = RackSerializer(nested=True)
47
+
48
+ class Meta:
49
+ model = RackPlacement
50
+ fields = (
51
+ 'id',
52
+ 'url',
53
+ 'display',
54
+ 'floor',
55
+ 'rack',
56
+ 'x',
57
+ 'y',
58
+ 'rotation',
59
+ 'tags',
60
+ 'custom_fields',
61
+ 'created',
62
+ 'last_updated',
63
+ )
64
+ brief_fields = ('id', 'url', 'display', 'rack', 'x', 'y', 'rotation')
65
+
66
+
67
+ class FloorLayerSerializer(NetBoxModelSerializer):
68
+ url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_spatial_lens-api:floorlayer-detail')
69
+ floor = FloorSerializer(nested=True)
70
+ # Where the browser actually fetches the image, whether it was uploaded or linked. A
71
+ # client should not have to know which of the two fields was filled in.
72
+ source = serializers.CharField(read_only=True)
73
+
74
+ class Meta:
75
+ model = FloorLayer
76
+ fields = (
77
+ 'id',
78
+ 'url',
79
+ 'display',
80
+ 'floor',
81
+ 'name',
82
+ 'file',
83
+ 'external_url',
84
+ 'source',
85
+ 'x',
86
+ 'y',
87
+ 'width',
88
+ 'height',
89
+ 'rotation',
90
+ 'opacity',
91
+ 'weight',
92
+ 'enabled',
93
+ 'tags',
94
+ 'custom_fields',
95
+ 'created',
96
+ 'last_updated',
97
+ )
98
+ brief_fields = ('id', 'url', 'display', 'name', 'source')
@@ -0,0 +1,12 @@
1
+ from netbox.api.routers import NetBoxRouter
2
+
3
+ from netbox_spatial_lens.api import views
4
+
5
+ app_name = 'netbox_spatial_lens-api'
6
+
7
+ router = NetBoxRouter()
8
+ router.register('floors', views.FloorViewSet)
9
+ router.register('floor-layers', views.FloorLayerViewSet)
10
+ router.register('rack-placements', views.RackPlacementViewSet)
11
+
12
+ urlpatterns = router.urls
@@ -0,0 +1,164 @@
1
+ """
2
+ REST API.
3
+
4
+ The placement editor writes through these endpoints rather than through a private one of its
5
+ own, so there is a single way to move a rack and a single permission guarding it.
6
+ """
7
+
8
+ from django.db.models import Count
9
+ from netbox.api.viewsets import NetBoxModelViewSet
10
+ from rest_framework.decorators import action
11
+ from rest_framework.response import Response
12
+
13
+ from netbox_spatial_lens import filtersets
14
+ from netbox_spatial_lens.api.serializers import FloorLayerSerializer, FloorSerializer, RackPlacementSerializer
15
+ from netbox_spatial_lens.models import Floor, FloorLayer, RackPlacement
16
+
17
+ __all__ = (
18
+ 'FloorLayerViewSet',
19
+ 'FloorViewSet',
20
+ 'RackPlacementViewSet',
21
+ )
22
+
23
+
24
+ class FloorViewSet(NetBoxModelViewSet):
25
+ queryset = Floor.objects.prefetch_related('tags').annotate(placement_count=Count('placements'))
26
+ serializer_class = FloorSerializer
27
+ filterset_class = filtersets.FloorFilterSet
28
+
29
+ @action(detail=True, methods=['get'])
30
+ def layout(self, request, pk=None):
31
+ """
32
+ Everything one render of this floor needs, in a single response.
33
+
34
+ The web view builds the same structure server-side. This endpoint exists so a second
35
+ renderer, such as a 3D projection, consumes the floor without restating how a
36
+ footprint is resolved or how an overlay is evaluated.
37
+ """
38
+ from dcim.models import Device, Rack
39
+
40
+ from netbox_spatial_lens.floor_cabling import build_floor_exits, build_floor_runs
41
+ from netbox_spatial_lens.layout import build_layout, resolve_overlay
42
+
43
+ floor = self.get_object()
44
+ overlay = resolve_overlay(request.GET.get('overlay'))
45
+ # Restricted as the floor page is: a placement is the plugin's own object, the rack and
46
+ # the devices behind it are not, and the API must not show what the page hides.
47
+ placed = build_layout(
48
+ floor,
49
+ overlay,
50
+ racks=Rack.objects.restrict(request.user, 'view'),
51
+ devices=Device.objects.restrict(request.user, 'view'),
52
+ )
53
+ # As on the page: the runs cost a query, so they are sent only when asked for.
54
+ show_runs = request.GET.get('runs') == '1'
55
+ runs = build_floor_runs(placed) if show_runs else []
56
+ exits = build_floor_exits(placed, floor, user=request.user) if show_runs else []
57
+
58
+ return Response(
59
+ {
60
+ 'floor': {
61
+ 'id': floor.pk,
62
+ 'name': floor.name,
63
+ 'width_cm': floor.width_cm,
64
+ 'depth_cm': floor.depth_cm,
65
+ },
66
+ 'overlay': {
67
+ 'name': overlay.name,
68
+ 'label': overlay.label,
69
+ 'legend': [
70
+ {'colour': e.colour, 'label': e.label} for e in overlay.legend_for([p.value for p in placed])
71
+ ],
72
+ }
73
+ if overlay
74
+ else None,
75
+ 'racks': [
76
+ {
77
+ 'rack_id': p.rack.pk,
78
+ 'name': p.rack.name,
79
+ 'x': p.x,
80
+ 'y': p.y,
81
+ 'rotation': p.rotation,
82
+ 'width': p.width,
83
+ 'depth': p.depth,
84
+ 'u_height': p.rack.u_height,
85
+ 'estimated_footprint': p.estimated,
86
+ 'colour': p.colour,
87
+ 'label': p.label,
88
+ # Where this rack sits between empty and full, or null where the
89
+ # overlay measures a name rather than a quantity. A second renderer
90
+ # needs the magnitude for the same reason the plan does: a band alone
91
+ # cannot tell 12% from 48%.
92
+ 'fraction': p.fraction,
93
+ 'facts': [[label, value] for label, value in p.facts],
94
+ }
95
+ for p in placed
96
+ ],
97
+ 'layers': [
98
+ {
99
+ 'id': layer.pk,
100
+ 'name': layer.name,
101
+ 'source': layer.source,
102
+ 'x': float(layer.x),
103
+ 'y': float(layer.y),
104
+ 'width': float(layer.width),
105
+ 'height': float(layer.height),
106
+ 'rotation': float(layer.rotation),
107
+ 'opacity': float(layer.opacity),
108
+ }
109
+ for layer in floor.layers.filter(enabled=True)
110
+ ],
111
+ 'runs': [
112
+ {
113
+ 'rack_a': run.a.rack.pk,
114
+ 'rack_b': run.b.rack.pk,
115
+ 'count': run.count,
116
+ }
117
+ for run in runs
118
+ ],
119
+ 'exits': [
120
+ {
121
+ 'rack': item.rack.rack.pk,
122
+ 'label': item.label,
123
+ 'kind': item.kind,
124
+ 'count': item.count,
125
+ 'x': item.x,
126
+ 'y': item.y,
127
+ }
128
+ for item in exits
129
+ ],
130
+ }
131
+ )
132
+
133
+ @action(detail=True, methods=['get'])
134
+ def devices(self, request, pk=None):
135
+ """
136
+ The devices in every rack on this floor, placed in their cabinets.
137
+
138
+ What the floor's Devices view draws, fetched when the reader switches to it rather than
139
+ rendered into every floor page. Restricted like the layout: racks and devices the caller
140
+ may not view are left out.
141
+ """
142
+ from dcim.models import Device, Rack
143
+
144
+ from netbox_spatial_lens.floor_scene import build_floor_devices
145
+
146
+ return Response(
147
+ build_floor_devices(
148
+ self.get_object(),
149
+ racks=Rack.objects.restrict(request.user, 'view'),
150
+ devices=Device.objects.restrict(request.user, 'view'),
151
+ )
152
+ )
153
+
154
+
155
+ class RackPlacementViewSet(NetBoxModelViewSet):
156
+ queryset = RackPlacement.objects.prefetch_related('tags').select_related('floor', 'rack')
157
+ serializer_class = RackPlacementSerializer
158
+ filterset_class = filtersets.RackPlacementFilterSet
159
+
160
+
161
+ class FloorLayerViewSet(NetBoxModelViewSet):
162
+ queryset = FloorLayer.objects.prefetch_related('tags').select_related('floor')
163
+ serializer_class = FloorLayerSerializer
164
+ filterset_class = filtersets.FloorLayerFilterSet