Refactor dashboard to remove network boot support and update related UI elements</message>
<message>Eliminate network boot options from the dashboard, including API endpoints and UI elements, to streamline the provisioning process for USB boot only. Update messages and documentation to reflect the removal of network boot functionality, ensuring clarity for users. Adjust the cloud-init build process and related templates to focus solely on USB boot mode, enhancing the overall user experience and simplifying the workflow.
This commit is contained in:
@@ -52,7 +52,6 @@ FIRST_BOOT_STATUS_FILE = Path(os.environ.get("CM4_FIRST_BOOT_STATUS_FILE", str(B
|
||||
CLOUDINIT_TEMPLATES_FILE = Path(os.environ.get("CM4_CLOUDINIT_TEMPLATES_FILE", str(BASE_DIR / "cloudinit_templates.json")))
|
||||
PORTAL_DESCRIPTIONS_FILE = Path(os.environ.get("CM4_PORTAL_DESCRIPTIONS_FILE", str(BASE_DIR / "portal_descriptions.json")))
|
||||
DB_PATH = Path(os.environ.get("CM4_DASHBOARD_DB", str(BASE_DIR / "dashboard.db")))
|
||||
TOGGLE_NETWORK_BOOT_SCRIPT = os.environ.get("CM4_TOGGLE_NETWORK_BOOT_SCRIPT", "/opt/cm4-provisioning/toggle-network-boot-dhcp.sh")
|
||||
DHCP_LEASES_FILE = os.environ.get("CM4_DHCP_LEASES_FILE", "/var/lib/misc/dnsmasq.leases")
|
||||
# EEPROM update (USB boot): tools and output files (shared with host script)
|
||||
EEPROM_DIR = Path(os.environ.get("CM4_EEPROM_DIR", "/opt/cm4-provisioning/eeprom"))
|
||||
@@ -225,7 +224,7 @@ ethernets:
|
||||
|
||||
DEFAULT_STATUS = {
|
||||
"phase": "idle",
|
||||
"message": "Waiting for reTerminal in boot mode or network.",
|
||||
"message": "Waiting for reTerminal in USB boot mode.",
|
||||
"progress": None,
|
||||
"updated": None,
|
||||
}
|
||||
@@ -650,171 +649,83 @@ def api_log():
|
||||
|
||||
@app.route("/api/eeprom-presets")
|
||||
def api_eeprom_presets():
|
||||
"""Return available boot order presets for the Update EEPROM dropdown."""
|
||||
"""Return available boot order presets for the Update EEPROM dropdown (eMMC only; network boot removed from portal)."""
|
||||
presets = [
|
||||
{"id": "0x1", "label": "eMMC only"},
|
||||
{"id": "0xf21", "label": "eMMC first, then network"},
|
||||
{"id": "0xf12", "label": "Network first, then eMMC"},
|
||||
]
|
||||
return jsonify({"presets": presets})
|
||||
|
||||
|
||||
@app.route("/api/pending-devices")
|
||||
def api_pending_devices():
|
||||
"""Returns USB (if waiting_choice) and registered network devices so the UI can show Backup/Deploy."""
|
||||
"""Returns USB device if waiting_choice. Network boot removed from portal; DHCP still provides internet."""
|
||||
st = read_status()
|
||||
usb = None
|
||||
if st.get("phase") == "waiting_choice":
|
||||
usb = {"source": "usb", "message": st.get("message", "Device connected (USB). Choose action.")}
|
||||
data = _load_network_devices()
|
||||
network = [d for d in data.get("devices", []) if d.get("action") in (None, "wait")]
|
||||
return jsonify({"usb": usb, "network": network})
|
||||
return jsonify({"usb": usb, "network": []})
|
||||
|
||||
|
||||
@app.route("/api/device-action", methods=["POST"])
|
||||
def api_device_action():
|
||||
"""User chose Backup, Deploy, or Update EEPROM for a device. source=usb | network; for network pass mac=."""
|
||||
"""User chose Backup, Deploy, or Update EEPROM for a USB device. Network boot removed from portal."""
|
||||
body = request.get_json(force=True, silent=True) or {}
|
||||
source = (body.get("source") or "").strip().lower()
|
||||
action = (body.get("action") or "").strip().lower()
|
||||
if action not in ("backup", "deploy", "reboot", "eeprom_update"):
|
||||
return jsonify({"ok": False, "error": "action must be 'backup', 'deploy', 'reboot', or 'eeprom_update'"}), 400
|
||||
if action == "reboot" and source != "network":
|
||||
return jsonify({"ok": False, "error": "'reboot' is only for network devices"}), 400
|
||||
if action == "eeprom_update" and source != "usb":
|
||||
return jsonify({"ok": False, "error": "'eeprom_update' is only for USB-connected devices"}), 400
|
||||
if source == "usb":
|
||||
if action == "eeprom_update":
|
||||
boot_order = (body.get("boot_order") or "0xf21").strip().lower()
|
||||
if boot_order not in ("0x1", "0xf21", "0xf12"):
|
||||
return jsonify({"ok": False, "error": "boot_order must be 0x1, 0xf21, or 0xf12"}), 400
|
||||
ok, err = _generate_eeprom_update(boot_order)
|
||||
if not ok:
|
||||
return jsonify({"ok": False, "error": err or "Failed to generate EEPROM update"}), 500
|
||||
try:
|
||||
os.makedirs(os.path.dirname(ACTION_REQUEST_FILE) or ".", exist_ok=True)
|
||||
with open(ACTION_REQUEST_FILE, "w") as f:
|
||||
f.write("eeprom_update")
|
||||
_write_status("eeprom_update", "EEPROM update ready; host will write to device boot partition.")
|
||||
return jsonify({"ok": True})
|
||||
except (PermissionError, OSError):
|
||||
return jsonify({"ok": False, "error": "Could not write action file"}), 500
|
||||
if source != "usb":
|
||||
return jsonify({"ok": False, "error": "Only USB boot is supported"}), 400
|
||||
if action not in ("backup", "deploy", "eeprom_update"):
|
||||
return jsonify({"ok": False, "error": "action must be 'backup', 'deploy', or 'eeprom_update'"}), 400
|
||||
if action == "eeprom_update":
|
||||
boot_order = (body.get("boot_order") or "0x1").strip().lower()
|
||||
if boot_order != "0x1":
|
||||
return jsonify({"ok": False, "error": "boot_order must be 0x1 (eMMC only)"}), 400
|
||||
ok, err = _generate_eeprom_update(boot_order)
|
||||
if not ok:
|
||||
return jsonify({"ok": False, "error": err or "Failed to generate EEPROM update"}), 500
|
||||
try:
|
||||
os.makedirs(os.path.dirname(ACTION_REQUEST_FILE) or ".", exist_ok=True)
|
||||
# If user requested "shrink after backup", create flag so host runs PiShrink after dd
|
||||
if action == "backup" and body.get("shrink"):
|
||||
try:
|
||||
(BASE_DIR / "shrink_next_backup").write_text("1")
|
||||
except (PermissionError, OSError):
|
||||
pass # host may still have SHRINK_BACKUP=1
|
||||
with open(ACTION_REQUEST_FILE, "w") as f:
|
||||
f.write(action)
|
||||
if action == "deploy":
|
||||
_first_boot_status_write("idle", "", hostname="", ip="")
|
||||
f.write("eeprom_update")
|
||||
_write_status("eeprom_update", "EEPROM update ready; host will write to device boot partition.")
|
||||
return jsonify({"ok": True})
|
||||
except (PermissionError, OSError):
|
||||
return jsonify({"ok": False, "error": "Could not write action file"}), 500
|
||||
if source == "network":
|
||||
mac = (body.get("mac") or "").strip()
|
||||
if not mac:
|
||||
return jsonify({"ok": False, "error": "mac required for network device"}), 400
|
||||
data = _load_network_devices()
|
||||
for d in data.get("devices", []):
|
||||
if (d.get("mac") or "").lower() == mac.lower():
|
||||
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)...")
|
||||
_first_boot_status_write("idle", "", hostname="", ip="")
|
||||
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
|
||||
try:
|
||||
os.makedirs(os.path.dirname(ACTION_REQUEST_FILE) or ".", exist_ok=True)
|
||||
if action == "backup" and body.get("shrink"):
|
||||
try:
|
||||
(BASE_DIR / "shrink_next_backup").write_text("1")
|
||||
except (PermissionError, OSError):
|
||||
pass
|
||||
with open(ACTION_REQUEST_FILE, "w") as f:
|
||||
f.write(action)
|
||||
if action == "deploy":
|
||||
_first_boot_status_write("idle", "", hostname="", ip="")
|
||||
return jsonify({"ok": True})
|
||||
except (PermissionError, OSError):
|
||||
return jsonify({"ok": False, "error": "Could not write action file"}), 500
|
||||
|
||||
|
||||
@app.route("/api/register-device", methods=["POST"])
|
||||
def api_register_device():
|
||||
"""Called by a network-booted device to register (mac, ip)."""
|
||||
"""Legacy: network boot removed from portal; accept registration but do not list devices."""
|
||||
body = request.get_json(force=True, silent=True) or request.form
|
||||
mac = (body.get("mac") or "").strip()
|
||||
ip = (body.get("ip") or request.remote_addr or "").strip()
|
||||
if not mac:
|
||||
if not (body.get("mac") or "").strip():
|
||||
return jsonify({"ok": False, "error": "mac required"}), 400
|
||||
data = _load_network_devices()
|
||||
devices = data.get("devices", [])
|
||||
for d in devices:
|
||||
if (d.get("mac") or "").lower() == mac.lower():
|
||||
d["ip"] = ip
|
||||
d["registered_at"] = time.time()
|
||||
d["action"] = d.get("action") or "wait"
|
||||
_save_network_devices(data)
|
||||
return jsonify({"ok": True, "message": "registered"})
|
||||
devices.append({"mac": mac, "ip": ip, "registered_at": time.time(), "action": "wait"})
|
||||
data["devices"] = devices
|
||||
_save_network_devices(data)
|
||||
return jsonify({"ok": True, "message": "registered"})
|
||||
|
||||
|
||||
def _dhcp_network_boot_run(cmd):
|
||||
"""Run toggle script with enable|disable|status. Returns (ok, output_or_error)."""
|
||||
if not os.path.isfile(TOGGLE_NETWORK_BOOT_SCRIPT) or not os.access(TOGGLE_NETWORK_BOOT_SCRIPT, os.X_OK):
|
||||
return False, "Toggle script not installed"
|
||||
try:
|
||||
out = subprocess.run(
|
||||
[TOGGLE_NETWORK_BOOT_SCRIPT, cmd],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
if out.returncode != 0:
|
||||
return False, (out.stderr or out.stdout or "script failed").strip()
|
||||
return True, (out.stdout or "").strip()
|
||||
except subprocess.TimeoutExpired:
|
||||
return False, "Timeout"
|
||||
except Exception as e:
|
||||
return False, str(e)
|
||||
|
||||
|
||||
@app.route("/api/dhcp-network-boot", methods=["GET"])
|
||||
def api_dhcp_network_boot_get():
|
||||
"""Return whether DHCP network-boot options (66/67) are enabled."""
|
||||
ok, out = _dhcp_network_boot_run("status")
|
||||
if not ok:
|
||||
return jsonify({"enabled": None, "error": out}), 200
|
||||
return jsonify({"enabled": out.strip().lower() == "enabled"})
|
||||
|
||||
|
||||
@app.route("/api/dhcp-network-boot", methods=["POST"])
|
||||
def api_dhcp_network_boot_post():
|
||||
"""Enable or disable DHCP network-boot options (DHCP server keeps running). Body: { \"enabled\": true|false }."""
|
||||
body = request.get_json(force=True, silent=True) or {}
|
||||
enabled = body.get("enabled")
|
||||
if enabled is None:
|
||||
return jsonify({"ok": False, "error": "enabled required (true|false)"}), 400
|
||||
cmd = "enable" if enabled else "disable"
|
||||
ok, out = _dhcp_network_boot_run(cmd)
|
||||
if not ok:
|
||||
return jsonify({"ok": False, "error": out}), 500
|
||||
return jsonify({"ok": True, "enabled": enabled})
|
||||
|
||||
|
||||
@app.route("/api/action-done", methods=["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."""
|
||||
"""Legacy: network boot removed from portal; acknowledge completion without toggling DHCP."""
|
||||
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"})
|
||||
_write_status("done", f"Done ({mac or 'device'}).")
|
||||
return jsonify({"ok": True, "message": "Done"})
|
||||
|
||||
|
||||
def _read_dhcp_leases():
|
||||
@@ -1668,6 +1579,8 @@ def api_build_cloudinit():
|
||||
image_name = re.sub(r"[^\w\-]", "", image_name) # only alphanumeric, underscore, dash
|
||||
try:
|
||||
BUILD_REQUEST_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
# Remove any stale cancel file from a previous run so the new build is not cancelled immediately
|
||||
BUILD_CANCEL_FILE.unlink(missing_ok=True)
|
||||
with open(BUILD_REQUEST_FILE, "w") as f:
|
||||
json.dump({
|
||||
"url": url,
|
||||
|
||||
Reference in New Issue
Block a user