Act on the console's rows: scale, class, owner, resources, adapters, restart, remove; cordon, drain, engines, upgrade; quotas; cluster tasks

Enter on a row of Models, Nodes or Replicas opens what can be done to it,
as forms and questions over the admin API. A Quotas view sets and clears
capacity quotas. Do gains serving a model, upgrading the cluster,
restarting every replica and a backup.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-03 23:23:12 +02:00
1 parent e0384fb148
commit c7d5ee16b5
3 files changed
+934 -12

No files matched your search

+95 -12
View File
@@ -35,21 +35,27 @@ const (
cModels
cReplicas
cUsage
cQuotas
cLogs
cSettings
cAddNode
cReplicate
cServe
cUpgrade
cRestartAll
cBackup
cLeave
cCount
)
var consoleLabels = [cCount]string{"Overview", "Nodes", "GPUs", "Models", "Replicas", "Usage", "Logs",
"server.yaml", "Add a node", "Replicate the store", "Leave"}
var consoleLabels = [cCount]string{"Overview", "Nodes", "GPUs", "Models", "Replicas", "Usage", "Quotas", "Logs",
"server.yaml", "Add a node", "Replicate the store", "Serve a model", "Upgrade the cluster",
"Restart all replicas", "Back up now", "Leave"}
// consoleAction is what is done once the screen closes: each runs its own
// screen, and the console comes back after.
type consoleAction struct {
kind string // "", "node", "patroni", "restart"
kind string // "", "node", "patroni", "restart", "run" (llmgw with targets as its arguments)
targets []string
}
@@ -127,6 +133,16 @@ type consoleModel struct {
editKind settings.Kind
action consoleAction
// What can be done to a row: a menu, a form, a question, and the request
// under way.
menuD *menuDialog
formD *formDialog
confirmD *confirmDialog
busy string
quotas []adminapi.QuotaView
quotasErr error
}
var usageGroupings = []string{"team", "project", "org"}
@@ -235,6 +251,9 @@ func (m consoleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.menu == cUsage {
cmds = append(cmds, m.fetchUsage())
}
if m.menu == cQuotas {
cmds = append(cmds, m.fetchQuotas())
}
if m.menu == cLogs && m.detail && m.logs.node != "" {
cmds = append(cmds, m.fetchLogs(m.logs.node))
}
@@ -250,6 +269,18 @@ func (m consoleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.usage, m.usageErr = msg.rows, msg.err
case consoleLogsMsg:
m.logs = msg
case consoleQuotasMsg:
m.quotas, m.quotasErr = msg.rows, msg.err
case actionDoneMsg:
m.busy = ""
m.dialog, m.dialogTitle = "error", msg.title
if msg.err != nil {
m.dialogText = sBad.Render("✗ ") + msg.err.Error()
} else {
m.dialogText = sOK.Render("✓ ") + msg.text
}
m.dialogText += "\n\n" + sDim.Render("any key")
return m, tea.Batch(m.fetch(), m.onEnter())
case tea.KeyMsg:
if msg.Type == tea.KeyCtrlC {
return m, tea.Quit
@@ -269,9 +300,15 @@ func (m consoleModel) entryOK(i int) bool {
func (m consoleModel) storeReplicated() bool { return len(m.data.sum.Store) > 0 }
func (m consoleModel) key(k tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.busy != "" {
return m, nil
}
if m.dialog != "" {
return m.dialogKey(k)
}
if mm, cmd, ok := m.actionKey(k); ok {
return mm, cmd
}
switch k.Type {
case tea.KeyPgDown:
m.scroll += max(1, m.height-8)
@@ -310,6 +347,8 @@ func (m consoleModel) key(k tea.KeyMsg) (tea.Model, tea.Cmd) {
return m.ask("Replicate the store", "user@address of database machine", 2)
case cLeave:
return m.leave()
case cServe, cUpgrade, cRestartAll, cBackup:
return m, m.doEntry()
case cOverview:
return m, nil
}
@@ -331,13 +370,27 @@ func (m consoleModel) key(k tea.KeyMsg) (tea.Model, tea.Cmd) {
m.row++
}
case "enter":
if !m.detail && n > 0 && m.menu != cGPUs && m.menu != cReplicas && m.menu != cUsage {
if m.detail || n == 0 || m.row >= n {
break
}
switch m.menu {
case cLogs:
m.detail, m.scroll = true, 0
if m.menu == cLogs {
node := m.data.nodes[m.row].ID
m.logs = consoleLogsMsg{node: node}
return m, m.fetchLogs(node)
}
node := m.data.nodes[m.row].ID
m.logs = consoleLogsMsg{node: node}
return m, m.fetchLogs(node)
case cNodes:
m.menuD = m.nodeMenu(m.data.nodes[m.row])
case cModels:
m.menuD = m.modelMenu(m.data.models[m.row])
case cReplicas:
m.menuD = m.replicaMenu(m.data.replicas[m.row])
case cQuotas:
m.menuD = m.quotaMenu(m.quotas[m.row])
}
case "a":
if m.menu == cQuotas {
m.quotaForm(adminapi.QuotaView{})
}
case "right", "l":
if m.menu == cUsage {
@@ -358,8 +411,11 @@ func (m consoleModel) key(k tea.KeyMsg) (tea.Model, tea.Cmd) {
// onEnter loads what a view needs when it is chosen.
func (m consoleModel) onEnter() tea.Cmd {
if m.menu == cUsage {
switch m.menu {
case cUsage:
return m.fetchUsage()
case cQuotas:
return m.fetchQuotas()
}
return nil
}
@@ -659,6 +715,8 @@ func (m consoleModel) rowCount() int {
return len(m.data.replicas)
case cUsage:
return len(m.usage)
case cQuotas:
return len(m.quotas)
}
return 0
}
@@ -718,6 +776,10 @@ func (m consoleModel) View() string {
}
f.Dialog = q + "\n\n" + m.prompt.View() + "\n\n" + sDim.Render("Enter · Esc cancel")
}
} else if m.busy != "" {
f.DialogTitle, f.Dialog = m.busy, m.spin.View()+" asking the control plane…"
} else if t, d := m.actionDialog(); d != "" {
f.DialogTitle, f.Dialog = t, d
}
return f.render()
}
@@ -725,7 +787,7 @@ func (m consoleModel) View() string {
// panel is the right-hand side for the entry chosen.
func (m consoleModel) panel() (title, body, keys string) {
pw := max(40, m.width-navWidth-8)
rowKeys := "↑↓ row · Enter detail · ← back · PgUp/PgDn · Q leave"
rowKeys := "↑↓ row · Enter actions · ← back · PgUp/PgDn · Q leave"
if !m.inPanel {
keys = "↑↓ choose · → or Enter open · Q leave · refreshed every three seconds"
}
@@ -823,7 +885,7 @@ func (m consoleModel) panel() (title, body, keys string) {
(time.Duration(r.AgeSec) * time.Second).Round(time.Second).String()})
}
if m.inPanel {
keys = "↑↓ row · ← back · PgUp/PgDn · Q leave"
keys = rowKeys
}
return "Replicas", "\n" + table([]string{"REPLICA", "MODEL", "STATE", "POOL", "ON", "AGE"}, rows, m.row, pw, m.inPanel), keys
case cUsage:
@@ -841,6 +903,8 @@ func (m consoleModel) panel() (title, body, keys string) {
keys = "↑↓ row · → grouping · ← back · Q leave"
}
return "Usage", head + table([]string{"WHO", "REQUESTS", "TOKENS", "ERRORS", "SPENT"}, rows, m.row, pw, m.inPanel), keys
case cQuotas:
return m.quotasPanel(pw)
case cSettings:
return m.settingsPanel(pw)
}
@@ -853,6 +917,18 @@ func (m consoleModel) panel() (title, body, keys string) {
item = "\n Moves the store onto two machines under Patroni, replicated,\n so losing one loses nothing.\n\n " +
sDim.Render("On the command line:") +
"\n sudo --preserve-env=SSH_AUTH_SOCK llmgw server init \\\n --patroni <user>@<a> --patroni <user>@<b> --no-mirror --no-node --no-model"
case cServe:
item = "\n Takes a GGUF model from Hugging Face to a replica that answers:\n the mirror fetches it, its checksum and memory are checked, it joins\n the catalog, and a replica is started and asked to say hello.\n\n " +
sDim.Render("On the command line:") + "\n llmgw ctl model serve OWNER/REPO"
case cUpgrade:
item = "\n Moves the cluster to a release: this machine first, then each node\n in turn. Engines keep serving; a node that does not come back stops it.\n\n " +
sDim.Render("On the command line:") + "\n sudo llmgw ctl upgrade VERSION"
case cRestartAll:
item = "\n Replaces every replica, one at a time, each new one up before the\n old one stops.\n\n " +
sDim.Render("On the command line:") + "\n llmgw ctl restart --all"
case cBackup:
item = "\n Writes the store and /etc/llmgw to one archive in " + DefaultBackupDir + ",\n and keeps the last few. Copy it off this machine.\n\n " +
sDim.Render("On the command line:") + "\n sudo llmgw server backup"
case cLeave:
item = "\n Closes the console. The cluster keeps running."
}
@@ -1114,6 +1190,13 @@ func runConsole(ctx context.Context, out io.Writer, file string) error {
// Already set up: only the store changes.
in.noMirror, in.noNode, in.noModel = true, true, true
err = in.runInitTUI(ctx, out)
case "run":
c := Root()
c.SetArgs(act.targets)
c.SetOut(out)
c.SetErr(out)
fmt.Fprintln(out, sDim.Render("llmgw "+strings.Join(act.targets, " ")))
err = c.ExecuteContext(ctx)
case "restart":
fmt.Fprintf(out, "restarting %s…\n", fm.service())
if b, e := exec.CommandContext(ctx, "systemctl", "restart", fm.service()).CombinedOutput(); e != nil {