сонет вайб 3
This commit is contained in:
parent
3460a7ccac
commit
0c9ee8b51b
1 changed files with 28 additions and 17 deletions
|
|
@ -542,8 +542,8 @@ async def discover_via_ssh(
|
|||
infra_devices = []
|
||||
if obj.server_ip:
|
||||
infra_devices.append((obj.server_ip, "main_server", "caps_server"))
|
||||
if obj.db_host and obj.db_host != obj.server_ip:
|
||||
infra_devices.append((obj.db_host, "vm", "db_server"))
|
||||
if db_host and db_host != obj.server_ip:
|
||||
infra_devices.append((db_host, "vm", "db_server"))
|
||||
|
||||
for infra_ip, infra_category, infra_hostname in infra_devices:
|
||||
try:
|
||||
|
|
@ -694,9 +694,17 @@ async def discover_via_ssh(
|
|||
logger.info(f"[ssh_discovery] Found {len(devices_found)} devices from plugins in {rack_host}")
|
||||
|
||||
for found in devices_found:
|
||||
# Hostname: "{external_id}-{plugin_name}", e.g. "lane-1-1-camera_1"
|
||||
hostname = f"{external_id}-{found.plugin_name}"
|
||||
rack_id = rack_id_mapping.get(external_id)
|
||||
# vm devices (RTSP, Asterisk, etc.) are shared infrastructure — place in server_room,
|
||||
# not tied to any specific rack. Other devices belong to the current rack.
|
||||
is_shared = found.category == "vm"
|
||||
if is_shared:
|
||||
hostname = found.plugin_name # e.g. "asterisk", "camera_1_rtsp"
|
||||
rack_id = None
|
||||
device_location = "server_room"
|
||||
else:
|
||||
hostname = f"{external_id}-{found.plugin_name}" # e.g. "lane-1-1-camera_1"
|
||||
rack_id = rack_id_mapping.get(external_id)
|
||||
device_location = None
|
||||
|
||||
try:
|
||||
existing = (await db.execute(
|
||||
|
|
@ -730,22 +738,24 @@ async def discover_via_ssh(
|
|||
if existing.role == "other" and found.role != "other":
|
||||
changes.append(f"role: other→{found.role}")
|
||||
existing.role = found.role
|
||||
# Update hostname if it was never set or still auto-generated
|
||||
if not existing.hostname or existing.hostname.startswith("rack") or (existing.hostname.startswith("lane") and not existing.hostname.startswith(f"{external_id}")):
|
||||
if existing.hostname != hostname:
|
||||
changes.append(f"hostname: '{existing.hostname}'→'{hostname}'")
|
||||
existing.hostname = hostname
|
||||
# Update rack_id if not set
|
||||
if existing.rack_id is None and rack_id is not None:
|
||||
existing.rack_id = rack_id
|
||||
changes.append(f"rack_id: None→{rack_id}")
|
||||
if not is_shared:
|
||||
# Rack-specific device: update hostname if stale
|
||||
if not existing.hostname or existing.hostname.startswith("rack"):
|
||||
if existing.hostname != hostname:
|
||||
changes.append(f"hostname: '{existing.hostname}'→'{hostname}'")
|
||||
existing.hostname = hostname
|
||||
# Update rack_id if not set
|
||||
if existing.rack_id is None and rack_id is not None:
|
||||
existing.rack_id = rack_id
|
||||
changes.append(f"rack_id: None→{rack_id}")
|
||||
# Shared vm devices: never update hostname/rack_id — they're already in server_room
|
||||
|
||||
if changes:
|
||||
logger.info(f"[ssh_discovery] {found.ip} ({found.plugin_name}) - UPDATED: {', '.join(changes)}")
|
||||
result.updated += 1
|
||||
result.actions.append(DeviceAction(
|
||||
ip=found.ip,
|
||||
hostname=hostname,
|
||||
hostname=existing.hostname,
|
||||
action="UPDATED",
|
||||
reason="; ".join(changes),
|
||||
category=found.category,
|
||||
|
|
@ -756,7 +766,7 @@ async def discover_via_ssh(
|
|||
result.skipped += 1
|
||||
result.actions.append(DeviceAction(
|
||||
ip=found.ip,
|
||||
hostname=hostname,
|
||||
hostname=existing.hostname,
|
||||
action="SKIPPED",
|
||||
reason=f"already exists with same values (source={existing.source}, category={existing.category}, role={existing.role}, hostname={existing.hostname})",
|
||||
category=existing.category,
|
||||
|
|
@ -771,9 +781,10 @@ async def discover_via_ssh(
|
|||
role=found.role,
|
||||
source="auto_ssh",
|
||||
rack_id=rack_id,
|
||||
location=device_location,
|
||||
device_meta={"plugin": found.plugin_name, "cls": found.cls},
|
||||
))
|
||||
logger.info(f"[ssh_discovery] {found.ip} ({found.plugin_name}) - ADDED: category={found.category}, role={found.role}, hostname={hostname}, rack_id={rack_id}, source=auto_ssh")
|
||||
logger.info(f"[ssh_discovery] {found.ip} ({found.plugin_name}) - ADDED: category={found.category}, role={found.role}, hostname={hostname}, rack_id={rack_id}, location={device_location}, source=auto_ssh")
|
||||
result.created += 1
|
||||
result.actions.append(DeviceAction(
|
||||
ip=found.ip,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue