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