Add update functionality for cloud-init templates in the dashboard

Implement a new API endpoint to update existing cloud-init templates, allowing users to modify template attributes such as name, user_data, meta_data, and network_config. Enhance the dashboard UI to include an update button for templates, along with associated JavaScript for handling update requests. This improves user experience by enabling direct template modifications from the interface.
This commit is contained in:
nearxos
2026-02-22 17:18:50 +02:00
parent fd56ed4049
commit 196b13c2fa
3 changed files with 62 additions and 2 deletions

View File

@@ -1663,6 +1663,32 @@ def api_cloudinit_templates_get(tid):
return jsonify({"error": "not found"}), 404
@app.route("/api/cloudinit-templates/<tid>", methods=["PUT"])
@require_admin
def api_cloudinit_templates_update(tid):
"""Update an existing template (name, user_data, meta_data, network_config). Id unchanged."""
body = request.get_json(force=True, silent=True) or {}
data = _load_cloudinit_templates()
templates = data.get("templates", [])
for i, t in enumerate(templates):
if t.get("id") == tid:
name = (body.get("name") or t.get("name") or "").strip()
if not name:
return jsonify({"ok": False, "error": "name required"}), 400
templates[i] = {
"id": tid,
"name": name,
"user_data": body.get("user_data", t.get("user_data", "")),
"meta_data": body.get("meta_data", t.get("meta_data", "")),
"network_config": body.get("network_config", t.get("network_config", "")),
}
data["templates"] = templates
if not _save_cloudinit_templates(data):
return jsonify({"ok": False, "error": "Failed to save"}), 500
return jsonify({"ok": True, "id": tid, "name": name})
return jsonify({"ok": False, "error": "not found"}), 404
@app.route("/api/cloudinit-templates/<tid>", methods=["DELETE"])
@require_admin
def api_cloudinit_templates_delete(tid):