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

@@ -39,6 +39,14 @@ def get_storages(
try:
client = _get_proxmox_client(server)
storages = client.get_cluster_storages()
# Конфиг кластера общий для всех нод и ничего не говорит о том, поднялось ли
# хранилище на конкретной ноде. Доступность берём из /cluster/resources —
# один запрос на весь кластер.
node_status = client.get_storage_node_status()
for s in storages:
statuses = node_status.get(s.get("storage"), [])
s["nodes_status"] = statuses
s["inactive_nodes"] = [n["node"] for n in statuses if not n["active"]]
return JSONResponse(content={"storages": storages})
except Exception as e:
logger.error(f"Error listing storages for server {server_id}: {e}")

View File

@@ -142,10 +142,11 @@ def create_proxmox_server(
# в 30 секунд (период monitoring_worker.run_server_availability_check).
try:
client = _get_proxmox_client(server)
if client.is_connected():
ok, error_kind, check_error = client.check_connection()
if ok:
server.update_status(True)
else:
server.update_status(False, "Failed to connect")
server.update_status(False, check_error or "Failed to connect", error_kind)
db.commit()
db.refresh(server)
except Exception as e:
@@ -297,10 +298,11 @@ def update_proxmox_server(
if creds_changed:
try:
client = _get_proxmox_client(server)
if client.is_connected():
ok, error_kind, check_error = client.check_connection()
if ok:
server.update_status(True)
else:
server.update_status(False, "Failed to connect")
server.update_status(False, check_error or "Failed to connect", error_kind)
db.commit()
db.refresh(server)
if server.is_online: