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:
@@ -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}")
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user