// public/views/cards/cluster.js — Proxmox cluster health + quorum across nodes. import { el, mount } from '../../dom.js'; import { api } from '../../api.js'; let body, timer; function nodeRow(n, master) { const tags = []; if (n.local) tags.push('local'); if (master === n.name) tags.push('master'); return el('div', { class: 'sv-row status-' + (n.online ? 'ok' : 'down') }, el('span', { class: 'k' }, el('span', { class: 'dot' }), n.name), el('span', {}, (n.online ? 'online' : 'OFFLINE') + (tags.length ? ' · ' + tags.join(' · ') : ''))); } async function load() { if (!body) return; try { const c = await api.get('/api/cluster'); if (c.error) { mount(body, el('span', { class: 'muted' }, 'Cluster: ' + c.error)); return; } const haIssues = c.ha?.services_error || 0; const rows = el('div', { class: 'sv-cluster' }, el('div', { class: 'sv-row' }, el('span', { class: 'k' }, 'Quorum'), el('span', { class: 'cl-badge ' + (c.quorate ? 'ok' : 'bad') }, c.quorate ? 'QUORATE' : 'NO QUORUM')), el('div', { class: 'sv-row' }, el('span', { class: 'k' }, 'Nodes'), el('span', { class: c.nodes_online < c.nodes_total ? 'warn' : '' }, `${c.nodes_online}/${c.nodes_total} online`)), ...(c.nodes || []).map(n => nodeRow(n, c.ha?.master)), el('div', { class: 'sv-row' }, el('span', { class: 'k' }, 'HA services'), el('span', { class: haIssues ? 'warn' : '' }, haIssues ? `${c.ha.services_total} · ${haIssues} ⚠` : `${c.ha?.services_total ?? 0} · ok`)) ); mount(body, rows); } catch { mount(body, el('span', { class: 'muted' }, 'Cluster unavailable')); } } export default { id: 'cluster', title: 'Cluster · HZ', size: 'm', mount(e) { body = e; load(); }, start() { timer = setInterval(load, 30000); }, stop() { clearInterval(timer); body = null; } };