Repository navigation
Surface circuit A/Z terminations and the circuit path - #68
Merged
Merged
Conversation
A circuit's view showed only flat attributes (provider/type/status/rate) with no indication of where it lands. Resolve its A/Z terminations (one call to /api/circuits/circuit-terminations/?circuit_id=) and render the path: each side's endpoint (a site or a provider network), the device port it's patched into, and the cable — drawn as a vertical A↔Z diagram, mirroring the interface cable-path view. - `nbox circuit <cid>` plain output gains a "Circuit Path" section. - `-o json` carries a structured `terminations` array (A first). - The TUI circuit detail gains a `p` path tab and navigable links to the provider, the sites, and the patched devices. - Commit/port rates are humanized (e.g. 400 Gbps). New `CircuitTermination` model + `Endpoint::CircuitTerminations` + `circuit_terminations()` query helper; the shared `CircuitView` gains `build(circuit, terminations)` (`from_model` delegates with no terminations). Covered by circuit_view diagram/humanize tests, a circuit_links test, and the updated MCP get-circuit test.
Circuit terminations have no /trace/ endpoint in NetBox (schema-confirmed: only
interfaces/console/power ports do), and the API doesn't resolve their
connected_endpoints through a panel. So follow the chain ourselves: from each
termination's immediate link peer, hop through patch panels (rear<->front) to the
device interface it lands on, capped and cycle-guarded.
- The A and Z sides are walked concurrently (join_all); hops within a side stay
sequential (each depends on the previous).
- The diagram now shows every cable segment under a termination, not just the
first hop to the panel.
- Dead-ends honestly: an unwired panel (no rear<->front mapping) stops the walk
rather than fabricating the far device.
- TUI links now cover every device along the path.
The view stays pure: the walker (detail.rs) produces ResolvedTermination
{termination, path}; CircuitView::build renders it. JSON terminations gain a
`path` array. Covered by wiremock integration tests (two-segment resolve through
a wired panel + graceful dead-end) plus the existing view/diagram unit tests.
The panel walker only matched a front-port's singular `rear_port` field, but some
NetBox instances serialize the pairing as a `rear_ports` array
(`[{rear_port: <id>, position, rear_port_position}]`) with the singular field left
null. The walker saw 'no mapping' and dead-ended at the panel rear-port even
though the path continues to the device. Match either form via `front_rear_ids`
(also used for the front→rear direction). Live-verified: A circuit now resolves
through its panel to the device interface. Regression test added for the
`rear_ports` form.
The resolved path read outward from the circuit (panel first, then the device), so the router landed adjacent to the circuit segment — backwards. Present it device-first: the resolved endpoint device leads and the circuit-adjacent panel comes last. The diagram renders the side above the segment as-is and the side below it reversed, so the whole A↔Z reads as one continuous physical line (device → panel → circuit → panel → device). JSON `terminations[].path` is now device-first too. Tests updated for the new order.
lance0
force-pushed
the
feat/circuit-path
branch
from
June 23, 2026 16:38
c6902d2 to
450ec7d
Compare
Switch the circuit-path tests and the diagram doc example to neutral placeholders (ACME / DC1 / panel-1 / edge-1 / xe-0/0/0), consistent with the other tests' fixtures.
lance0
force-pushed
the
feat/circuit-path
branch
from
June 23, 2026 16:45
450ec7d to
b11d8f3
Compare
Two review findings:
- front_for_rear scanned only the first 200 front-ports of a panel device, so a
mapping beyond that page made the path silently dead-end. Page through via the
shared list_all pattern (new Endpoint::FrontPorts) with a sane cap.
- Termination sides were sorted lexicographically, which puts a missing/unknown
side ("?") before "A". Use an explicit rank (A, Z, then unknown last).
Note the multi-position panel limitation (first matching front-port) in a code
comment + ROADMAP. Regression tests added: paginated front-port match, and
unknown-side ordering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A circuit's view showed only flat attributes (provider / type / status / rate) — nothing about where it lands, which is the whole point of a circuit. This resolves the A/Z terminations and walks the cable path through patch panels to the device each side lands on, rendered as a vertical A↔Z diagram (mirroring the interface cable-path visualizer).
Example output (
nbox circuit <cid>):Surfaces
nbox circuit <cid>— a "Circuit Path" section (the A↔Z diagram).-o json— a structuredterminationsarray (A first); each carries a device-firstpath(the endpoint device leads; the circuit-adjacent panel is last).ppath tab + navigable links to the provider, the A/Z sites, and every device along the path.10 Gbps).How
NetBox exposes no
/trace/endpoint for circuit terminations (only interfaces / console / power ports), and doesn't resolve theirconnected_endpointsthrough a panel — so nbox walks the chain itself: from each termination's link peer, hop through patch panels (rear↔front, tolerating both the singularrear_portand therear_portsarray serialization) to the device interface it lands on. Bounded (hop cap + cycle guard); the A and Z sides are walked concurrently; an unwired panel stops the walk cleanly rather than guessing. The path is presented device-first so the diagram reads as one continuous physical line.New
CircuitTerminationmodel,Endpoint::CircuitTerminations, and acircuit_terminations()helper. The view stays pure: the walker (indetail.rs) producesResolvedTermination { termination, path };CircuitView::buildrenders it.Tests
circuit_view: A↔Z diagram (device-first order, endpoint kinds, multi-hop), speed humanization, attribute flattening.circuit_links: provider/tenant/site/path-device links; provider-network side emits no site link.tests/circuit_path_tests.rs(wiremock): two-segment resolve through a wired panel, therear_portsarray form, and the graceful dead-end at an unwired panel.get_circuitupdated to assert theterminationsfield.Gate
cargo fmt --check,clippy --all-targets --all-features -D warnings,clippy --no-default-features, andcargo testin both feature modes — all green.