Skip to content

Surface circuit A/Z terminations and the circuit path - #68

Merged
lance0 merged 6 commits into
masterfrom
feat/circuit-path
Jun 23, 2026
Merged

lance0 merged 6 commits into
masterfrom
feat/circuit-path

Conversation

@lance0

@lance0 lance0 commented Jun 23, 2026 •

Copy link
Copy Markdown
Owner

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>):

cid: ACME-1001
provider: ACME
type: Wave
status: active
commit_rate: 10 Gbps

Circuit Path
   A  DC1  (site)
      ↳ edge-1 xe-0/0/0  ·  #200
      ↳ panel-1 7  ·  #100
      │
      ┿ Wave · 10 Gbps · Active
      │
   Z  ACME Cloud  (provider network)

Surfaces

  • CLI nbox circuit <cid> — a "Circuit Path" section (the A↔Z diagram).
  • JSON -o json — a structured terminations array (A first); each carries a device-first path (the endpoint device leads; the circuit-adjacent panel is last).
  • TUI circuit detail — a p path tab + navigable links to the provider, the A/Z sites, and every device along the path.
  • Commit/port rates are humanized (e.g. 10 Gbps).

How

NetBox exposes no /trace/ endpoint for circuit terminations (only interfaces / console / power ports), and doesn't resolve their connected_endpoints through a panel — so nbox walks the chain itself: from each termination's link peer, hop through patch panels (rear↔front, tolerating both the singular rear_port and the rear_ports array 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 CircuitTermination model, Endpoint::CircuitTerminations, and a circuit_terminations() helper. The view stays pure: the walker (in detail.rs) produces ResolvedTermination { termination, path }; CircuitView::build renders 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, the rear_ports array form, and the graceful dead-end at an unwired panel.
  • MCP get_circuit updated to assert the terminations field.

Gate

cargo fmt --check, clippy --all-targets --all-features -D warnings, clippy --no-default-features, and cargo test in both feature modes — all green.

lance0 added 4 commits June 23, 2026 11:43
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
lance0 force-pushed the feat/circuit-path branch from c6902d2 to 450ec7d Compare June 23, 2026 16:38
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
lance0 force-pushed the feat/circuit-path branch from 450ec7d to b11d8f3 Compare June 23, 2026 16:45
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.
@lance0
lance0 merged commit f48a7dd into master Jun 23, 2026
4 checks passed
@lance0
lance0 deleted the feat/circuit-path branch June 23, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant