fix: power control 502 error and add instant refresh

- Power operations use /api2/extjs endpoint (not /api2/json)
- Remove unprivileged parameter that causes 400 validation error
- Refetch VM/LXC/node/status after successful power action via SWR mutate

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 18:56:29 +01:00
parent 33d2f6e42a
commit ad328efa3c
2 changed files with 38 additions and 58 deletions

View File

@@ -1,7 +1,7 @@
'use client';
import { useState } from 'react';
import useSWR from 'swr';
import useSWR, { mutate } from 'swr';
import NodeList from './NodeList';
import VMList from './VMList';
import LXCList from './LXCList';
@@ -45,6 +45,11 @@ export default function Dashboard() {
setPowerActionStatus({ text: `${action.charAt(0).toUpperCase() + action.slice(1)}ing ${type === 'qemu' ? 'VM' : 'LXC'} ${vmid}...`, type: 'pending' });
try {
await axios.post('/api/power', { node, vmid, type, action });
// Immediately refetch all data instead of waiting for polling interval
await mutate('/api/nodes');
await mutate('/api/vms');
await mutate('/api/lxc');
await mutate('/api/status');
setPowerActionStatus({ text: `${action.charAt(0).toUpperCase() + action.slice(1)} successful`, type: 'success' });
} catch (err) {
setPowerActionStatus({ text: err.message || `${action.charAt(0).toUpperCase() + action.slice(1)} failed`, type: 'error' });