Topology: power map, what each outlet feeds
Lint / JS (eslint) (push) Successful in 21s
Lint / Python (flake8) (push) Successful in 2m36s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Test / Python Tests (pytest) (push) Successful in 2m46s
Lint / JS (eslint) (pull_request) Successful in 15s
Lint / Python (flake8) (pull_request) Successful in 2m14s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m33s
Security / Python Security (bandit) (pull_request) Successful in 54s
Test / Python Tests (pytest) (pull_request) Successful in 1m3s
Lint / JS (eslint) (push) Successful in 21s
Lint / Python (flake8) (push) Successful in 2m36s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Test / Python Tests (pytest) (push) Successful in 2m46s
Lint / JS (eslint) (pull_request) Successful in 15s
Lint / Python (flake8) (pull_request) Successful in 2m14s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (push) Successful in 1m33s
Security / Python Security (bandit) (pull_request) Successful in 54s
Test / Python Tests (pytest) (pull_request) Successful in 1m3s
- Each PDU, UPS and power strip card lists its outlets that feed something, draw power or are off, with live watts. Each device fed gets a power badge with what it draws. Hovering a power card or a device draws its feeds as dotted lines and keeps both ends lit. - What an outlet feeds: a saved assignment, else the outlet's UniFi name when it names a device (or the modem), else a MAC in its name that belongs to a host NIC (the monitor's host_macs) or UniFi device. - Admins click an outlet to set what it feeds, nothing, or automatic. Saved in a new power_feeds table (created with the cutsheet tables); PUT /api/topology/power/<device>/<outlet>, admin and JSON only, with the device, outlet and target checked. UniFi is never changed. - An outlet that is off but feeds something is listed under "to look at". - Power gear is shown by default again, now that it has something to say. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -826,9 +826,44 @@ _CUTSHEET_SCHEMA = (
|
||||
updated_by VARCHAR(255) NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB""",
|
||||
# What each PDU, UPS or power strip outlet feeds, set by hand on the topology page. An empty
|
||||
# target means "nothing": it overrides a guess from the outlet's name. Gandalf never renames
|
||||
# outlets in UniFi.
|
||||
"""CREATE TABLE IF NOT EXISTS power_feeds (
|
||||
source VARCHAR(255) NOT NULL,
|
||||
outlet SMALLINT NOT NULL,
|
||||
target VARCHAR(255) NOT NULL DEFAULT '',
|
||||
updated_by VARCHAR(255) NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (source, outlet)
|
||||
) ENGINE=InnoDB""",
|
||||
)
|
||||
|
||||
|
||||
def get_power_feeds() -> list:
|
||||
"""Every outlet assignment: [{source, outlet, target, updated_by, updated_at}]."""
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('SELECT source, outlet, target, updated_by, updated_at FROM power_feeds')
|
||||
rows = cur.fetchall()
|
||||
return [dict(r, updated_at=r['updated_at'].isoformat() + 'Z' if hasattr(r['updated_at'], 'isoformat')
|
||||
else r['updated_at']) for r in rows]
|
||||
|
||||
|
||||
def set_power_feed(source: str, outlet: int, target: Optional[str], user: str) -> None:
|
||||
"""Say what an outlet feeds: a device name, '' for nothing, or None to go back to the guess."""
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
if target is None:
|
||||
cur.execute('DELETE FROM power_feeds WHERE source=%s AND outlet=%s', (source, outlet))
|
||||
return
|
||||
cur.execute(
|
||||
"""INSERT INTO power_feeds (source, outlet, target, updated_by) VALUES (%s, %s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE target=VALUES(target), updated_by=VALUES(updated_by)""",
|
||||
(source, outlet, target, user),
|
||||
)
|
||||
|
||||
|
||||
def get_device_link(name: str) -> str:
|
||||
"""The device's inventory URL, or ''."""
|
||||
with get_conn() as conn:
|
||||
|
||||
Reference in New Issue
Block a user