Compare commits
No commits in common. "main" and "v0.1.0-dev" have entirely different histories.
main
...
v0.1.0-dev
@ -1,20 +0,0 @@
|
||||
// src/api/handlers/provisionDev.js
|
||||
|
||||
export function normalizeDevRequest(body = {}) {
|
||||
if (!body.runtime) {
|
||||
throw new Error("runtime is required for dev container");
|
||||
}
|
||||
|
||||
if (!body.version) {
|
||||
throw new Error("version is required for dev container");
|
||||
}
|
||||
|
||||
return {
|
||||
customerId: body.customerId,
|
||||
runtime: body.runtime,
|
||||
version: body.version,
|
||||
memoryMiB: body.memoryMiB || 2048,
|
||||
cpuCores: body.cpuCores || 2,
|
||||
portsNeeded: body.portsNeeded || 0,
|
||||
};
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
// src/api/handlers/provisionGame.js
|
||||
|
||||
export function normalizeGameRequest(body = {}) {
|
||||
if (!body.game) {
|
||||
throw new Error("game is required");
|
||||
}
|
||||
|
||||
if (!body.variant) {
|
||||
throw new Error("variant is required");
|
||||
}
|
||||
|
||||
return {
|
||||
customerId: body.customerId,
|
||||
game: body.game,
|
||||
variant: body.variant,
|
||||
version: body.version,
|
||||
world: body.world || "world",
|
||||
memoryMiB: body.memoryMiB || 2048,
|
||||
cpuCores: body.cpuCores || 2,
|
||||
portsNeeded: body.portsNeeded || 0,
|
||||
};
|
||||
}
|
||||
@ -1,11 +1,13 @@
|
||||
// src/api/provisionAgent.js
|
||||
// FINAL AGENT-DRIVEN PROVISIONING PIPELINE (STABLE + SCALABLE)
|
||||
// FINAL AGENT-DRIVEN PROVISIONING PIPELINE
|
||||
// Supports: paper, vanilla, purpur, forge, fabric, neoforge + Steam creds passthrough
|
||||
|
||||
import "dotenv/config";
|
||||
import fetch from "node-fetch";
|
||||
import crypto from "crypto";
|
||||
|
||||
import prisma from "../services/prisma.js";
|
||||
import {
|
||||
import proxmox, {
|
||||
cloneContainer,
|
||||
configureContainer,
|
||||
startWithRetry,
|
||||
@ -13,6 +15,7 @@ import {
|
||||
} from "../services/proxmoxClient.js";
|
||||
|
||||
import { getCtIpWithRetry } from "../services/getCtIp.js";
|
||||
import { PortAllocationService } from "../services/portAllocator.js";
|
||||
import {
|
||||
allocateVmid,
|
||||
confirmVmidAllocated,
|
||||
@ -20,131 +23,184 @@ import {
|
||||
} from "../services/vmidAllocator.js";
|
||||
|
||||
import { enqueuePublishEdge } from "../queues/postProvision.js";
|
||||
import { normalizeGameRequest } from "./handlers/provisionGame.js";
|
||||
import { normalizeDevRequest } from "./handlers/provisionDev.js";
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
const AGENT_TEMPLATE_VMID = Number(
|
||||
process.env.AGENT_TEMPLATE_VMID ||
|
||||
process.env.BASE_TEMPLATE_VMID ||
|
||||
process.env.PROXMOX_AGENT_TEMPLATE_VMID
|
||||
process.env.PROXMOX_AGENT_TEMPLATE_VMID ||
|
||||
900
|
||||
);
|
||||
|
||||
const AGENT_PORT = Number(process.env.ZLH_AGENT_PORT || 18888);
|
||||
const AGENT_TOKEN = process.env.ZLH_AGENT_TOKEN || null;
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
const step = (name) =>
|
||||
console.log(`[agentProvision] step=${name}`);
|
||||
/* -------------------------------------------------------------
|
||||
VERSION PARSER
|
||||
------------------------------------------------------------- */
|
||||
function parseMcVersion(ver) {
|
||||
if (!ver) return { major: 0, minor: 0, patch: 0 };
|
||||
const p = String(ver).split(".");
|
||||
return {
|
||||
major: Number(p[0]) || 0,
|
||||
minor: Number(p[1]) || 0,
|
||||
patch: Number(p[2]) || 0,
|
||||
};
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
HOSTNAME BUILDER
|
||||
JAVA RUNTIME SELECTOR
|
||||
------------------------------------------------------------- */
|
||||
function buildHostname({ ctype, game, variant, vmid }) {
|
||||
if (ctype === "dev") return `dev-${vmid}`;
|
||||
function pickJavaRuntimeForMc(version) {
|
||||
const { major, minor, patch } = parseMcVersion(version);
|
||||
|
||||
if (game === "minecraft") {
|
||||
if (major > 1) return 21;
|
||||
|
||||
if (major === 1) {
|
||||
if (minor >= 21) return 21;
|
||||
if (minor === 20 && patch >= 5) return 21;
|
||||
if (minor > 20) return 21;
|
||||
return 17;
|
||||
}
|
||||
|
||||
return 17;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
HOSTNAME GENERATION
|
||||
------------------------------------------------------------- */
|
||||
function generateSystemHostname({ game, variant, vmid }) {
|
||||
const g = (game || "").toLowerCase();
|
||||
const v = (variant || "").toLowerCase();
|
||||
if (v) return `mc-${v}-${vmid}`;
|
||||
return `mc-${vmid}`;
|
||||
|
||||
let prefix = "game";
|
||||
if (g.includes("minecraft")) prefix = "mc";
|
||||
else if (g.includes("terraria")) prefix = "terraria";
|
||||
else if (g.includes("valheim")) prefix = "valheim";
|
||||
else if (g.includes("rust")) prefix = "rust";
|
||||
|
||||
let varPart = "";
|
||||
if (g.includes("minecraft")) {
|
||||
if (["paper", "forge", "fabric", "vanilla", "purpur", "neoforge"].includes(v))
|
||||
varPart = v;
|
||||
}
|
||||
|
||||
return `${game || "game"}-${vmid}`;
|
||||
return varPart ? `${prefix}-${varPart}-${vmid}` : `${prefix}-${vmid}`;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
JAVA SELECTION (FIX)
|
||||
ADMIN PASSWORD GENERATOR
|
||||
------------------------------------------------------------- */
|
||||
function pickJavaForMinecraftVersion(version) {
|
||||
// version like "1.21.7"
|
||||
const parts = String(version).split(".");
|
||||
const minor = Number(parts[1] || 0);
|
||||
function generateAdminPassword() {
|
||||
return crypto.randomBytes(12).toString("base64url");
|
||||
}
|
||||
|
||||
return minor >= 21
|
||||
/* -------------------------------------------------------------
|
||||
BUILD AGENT PAYLOAD
|
||||
------------------------------------------------------------- */
|
||||
function buildAgentPayload({
|
||||
vmid,
|
||||
game,
|
||||
variant,
|
||||
version,
|
||||
world,
|
||||
ports,
|
||||
artifactPath,
|
||||
javaPath,
|
||||
memoryMiB,
|
||||
steamUser,
|
||||
steamPass,
|
||||
steamAuth,
|
||||
adminUser,
|
||||
adminPass,
|
||||
}) {
|
||||
const g = (game || "minecraft").toLowerCase();
|
||||
const v = (variant || "").toLowerCase();
|
||||
const ver = version || "1.20.1";
|
||||
const w = world || "world";
|
||||
|
||||
if (!v) throw new Error("variant is required (paper, forge, fabric, vanilla, purpur)");
|
||||
|
||||
let art = artifactPath;
|
||||
let jpath = javaPath;
|
||||
|
||||
// --------- VARIANT → ARTIFACT PATH ---------
|
||||
if (!art && g === "minecraft") {
|
||||
switch (v) {
|
||||
case "paper":
|
||||
case "vanilla":
|
||||
case "purpur":
|
||||
art = `minecraft/${v}/${ver}/server.jar`;
|
||||
break;
|
||||
|
||||
case "forge":
|
||||
art = `minecraft/forge/${ver}/forge-installer.jar`;
|
||||
break;
|
||||
|
||||
case "fabric":
|
||||
art = `minecraft/fabric/${ver}/fabric-server.jar`;
|
||||
break;
|
||||
|
||||
case "neoforge":
|
||||
art = `minecraft/neoforge/${ver}/neoforge-installer.jar`;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error(`Unsupported Minecraft variant: ${v}`);
|
||||
}
|
||||
}
|
||||
|
||||
// --------- JAVA RUNTIME SELECTOR ----------
|
||||
if (!jpath && g === "minecraft") {
|
||||
const javaVersion = pickJavaRuntimeForMc(ver);
|
||||
jpath =
|
||||
javaVersion === 21
|
||||
? "java/21/OpenJDK21.tar.gz"
|
||||
: "java/17/OpenJDK17.tar.gz";
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
PAYLOAD BUILDERS
|
||||
------------------------------------------------------------- */
|
||||
// --------- MEMORY DEFAULTS ----------
|
||||
let mem = Number(memoryMiB) || 0;
|
||||
if (mem <= 0) mem = ["forge", "neoforge"].includes(v) ? 4096 : 2048;
|
||||
|
||||
function buildDevAgentPayload({ vmid, runtime, version, memoryMiB }) {
|
||||
if (!runtime) throw new Error("runtime required for dev container");
|
||||
if (!version) throw new Error("version required for dev container");
|
||||
// Steam + admin credentials (persisted, optional)
|
||||
const resolvedSteamUser = steamUser || "anonymous";
|
||||
const resolvedSteamPass = steamPass || "";
|
||||
const resolvedSteamAuth = steamAuth || "";
|
||||
|
||||
const resolvedAdminUser = adminUser || "admin";
|
||||
const resolvedAdminPass = adminPass || generateAdminPassword();
|
||||
|
||||
return {
|
||||
vmid,
|
||||
container_type: "dev",
|
||||
runtime,
|
||||
version,
|
||||
memory_mb: Number(memoryMiB) || 2048,
|
||||
};
|
||||
}
|
||||
game: g,
|
||||
variant: v,
|
||||
version: ver,
|
||||
world: w,
|
||||
ports: Array.isArray(ports) ? ports : [ports].filter(Boolean),
|
||||
artifact_path: art,
|
||||
java_path: jpath,
|
||||
memory_mb: mem,
|
||||
|
||||
function buildGameAgentPayload(req) {
|
||||
let javaPath = req.javaPath;
|
||||
let artifactPath = req.artifactPath;
|
||||
steam_user: resolvedSteamUser,
|
||||
steam_pass: resolvedSteamPass,
|
||||
steam_auth: resolvedSteamAuth,
|
||||
|
||||
// 🔧 FIXED JAVA LOGIC — NOTHING ELSE CHANGED
|
||||
if (!javaPath && req.game === "minecraft") {
|
||||
if (!req.version) {
|
||||
throw new Error("minecraft version required for java selection");
|
||||
}
|
||||
javaPath = pickJavaForMinecraftVersion(req.version);
|
||||
}
|
||||
|
||||
if (!artifactPath && req.game === "minecraft") {
|
||||
switch (req.variant) {
|
||||
case "forge":
|
||||
artifactPath = `minecraft/forge/${req.version}/forge-installer.jar`;
|
||||
break;
|
||||
case "fabric":
|
||||
artifactPath = `minecraft/fabric/${req.version}/fabric-server.jar`;
|
||||
break;
|
||||
case "neoforge":
|
||||
artifactPath = `minecraft/neoforge/${req.version}/neoforge-installer.jar`;
|
||||
break;
|
||||
case "paper":
|
||||
case "purpur":
|
||||
case "vanilla":
|
||||
artifactPath = `minecraft/${req.variant}/${req.version}/server.jar`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!javaPath) {
|
||||
throw new Error(`BUG: java_path missing for ${req.game} ${req.variant}`);
|
||||
}
|
||||
|
||||
if (!artifactPath) {
|
||||
throw new Error(`BUG: artifact_path missing for ${req.game} ${req.variant}`);
|
||||
}
|
||||
|
||||
return {
|
||||
vmid: req.vmid,
|
||||
container_type: "game",
|
||||
game: req.game,
|
||||
variant: req.variant,
|
||||
version: req.version,
|
||||
world: req.world,
|
||||
ports: req.ports || [],
|
||||
artifact_path: artifactPath,
|
||||
java_path: javaPath,
|
||||
memory_mb: req.memoryMiB,
|
||||
admin_user: req.adminUser,
|
||||
admin_pass: req.adminPass,
|
||||
admin_user: resolvedAdminUser,
|
||||
admin_pass: resolvedAdminPass,
|
||||
};
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
AGENT COMMUNICATION
|
||||
SEND CONFIG → triggers async provision+start in agent
|
||||
------------------------------------------------------------- */
|
||||
|
||||
async function sendAgentConfig({ ip, payload }) {
|
||||
const url = `http://${ip}:${AGENT_PORT}/config`;
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
if (AGENT_TOKEN) headers.Authorization = `Bearer ${AGENT_TOKEN}`;
|
||||
if (AGENT_TOKEN) headers["Authorization"] = `Bearer ${AGENT_TOKEN}`;
|
||||
|
||||
const resp = await fetch(`http://${ip}:${AGENT_PORT}/config`, {
|
||||
const resp = await fetch(url, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
@ -156,147 +212,239 @@ async function sendAgentConfig({ ip, payload }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForAgentTerminalState({ ip, timeoutMs = 10 * 60_000 }) {
|
||||
/* -------------------------------------------------------------
|
||||
WAIT FOR AGENT READY (poll /status)
|
||||
------------------------------------------------------------- */
|
||||
async function waitForAgentRunning({ ip, timeoutMs = 10 * 60_000 }) {
|
||||
const url = `http://${ip}:${AGENT_PORT}/status`;
|
||||
const headers = {};
|
||||
if (AGENT_TOKEN) headers["Authorization"] = `Bearer ${AGENT_TOKEN}`;
|
||||
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
let last;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
try {
|
||||
const res = await fetch(`http://${ip}:${AGENT_PORT}/status`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
const resp = await fetch(url, { headers });
|
||||
if (!resp.ok) {
|
||||
last = new Error(`/status HTTP ${resp.status}`);
|
||||
} else {
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
const state = (data.state || data.status || "").toLowerCase();
|
||||
|
||||
if (data.state === "running") return;
|
||||
// Agent's state machine:
|
||||
// idle → installing → verifying → starting → running
|
||||
if (state === "running") return { state: "running", raw: data };
|
||||
if (state === "error" || state === "crashed") {
|
||||
const msg = data.error || "";
|
||||
throw new Error(`agent state=${state} ${msg ? `(${msg})` : ""}`);
|
||||
}
|
||||
|
||||
if (data.state === "error") {
|
||||
throw new Error(data.error || "agent error");
|
||||
last = new Error(`agent state=${state || "unknown"}`);
|
||||
}
|
||||
} catch (err) {
|
||||
last = err;
|
||||
}
|
||||
} catch {}
|
||||
|
||||
await sleep(3000);
|
||||
}
|
||||
|
||||
throw new Error("Agent did not reach running state");
|
||||
throw last || new Error("Agent did not reach running state");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
MAIN ENTRYPOINT
|
||||
MAIN PROVISION ENTRYPOINT
|
||||
------------------------------------------------------------- */
|
||||
|
||||
export async function provisionAgentInstance(body = {}) {
|
||||
const rawType =
|
||||
body.container_type ??
|
||||
body.containerType ??
|
||||
body.ctype ??
|
||||
"game";
|
||||
const {
|
||||
customerId,
|
||||
game,
|
||||
variant,
|
||||
version,
|
||||
world,
|
||||
ctype: rawCtype,
|
||||
name,
|
||||
cpuCores,
|
||||
memoryMiB,
|
||||
diskGiB,
|
||||
portsNeeded,
|
||||
artifactPath,
|
||||
javaPath,
|
||||
|
||||
if (!["game", "dev"].includes(rawType)) {
|
||||
throw new Error(`invalid container type: ${rawType}`);
|
||||
}
|
||||
// NEW optional fields
|
||||
steamUser,
|
||||
steamPass,
|
||||
steamAuth,
|
||||
adminUser,
|
||||
adminPass,
|
||||
} = body;
|
||||
|
||||
const ctype = rawType;
|
||||
console.log(`[agentProvision] starting ${ctype} provisioning`);
|
||||
if (!customerId) throw new Error("customerId required");
|
||||
if (!game) throw new Error("game required");
|
||||
if (!variant) throw new Error("variant required");
|
||||
|
||||
const req =
|
||||
ctype === "dev"
|
||||
? normalizeDevRequest(body)
|
||||
: normalizeGameRequest(body);
|
||||
const ctype = rawCtype || "game";
|
||||
const isMinecraft = game.toLowerCase().includes("minecraft");
|
||||
|
||||
let vmid;
|
||||
let allocatedPortsMap = null;
|
||||
let gamePorts = [];
|
||||
let ctIp;
|
||||
let instanceHostname;
|
||||
|
||||
try {
|
||||
step("allocate-vmid");
|
||||
console.log("[agentProvision] STEP 1: allocate VMID");
|
||||
vmid = await allocateVmid(ctype);
|
||||
|
||||
const hostname = buildHostname({
|
||||
ctype,
|
||||
game: req.game,
|
||||
variant: req.variant,
|
||||
vmid,
|
||||
});
|
||||
instanceHostname = generateSystemHostname({ game, variant, vmid });
|
||||
|
||||
console.log("[agentProvision] STEP 2: port allocation");
|
||||
if (!isMinecraft && (portsNeeded ?? 0) > 0) {
|
||||
gamePorts = await PortAllocationService.reserve({
|
||||
vmid,
|
||||
count: portsNeeded,
|
||||
portType: "game",
|
||||
});
|
||||
allocatedPortsMap = { game: gamePorts };
|
||||
} else {
|
||||
gamePorts = [25565];
|
||||
allocatedPortsMap = { game: gamePorts };
|
||||
}
|
||||
|
||||
const node = process.env.PROXMOX_NODE || "zlh-prod1";
|
||||
const bridge = ctype === "dev" ? "vmbr2" : "vmbr3";
|
||||
const cpu = cpuCores ? Number(cpuCores) : 2;
|
||||
const memory = memoryMiB ? Number(memoryMiB) : 2048;
|
||||
|
||||
const description = name
|
||||
? `${name} (customer=${customerId}; vmid=${vmid}; agent=v1)`
|
||||
: `customer=${customerId}; vmid=${vmid}; agent=v1`;
|
||||
|
||||
const tags = [
|
||||
`cust-${customerId}`,
|
||||
`type-${ctype}`,
|
||||
`game-${game}`,
|
||||
variant ? `var-${variant}` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(",");
|
||||
|
||||
console.log(
|
||||
`[agentProvision] STEP 3: clone template ${AGENT_TEMPLATE_VMID} → vmid=${vmid}`
|
||||
);
|
||||
|
||||
step("clone-container");
|
||||
await cloneContainer({
|
||||
templateVmid: AGENT_TEMPLATE_VMID,
|
||||
vmid,
|
||||
name: hostname,
|
||||
name: instanceHostname,
|
||||
full: 1,
|
||||
});
|
||||
|
||||
step("configure-container");
|
||||
console.log("[agentProvision] STEP 4: configure CPU/mem/bridge/tags");
|
||||
await configureContainer({
|
||||
vmid,
|
||||
cpu: req.cpuCores || 2,
|
||||
memory: req.memoryMiB || 2048,
|
||||
bridge: ctype === "dev" ? "vmbr2" : "vmbr3",
|
||||
cpu,
|
||||
memory,
|
||||
bridge,
|
||||
description,
|
||||
tags,
|
||||
});
|
||||
|
||||
step("start-container");
|
||||
console.log("[agentProvision] STEP 5: start container");
|
||||
await startWithRetry(vmid);
|
||||
|
||||
step("wait-for-ip");
|
||||
ctIp = await getCtIpWithRetry(vmid);
|
||||
console.log("[agentProvision] STEP 6: detect container IP");
|
||||
const ip = await getCtIpWithRetry(vmid, node, 12, 10_000);
|
||||
if (!ip) throw new Error("Failed to detect container IP");
|
||||
ctIp = ip;
|
||||
|
||||
step("build-agent-payload");
|
||||
const payload =
|
||||
ctype === "dev"
|
||||
? buildDevAgentPayload({
|
||||
console.log(`[agentProvision] ctIp=${ctIp}`);
|
||||
|
||||
console.log("[agentProvision] STEP 7: build agent payload");
|
||||
const payload = buildAgentPayload({
|
||||
vmid,
|
||||
runtime: body.runtime,
|
||||
version: body.version,
|
||||
memoryMiB: req.memoryMiB,
|
||||
})
|
||||
: buildGameAgentPayload({ ...req, vmid });
|
||||
game,
|
||||
variant,
|
||||
version,
|
||||
world,
|
||||
ports: gamePorts,
|
||||
artifactPath,
|
||||
javaPath,
|
||||
memoryMiB,
|
||||
|
||||
step("send-agent-config");
|
||||
steamUser,
|
||||
steamPass,
|
||||
steamAuth,
|
||||
adminUser,
|
||||
adminPass,
|
||||
});
|
||||
|
||||
console.log("[agentProvision] STEP 8: POST /config to agent (async provision+start)");
|
||||
await sendAgentConfig({ ip: ctIp, payload });
|
||||
|
||||
await waitForAgentTerminalState({ ip: ctIp });
|
||||
console.log("[agentProvision] STEP 9: wait for agent to be running via /status");
|
||||
const agentResult = await waitForAgentRunning({ ip: ctIp });
|
||||
|
||||
step("persist-instance");
|
||||
await prisma.containerInstance.create({
|
||||
console.log("[agentProvision] STEP 10: DB save");
|
||||
const instance = await prisma.containerInstance.create({
|
||||
data: {
|
||||
vmid,
|
||||
customerId: req.customerId,
|
||||
customerId,
|
||||
ctype,
|
||||
hostname,
|
||||
hostname: instanceHostname,
|
||||
ip: ctIp,
|
||||
allocatedPorts: allocatedPortsMap,
|
||||
payload,
|
||||
agentState: "running",
|
||||
agentState: agentResult.state,
|
||||
agentLastSeen: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
if (ctype === "game") {
|
||||
step("publish-edge");
|
||||
|
||||
const edgePorts =
|
||||
req.ports?.length
|
||||
? req.ports
|
||||
: req.game === "minecraft"
|
||||
? [25565]
|
||||
: [];
|
||||
|
||||
await enqueuePublishEdge({
|
||||
console.log("[agentProvision] STEP 11: commit ports");
|
||||
if (!isMinecraft && gamePorts.length) {
|
||||
await PortAllocationService.commit({
|
||||
vmid,
|
||||
slotHostname: hostname,
|
||||
ctIp,
|
||||
game: req.game,
|
||||
ports: edgePorts,
|
||||
ports: gamePorts,
|
||||
portType: "game",
|
||||
});
|
||||
}
|
||||
|
||||
step("confirm-vmid");
|
||||
console.log("[agentProvision] STEP 12: publish edge");
|
||||
await enqueuePublishEdge({
|
||||
vmid,
|
||||
slotHostname: instanceHostname,
|
||||
instanceHostname,
|
||||
ports: gamePorts,
|
||||
ctIp,
|
||||
game,
|
||||
});
|
||||
|
||||
await confirmVmidAllocated(vmid);
|
||||
|
||||
return { vmid, hostname, ip: ctIp };
|
||||
console.log("[agentProvision] COMPLETE");
|
||||
|
||||
return {
|
||||
vmid,
|
||||
ip: ctIp,
|
||||
hostname: instanceHostname,
|
||||
ports: gamePorts,
|
||||
instance,
|
||||
};
|
||||
} catch (err) {
|
||||
step("error-cleanup");
|
||||
if (vmid) {
|
||||
try { await deleteContainer(vmid); } catch {}
|
||||
try { await releaseVmid(vmid); } catch {}
|
||||
}
|
||||
console.error("[agentProvision] ERROR:", err.message);
|
||||
|
||||
try {
|
||||
if (vmid) await PortAllocationService.releaseByVmid(vmid);
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
if (vmid) await deleteContainer(vmid);
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
if (vmid) await releaseVmid(vmid);
|
||||
} catch {}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user