Files
proxmox-monitor/src/app/api/vms/route.js
Rob Bond 4deadcba3f fix IP addresses: parse from config/agent endpoints instead of guest agent
- LXCs: use /interfaces endpoint first, fallback to net0-net7 config parsing
- QEMU: use /agent/network-get-interfaces with correct result nesting
- IPv4 only filtering (ip-address-type check)
- Drop ip6= and nameserver from config fallback

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 11:36:05 +01:00

37 lines
1.2 KiB
JavaScript

import { NextResponse } from 'next/server';
import { getNodes, getVMs, getConfigIPs } from '@/lib/proxmox';
const PROXMOX_WEB_URL = process.env.PROXMOX_WEB_URL || process.env.PROXMOX_API_URL?.replace('/api2/json', '');
/** @param {import('next').Request} _req */
export async function GET(_req) {
try {
const nodes = await getNodes();
const allVMs = [];
for (const node of nodes) {
try {
const vms = await getVMs(node.name);
for (const vm of vms) {
let ips = [];
if (vm.status === 'running') {
try {
ips = await getConfigIPs(node.name, vm.vmid, 'qemu');
} catch { /* guest agent not available */ }
}
allVMs.push({
...vm,
node: node.name,
consoleUrl: `${PROXMOX_WEB_URL}/?console=qemu&vmid=${vm.vmid}&node=${encodeURIComponent(node.name)}&resize=scale&novnc=1`,
ips,
});
}
} catch { /* skip node */ }
}
return NextResponse.json({ data: allVMs, timestamp: Date.now() });
} catch (error) {
return NextResponse.json({ error: error.message, data: null }, { status: 502 });
}
}