сонет вайб 4
This commit is contained in:
parent
22b88fed1a
commit
b59f0222f0
1 changed files with 20 additions and 15 deletions
|
|
@ -632,6 +632,7 @@ async def discover_via_ssh(
|
|||
"config_path", config_path
|
||||
)
|
||||
|
||||
rack_hostname = external_id
|
||||
try:
|
||||
config_text = await _read_remote_config(
|
||||
host=rack_host,
|
||||
|
|
@ -640,13 +641,11 @@ async def discover_via_ssh(
|
|||
password=ssh_password,
|
||||
config_path=effective_config_path,
|
||||
)
|
||||
rack_ssh_ok = True
|
||||
except Exception as exc:
|
||||
result.errors.append(f"SSH to {rack_host} failed: {exc}")
|
||||
continue
|
||||
|
||||
# Add the rack itself as a main_server device if it doesn't exist
|
||||
# Use external_id (e.g., "lane-1-1") as the hostname
|
||||
rack_hostname = external_id
|
||||
rack_ssh_ok = False
|
||||
config_text = None
|
||||
logger.info(f"[ssh_discovery] Processing rack {rack_host} ({rack_hostname})")
|
||||
try:
|
||||
existing_rack = (await db.execute(
|
||||
|
|
@ -665,22 +664,24 @@ async def discover_via_ssh(
|
|||
role="other",
|
||||
source="auto_ssh",
|
||||
rack_id=rack_id_mapping.get(external_id),
|
||||
status="online",
|
||||
last_seen=now,
|
||||
status="online" if rack_ssh_ok else "unknown",
|
||||
last_seen=now if rack_ssh_ok else None,
|
||||
))
|
||||
logger.info(f"[ssh_discovery] {rack_host} ({rack_hostname}) - ADDED: category=embedded, role=other, hostname={rack_hostname}, status=online, source=auto_ssh")
|
||||
status_str = "online" if rack_ssh_ok else "unknown"
|
||||
logger.info(f"[ssh_discovery] {rack_host} ({rack_hostname}) - ADDED: category=embedded, role=other, hostname={rack_hostname}, status={status_str}, source=auto_ssh")
|
||||
result.created += 1
|
||||
result.actions.append(DeviceAction(
|
||||
ip=rack_host,
|
||||
hostname=rack_hostname,
|
||||
action="ADDED",
|
||||
reason="rack PC discovered via SSH connection",
|
||||
reason="rack PC from racks table" + (" (SSH ok)" if rack_ssh_ok else " (SSH failed, added as unknown)"),
|
||||
category="embedded",
|
||||
role="other",
|
||||
))
|
||||
else:
|
||||
rack_changes = []
|
||||
# SSH succeeded → always update status and last_seen
|
||||
if rack_ssh_ok:
|
||||
# SSH succeeded → update status and last_seen
|
||||
if existing_rack.status != "online":
|
||||
existing_rack.status = "online"
|
||||
rack_changes.append("status: →online")
|
||||
|
|
@ -722,6 +723,10 @@ async def discover_via_ssh(
|
|||
category="embedded",
|
||||
role="other",
|
||||
))
|
||||
if not rack_ssh_ok:
|
||||
await db.flush()
|
||||
continue # no config to parse
|
||||
|
||||
# Get all rack IPs to exclude them from device discovery
|
||||
all_rack_ips = [host for _, host, _ in rack_hosts]
|
||||
devices_found = _parse_config(config_text, rack_host, all_rack_ips)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue