Files
NetBox-Concept/netbox_rack_concept/__init__.py
T
MrBlakeandClaude Sonnet 5 67d999e234 v0.2.1: rework PNG export to draw directly on canvas, like netbox-topology-views
Investigated how MrBlake/mrb-netbox-topology-views does its PNG export:
it renders its topology natively onto a canvas (vis-network draws
there directly) and just calls canvas.toDataURL() - no SVG round-trip
at all. Applied the same principle here.

Previous approach loaded the standalone SVG export via <img src="blob:...">
and rasterized that onto a canvas - fragile, because the whole export
failed if that SVG document wasn't strictly valid XML (as our leaked
{# #} comment bug demonstrated) or if a single device type image
reference inside it couldn't be resolved.

New approach: a dedicated export/data/ endpoint returns the elevation's
plain pixel geometry as JSON (positions, sizes, colors, labels, image
URLs - the same numbers the SVG is built from), and export.js draws
that directly onto a <canvas> with native 2D primitives (fillRect,
strokeRect, fillText/strokeText, drawImage). Device type images are
fetched individually as same-origin blobs before drawing; one image
failing to load only drops that picture; the rest of the export still
succeeds. Added a combined front+rear PNG option.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 12:53:42 +02:00

50 lines
1.7 KiB
Python

from netbox.plugins import PluginConfig
__version__ = '0.2.1'
class RackConceptConfig(PluginConfig):
name = 'netbox_rack_concept'
verbose_name = 'NetBox Rack Concepts'
description = 'Rack blueprints: plan racks and their equipment without creating real racks or devices'
version = __version__
author = 'Claude'
base_url = 'rack-concepts'
min_version = '4.6.0'
max_version = '4.6.99'
# These paths are relative to this module (NetBox prepends self.__module__),
# so they must NOT be prefixed with 'netbox_rack_concept.' again.
menu = 'navigation.menu'
template_extensions = 'template_content.template_extensions'
default_settings = {
# Defaults used when a concept is created from scratch.
'default_u_height': 42,
'default_width': 19,
# Show the "Copy to concept" button on the dcim.Rack detail page.
'enable_rack_tab': True,
# Status assigned to the objects created when a concept is deployed.
'deployed_rack_status': 'planned',
'deployed_device_status': 'planned',
# Mapping onto the partial-width implementation of netbox_utilities.
# Adjust these if that plugin renames its fields; set 'enabled' to False
# to never write partial-width data during deployment.
'partial_width': {
'enabled': True,
'model': 'netbox_utilities.RackDevicePosition',
'device_field': 'device',
'fraction_field': 'width_fraction',
'position_field': 'horizontal_position',
},
}
def ready(self):
super().ready()
from . import search # noqa: F401
config = RackConceptConfig