NetBox's web UI through Rollcall, and links to it from the web UI
With NetBox as the IPAM under a path (its BASE_PATH) and ipam.url carrying it, Rollcall serves NetBox's UI at that same path, for admins only (the admin certificate, as for the API); NetBox keeps its own login. Redirects that name NetBox's own address are turned back to Rollcall's, Rollcall's credentials are not passed on. NetBox opens wherever Rollcall does: a lab NetBox on a segment the browser cannot reach, say. The web UI links to NetBox: the sidebar, sites, rooms, racks, switches and a machine's device (by its rollcall_machine field). ipam.ui_url points the links at NetBox directly instead. NetBox paging under a BASE_PATH doubled the path on the next page (the next link carries it already); fixed. The lab NetBox moves under /netbox/ and trusts the region's addresses for its forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c31a89482e
commit
cc1245da1e
11 files changed
+214
-12
No files matched your search
@@ -7,6 +7,15 @@ publish a tag that has no section here.
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Rooms in 3D (three.js shipped in the binary, loaded on first use): racks at their places and
|
||||
height, servers drawn from their model's front (drive bays, ears, vents; no photos or logos) with
|
||||
the state on the ear, multi-node sleds side by side, backs with power supplies and the network
|
||||
cards' ports. Drag to turn, double click to go to a rack; selection is shared with the floor plan.
|
||||
- Cabling from LLDP: `GET /api/v1/cabling` (each machine's ports and the switch port they lead to),
|
||||
switches placed from NetBox or by hand (`POST`/`DELETE /api/v1/switches`), cables drawn in the 3D
|
||||
room from port to switch port, coloured per switch, and listed per rack in the side panel.
|
||||
- NetBox's web UI through Rollcall at its `BASE_PATH` (admins only), and links to NetBox from the
|
||||
web UI (sidebar, sites, rooms, racks, switches, machine devices); `ipam.ui_url` for direct links.
|
||||
- Sites page: sites on an OpenStreetMap map (Leaflet shipped in the binary), a site's rooms, and a
|
||||
room's floor plan with racks on 600 mm tiles coloured by their machines; a rack opens its front.
|
||||
Racks are placed by dragging and rotated in an edit mode; unplaced ones are laid out
|
||||
@@ -37,6 +46,11 @@ publish a tag that has no section here.
|
||||
### Changed
|
||||
- `rollcall ca rotate -yes` (replace the root, racks join again) is gone; the three steps replace it.
|
||||
|
||||
### Fixed
|
||||
- A rack typed in from a machine's location and the same rack from NetBox in another case showed
|
||||
twice; the layout sync folds it into NetBox's spelling (place, comment and machines follow).
|
||||
- NetBox paging under a `BASE_PATH` doubled the path on the next page.
|
||||
|
||||
## [0.3.0] - 2026-10-30
|
||||
|
||||
Third release: working with a site's existing network services (DNS provider, fixed leases on
|
||||
|
||||
@@ -878,6 +878,37 @@ The NetBox user needs `view/add/change/delete` on `dcim.device`,
|
||||
`dcim.devicetype` and `dcim.devicerole`, and `view` on `dcim.location` and
|
||||
`dcim.rack`, on top of the IPAM permissions.
|
||||
|
||||
### NetBox's UI through Rollcall
|
||||
|
||||
When NetBox runs under a path (its `BASE_PATH`, e.g. `BASE_PATH = 'netbox/'`)
|
||||
and `ipam.url` carries it (`"url": "https://netbox.example/netbox/"`), Rollcall
|
||||
serves NetBox's web UI at that same path, `https://<rollcall>/netbox/`, for
|
||||
admins only (the admin certificate, as for the API). NetBox keeps its own login.
|
||||
This opens NetBox wherever Rollcall opens, also when the browser cannot reach
|
||||
NetBox itself. Two settings on the NetBox side:
|
||||
|
||||
```python
|
||||
BASE_PATH = 'netbox/'
|
||||
CSRF_TRUSTED_ORIGINS = ['https://rollcall.example'] # where browsers post from
|
||||
```
|
||||
|
||||
The web UI then links to NetBox: the sidebar, a site, room and rack on the Sites
|
||||
pages, a switch, and a machine's device. `ipam.ui_url` points those links
|
||||
elsewhere (NetBox reached directly) when that is preferred; a NetBox at the root
|
||||
of its host gets links to `ui_url` only.
|
||||
|
||||
### Cabling and switches
|
||||
|
||||
`GET /api/v1/cabling` gives each located machine's ports and the switch port
|
||||
each is plugged into, from the LLDP its commissioning saw (`lldpd` in the
|
||||
commissioning image). A switch's place is NetBox's (the device with that name,
|
||||
its rack and position, read with the layout on every reconcile; the NetBox user
|
||||
needs `view` on `dcim.device`) or set by hand (`POST /api/v1/switches
|
||||
{"name","building","room","rack","unit"}`, which NetBox does not move; `DELETE
|
||||
?name=` forgets it). The 3D room draws the backs of the servers, the switches
|
||||
and the cables; a switch with no place is drawn where most of its cables are,
|
||||
marked as estimated.
|
||||
|
||||
### Infoblox
|
||||
|
||||
The same contract over Infoblox WAPI (v2.12 by default; give a full
|
||||
|
||||
@@ -38,7 +38,8 @@ import (
|
||||
|
||||
type IPAMConfig struct {
|
||||
Provider string `json:"provider"` // "" = built-in only | netbox | infoblox
|
||||
URL string `json:"url"` // https://netbox.example
|
||||
URL string `json:"url"` // https://netbox.example; with NetBox's BASE_PATH (…/netbox/) its UI is served here too (nbproxy.go)
|
||||
UIURL string `json:"ui_url"` // where "open in NetBox" links go when not through Rollcall
|
||||
TokenFile string `json:"token_file"` // API token (NetBox v2 "nbt_..." or v1)
|
||||
User string `json:"user"` // Infoblox WAPI user
|
||||
PasswordFile string `json:"password_file"` // Infoblox WAPI password
|
||||
@@ -415,7 +416,7 @@ func (a *App) handleIPAM(w http.ResponseWriter, r *http.Request) {
|
||||
a.ipamSt.mu.Lock()
|
||||
last := a.ipamSt.last
|
||||
a.ipamSt.mu.Unlock()
|
||||
writeJSON(w, 200, obj{"provider": a.ipam.Name(), "url": a.cfg.IPAM.URL, "dns_zone": a.cfg.IPAM.DNSZone,
|
||||
writeJSON(w, 200, obj{"provider": a.ipam.Name(), "url": a.cfg.IPAM.URL, "ui": a.netboxUILink(), "dns_zone": a.cfg.IPAM.DNSZone,
|
||||
"tag": a.cfg.IPAM.tag(), "machine_field": a.cfg.IPAM.field(), "last_sync": last})
|
||||
}
|
||||
|
||||
@@ -537,9 +538,10 @@ func (n *netBox) do(ctx context.Context, method, path string, body, out any) err
|
||||
rd = bytes.NewReader(b)
|
||||
}
|
||||
u := n.base + "/api/" + strings.TrimPrefix(path, "/")
|
||||
if strings.HasPrefix(path, "http") { // a "next" link: keep our base, the server may name itself differently
|
||||
if strings.HasPrefix(path, "http") { // a "next" link: keep our scheme and host, the server may name itself differently
|
||||
if p, err := url.Parse(path); err == nil {
|
||||
u = n.base + p.Path
|
||||
b, _ := url.Parse(n.base)
|
||||
u = b.Scheme + "://" + b.Host + p.Path // p.Path has NetBox's BASE_PATH already
|
||||
if p.RawQuery != "" {
|
||||
u += "?" + p.RawQuery
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
// The NetBox web UI through Rollcall, so it opens wherever Rollcall's does
|
||||
// (a lab NetBox on a network the browser cannot reach, say). With NetBox as
|
||||
// the IPAM and its url carrying a path (NetBox's BASE_PATH:
|
||||
// "url": "https://netbox.example/netbox/"), that path on Rollcall is NetBox,
|
||||
// for admins only (the admin certificate, as for the API). NetBox keeps its
|
||||
// own login and session. Its CSRF_TRUSTED_ORIGINS must list Rollcall's
|
||||
// address for its forms to work: the browser posts from there.
|
||||
//
|
||||
// ui_url, when set, is where links to NetBox point instead (NetBox reached
|
||||
// directly); the proxy stays.
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// netboxUIPath: the path NetBox is served under here ("/netbox"), "" when there is no proxy
|
||||
func (a *App) netboxUIPath() string {
|
||||
if _, ok := a.ipam.(*netBox); !ok {
|
||||
return ""
|
||||
}
|
||||
u, err := url.Parse(a.cfg.IPAM.URL)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
p := strings.TrimRight(u.Path, "/")
|
||||
if p == "" || strings.HasPrefix(p, "/api") || strings.HasPrefix(p, "/rollcall") || strings.HasPrefix(p, "/images") || strings.HasPrefix(p, "/os") {
|
||||
return "" // NetBox at the root would shadow Rollcall's own paths
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// netboxUILink: where the UI's "open in NetBox" links go
|
||||
func (a *App) netboxUILink() string {
|
||||
if a.cfg.IPAM.UIURL != "" {
|
||||
return strings.TrimRight(a.cfg.IPAM.UIURL, "/")
|
||||
}
|
||||
return a.netboxUIPath()
|
||||
}
|
||||
|
||||
func (a *App) netboxProxy() http.Handler {
|
||||
nb := a.ipam.(*netBox)
|
||||
target, _ := url.Parse(nb.base)
|
||||
origin := target.Scheme + "://" + target.Host
|
||||
return &httputil.ReverseProxy{
|
||||
Transport: nb.client.Transport,
|
||||
Rewrite: func(pr *httputil.ProxyRequest) {
|
||||
pr.Out.URL.Scheme, pr.Out.URL.Host = target.Scheme, target.Host
|
||||
pr.Out.Host = target.Host
|
||||
pr.Out.Header.Del("Authorization") // Rollcall's credentials are not NetBox's
|
||||
pr.SetXForwarded()
|
||||
},
|
||||
ModifyResponse: func(resp *http.Response) error {
|
||||
if loc := resp.Header.Get("Location"); strings.HasPrefix(loc, origin+"/") { // keep the browser here
|
||||
resp.Header.Set("Location", strings.TrimPrefix(loc, origin))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNetBoxUIPath(t *testing.T) {
|
||||
for url, want := range map[string]string{"https://nb.example/netbox/": "/netbox", "https://nb.example": "", "https://nb.example/api/": "", "http://10.0.0.6/ipam/nb": "/ipam/nb"} {
|
||||
a := &App{cfg: &Config{IPAM: IPAMConfig{URL: url}}, ipam: &netBox{base: url}}
|
||||
if got := a.netboxUIPath(); got != want {
|
||||
t.Errorf("%s: %q, want %q", url, got, want)
|
||||
}
|
||||
}
|
||||
if (&App{cfg: &Config{IPAM: IPAMConfig{URL: "https://x/netbox/"}}}).netboxUIPath() != "" {
|
||||
t.Error("no NetBox IPAM, no proxy")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetBoxProxy(t *testing.T) {
|
||||
var seen *http.Request
|
||||
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seen = r
|
||||
if r.URL.Path == "/netbox/" {
|
||||
http.Redirect(w, r, "http://"+r.Host+"/netbox/login/?next=/netbox/", http.StatusFound) // NetBox names itself
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, "netbox page")
|
||||
}))
|
||||
defer up.Close()
|
||||
a := &App{cfg: &Config{IPAM: IPAMConfig{URL: up.URL + "/netbox/"}}, ipam: &netBox{base: up.URL + "/netbox", client: up.Client()}}
|
||||
h := a.netboxProxy()
|
||||
|
||||
req := httptest.NewRequest("GET", "https://rollcall.example/netbox/", nil)
|
||||
req.Header.Set("Authorization", "Bearer rollcall-admin")
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusFound || rec.Header().Get("Location") != "/netbox/login/?next=/netbox/" {
|
||||
t.Fatalf("redirect: %d %q", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
if seen.Header.Get("Authorization") != "" {
|
||||
t.Fatal("Rollcall's credentials went to NetBox")
|
||||
}
|
||||
rec = httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, httptest.NewRequest("GET", "https://rollcall.example/netbox/dcim/sites/?q=lab", nil))
|
||||
if rec.Body.String() != "netbox page" || seen.URL.RequestURI() != "/netbox/dcim/sites/?q=lab" || seen.Header.Get("X-Forwarded-Host") != "rollcall.example" {
|
||||
t.Fatalf("page: %q %s %q", rec.Body.String(), seen.URL.RequestURI(), seen.Header.Get("X-Forwarded-Host"))
|
||||
}
|
||||
}
|
||||
|
||||
// a NetBox under a BASE_PATH names its next pages with that path: it must not be doubled
|
||||
func TestNetBoxNextLinkBasePath(t *testing.T) {
|
||||
var paths []string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
paths = append(paths, r.URL.Path)
|
||||
if r.URL.Query().Get("offset") == "" {
|
||||
fmt.Fprintf(w, `{"results": [{"id": 1}], "next": "http://elsewhere%s?limit=500&offset=500"}`, r.URL.Path)
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, `{"results": [{"id": 2}], "next": null}`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
n := &netBox{base: srv.URL + "/netbox", token: "t", client: srv.Client()}
|
||||
got, err := n.all(context.Background(), "dcim/sites/", nil)
|
||||
if err != nil || len(got) != 2 || paths[1] != "/netbox/api/dcim/sites/" {
|
||||
t.Fatalf("%v %d %v", err, len(got), paths)
|
||||
}
|
||||
}
|
||||
@@ -287,6 +287,9 @@ func (a *App) routes() http.Handler {
|
||||
mux.HandleFunc("DELETE /api/v1/racks", a.adminAuth(a.handleRacks))
|
||||
mux.HandleFunc("POST /api/v1/racks/positions", a.adminAuth(a.handleRackPositions))
|
||||
mux.HandleFunc("GET /api/v1/cabling", a.adminAuth(a.handleCabling))
|
||||
if p := a.netboxUIPath(); p != "" {
|
||||
mux.Handle(p+"/", a.adminAuth(a.netboxProxy().ServeHTTP))
|
||||
}
|
||||
mux.HandleFunc("POST /api/v1/switches", a.adminAuth(a.handleSwitches))
|
||||
mux.HandleFunc("DELETE /api/v1/switches", a.adminAuth(a.handleSwitches))
|
||||
mux.HandleFunc("GET /api/v1/sites", a.adminAuth(a.handleSites))
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
// Rollcall web UI: a fleet view first (filters, selection, bulk actions), machine detail second.
|
||||
const $ = (s, el = document) => el.querySelector(s);
|
||||
const $$ = (s, el = document) => Array.from(el.querySelectorAll(s));
|
||||
// nbLink: "open in NetBox" for a NetBox page (path and query), when NetBox is the IPAM
|
||||
function nbLink(path, label = 'NetBox ↗') {
|
||||
const ui = S.ipam && S.ipam.provider === 'netbox' && S.ipam.ui;
|
||||
return ui ? `<a class="nb-link" href="${esc(ui + path)}" target="_blank" rel="noopener" title="open in NetBox">${esc(label)}</a>` : '';
|
||||
}
|
||||
const nbQ = o => '?' + new URLSearchParams(Object.entries(o).filter(([, v]) => v)).toString();
|
||||
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||||
const human = n => { n = Number(n || 0); const u = ['B', 'K', 'M', 'G', 'T', 'P']; let i = 0; while (n >= 1024 && i < u.length - 1) { n /= 1024; i++; } return (i <= 2 ? n.toFixed(0) : n.toFixed(1)) + u[i]; };
|
||||
const ago = ts => { if (!ts) return '-'; const s = (Date.now() - new Date(ts)) / 1000; if (s < 90) return `${s | 0}s`; if (s < 5400) return `${(s / 60) | 0}m`; if (s < 172800) return `${(s / 3600) | 0}h`; return `${(s / 86400) | 0}d`; };
|
||||
@@ -82,6 +88,7 @@ async function refresh(full) {
|
||||
[S.ips, S.ipam] = await Promise.all([api('GET', '/api/v1/ips'), api('GET', '/api/v1/ipam').catch(() => null)]);
|
||||
}
|
||||
$('#n-machines').textContent = machines.length;
|
||||
const nb = $('#nav-netbox'), ui = S.ipam && S.ipam.provider === 'netbox' && S.ipam.ui; nb.hidden = !ui; if (ui) nb.href = ui + '/';
|
||||
const active = S.jobs.filter(j => j.state === 'pending' || j.state === 'running').length;
|
||||
$('#n-jobs').textContent = active ? `${active} active` : '';
|
||||
$('#status').textContent = `updated ${new Date().toLocaleTimeString()}`;
|
||||
@@ -513,7 +520,7 @@ function pageMachine(d, tab) {
|
||||
|
||||
const hasJob = !!s.job;
|
||||
return `
|
||||
<div class="d-head"><a href="#/machines" class="btn ghost">← Machines</a><h1>${esc(nameOf(s))}</h1>${pill(s.state)}<span class="id">${esc(s.id)}</span>
|
||||
<div class="d-head"><a href="#/machines" class="btn ghost">← Machines</a><h1>${esc(nameOf(s))}</h1>${pill(s.state)}<span class="id">${esc(s.id)}</span>${nbLink('/dcim/devices/' + nbQ({ ['cf_' + ((S.ipam || {}).machine_field || 'rollcall_machine')]: s.id }), 'NetBox device ↗')}
|
||||
<div class="right" style="margin-left:auto;display:flex;gap:6px;flex-wrap:wrap">
|
||||
${menuBtn('Power', [['status', 'Status'], ['on', 'Power on'], ['off', 'Power off'], ['soft', 'Soft off'], ['cycle', 'Power cycle'], ['reset', 'Reset']], 'dpower')}
|
||||
${menuBtn('Boot device', [['pxe', 'PXE'], ['disk', 'Disk'], ['bios', 'BIOS setup'], ['cdrom', 'CD-ROM']], 'dboot')}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<a href="#/tags" data-nav="tags">Tags</a>
|
||||
<a href="#/profiles" data-nav="profiles">Profiles</a>
|
||||
<a href="#/images" data-nav="images">OS images</a>
|
||||
<a id="nav-netbox" href="#" target="_blank" rel="noopener" hidden title="NetBox, through Rollcall: its own login">NetBox ↗</a>
|
||||
<div class="side-foot">
|
||||
<span id="status" class="muted"></span>
|
||||
<button id="logout" class="btn ghost" title="forget the admin token">Token</button>
|
||||
|
||||
@@ -66,7 +66,7 @@ function pageSites() {
|
||||
const st = siteStats(s);
|
||||
const where = s.lat != null ? `<span class="mono muted">${s.lat.toFixed(4)}, ${s.lon.toFixed(4)}</span>` : '<span class="muted">not on the map</span>';
|
||||
return [`<a href="#/sites/${encodeURIComponent(s.name)}"><b>${esc(s.name)}</b></a>${s.address ? `<br><span class="muted">${esc(s.address)}</span>` : ''}`,
|
||||
`<span class="pill tag">${esc(s.source)}</span>`, st.rooms.filter(Boolean).length || '—', st.racks.length, st.ms.length,
|
||||
`<span class="pill tag">${esc(s.source)}</span>${s.source === 'netbox' ? ' ' + nbLink('/dcim/sites/' + nbQ({ slug: s.slug || '', name: s.slug ? '' : s.name }), '↗') : ''}`, st.rooms.filter(Boolean).length || '—', st.racks.length, st.ms.length,
|
||||
`<span class="dot ${st.worst}"></span>${esc(groupLine(Object.fromEntries(st.ms.map(m => [m.state, st.ms.filter(x => x.state === m.state).length])), 40) || '—')}`,
|
||||
where, `<button class="btn sm" data-place="${esc(s.name)}">${s.lat != null ? 'move' : 'place on map'}</button>`];
|
||||
});
|
||||
@@ -141,7 +141,7 @@ function pageSite(name) {
|
||||
<div class="muted">${racks.length} racks · ${ms.length} machines${bad ? ` · <span class="bad">${bad} failed</span>` : ''}</div></a>`;
|
||||
});
|
||||
return `<div class="page-head"><h1><a href="#/sites" class="muted" style="font-weight:400">Sites</a> / ${esc(site.name)}</h1><span class="sub">${esc(site.address || '')} · ${st.racks.length} racks · ${st.ms.length} machines</span>
|
||||
<div class="right"><button class="btn" id="new-room">New room…</button></div></div>
|
||||
<div class="right">${site.source === 'netbox' ? nbLink('/dcim/sites/' + nbQ({ slug: site.slug || '', name: site.slug ? '' : site.name })) : ''}<button class="btn" id="new-room">New room…</button></div></div>
|
||||
${cards.length ? `<div class="room-cards">${cards.join('')}</div>` : '<div class="empty">No rooms or racks here yet: add a room, or set machines\' location to this site.</div>'}`;
|
||||
}
|
||||
function wireSite(name) {
|
||||
@@ -213,7 +213,8 @@ function pageRoom(siteName, roomArg) {
|
||||
const racks = racksOnFloor(site, room);
|
||||
const autoN = racks.filter(r => r.auto).length, v3 = !SITE.edit && roomView.get() === '3d';
|
||||
const selRack = racks.find(r => r.name === SITE.sel);
|
||||
const panel = selRack ? `<div class="card floor-side"><h3>${esc(selRack.name)} <span class="muted">${selRack.height}U · front ${({ N: 'north', S: 'south', E: 'east', W: 'west' })[selRack.facing]}</span></h3>
|
||||
const nbSite = (siteOf(site.name) || {}).slug || '';
|
||||
const panel = selRack ? `<div class="card floor-side"><h3>${esc(selRack.name)} <span class="muted">${selRack.height}U · front ${({ N: 'north', S: 'south', E: 'east', W: 'west' })[selRack.facing]}</span> ${nbLink('/dcim/racks/' + nbQ({ name: selRack.name, site: nbSite }))}</h3>
|
||||
${SITE.edit ? `<div class="actions" style="margin-bottom:8px"><button class="btn sm" id="rk-rotate">Rotate</button></div>` : ''}
|
||||
${rackElev(selRack)}${cablingTable(site, selRack)}</div>`
|
||||
: `<div class="card floor-side"><span class="muted">Click a rack for its front.${autoN ? `<br><br>${autoN} rack(s) have no place yet and are laid out automatically (${v3 ? 'see-through' : 'dashed'}): Edit layout to place them.` : ''}</span>${v3 ? switchTable() : ''}</div>`;
|
||||
@@ -221,7 +222,7 @@ function pageRoom(siteName, roomArg) {
|
||||
: `<span><b class="lg vacant"></b>empty</span><span>thick edge: the front · bar: units used${SITE.edit ? ' · drag to move, select and Rotate' : ''}</span>`;
|
||||
return `<div class="page-head"><h1><a href="#/sites" class="muted" style="font-weight:400">Sites</a> / <a href="#/sites/${encodeURIComponent(site.name)}" class="muted" style="font-weight:400">${esc(site.name)}</a> / ${esc(room || '(no room)')}</h1>
|
||||
<span class="sub">${racks.length} racks · floor tiles of 600 mm</span>
|
||||
<div class="right">${SITE.edit ? '<button class="btn" id="fl-cancel">Cancel</button><button class="btn" id="fl-auto">Automatic again</button><button class="btn primary" id="fl-save">Save layout</button>'
|
||||
<div class="right">${room ? nbLink('/dcim/locations/' + nbQ({ name: room, site: nbSite })) : ''}${SITE.edit ? '<button class="btn" id="fl-cancel">Cancel</button><button class="btn" id="fl-auto">Automatic again</button><button class="btn primary" id="fl-save">Save layout</button>'
|
||||
: `<span class="seg-btns"><button class="btn${v3 ? '' : ' on'}" data-roomview="2d">2D</button><button class="btn${v3 ? ' on' : ''}" data-roomview="3d">3D</button></span>${v3 ? `<span class="seg-btns" title="servers: their fronts as the model has them, or blocks in their state's colour"><button class="btn${frontView.get() === 'real' ? ' on' : ''}" data-fronts="real">Fronts</button><button class="btn${frontView.get() === 'state' ? ' on' : ''}" data-fronts="state">State</button></span><button class="btn${cablesView.get() ? ' on' : ''}" id="r3-cables" title="cables from the servers' ports to their switches (LLDP)">Cables</button><button class="btn" id="r3-turn" title="look from the other side: the backs, the switches and the cables">Turn around</button><button class="btn" id="r3-reset">Reset view</button>` : ''}<button class="btn" id="fl-edit">Edit layout</button>`}</div></div>
|
||||
<div class="floor-wrap"><div class="card floor-card">${v3 ? '<div id="room3d" class="room3d"></div>' : floorSVG(site, room)}
|
||||
<div class="legend"><span><b class="lg ok"></b>deployed / ready</span><span><b class="lg warn"></b>busy / new</span><span><b class="lg bad"></b>failed</span>${legend}</div></div>${panel}</div>`;
|
||||
@@ -314,7 +315,7 @@ function switchTable() {
|
||||
const sws = (typeof R3 !== 'undefined' && R3.switches) || []; if (!sws.length) return '';
|
||||
const where = s => s.away ? `in ${esc(s.away)}` : s.at ? `${esc(rackLabel(s.at.rack))} U${s.at.unit}${s.at.estimated ? ' <span class="warn">estimated</span>' : ` <span class="muted">${esc(s.source)}</span>`}` : '';
|
||||
return `<h3 style="margin-top:12px">Switches</h3><div class="sw-list">${sws.map(s => `<div class="sw-row"><b class="sw-dot" style="background:${esc(s.color)}"></b>
|
||||
<div><div><b>${esc(s.name)}</b>${s.model ? ` <span class="muted">${esc(s.model)}</span>` : ''}</div><div class="muted">${where(s)} · ${s.here} cables</div></div>
|
||||
<div><div><b>${esc(s.name)}</b>${s.model ? ` <span class="muted">${esc(s.model)}</span>` : ''} ${s.source === 'netbox' ? nbLink('/dcim/devices/' + nbQ({ name: s.name }), '↗') : ''}</div><div class="muted">${where(s)} · ${s.here} cables</div></div>
|
||||
<button class="btn sm" data-swplace="${esc(s.name)}">place…</button></div>`).join('')}</div>
|
||||
<p class="muted">A switch's place comes from NetBox (its rack and position) or is set here; without either it is drawn where most of its cables are.</p>`;
|
||||
}
|
||||
|
||||
@@ -239,3 +239,5 @@ svg.floor .rk text { font-size: 9px; fill: var(--fg); pointer-events: none; font
|
||||
.r3-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
|
||||
.sw-list { display: grid; gap: 6px; } .sw-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
|
||||
.sw-row > div { min-width: 0; overflow-wrap: anywhere; } .sw-dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
|
||||
.nb-link { font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; white-space: nowrap; align-self: center; }
|
||||
.page-head .right .nb-link { margin-right: 6px; }
|
||||
@@ -3,6 +3,9 @@
|
||||
# container on the lab segment, so tests never write to a real NetBox.
|
||||
# Same install as netops (altyapi hosts/netops/kurulum.sh) without PowerDNS,
|
||||
# ACME and backups; plain HTTP on :80 (the segment is isolated).
|
||||
# NetBox lives under /netbox/ (BASE_PATH) so the region can serve its UI
|
||||
# through Rollcall (cmd/rollcall/nbproxy.go): Rollcall's ipam url is then
|
||||
# http://$MYIP/netbox/, and ROLLCALL_ORIGINS are where browsers post from.
|
||||
#
|
||||
# Run as root inside the container; rerunnable. Secrets are generated here:
|
||||
# /etc/lab-netbox/secrets.env (admin password, Rollcall's API token)
|
||||
@@ -16,6 +19,7 @@ set -euo pipefail
|
||||
NETBOX_VERSION=${NETBOX_VERSION:-4.7.4}
|
||||
MYIP=${MYIP:-10.213.77.6}
|
||||
SITE=${SITE:-lab}
|
||||
ROLLCALL_ORIGINS=${ROLLCALL_ORIGINS:-"https://10.0.0.234 https://10.213.77.1"}
|
||||
PREFIXES=${PREFIXES:-"10.213.77.0/24 10.213.78.0/24 10.213.79.0/24 fd00:213:77::/64 fd00:213:78::/64"}
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -69,7 +73,8 @@ REDIS = {
|
||||
SECRET_KEY = '$NETBOX_SECRET_KEY'
|
||||
API_TOKEN_PEPPERS = {1: '$NETBOX_PEPPER'}
|
||||
TIME_ZONE = 'Europe/Stockholm'
|
||||
CSRF_TRUSTED_ORIGINS = ['http://$MYIP']
|
||||
BASE_PATH = 'netbox/'
|
||||
CSRF_TRUSTED_ORIGINS = ['http://$MYIP'$(for o in $ROLLCALL_ORIGINS; do printf ", '%s'" "$o"; done)]
|
||||
EOF
|
||||
chown -R netbox:netbox $D/netbox/media $D/netbox/reports $D/netbox/scripts 2>/dev/null || true
|
||||
cd /opt/netbox && PYTHON=/usr/bin/python3 ./upgrade.sh >/var/log/netbox-upgrade.log 2>&1 || { tail -40 /var/log/netbox-upgrade.log; exit 1; }
|
||||
@@ -84,7 +89,8 @@ systemctl restart netbox netbox-rq
|
||||
cat > /etc/caddy/Caddyfile <<EOF
|
||||
# pxestuff lab/netbox/install.sh
|
||||
http://$MYIP, http://localhost {
|
||||
handle_path /static/* {
|
||||
redir / /netbox/
|
||||
handle_path /netbox/static/* {
|
||||
root * /opt/netbox/netbox/static
|
||||
file_server
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user