refactor(proxmox): unify ProxmoxClient construction via from_server
Collapse four duplicated host+auth client-building blocks into a single ProxmoxClient.from_server() classmethod (the canonical source of truth): - _helpers._get_proxmox_client now delegates to from_server (107 callers untouched) - ipam._build_proxmox_client removed; its one call site uses from_server - task_queue_service keeps its per-server cache pool, builds via from_server - monitoring_worker keeps its ValueError-on-missing-auth contract, builds via from_server Behaviour preserved (token-first, then password; non-default port appended). Verified: containers rebuild healthy, smoke test of both auth paths passes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -147,30 +147,16 @@ class TaskQueueProcessor:
|
||||
server = db.query(ProxmoxServer).filter(ProxmoxServer.id == server_id).first()
|
||||
if not server:
|
||||
return None
|
||||
|
||||
|
||||
# Require valid credentials before building (from_server would otherwise
|
||||
# construct a client with no usable auth).
|
||||
has_password = server.use_password and server.password
|
||||
has_token = server.api_token_name and server.api_token_value
|
||||
if not (has_password or has_token):
|
||||
return None
|
||||
|
||||
try:
|
||||
host = server.ip_address or server.hostname
|
||||
if server.port and server.port != 8006:
|
||||
host = f"{host}:{server.port}"
|
||||
|
||||
if server.use_password and server.password:
|
||||
client = ProxmoxClient(
|
||||
host=host,
|
||||
user=server.api_user,
|
||||
password=server.password,
|
||||
verify_ssl=server.verify_ssl
|
||||
)
|
||||
elif server.api_token_name and server.api_token_value:
|
||||
client = ProxmoxClient(
|
||||
host=host,
|
||||
user=server.api_user,
|
||||
token_name=server.api_token_name,
|
||||
token_value=server.api_token_value,
|
||||
verify_ssl=server.verify_ssl
|
||||
)
|
||||
else:
|
||||
return None
|
||||
|
||||
client = ProxmoxClient.from_server(server)
|
||||
self._proxmox_clients[server_id] = client
|
||||
return client
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user