Network page for large sites: problems, filters, matrix, machine path
CI / agent (push) Successful in 2s
CI / site (push) Successful in 3s
CI / go (push) Successful in 41s

The topology drawing became an unreadable strip at a few hundred
machines and dozens of VLANs. The page now starts with what needs
attention (offline rack controllers and the VLANs they leave without
DHCP/PXE, provisioning VLANs without it, nearly full subnets, IPAM
errors), has filters by fabric, purpose and rack controller and a
search that shows a machine's path to the region, and a VLAN x rack
controller matrix that is the default once a site is large. The
topology groups machines by rack and VLAN, then by rack, when boxes
would not fit, and scrolls instead of shrinking; the overview shows one
row per fabric on a large site. Filters can come from the URL.

Checked with a synthetic site (3 fabrics, 9 rack controllers, 43
subnets, 360 machines) and the lab in headless Chrome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-31 18:55:42 +01:00
1 parent a25b5c1f33
commit 355401465c
6 files changed
+294 -25

No files matched your search

+7
View File
@@ -7,6 +7,13 @@ publish a tag that has no section here.
## [Unreleased]
### Added
- Network page for large sites: a problems strip (offline rack controllers and the VLANs left
without DHCP/PXE, provisioning VLANs without it, subnets over 80%, IPAM errors), filters by fabric,
purpose and rack controller, a search that shows a machine's path (interface, address, VLAN,
rack controller, region), and a VLAN x rack-controller matrix, the default once a site is large.
The topology groups machines more coarsely when boxes would not fit and scrolls instead of
shrinking; the overview shows one row per fabric on a large site. Filters can be put on the URL
(`?fabric=…&view=matrix&q=…`) to share a view.
- Root rotation without re-joining (`rollcall ca rotate prepare | switch | retire`, status without
an argument). The trust bundle (all current roots, `/ca-bundle.pem`) reaches rack controllers
signed by the active root and is installed by their root unit only when that signature verifies;
+18 -7
View File
@@ -175,7 +175,8 @@ function pageOverview() {
const subRows = S.subnets.filter(s => s.size).sort((a, b) => b.used / b.size - a.used / a.size).slice(0, 6)
.map(s => [`<span class="mono">${esc(s.cidr)}</span>`, s.used, `${s.purpose} · ${s.used} of ${s.size} addresses`, '', s.size, `${s.used}/${s.size}`]);
const maxPct = S.subnets.filter(s => s.size).map(s => [s, s.used / s.size]).sort((a, b) => b[1] - a[1])[0];
const network = `<div class="topo-wrap">${topoSVG({ compact: true })}</div>
// a drawing for a small site; one row per fabric for a large one (netview.js)
const network = `${nvLarge() ? nvFabricSummaryHTML() : `<div class="topo-wrap">${topoSVG({ compact: true })}</div>`}
<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:10px">
<div><div class="muted" style="font-size:11.5px;margin-bottom:4px">ADDRESSES IN USE</div>${hbars(subRows)}</div>
<div>${kv([['Subnets', `${S.subnets.length} (${S.subnets.filter(s => s.family === 6).length} IPv6)`], ['VLANs with DHCP', String(new Set(S.subnets.filter(s => s.dhcp).map(s => s.vlan_id)).size)],
@@ -226,6 +227,7 @@ function pageOverview() {
}
function wireOverview() {
wireTopo();
wireFabricSummary();
$$('[data-go]').forEach(el => { if (el.closest('.topo') && !el.dataset.go.includes('/')) return; el.onclick = ev => { ev.preventDefault(); const [p, st] = el.dataset.go.split('/'); S.states.clear(); S.tagf.clear(); if (st) S.states.add(st); nav(p); }; });
$$('[data-tag]').forEach(el => el.onclick = () => { S.states.clear(); S.tagf.clear(); S.tagf.add(el.dataset.tag); nav('machines'); });
}
@@ -742,10 +744,13 @@ function wireNetPlan(id) {
// ---------------------------------------------------------------- network page
function pageNetwork() {
const regionVer = (S.controllers.find(c => c.kind === 'embedded') || {}).version;
const ctl = table(['Controller', 'Kind', 'State', 'URL', 'Machines', 'Version', 'Last seen', 'Interfaces', ''], S.controllers.map(c => [`<b>${esc(c.name)}</b>`, esc(c.kind), c.online ? '<span class="dot ok"></span>online' : '<span class="dot bad"></span><span class="bad">offline</span>', `<span class="mono">${esc(c.url)}</span>`, c.machines,
const f = nvFilter(), large = nvLarge(), view = NV.view || (large ? 'matrix' : 'topology');
const subs = S.subnets.filter(f.subnet);
const ctls = S.controllers.filter(c => f.rack(c.name) && (!f.active || NV.rack || topoModel(f).racks.some(r => r.c.name === c.name && r.at.length)));
const ctl = table(['Controller', 'Kind', 'State', 'URL', 'Machines', 'Version', 'Last seen', 'Interfaces', ''], ctls.map(c => [`<b>${esc(c.name)}</b>`, esc(c.kind), c.online ? '<span class="dot ok"></span>online' : '<span class="dot bad"></span><span class="bad">offline</span>', `<span class="mono">${esc(c.url)}</span>`, c.machines,
`<span class="mono${regionVer && c.version && c.version !== regionVer ? ' warn" title="differs from the region; it updates itself' : ''}">${esc(c.version || '—')}</span>`,
`<span class="muted" title="${esc(when(c.last_seen))}">${ago(c.last_seen)}</span>`, `<span class="mono muted">${esc((c.interfaces || []).map(i => i.name + ' ' + (i.addrs || []).join(',')).join(' · '))}</span>`, `<button class="btn sm" data-dhcp="${esc(c.name)}">dnsmasq</button>${c.kind === 'remote' ? ` <button class="btn sm danger" data-rmctl="${esc(c.name)}">remove</button>` : ''}`]));
const sub = table(['Subnet', 'Purpose', 'Fabric / VLAN', 'DHCP', 'Gateway', 'DNS', 'Usage', 'Ranges', ''], S.subnets.map(s => {
const sub = table(['Subnet', 'Purpose', 'Fabric / VLAN', 'DHCP', 'Gateway', 'DNS', 'Usage', 'Ranges', ''], subs.map(s => {
const pct = s.size ? Math.round(s.used * 100 / s.size) : 0;
const sizeTxt = s.size ? s.size : '∞';
const ranges = (s.ranges || []).map(r => `<span class="pill tag" title="${esc(r.comment || '')}">${esc(r.kind)} ${esc(r.start)}–${esc(r.end.split('.').pop())} <a href="#" data-rmrange="${r.id}" title="remove">×</a></span>`).join(' ');
@@ -757,10 +762,15 @@ function pageNetwork() {
const lay = table(['Layout', 'Machines', 'Interfaces', 'Comment', ''], S.layouts.map(l => [`<b>${esc(l.name)}</b>`, l.machines || 0, `<span class="mono">${esc(layoutSummary(l))}</span>`, esc(l.comment || ''), `<button class="btn sm" data-editlayout="${esc(l.name)}">edit</button> <button class="btn sm danger" data-rmlayout="${esc(l.name)}">delete</button>`]));
return `<div class="page-head"><h1>Network</h1><span class="sub">fabrics, VLANs and subnets (MAAS-style); rack controllers serve DHCP/PXE on their VLANs</span>
<div class="right"><button class="btn primary" id="new-subnet">New subnet…</button><button class="btn" id="new-layout">New layout…</button></div></div>
<div class="card wide" style="margin-bottom:12px"><h3>Topology</h3><div class="topo-wrap">${topoSVG()}</div>
<div class="legend"><span><i></i>VLAN with DHCP/PXE</span><span><i class="plain"></i>VLAN</span><span><i class="dash"></i>storage / IB</span><span><i class="ctl"></i>rack ↔ region (mTLS)</span><span><i class="down"></i>rack offline</span><span><b class="sq"></b>rack serves/sits on the VLAN</span><span><b class="ci"></b>machine address</span><span>click a bus for its addresses, a machine for its page</span></div></div>
<div class="card wide" style="margin-bottom:12px"><h3>Rack controllers</h3><div class="tw">${ctl}</div><p class="muted" style="margin:8px 0 0">Add one next to a segment: <code>rollcall controller join-code -name NAME -addr REGION:443</code> here, then on that host <code>./rollcall rack join CODE -url http://ITS-ADDRESS</code> and <code>sh install-rack.sh</code>. It talks to the region over mutual TLS.</p></div>
<div class="card wide" style="margin-bottom:12px"><h3>Subnets</h3><div class="tw">${sub}</div></div>
${nvToolbarHTML(large)}
${nvIssuesHTML()}
${nvPathHTML()}
${view === 'matrix'
? `<div class="card wide" style="margin-bottom:12px"><h3>VLANs × rack controllers${f.active ? ' <span class="muted">(filtered)</span>' : ''}</h3>${nvMatrixHTML(f)}</div>`
: `<div class="card wide" style="margin-bottom:12px"><h3>Topology${f.active ? ' <span class="muted">(filtered)</span>' : ''}</h3><div class="topo-wrap">${topoSVG({ filter: f })}</div>
<div class="legend"><span><i></i>VLAN with DHCP/PXE</span><span><i class="plain"></i>VLAN</span><span><i class="dash"></i>storage / IB</span><span><i class="ctl"></i>rack ↔ region (mTLS)</span><span><i class="down"></i>rack offline</span><span><b class="sq"></b>rack serves/sits on the VLAN</span><span><b class="ci"></b>machine address</span><span>click a bus for its addresses, a machine for its page${large && !f.active ? '; filter by fabric or rack for a readable part of a large site' : ''}</span></div></div>`}
<div class="card wide" style="margin-bottom:12px"><h3>Rack controllers${ctls.length < S.controllers.length ? ` <span class="muted">(${ctls.length} of ${S.controllers.length})</span>` : ''}</h3><div class="tw">${ctl}</div><p class="muted" style="margin:8px 0 0">Add one next to a segment: <code>rollcall controller join-code -name NAME -addr REGION:443</code> here, then on that host <code>./rollcall rack join CODE -url http://ITS-ADDRESS</code> and <code>sh install-rack.sh</code>. It talks to the region over mutual TLS.</p></div>
<div class="card wide" style="margin-bottom:12px"><h3>Subnets${subs.length < S.subnets.length ? ` <span class="muted">(${subs.length} of ${S.subnets.length})</span>` : ''}</h3><div class="tw">${sub}</div></div>
<div class="card wide"><h3>Interface layouts</h3>${lay}<p class="muted" style="margin:8px 0 0">A layout applies to a machine directly (More → Network layout…) or through a tag (Tags → layout). Without one, the boot NIC gets an address on its subnet.</p></div>`;
}
const layoutExample = JSON.stringify({ interfaces: [
@@ -800,6 +810,7 @@ async function editLayout(l) {
}
function wireNetwork() {
wireTopo();
wireNetView();
let dl = $('#dl-fabrics'); if (!dl) { dl = document.createElement('datalist'); dl.id = 'dl-fabrics'; document.body.appendChild(dl); }
dl.innerHTML = S.fabrics.map(f => `<option value="${esc(f.name)}">`).join('');
$('#new-subnet').onclick = () => editSubnet(null);
+1
View File
@@ -49,6 +49,7 @@
<div id="toast" hidden></div>
<script src="topo.js"></script>
<script src="netview.js"></script>
<script src="app.js"></script>
</body>
</html>
+205
View File
@@ -0,0 +1,205 @@
'use strict';
// The network page for sites of any size: problems first, filters, then a
// VLAN x rack-controller matrix (the default once a site is large) or the
// topology drawing (small sites, or a filtered part of a large one), and the
// path of a machine or address that was searched for.
const NV = { view: '', fabric: '', purpose: '', rack: '', q: '', allIssues: false };
try { Object.assign(NV, JSON.parse(localStorage.getItem('rollcall.netview') || '{}'), { q: '', allIssues: false }); } catch (e) { /* storage unavailable */ }
// ?view=matrix&fabric=…&purpose=…&rack=…&q=… on the URL: a view to share or bookmark
{ const u = new URLSearchParams(location.search); for (const k of ['view', 'fabric', 'purpose', 'rack', 'q']) if (u.has(k)) NV[k] = u.get(k); }
function nvSave() { try { localStorage.setItem('rollcall.netview', JSON.stringify({ view: NV.view, fabric: NV.fabric, purpose: NV.purpose, rack: NV.rack })); } catch (e) { /* ignore */ } }
// nvFilter: what the filters keep, for topoModel and the tables
function nvFilter() {
const hit = nvSearch();
const keepSub = s => (!NV.fabric || s.fabric === NV.fabric) && (!NV.purpose || s.purpose === NV.purpose) &&
(!NV.rack || s.primary_rack === NV.rack || s.secondary_rack === NV.rack || (S.controllers.find(c => c.name === NV.rack)?.interfaces || []).some(i => (i.addrs || []).some(a => inCidr(a, s.cidr)))) &&
(!hit || hit.subnets.has(s.cidr));
return {
subnet: keepSub,
machine: m => (!NV.rack || m.rack_controller === NV.rack) && (!hit || hit.machines.has(m.id)),
rack: name => !NV.rack || name === NV.rack,
active: !!(NV.fabric || NV.purpose || NV.rack || hit),
};
}
// nvSearch: machines and subnets matching the search box (name, id, IP or CIDR)
function nvSearch() {
const q = NV.q.trim().toLowerCase();
if (!q) return null;
const machines = new Set(), subnets = new Set();
for (const m of S.machines) if (nameOf(m).toLowerCase().includes(q) || m.id.toLowerCase() === q || m.mgmt_ip === q) machines.add(m.id);
for (const x of S.ips) if (x.ip === q || (x.hostname || '').toLowerCase() === q) { if (x.machine_id) machines.add(x.machine_id); subnets.add(x.subnet); }
for (const s of S.subnets) if (s.cidr.toLowerCase() === q || (s.name || '').toLowerCase() === q || (parseIP(q) && inCidr(q, s.cidr))) subnets.add(s.cidr);
for (const x of S.ips) if (machines.has(x.machine_id)) subnets.add(x.subnet);
return { machines, subnets };
}
// ---------------------------------------------------------------- problems
// nvIssues: what needs attention, worst first: [{sev, text, cidr?, rack?}]
function nvIssues() {
const out = [];
const ctl = Object.fromEntries(S.controllers.map(c => [c.name, c]));
const regionVer = (S.controllers.find(c => c.kind === 'embedded') || {}).version;
const segs = topoModel().segs;
for (const c of S.controllers) {
if (!c.online) {
const serves = segs.filter(g => g.racks.has(c.name));
const alone = serves.filter(g => ![...g.racks].some(r => r !== c.name && ctl[r]?.online));
out.push({ sev: 'bad', rack: c.name, text: `rack controller ${c.name} is offline${alone.length ? `: no DHCP/PXE on ${alone.map(segLabel).join(', ')}` : ''}${c.machines ? ` (${c.machines} machines)` : ''}` });
} else if (regionVer && c.version && c.version !== regionVer) {
out.push({ sev: 'warn', rack: c.name, text: `${c.name} runs ${c.version}, the region ${regionVer} (it updates itself)` });
}
}
for (const g of segs) if (g.purpose === 'provisioning' && !g.dhcp) out.push({ sev: 'warn', cidr: g.subnets[0].cidr, text: `${segLabel(g)} (provisioning) has no DHCP/PXE: its machines cannot network-boot` });
for (const s of S.subnets) {
if (!s.size) continue;
const pct = s.used * 100 / s.size;
if (pct >= 80) out.push({ sev: pct >= 90 ? 'bad' : 'warn', cidr: s.cidr, text: `${s.cidr}${s.name ? ' ' + s.name : ''} is ${Math.round(pct)}% used (${s.used}/${s.size})` });
}
const last = S.ipam && S.ipam.last_sync;
if (last && last.error) out.push({ sev: 'bad', text: `${S.ipam.provider} IPAM: ${last.error}` });
if (last && last.conflicts && last.conflicts.length) out.push({ sev: 'warn', text: `${S.ipam.provider} IPAM: ${last.conflicts.length} conflict(s): ${last.conflicts.slice(0, 3).join('; ')}` });
return out.sort((a, b) => (a.sev === 'bad' ? 0 : 1) - (b.sev === 'bad' ? 0 : 1));
}
const segLabel = g => `${g.fabric || 'no fabric'}/${g.vid ? 'vlan ' + g.vid : 'untagged'}`;
function nvIssuesHTML() {
const is = nvIssues();
if (!is.length) return `<div class="nv-issues ok"><span class="dot ok"></span>No network problems found: every rack controller online, provisioning VLANs served, subnets below 80%.</div>`;
const show = NV.allIssues ? is : is.slice(0, 5);
return `<div class="nv-issues">${show.map(i => `<div class="nv-issue ${i.sev}"${i.cidr ? ` data-ips="${esc(i.cidr)}"` : ''}${i.rack ? ` data-nvrack="${esc(i.rack)}"` : ''}><span class="dot ${i.sev}"></span>${esc(i.text)}</div>`).join('')}
${is.length > 5 ? `<a href="#" id="nv-more">${NV.allIssues ? 'fewer' : `${is.length - 5} more`}</a>` : ''}</div>`;
}
// ---------------------------------------------------------------- matrix
// One row per VLAN (grouped by fabric), one column per rack controller:
// what the rack does there, then subnets, machines and how full it is.
function nvMatrixHTML(f) {
const { segs: drawn, racks, ms } = topoModel(f);
if (!drawn.length) return `<div class="empty">${NV.q.trim() && !nvSearch().machines.size && !nvSearch().subnets.size ? `No machine, address or subnet matches “${esc(NV.q.trim())}”.` : 'No VLAN matches the filters.'}</div>`;
// fabric by fabric, VLANs in order (topoModel puts DHCP VLANs first, for the drawing)
const order = drawn.map((g, i) => i).sort((a, b) => String(drawn[a].fabric).localeCompare(String(drawn[b].fabric)) || drawn[a].vid - drawn[b].vid);
const segs = order.map(i => drawn[i]), pos = {}; order.forEach((i, j) => { pos[i] = j; });
for (const r of racks) r.at = r.at.map(i => pos[i]);
for (const x of ms) x.at = x.at.map(i => pos[i]);
const cols = racks.filter(r => r.at.length && f.rack(r.c.name));
const perSeg = segs.map(() => ({}));
for (const x of ms) for (const i of x.at) perSeg[i][x.m.state] = (perSeg[i][x.m.state] || 0) + 1;
const hit = nvSearch();
const cell = (r, i, g) => {
const s0 = g.subnets.find(s => s.dhcp) || {};
let sym = '', cls = '', tip = '';
if (s0.primary_rack === r.c.name) { sym = s0.dhcp_mode === 'proxy' ? '◐' : '●'; cls = 'serve'; tip = s0.dhcp_mode === 'proxy' ? 'proxy DHCP: PXE only' : 'DHCP + PXE'; }
else if (s0.secondary_rack === r.c.name) { sym = '●'; cls = 'serve second'; tip = 'DHCP + PXE (secondary)'; }
else if (r.at.includes(i)) { sym = '○'; cls = 'on'; tip = 'has an address on this VLAN'; }
if (sym && !r.c.online) { cls += ' down'; tip += ' · rack OFFLINE'; }
return `<td class="nv-cell ${cls}" title="${esc(r.c.name + ': ' + (tip || 'not on this VLAN'))}">${sym}</td>`;
};
const rows = [];
let fab = null;
segs.forEach((g, i) => {
if (g.fabric !== fab) { fab = g.fabric; rows.push(`<tr class="nv-fab"><td colspan="${6 + cols.length}">${esc(fab || 'no fabric')}</td></tr>`); }
const used = g.subnets.reduce((a, s) => a + (s.used || 0), 0), size = g.subnets.reduce((a, s) => a + (s.size || 0), 0);
const pct = Math.max(0, ...g.subnets.map(s => s.size ? s.used * 100 / s.size : 0));
const n = Object.values(perSeg[i]).reduce((a, b) => a + b, 0);
const hl = hit && g.subnets.some(s => hit.subnets.has(s.cidr));
rows.push(`<tr class="nv-row${hl ? ' hl' : ''}" data-ips="${esc(g.subnets[0].cidr)}">
<td class="mono">${g.vid || '<span class="muted">untagged</span>'}</td>
<td>${g.subnets.map(s => `<span class="mono">${esc(s.cidr)}</span>${s.name ? ` <span class="muted">${esc(s.name)}</span>` : ''}`).join('<br>')}</td>
<td>${esc(g.purpose)}${g.mtu && g.mtu !== 1500 ? ` <span class="pill tag">mtu ${g.mtu}</span>` : ''}</td>
${cols.map(r => cell(r, i, g)).join('')}
<td class="num">${n ? `${n}<div class="nv-states">${nvStateBar(perSeg[i], n)}</div>` : '<span class="muted">0</span>'}</td>
<td><div class="bar${pct >= 90 ? ' bad' : pct >= 80 ? ' warn' : ''}" title="${used}/${size || '∞'}"><span style="width:${Math.round(pct)}%"></span></div><span class="muted">${size ? Math.round(pct) + '%' : used + ' addr'}</span></td>
<td class="muted">${g.dhcp ? (g.subnets.some(s => s.dhcp_mode === 'proxy') ? 'proxy' : 'DHCP') : ''}</td></tr>`);
});
return `<div class="tw"><table class="nv-matrix"><thead><tr><th>VLAN</th><th>Subnets</th><th>Purpose</th>
${cols.map(r => `<th class="nv-rackh${r.c.online ? '' : ' down'}" title="${esc(`${r.c.name} (${r.c.kind}) ${r.c.online ? 'online' : 'OFFLINE'}`)}"><span>${esc(r.c.name)}</span></th>`).join('')}
<th class="num">Machines</th><th>Used</th><th></th></tr></thead><tbody>${rows.join('')}</tbody></table></div>
<div class="legend"><span><b class="g">●</b> serves DHCP + PXE</span><span><b class="g">◐</b> proxy DHCP (PXE only)</span><span><b>○</b> has an address there</span><span><b class="r">●</b> rack offline</span><span>click a row for its addresses</span></div>`;
}
function nvStateBar(by, n) {
const order = ['bad', 'warn', 'ok', 'idle'];
const agg = {};
for (const [st, c] of Object.entries(by)) agg[stateClass(st)] = (agg[stateClass(st)] || 0) + c;
return order.filter(k => agg[k]).map(k => `<i class="${k}" style="width:${(agg[k] * 100 / n).toFixed(1)}%" title="${agg[k]} ${k === 'bad' ? 'failed' : k === 'warn' ? 'busy / new' : k === 'ok' ? 'deployed / ready' : 'other'}"></i>`).join('');
}
// ---------------------------------------------------------------- path
// The way from a machine to the region: interface, address, VLAN, the rack
// controllers serving it, the region.
function nvPathHTML() {
const hit = nvSearch();
if (!hit || hit.machines.size !== 1) return hit && hit.machines.size > 1 ? `<p class="muted">${hit.machines.size} machines match; the views show their VLANs.</p>` : '';
const m = S.machines.find(x => x.id === [...hit.machines][0]);
if (!m) return '';
const ctl = Object.fromEntries(S.controllers.map(c => [c.name, c]));
const lines = S.ips.filter(x => x.machine_id === m.id).map(x => {
const s = S.subnets.find(y => y.cidr === x.subnet) || {};
const serving = [s.primary_rack, s.secondary_rack].filter(Boolean);
const rk = serving.length ? serving : [m.rack_controller].filter(Boolean);
return `<div class="nv-path"><span class="pill tag">${esc(x.iface || '?')}</span><span class="arr">→</span><span class="mono">${esc(x.ip)}</span><span class="arr">→</span>
<span>${esc(s.fabric || 'no fabric')} / ${s.vid ? 'vlan ' + s.vid : 'untagged'} <span class="muted">${esc(s.cidr || x.subnet)} ${esc(s.purpose || '')}</span></span>
${rk.length ? `<span class="arr">→</span>${rk.map(r => `<span class="${ctl[r] && !ctl[r].online ? 'bad' : ''}">${serving.includes(r) ? '' : '<span class="muted">via</span> '}${esc(r)}${ctl[r] && !ctl[r].online ? ' (offline)' : ''}${s.dhcp && serving.includes(r) ? ' <span class="muted">DHCP/PXE</span>' : ''}</span>`).join(', ')}<span class="arr">→</span><span>region</span>` : ''}</div>`;
});
return `<div class="card wide nv-pathcard"><h3>Path of <a href="#/machine/${esc(m.id)}">${esc(nameOf(m))}</a> ${pill(m.state)}</h3>${lines.join('') || '<p class="muted">no addresses on modelled subnets</p>'}</div>`;
}
// ---------------------------------------------------------------- page parts
function nvToolbarHTML(large) {
const view = NV.view || (large ? 'matrix' : 'topology');
const opt = (v, l, cur) => `<option value="${esc(v)}"${v === cur ? ' selected' : ''}>${esc(l)}</option>`;
const fabrics = [...new Set(S.subnets.map(s => s.fabric).filter(Boolean))].sort();
const purposes = [...new Set(S.subnets.map(s => s.purpose).filter(Boolean))].sort();
return `<div class="nv-bar">
<input id="nv-q" type="search" placeholder="machine, IP, subnet…" value="${esc(NV.q)}">
<select id="nv-fabric">${opt('', 'all fabrics', NV.fabric)}${fabrics.map(x => opt(x, x, NV.fabric)).join('')}</select>
<select id="nv-purpose">${opt('', 'all purposes', NV.purpose)}${purposes.map(x => opt(x, x, NV.purpose)).join('')}</select>
<select id="nv-rack">${opt('', 'all rack controllers', NV.rack)}${S.controllers.map(c => opt(c.name, c.name + (c.online ? '' : ' (offline)'), NV.rack)).join('')}</select>
${NV.fabric || NV.purpose || NV.rack || NV.q ? '<button class="btn sm ghost" id="nv-clear">clear</button>' : ''}
<span class="right"><span class="seg-btns"><button class="btn sm${view === 'matrix' ? ' on' : ''}" data-nvview="matrix">Matrix</button><button class="btn sm${view === 'topology' ? ' on' : ''}" data-nvview="topology">Topology</button></span></span>
</div>`;
}
function nvLarge() { return S.subnets.length > 12 || S.machines.length > 60 || S.controllers.length > 4; }
function wireNetView() {
const again = () => { nvSave(); render(); };
const q = $('#nv-q');
if (q) {
q.oninput = () => { NV.q = q.value; clearTimeout(q._t); q._t = setTimeout(() => { render(); const n = $('#nv-q'); if (n) { n.focus(); n.setSelectionRange(n.value.length, n.value.length); } }, 250); };
}
for (const k of ['fabric', 'purpose', 'rack']) { const el = $('#nv-' + k); if (el) el.onchange = () => { NV[k] = el.value; again(); }; }
const c = $('#nv-clear'); if (c) c.onclick = () => { Object.assign(NV, { fabric: '', purpose: '', rack: '', q: '' }); again(); };
$$('[data-nvview]').forEach(b => b.onclick = () => { NV.view = b.dataset.nvview; again(); });
$$('[data-nvrack]').forEach(d => d.onclick = () => { NV.rack = d.dataset.nvrack; again(); });
const more = $('#nv-more'); if (more) more.onclick = ev => { ev.preventDefault(); NV.allIssues = !NV.allIssues; render(); };
}
// nvFabricSummaryHTML: the overview's network card on a large site, one row
// per fabric instead of a drawing; a row opens the network page filtered to it.
function nvFabricSummaryHTML() {
const { segs, racks, ms } = topoModel();
const issues = nvIssues();
const fabs = [...new Set(segs.map(g => g.fabric || ''))].sort();
const rows = fabs.map(fab => {
const idx = segs.map((g, i) => (g.fabric || '') === fab ? i : -1).filter(i => i >= 0);
const rk = racks.filter(r => r.at.some(i => idx.includes(i)));
const down = rk.filter(r => !r.c.online).length;
const n = ms.filter(x => x.at.some(i => idx.includes(i))).length;
const subs = idx.flatMap(i => segs[i].subnets);
const full = subs.filter(s => s.size).map(s => [s, s.used / s.size]).sort((a, b) => b[1] - a[1])[0];
const cidrs = new Set(subs.map(s => s.cidr)), names = new Set(rk.map(r => r.c.name));
const probs = issues.filter(i => (i.cidr && cidrs.has(i.cidr)) || (i.rack && names.has(i.rack))).length;
const pct = full ? Math.round(full[1] * 100) : 0;
return `<tr class="nv-row" data-nvfabric="${esc(fab)}"><td><b>${esc(fab || 'no fabric')}</b></td><td class="num">${idx.length}</td><td class="num">${idx.filter(i => segs[i].dhcp).length}</td>
<td>${rk.length - down}/${rk.length}${down ? ` <span class="bad">${down} offline</span>` : ''}</td><td class="num">${n}</td>
<td>${full ? `<span class="mono">${esc(full[0].cidr)}</span> <span class="${pct >= 90 ? 'bad' : pct >= 80 ? 'warn' : 'muted'}">${pct}%</span>` : '—'}</td>
<td>${probs ? `<span class="${issues.some(i => i.sev === 'bad' && ((i.cidr && cidrs.has(i.cidr)) || (i.rack && names.has(i.rack)))) ? 'bad' : 'warn'}">${probs}</span>` : '<span class="ok">none</span>'}</td></tr>`;
});
return `<table class="nv-matrix"><thead><tr><th>Fabric</th><th class="num">VLANs</th><th class="num">with DHCP</th><th>Rack controllers</th><th class="num">Machines</th><th>Fullest subnet</th><th>Problems</th></tr></thead><tbody>${rows.join('')}</tbody></table>`;
}
function wireFabricSummary() {
$$('[data-nvfabric]').forEach(r => r.onclick = () => { NV.fabric = r.dataset.nvfabric; nvSave(); nav('network'); });
}
+29 -1
View File
@@ -33,7 +33,7 @@ a { color: var(--accent); }
.side a:hover { background: var(--side-act); } .side a.active { background: var(--side-act); color: #fff; }
.side .count { font-size: 11px; opacity: .8; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 10px; font-size: 11px; }
main { padding: 18px 22px; max-width: 1500px; width: 100%; }
main { padding: 18px 22px; max-width: 1500px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 18px; margin: 0; } .page-head .sub { color: var(--muted); }
.page-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
@@ -176,3 +176,31 @@ svg.topo .mach.group.ok rect:first-child { stroke: var(--ok); } svg.topo .mach.g
.statebar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--pill); margin: 4px 0 10px; }
.statebar span { height: 100%; } .statebar .ok { background: var(--ok); } .statebar .warn { background: var(--warn); } .statebar .bad { background: var(--danger); } .statebar .idle { background: var(--line2); }
@media (max-width: 1100px) { .ov > .card, .ov > .card.w6, .ov > .card.w8 { grid-column: 1 / -1; } }
/* network page for large sites (netview.js) */
.nv-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.nv-bar #nv-q { width: 240px; } .nv-bar .right { margin-left: auto; }
.seg-btns { display: inline-flex; } .seg-btns .btn { border-radius: 0; } .seg-btns .btn:first-child { border-radius: 6px 0 0 6px; } .seg-btns .btn:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.seg-btns .btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.nv-issues { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin-bottom: 12px; }
.nv-issues.ok { color: var(--muted); padding: 9px 12px; }
.nv-issue { padding: 4px 0; } .nv-issue[data-ips], .nv-issue[data-nvrack] { cursor: pointer; } .nv-issue[data-ips]:hover, .nv-issue[data-nvrack]:hover { text-decoration: underline; }
.nv-issue.bad { color: var(--danger); } .nv-issue.warn { color: var(--warn); }
.nv-issues > a { display: inline-block; margin: 2px 0 4px; font-size: 12px; }
table.nv-matrix { min-width: 0; } .nv-matrix td, .nv-matrix th { padding: 5px 8px; }
.nv-matrix th.nv-rackh { height: 92px; vertical-align: bottom; padding: 4px 2px; width: 26px; min-width: 26px; text-align: center; }
.nv-matrix th.nv-rackh span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-family: var(--mono); text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.nv-matrix th.nv-rackh.down span { color: var(--danger); }
.nv-matrix td.nv-cell { text-align: center; padding: 5px 2px; font-size: 14px; color: var(--muted); border-left: 1px solid var(--line); }
.nv-matrix td.nv-cell.serve { color: var(--ok); } .nv-matrix td.nv-cell.second { opacity: .65; } .nv-matrix td.nv-cell.down { color: var(--danger); opacity: 1; }
.nv-matrix tr.nv-fab td { background: var(--hover); font-weight: 600; font-size: 12px; padding: 5px 8px; }
.nv-matrix tr.nv-row { cursor: pointer; } .nv-matrix tr.nv-row:hover td { background: var(--hover); }
.nv-matrix tr.nv-row.hl td { background: var(--sel); }
.nv-matrix td.num, .nv-matrix th.num { text-align: right; }
.nv-states { display: flex; height: 4px; border-radius: 2px; overflow: hidden; margin-top: 2px; min-width: 60px; background: var(--pill); }
.nv-states i { display: block; } .nv-states i.ok { background: var(--ok); } .nv-states i.warn { background: var(--warn); } .nv-states i.bad { background: var(--danger); } .nv-states i.idle { background: var(--line2); }
.nv-matrix .bar { min-width: 70px; }
.bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--danger); }
.legend b.g { color: var(--ok); font-weight: 400; } .legend b.r { color: var(--danger); font-weight: 400; }
.nv-pathcard { margin-bottom: 12px; } .nv-path { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 4px 0; }
.nv-path .arr { color: var(--muted); }
+34 -17
View File
@@ -30,10 +30,12 @@ function inCidr(ip, cidr) {
}
// ---------------------------------------------------------------- model
// topoModel groups subnets into segments (one per VLAN), attaches racks and machines.
function topoModel() {
// topoModel groups subnets into segments (one per VLAN), attaches racks and
// machines; f (netview.js nvFilter) keeps part of the site.
function topoModel(f = {}) {
const keepSub = f.subnet || (() => true), keepRack = f.rack || (() => true), keepM = f.machine || (() => true);
const segs = [], byVlan = {};
for (const s of S.subnets) {
for (const s of S.subnets.filter(keepSub)) {
const key = s.vlan_id ? 'v' + s.vlan_id : 'c' + s.cidr;
if (!byVlan[key]) { byVlan[key] = { key, fabric: s.fabric, vid: s.vid, mtu: s.mtu, subnets: [], racks: new Set(), dhcp: false, purpose: s.purpose }; segs.push(byVlan[key]); }
const g = byVlan[key];
@@ -44,7 +46,7 @@ function topoModel() {
segs.sort((a, b) => (b.dhcp - a.dhcp) || String(a.fabric).localeCompare(String(b.fabric)) || a.vid - b.vid);
const segOf = ip => segs.findIndex(g => g.subnets.some(s => inCidr(ip, s.cidr)));
// rack controllers: the segments they serve DHCP on, plus those their interfaces sit on
const racks = S.controllers.map(c => {
const racks = S.controllers.filter(c => keepRack(c.name)).map(c => {
const at = new Set();
segs.forEach((g, i) => { if (g.racks.has(c.name)) at.add(i); });
for (const itf of (c.interfaces || [])) for (const a of (itf.addrs || [])) { const i = segOf(a); if (i >= 0) at.add(i); }
@@ -53,7 +55,7 @@ function topoModel() {
// machines: every address Rollcall knows for them
const ipsBy = {};
for (const x of S.ips) if (x.machine_id) (ipsBy[x.machine_id] = ipsBy[x.machine_id] || []).push(x.ip);
const ms = S.machines.map(m => {
const ms = S.machines.filter(keepM).map(m => {
const at = new Set();
for (const ip of [...(ipsBy[m.id] || []), m.mgmt_ip, m.ib_ip]) { if (!ip) continue; const i = segOf(ip); if (i >= 0) at.add(i); }
return { m, at: [...at].sort((a, b) => a - b) };
@@ -75,22 +77,36 @@ const stateClass = st => /failed/.test(st) ? 'bad' : /deploying|releasing|recomm
// topoSVG({compact}) -> svg markup. compact: overview card (fewer labels, collapsed groups).
function topoSVG(opt = {}) {
const { segs, racks, ms } = topoModel();
if (!segs.length && !racks.length) return '<div class="empty">No subnets or rack controllers yet.</div>';
const model = topoModel(opt.filter), { segs } = model;
let { racks, ms } = model;
const filtered = !!(opt.filter && opt.filter.active);
if (filtered) ms = ms.filter(x => x.at.length); // machines elsewhere are not part of this view
if (!segs.length && !racks.length) return '<div class="empty">No subnets or rack controllers match.</div>';
const compact = !!opt.compact;
const BW = compact ? 112 : 156, BH = compact ? 40 : 50, GAP = compact ? 12 : 16, M = 24;
const collapseAt = compact ? 4 : 8;
const maxItems = compact ? 10 : 28; // more boxes than this and the drawing stops being readable
// machine items: one box per machine, or one per group of machines with the same wiring
const groups = {};
for (const x of ms) { const k = (x.m.rack_controller || '') + '|' + x.at.join(','); (groups[k] = groups[k] || []).push(x); }
// machine items: one box per machine, or one per group of machines with the
// same wiring; when that still makes too many, coarser groups: by rack and
// first VLAN, then by rack alone (a group is wired to every VLAN of its members)
const rackIdx = name => { const i = racks.findIndex(r => r.c.name === name); return i < 0 ? 999 : i; };
let items = [];
for (const [k, xs] of Object.entries(groups)) {
const rack = k.split('|')[0];
if (xs.length >= collapseAt) items.push({ group: xs, at: xs[0].at, rack });
else for (const x of xs) items.push({ m: x.m, at: x.at, rack });
}
const build = (key, at) => {
const groups = {};
for (const x of ms) { const k = (x.m.rack_controller || '') + '|' + key(x); (groups[k] = groups[k] || []).push(x); }
const out = [];
for (const [k, xs] of Object.entries(groups)) {
const rack = k.split('|')[0];
if (xs.length >= collapseAt || at) out.push({ group: xs, at: [...new Set(xs.flatMap(x => x.at))].sort((a, b) => a - b), rack });
else for (const x of xs) out.push({ m: x.m, at: x.at, rack });
}
return out;
};
let items = build(x => x.at.join(','));
if (items.length > maxItems) items = build(x => String(x.at[0] ?? ''), true);
if (items.length > maxItems) items = build(() => '', true);
for (const it of items) if (it.group && it.group.length === 1) { it.m = it.group[0].m; delete it.group; }
if (filtered) racks = racks.filter(r => r.at.length || items.some(it => it.rack === r.c.name));
items.sort((a, b) => rackIdx(a.rack) - rackIdx(b.rack) || (a.at[0] ?? 99) - (b.at[0] ?? 99) || String(a.m ? nameOf(a.m) : '').localeCompare(String(b.m ? nameOf(b.m) : '')));
const minW = compact ? 640 : 980;
@@ -119,7 +135,8 @@ function topoSVG(opt = {}) {
if (hasIPAM) W = Math.max(W, ix + iw / 2 + M);
const o = [];
o.push(`<svg class="topo${compact ? ' compact' : ''}" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" style="max-width:100%;height:auto" role="img" aria-label="network topology">`);
// the overview card shrinks it to fit; the network page scrolls instead (text stays readable)
o.push(`<svg class="topo${compact ? ' compact' : ''}" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}"${compact ? ' style="max-width:100%;height:auto"' : ''} role="img" aria-label="network topology">`);
// segments (buses) with their labels in the left gutter
segs.forEach((g, i) => {
const y = segY[i];