diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx index 6f8c6d5..9d30ce4 100644 --- a/frontend/src/pages/Dashboard.jsx +++ b/frontend/src/pages/Dashboard.jsx @@ -45,7 +45,7 @@ export default function Dashboard() { const [instances, setInstances] = useState([]); const [templates, setTemplates] = useState([]); const [showForm, setShowForm] = useState(false); - const [guestType, setGuestType] = useState("vm"); // ← НОВОЕ: "vm" | "lxc" + const [guestType, setGuestType] = useState("vm"); // "vm" | "lxc" const [name, setName] = useState(""); const [ciuser, setCiuser] = useState("ubuntu"); const [cipassword, setCipassword] = useState(""); @@ -98,24 +98,36 @@ export default function Dashboard() { } }, [selectedOS, selectedPreset, osTemplates]); + // Открыть форму для конкретного типа — VM или LXC. + const openForm = (type) => { + setGuestType(type); + setShowForm(true); + }; + + const closeForm = () => { + setShowForm(false); + setError(""); + }; + async function onCreate(event) { event.preventDefault(); if (busy) return; setError(""); setBusy(true); try { - // Для LXC ciuser/cipassword не используются — пароль генерируется на бэкенде. - // Передаём пустые строки, чтобы схема Pydantic не ругалась. + const isLxc = guestType === "lxc"; + // Для LXC пользователь — root (зашит в бэкенде), пароль — ввод пользователя. + // Для VM — стандартная cloud-init пара. await api.createInstance({ name, template_id: Number(templateId), - ciuser: guestType === "vm" ? (ciuser || "") : "", - cipassword: guestType === "vm" ? (cipassword || "") : "", + ciuser: isLxc ? "" : (ciuser || ""), + cipassword: isLxc ? (cipassword || "") : (cipassword || ""), }); setName(""); setCipassword(""); - setShowForm(false); setSelectedPreset(null); + setShowForm(false); await refresh(); } catch (err) { setError(err.message); } finally { setBusy(false); } @@ -146,14 +158,30 @@ export default function Dashboard() { return (
{stats.total === 0 ? "Нет активных серверов" : `${stats.running} из ${stats.total} запущено`}
+ {stats.total === 0 ? "Нет активных серверов" : `${stats.running} из ${stats.total} запущено`} +
+