feat: add start/stop/restart buttons for VMs and LXCs
- New POST /api/power route for Proxmox power operations - powerControl() method in proxmox.js library - Start/Stop/Restart action buttons in VMList and LXCList tables - Status feedback banner in Dashboard on power action Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
28
src/app/api/power/route.js
Normal file
28
src/app/api/power/route.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { powerControl } from '@/lib/proxmox';
|
||||
|
||||
/**
|
||||
* @param {import('next').Request} req
|
||||
*/
|
||||
export async function POST(req) {
|
||||
try {
|
||||
const { node, vmid, type, action } = await req.json();
|
||||
|
||||
if (!node || !vmid || !type || !action) {
|
||||
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!['qemu', 'lxc'].includes(type)) {
|
||||
return NextResponse.json({ error: 'Invalid type, must be qemu or lxc' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!['start', 'stop', 'restart'].includes(action)) {
|
||||
return NextResponse.json({ error: 'Invalid action, must be start, stop, or restart' }, { status: 400 });
|
||||
}
|
||||
|
||||
await powerControl(node, vmid, type, action);
|
||||
return NextResponse.json({ ok: true, timestamp: Date.now() });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: error.message, ok: false }, { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user