- 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>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { NextResponse } from 'next/server';
|
|
import { getNodes, getLXC, 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 allLXC = [];
|
|
|
|
for (const node of nodes) {
|
|
try {
|
|
const lxcs = await getLXC(node.name);
|
|
for (const lxc of lxcs) {
|
|
let ips = [];
|
|
if (lxc.status === 'running') {
|
|
try {
|
|
ips = await getConfigIPs(node.name, lxc.vmid, 'lxc');
|
|
} catch { /* guest agent not available */ }
|
|
}
|
|
allLXC.push({
|
|
...lxc,
|
|
node: node.name,
|
|
consoleUrl: `${PROXMOX_WEB_URL}/?console=lxc&vmid=${lxc.vmid}&node=${encodeURIComponent(node.name)}&resize=scale&xtermjs=1`,
|
|
ips,
|
|
});
|
|
}
|
|
} catch { /* skip node */ }
|
|
}
|
|
|
|
return NextResponse.json({ data: allLXC, timestamp: Date.now() });
|
|
} catch (error) {
|
|
return NextResponse.json({ error: error.message, data: null }, { status: 502 });
|
|
}
|
|
}
|