Rack: link items to devices, shelves, several racks, export; fix layout and light mode
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 48s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 49s
Lint / Python (flake8) (pull_request) Successful in 51s
Test / Python Tests (pytest) (push) Successful in 1m2s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 50s
Test / Python Tests (pytest) (pull_request) Successful in 53s
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 48s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 49s
Lint / Python (flake8) (pull_request) Successful in 51s
Test / Python Tests (pytest) (push) Successful in 1m2s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 50s
Test / Python Tests (pytest) (pull_request) Successful in 53s
Cutsheet items gain a "Gandalf device" link, so an item named after the product (UDM-Pro) shows the live device's faceplate, ports and status. Cable checks, suggestions, tickets and the device page treat an item and its linked device as one. Without this, product-named items drew as bare name plates. Items can sit on a shelf instead of a rack unit; the shelf draws what is on it with live status. Items have a rack, the page shows a tab per rack (config "racks"), and a rack can be downloaded as SVG or PNG. The rack is centred, long runs of empty units fold into one band (with a toggle), every device fills the 19" width, the UPS shows its front only, and the rack keeps its own palette so it reads in light mode. New cutsheet_items columns rack, shelf and device are added on first use. Deleting a shelf, or making it something else, is refused while it holds items; renaming it carries over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+36
-7
@@ -32,6 +32,7 @@ NAME_MAX = 100
|
||||
PORT_MAX = 64
|
||||
TEXT_MAX = 255
|
||||
NOTES_MAX = 2000
|
||||
RACK_NAME_MAX = 100
|
||||
|
||||
# Comparison outcomes, and whether each counts as a problem
|
||||
VERDICTS = {
|
||||
@@ -79,7 +80,8 @@ def _int(data: dict, key: str, low: int, high: int, label: str) -> Optional[int]
|
||||
return number
|
||||
|
||||
|
||||
def validate_item(data: dict) -> dict:
|
||||
def validate_item(data: dict, items: Optional[Dict[str, dict]] = None) -> dict:
|
||||
"""An item from a form. `items` (by name) is needed to check a shelf placement."""
|
||||
kind = _text(data, 'kind', 20) or 'other'
|
||||
if kind not in ITEM_KINDS:
|
||||
raise ValidationError(f'kind must be one of {", ".join(ITEM_KINDS)}')
|
||||
@@ -90,8 +92,20 @@ def validate_item(data: dict) -> dict:
|
||||
'location': _text(data, 'location'),
|
||||
'rack_u': _int(data, 'rack_u', 1, 60, 'Rack unit'),
|
||||
'rack_height': _int(data, 'rack_height', 1, 20, 'Height'),
|
||||
'rack': _text(data, 'rack', RACK_NAME_MAX),
|
||||
'device': _text(data, 'device'),
|
||||
'shelf': _text(data, 'shelf', NAME_MAX),
|
||||
'notes': _text(data, 'notes', NOTES_MAX),
|
||||
}
|
||||
if item['shelf']:
|
||||
shelf = (items or {}).get(item['shelf'])
|
||||
if not shelf or shelf['kind'] != 'shelf':
|
||||
raise ValidationError(f'{item["shelf"]} is not a shelf on the cutsheet')
|
||||
if kind == 'shelf' or shelf['name'] == item['name']:
|
||||
raise ValidationError('A shelf cannot sit on a shelf')
|
||||
if item['rack_u'] or item['rack_height']:
|
||||
raise ValidationError('An item on a shelf takes its rack position from the shelf; clear the rack unit')
|
||||
item['rack'] = '' # the shelf's rack
|
||||
if item['rack_height'] and not item['rack_u']:
|
||||
raise ValidationError('Set a rack unit to go with the height')
|
||||
if item['rack_u'] and not item['rack_height']:
|
||||
@@ -259,6 +273,21 @@ def _same(a: str, b: str) -> bool:
|
||||
return bool(a) and bool(b) and a.strip().lower() == b.strip().lower()
|
||||
|
||||
|
||||
def device_of(name: str, items: Dict[str, dict]) -> str:
|
||||
"""The live device an item name stands for: its linked device, or the name itself."""
|
||||
return (items.get(name) or {}).get('device') or name
|
||||
|
||||
|
||||
def with_aliases(switches: dict, items: Dict[str, dict]) -> dict:
|
||||
"""Switches also reachable by the name of an item linked to them (item "UDM-Pro" -> "Dream Machine Pro")."""
|
||||
out = dict(switches or {})
|
||||
for name, item in (items or {}).items():
|
||||
device = item.get('device')
|
||||
if device and device in out and name not in out:
|
||||
out[name] = out[device]
|
||||
return out
|
||||
|
||||
|
||||
def _check_end(node: tuple, other: Optional[tuple], switches: dict, items: Dict[str, dict]) -> Optional[dict]:
|
||||
port = _switch_port(node, switches)
|
||||
if port is None:
|
||||
@@ -266,13 +295,13 @@ def _check_end(node: tuple, other: Optional[tuple], switches: dict, items: Dict[
|
||||
if port == {}:
|
||||
return {'verdict': 'missing_port', 'detail': f'{node[0]} reports no port {node[1]}'}
|
||||
other_passive = other is None or (items.get(other[0], {}).get('kind') in PASSIVE_KINDS)
|
||||
expected = None if other_passive else other[0]
|
||||
expected = None if other_passive else device_of(other[0], items)
|
||||
lldp = port.get('lldp') or {}
|
||||
seen = lldp.get('system_name') or ''
|
||||
sfp_peer = (port.get('sfp') or {}).get('cable_peer')
|
||||
|
||||
if sfp_peer and other is not None and not other_passive:
|
||||
if _same(sfp_peer.get('switch', ''), other[0]) and str(sfp_peer.get('port_idx')) == other[1]:
|
||||
if _same(sfp_peer.get('switch', ''), device_of(other[0], items)) and str(sfp_peer.get('port_idx')) == other[1]:
|
||||
return {'verdict': 'match', 'detail': 'Both ends report the same DAC serial'}
|
||||
if not port.get('up'):
|
||||
if expected:
|
||||
@@ -309,7 +338,7 @@ def compare_path(path: dict, cables_by_id: Dict[int, dict], switches: dict, item
|
||||
|
||||
def evaluate(cables: List[dict], items: Dict[str, dict], switches: dict) -> Dict[int, dict]:
|
||||
"""Trace and compare every cable. Returns {cable_id: {'path', 'verdict', 'detail'}}."""
|
||||
switches = switches or {}
|
||||
switches = with_aliases(switches, items)
|
||||
index = node_index(cables)
|
||||
by_id = {c['id']: c for c in cables}
|
||||
result: Dict[int, dict] = {}
|
||||
@@ -345,7 +374,7 @@ def describe_node(node: Optional[tuple]) -> str:
|
||||
|
||||
# ── Undocumented links ──────────────────────────────────────────────────────
|
||||
|
||||
def undocumented(cables: List[dict], switches: dict) -> List[dict]:
|
||||
def undocumented(cables: List[dict], switches: dict, items: Optional[Dict[str, dict]] = None) -> List[dict]:
|
||||
"""Linked switch ports that no live cable mentions, as suggestions to add."""
|
||||
documented = set()
|
||||
for c in cables:
|
||||
@@ -354,7 +383,7 @@ def undocumented(cables: List[dict], switches: dict) -> List[dict]:
|
||||
for end in ('a', 'b'):
|
||||
node = _node(c, end)
|
||||
if node:
|
||||
documented.add((node[0].lower(), node[1]))
|
||||
documented.add((device_of(node[0], items or {}).lower(), node[1]))
|
||||
suggestions = []
|
||||
for sw_name, sw in sorted((switches or {}).items()):
|
||||
for port_name, port in (sw.get('ports') or {}).items():
|
||||
@@ -489,7 +518,7 @@ def runs_for(device: str, cables: List[dict], items: Dict[str, dict], switches:
|
||||
if not _live(c):
|
||||
continue
|
||||
for end in ('a', 'b'):
|
||||
if not _same(c.get(f'{end}_device') or '', device):
|
||||
if not _same(device_of(c.get(f'{end}_device') or '', items), device):
|
||||
continue
|
||||
if port is not None and str(c.get(f'{end}_port') or '') != str(port):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user