фикс для бд локалхост
This commit is contained in:
parent
23da2fab55
commit
5dd2454c19
1 changed files with 17 additions and 0 deletions
|
|
@ -38,6 +38,7 @@ from .ssh_client import (
|
|||
from .types import DeviceAction, DiscoveredDevice, DiscoveryResult, ProgressCallback
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
_LOCAL_DB_HOSTS = {"localhost", "127.0.0.1", "::1"}
|
||||
|
||||
|
||||
# ── Public entry point ────────────────────────────────────────────────────────
|
||||
|
|
@ -249,6 +250,20 @@ def _embedded_ssh_ports(obj: Object) -> list[int]:
|
|||
return ports
|
||||
|
||||
|
||||
def _normalize_db_host(db_host: str | None, server_ip: str | None) -> str | None:
|
||||
"""Replace localhost-like DB hosts with object server IP for remote discovery."""
|
||||
if not db_host:
|
||||
return db_host
|
||||
host = db_host.strip()
|
||||
if host.lower() in _LOCAL_DB_HOSTS and server_ip:
|
||||
logger.info(
|
||||
"[discovery] DB host '%s' mapped to object server_ip '%s'",
|
||||
host, server_ip,
|
||||
)
|
||||
return server_ip
|
||||
return host
|
||||
|
||||
|
||||
async def _resolve_db_connection(
|
||||
obj: Object,
|
||||
ssh_port: int,
|
||||
|
|
@ -275,6 +290,7 @@ async def _resolve_db_connection(
|
|||
except Exception:
|
||||
result.errors.append("Failed to decrypt DB password")
|
||||
return None
|
||||
db_host = _normalize_db_host(db_host, obj.server_ip)
|
||||
elif obj.server_ip:
|
||||
await _emit("disc_action", {"message": f"Чтение конфигурации сервера {obj.server_ip}..."})
|
||||
try:
|
||||
|
|
@ -293,6 +309,7 @@ async def _resolve_db_connection(
|
|||
return None
|
||||
|
||||
db_host = detected["host"]
|
||||
db_host = _normalize_db_host(db_host, obj.server_ip)
|
||||
db_port = detected["port"]
|
||||
db_user = detected["user"]
|
||||
db_password = detected["password"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue