Add status tracking for network boot actions in dashboard

Implement a new function to write status updates during device deployment and backup actions, enhancing user feedback. Update the API to call this function with appropriate messages based on the action taken. Modify the network boot toggle script to improve clarity and functionality, ensuring proper management of DHCP options. Update permissions for the toggle script to ensure it is executable. Additionally, update the initrd.img to reflect recent changes in the network boot process.
This commit is contained in:
nearxos
2026-02-21 13:05:52 +02:00
parent ea6f846021
commit ff6258c2af
3 changed files with 50 additions and 14 deletions

View File

@@ -220,6 +220,15 @@ DEFAULT_STATUS = {
}
def _write_status(phase, message, progress=None):
try:
os.makedirs(os.path.dirname(STATUS_FILE) or ".", exist_ok=True)
with open(STATUS_FILE, "w") as f:
json.dump({"phase": phase, "message": message, "progress": progress, "updated": time.time()}, f)
except (PermissionError, OSError):
pass
def read_status():
try:
with open(STATUS_FILE, "r") as f:
@@ -555,6 +564,11 @@ def api_device_action():
d["action"] = action
d["action_at"] = time.time()
_save_network_devices(data)
ip = d.get("ip") or mac
if action == "deploy":
_write_status("flashing", f"Deploying to {ip} (network)...")
elif action == "backup":
_write_status("backup", f"Backing up {ip} (network)...")
return jsonify({"ok": True})
return jsonify({"ok": False, "error": "Device not found"}), 404
return jsonify({"ok": False, "error": "source must be 'usb' or 'network'"}), 400
@@ -630,7 +644,13 @@ def api_dhcp_network_boot_post():
def api_action_done():
"""Called by a device when deploy or backup has completed. Disables DHCP network-boot so the device boots from eMMC next time."""
mac = request.args.get("mac") or ((request.get_json(silent=True) or {}).get("mac") or "")
# Remove device from network-devices list so it doesn't keep showing
if mac:
data = _load_network_devices()
data["devices"] = [d for d in data.get("devices", []) if (d.get("mac") or "").lower() != mac.lower()]
_save_network_devices(data)
ok, _ = _dhcp_network_boot_run("disable")
_write_status("done", f"Done ({mac or 'network device'}). Network boot disabled; device will boot from eMMC on next boot.")
if not ok:
return jsonify({"ok": False, "error": "Could not disable DHCP network boot"}), 500
return jsonify({"ok": True, "message": "Network boot disabled; device will boot from eMMC on next boot"})