feat(servers): distinguish rejected credentials from unreachable nodes

An offline server used to report a single "Failed to connect" state, but
"the node does not answer" and "the node answered 401" are fixed in
completely different ways — the first is power or network, the second is a
stale token, which is what happens when a node joins a cluster and its
user.cfg and priv/token.cfg are replaced by the cluster ones.

- add ProxmoxClient.check_connection() returning (ok, error_kind, error);
  token auth surfaces 401 as ResourceException rather than
  AuthenticationError, since proxmoxer validates the token on first use
- store the reason in proxmox_servers.last_error_kind (migration 40) and
  expose it through the server response
- surface an auth_error state in the UI with a hint explaining the usual
  cause

Storage listings now also report per-node availability: the cluster config
declares a storage for the whole cluster but says nothing about whether it
actually came up on a given node, so a missing volume group or pool stayed
invisible. Availability comes from a single /cluster/resources call.
This commit is contained in:
markmorado
2026-07-24 04:42:59 +05:00
parent db7411b1bf
commit 075b8cdaaa
15 changed files with 218 additions and 31 deletions

View File

@@ -8,6 +8,8 @@ const statusColors: Record<string, string> = {
unknown: 'bg-muted-foreground/30',
online: 'bg-success',
offline: 'bg-danger',
// Сервер отвечает, но отверг учётные данные — чинится не так, как «не отвечает».
auth_error: 'bg-warning',
};
interface StatusDotProps {

View File

@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Plus, Pencil, Trash2, Database, CalendarClock, Power, PowerOff } from 'lucide-react';
import { Plus, Pencil, Trash2, Database, CalendarClock, Power, PowerOff, AlertTriangle } from 'lucide-react';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
@@ -50,6 +50,8 @@ interface StorageRow {
used?: number;
total?: number;
avail?: number;
/** Ноды, где хранилище объявлено, но недоступно (нет VG/пула, отвалился mount). */
inactive_nodes?: string[];
}
interface StorageForm {
@@ -563,15 +565,34 @@ export default function StoragesTab() {
<TableHead className="text-right">{t('common.actions')}</TableHead>
</TableRow></TableHeader>
<TableBody>
{storages.map(s => (
<TableRow key={s.storage}>
{storages.map(s => {
const inactiveNodes = s.inactive_nodes ?? [];
return (
<TableRow key={s.storage} className={inactiveNodes.length > 0 ? 'bg-destructive/5' : undefined}>
<TableCell className="font-mono font-medium">
{s.storage}
{s.disable === 1 && <Badge variant="secondary" className="ml-2 text-2xs">{t('storages.disabled')}</Badge>}
{inactiveNodes.length > 0 && (
<Badge
variant="destructive"
className="ml-2 text-2xs"
title={t('storages.inactive_hint', { nodes: inactiveNodes.join(', ') })}
>
<AlertTriangle className="h-3 w-3" />
{t('storages.inactive')}
</Badge>
)}
</TableCell>
<TableCell><Badge variant="outline">{s.type}</Badge></TableCell>
<TableCell className="text-xs">{s.content || '—'}</TableCell>
<TableCell className="text-xs text-muted-foreground">{s.nodes || t('storages.all_nodes')}</TableCell>
<TableCell className="text-xs text-muted-foreground">
{s.nodes || t('storages.all_nodes')}
{inactiveNodes.length > 0 && (
<span className="block text-2xs text-destructive">
{t('storages.inactive_on', { nodes: inactiveNodes.join(', ') })}
</span>
)}
</TableCell>
<TableCell className="text-xs text-muted-foreground">
{s.total ? `${formatBytes(s.used || 0)} / ${formatBytes(s.total)}` : '—'}
</TableCell>
@@ -591,7 +612,8 @@ export default function StoragesTab() {
</div>
</TableCell>
</TableRow>
))}
);
})}
</TableBody>
</Table>
)}

View File

@@ -116,8 +116,20 @@ export default function NodeDetailPage() {
: t('nodes.standalone')}
</Badge>
)}
<Badge variant={server?.is_online ? 'default' : 'destructive'}>
{server?.is_online ? t('common.online') : t('common.offline')}
<Badge
variant={
server?.is_online ? 'default'
: server?.last_error_kind === 'auth' ? 'outline'
: 'destructive'
}
className={server?.last_error_kind === 'auth' && !server?.is_online
? 'border-warning/40 text-warning' : undefined}
title={server?.last_error_kind === 'auth' && !server?.is_online
? t('nodes.auth_error_hint') : server?.last_error || undefined}
>
{server?.is_online ? t('common.online')
: server?.last_error_kind === 'auth' ? t('nodes.auth_error')
: t('common.offline')}
</Badge>
</div>
</div>

View File

@@ -13,6 +13,7 @@ import { useServers, useCreateServer, useUpdateServer, useDeleteServer, useTestS
import { useVirtualMachines } from '@/hooks/use-instances';
import type { ProxmoxServer, ProxmoxServerCreate } from '@/types';
import { formatUptime } from '@/lib/format';
import { cn } from '@/lib/utils';
import { toast } from 'sonner';
import { useConfirm } from '@/components/shared/ConfirmDialog';
import { StatusDot } from '@/components/shared/status-dot';
@@ -358,6 +359,8 @@ export default function NodesPage() {
{servers.map(srv => {
const srvVMs = vms.filter(v => v.server_id === srv.id && v.type === 'qemu');
const srvCTs = vms.filter(v => v.server_id === srv.id && v.type === 'lxc');
// Сервер ответил 401 — он жив, дело в учётных данных, а не в связи.
const authError = !srv.is_online && srv.last_error_kind === 'auth';
return (
<Card key={srv.id} className="relative group">
<CardContent className="p-5 space-y-4">
@@ -446,9 +449,17 @@ export default function NodesPage() {
<span className="font-mono tabular-nums">{srvCTs.length} LXC</span>
</div>
</div>
<Badge variant={srv.is_online ? 'default' : 'destructive'} className="gap-1.5">
<StatusDot status={srv.is_online ? 'online' : 'offline'} pulse className="h-1.5 w-1.5" />
{srv.is_online ? t('common.online') : t('common.offline')}
<Badge
variant={srv.is_online ? 'default' : authError ? 'outline' : 'destructive'}
className={cn('gap-1.5', authError && 'border-warning/40 text-warning')}
title={authError ? t('nodes.auth_error_hint') : srv.last_error || undefined}
>
<StatusDot
status={srv.is_online ? 'online' : authError ? 'auth_error' : 'offline'}
pulse
className="h-1.5 w-1.5"
/>
{srv.is_online ? t('common.online') : authError ? t('nodes.auth_error') : t('common.offline')}
</Badge>
</div>

View File

@@ -589,6 +589,8 @@
},
"nodes": {
"title": "Servers",
"auth_error": "Auth error",
"auth_error_hint": "The server is reachable but rejected the credentials (HTTP 401). Check the API token or password — this usually means the token was revoked or replaced, e.g. after the node joined a cluster.",
"vms": "VMs",
"containers": "Containers",
"cpu": "CPU",
@@ -1056,6 +1058,9 @@
"enabled_ok": "Storage enabled",
"disabled": "Disabled",
"enabled": "Enabled",
"inactive": "Inactive",
"inactive_on": "unavailable on: {{nodes}}",
"inactive_hint": "Declared in the cluster config but not available on: {{nodes}}. The volume group, pool or mount is missing on those nodes.",
"id_required": "Storage ID is required",
"created": "Storage created",
"saved": "Storage updated",

View File

@@ -589,6 +589,8 @@
},
"nodes": {
"title": "Серверы",
"auth_error": "Ошибка авторизации",
"auth_error_hint": "Сервер доступен, но отверг учётные данные (HTTP 401). Проверьте API-токен или пароль — обычно это значит, что токен отозван или заменён, например после ввода ноды в кластер.",
"vms": "ВМ",
"containers": "Контейнеры",
"cpu": "CPU",
@@ -1056,6 +1058,9 @@
"enabled_ok": "Хранилище включено",
"disabled": "Отключено",
"enabled": "Включено",
"inactive": "Недоступно",
"inactive_on": "недоступно на: {{nodes}}",
"inactive_hint": "Объявлено в конфиге кластера, но недоступно на: {{nodes}}. На этих нодах нет нужной volume group, пула или монтирования.",
"id_required": "Укажите ID хранилища",
"created": "Хранилище создано",
"saved": "Хранилище обновлено",

View File

@@ -60,6 +60,8 @@ export interface ProxmoxServer {
last_check?: string;
is_online?: boolean;
last_error?: string;
/** Почему сервер недоступен: 'auth' — отверг учётные данные, 'connection' — не отвечает. */
last_error_kind?: 'auth' | 'connection' | null;
workspaces?: ServerWorkspaceBrief[];
}