Files
ProxMenux/AppImage/components/virtual-machines.tsx

780 lines
33 KiB
TypeScript
Raw Normal View History

2025-09-28 23:09:31 +02:00
"use client"
2025-10-05 14:16:21 +02:00
import { useState, useMemo } from "react"
2025-09-28 23:09:31 +02:00
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"
import { Badge } from "./ui/badge"
import { Progress } from "./ui/progress"
2025-10-05 12:32:09 +02:00
import { Button } from "./ui/button"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog"
import {
Server,
Play,
Square,
Cpu,
MemoryStick,
HardDrive,
Network,
Power,
RotateCcw,
StopCircle,
2025-10-05 14:16:21 +02:00
AlertTriangle,
2025-10-05 12:32:09 +02:00
} from "lucide-react"
import useSWR from "swr"
2025-09-28 23:09:31 +02:00
2025-09-30 00:09:11 +02:00
interface VMData {
vmid: number
name: string
status: string
2025-10-05 12:32:09 +02:00
type: string
2025-09-30 00:09:11 +02:00
cpu: number
mem: number
maxmem: number
disk: number
maxdisk: number
uptime: number
2025-10-05 12:32:09 +02:00
netin?: number
netout?: number
diskread?: number
diskwrite?: number
2025-09-30 00:09:11 +02:00
}
2025-10-05 12:48:34 +02:00
interface VMConfig {
cores?: number
memory?: number
swap?: number
rootfs?: string
net0?: string
net1?: string
net2?: string
nameserver?: string
searchdomain?: string
onboot?: number
unprivileged?: number
features?: string
ostype?: string
arch?: string
hostname?: string
// VM specific
sockets?: number
scsi0?: string
ide0?: string
boot?: string
[key: string]: any
}
interface VMDetails extends VMData {
config?: VMConfig
node?: string
vm_type?: string
}
2025-10-05 12:32:09 +02:00
const fetcher = async (url: string) => {
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
signal: AbortSignal.timeout(5000),
})
2025-09-30 00:09:11 +02:00
2025-10-05 12:32:09 +02:00
if (!response.ok) {
throw new Error(`Flask server responded with status: ${response.status}`)
2025-09-30 00:09:11 +02:00
}
2025-10-05 12:32:09 +02:00
const data = await response.json()
return Array.isArray(data) ? data : []
2025-09-30 00:09:11 +02:00
}
2025-09-28 23:09:31 +02:00
2025-10-05 12:03:47 +02:00
const formatBytes = (bytes: number | undefined): string => {
if (!bytes || bytes === 0) return "0 B"
const k = 1024
const sizes = ["B", "KB", "MB", "GB", "TB"]
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`
}
2025-10-05 16:28:12 +02:00
const formatUptime = (seconds: number) => {
const days = Math.floor(seconds / 86400)
const hours = Math.floor((seconds % 86400) / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
return `${days}d ${hours}h ${minutes}m`
}
const extractIPFromConfig = (config?: VMConfig): string => {
if (!config) return "DHCP"
// Check net0, net1, net2, etc.
for (let i = 0; i < 10; i++) {
const netKey = `net${i}`
const netConfig = config[netKey]
if (netConfig && typeof netConfig === "string") {
// Look for ip=x.x.x.x/xx pattern
const ipMatch = netConfig.match(/ip=([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(\/\d+)?/)
if (ipMatch) {
return ipMatch[1] // Return just the IP without CIDR
}
// Check if it's explicitly DHCP
if (netConfig.includes("ip=dhcp")) {
return "DHCP"
}
}
}
return "DHCP"
}
2025-09-28 23:09:31 +02:00
export function VirtualMachines() {
2025-10-05 12:32:09 +02:00
const {
data: vmData,
error,
isLoading,
mutate,
} = useSWR<VMData[]>("/api/vms", fetcher, {
2025-10-05 12:48:34 +02:00
refreshInterval: 30000,
2025-10-05 12:32:09 +02:00
revalidateOnFocus: false,
revalidateOnReconnect: true,
})
const [selectedVM, setSelectedVM] = useState<VMData | null>(null)
2025-10-05 12:48:34 +02:00
const [vmDetails, setVMDetails] = useState<VMDetails | null>(null)
2025-10-05 12:32:09 +02:00
const [controlLoading, setControlLoading] = useState(false)
2025-10-05 12:48:34 +02:00
const [detailsLoading, setDetailsLoading] = useState(false)
const handleVMClick = async (vm: VMData) => {
setSelectedVM(vm)
setDetailsLoading(true)
try {
const response = await fetch(`/api/vms/${vm.vmid}`)
if (response.ok) {
const details = await response.json()
setVMDetails(details)
}
} catch (error) {
console.error("Error fetching VM details:", error)
} finally {
setDetailsLoading(false)
}
}
2025-10-05 12:32:09 +02:00
const handleVMControl = async (vmid: number, action: string) => {
setControlLoading(true)
try {
const response = await fetch(`/api/vms/${vmid}/control`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ action }),
})
if (response.ok) {
mutate()
setSelectedVM(null)
2025-10-05 12:48:34 +02:00
setVMDetails(null)
2025-10-05 12:32:09 +02:00
} else {
console.error("Failed to control VM")
2025-09-30 00:09:11 +02:00
}
2025-10-05 12:32:09 +02:00
} catch (error) {
console.error("Error controlling VM:", error)
} finally {
setControlLoading(false)
2025-09-30 00:09:11 +02:00
}
2025-10-05 12:32:09 +02:00
}
2025-09-30 00:09:11 +02:00
2025-10-05 12:48:34 +02:00
const handleDownloadLogs = async (vmid: number, vmName: string) => {
2025-10-05 12:32:09 +02:00
try {
const response = await fetch(`/api/vms/${vmid}/logs`)
if (response.ok) {
const data = await response.json()
2025-10-05 12:48:34 +02:00
// Format logs as plain text
let logText = `=== Logs for ${vmName} (VMID: ${vmid}) ===\n`
logText += `Node: ${data.node}\n`
logText += `Type: ${data.type}\n`
logText += `Total lines: ${data.log_lines}\n`
logText += `Generated: ${new Date().toISOString()}\n`
logText += `\n${"=".repeat(80)}\n\n`
if (data.logs && Array.isArray(data.logs)) {
data.logs.forEach((log: any) => {
if (typeof log === "object" && log.t) {
logText += `${log.t}\n`
} else if (typeof log === "string") {
logText += `${log}\n`
}
})
}
const blob = new Blob([logText], { type: "text/plain" })
2025-10-05 12:32:09 +02:00
const url = URL.createObjectURL(blob)
const a = document.createElement("a")
a.href = url
2025-10-05 12:48:34 +02:00
a.download = `${vmName}-${vmid}-logs.txt`
2025-10-05 12:32:09 +02:00
a.click()
URL.revokeObjectURL(url)
}
} catch (error) {
console.error("Error downloading logs:", error)
}
}
2025-09-30 00:09:11 +02:00
2025-09-28 23:09:31 +02:00
const getStatusColor = (status: string) => {
switch (status) {
case "running":
return "bg-green-500/10 text-green-500 border-green-500/20"
case "stopped":
return "bg-red-500/10 text-red-500 border-red-500/20"
default:
return "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
}
}
const getStatusIcon = (status: string) => {
switch (status) {
case "running":
return <Play className="h-3 w-3 mr-1" />
case "stopped":
return <Square className="h-3 w-3 mr-1" />
default:
2025-09-30 00:09:11 +02:00
return null
2025-09-28 23:09:31 +02:00
}
}
2025-10-05 12:03:47 +02:00
const getTypeBadge = (type: string) => {
if (type === "lxc") {
return { color: "bg-cyan-500/10 text-cyan-500 border-cyan-500/20", label: "LXC" }
}
return { color: "bg-purple-500/10 text-purple-500 border-purple-500/20", label: "VM" }
}
2025-10-05 12:56:06 +02:00
// Safe data handling with default empty array
const safeVMData = vmData || []
2025-10-05 14:16:21 +02:00
const totalAllocatedMemoryGB = useMemo(() => {
return (safeVMData.reduce((sum, vm) => sum + (vm.maxmem || 0), 0) / 1024 ** 3).toFixed(1)
}, [safeVMData])
const { data: overviewData } = useSWR("/api/overview", fetcher, {
refreshInterval: 30000,
revalidateOnFocus: false,
})
const physicalMemoryGB = useMemo(() => {
if (overviewData && overviewData.memory) {
return (overviewData.memory.total / 1024 ** 3).toFixed(1)
}
return null
}, [overviewData])
const isMemoryOvercommit = useMemo(() => {
if (physicalMemoryGB) {
return Number.parseFloat(totalAllocatedMemoryGB) > Number.parseFloat(physicalMemoryGB)
}
return false
}, [totalAllocatedMemoryGB, physicalMemoryGB])
2025-10-05 12:56:06 +02:00
if (isLoading) {
return (
<div className="space-y-6">
<div className="text-center py-8 text-muted-foreground">Loading virtual machines...</div>
</div>
)
}
if (error) {
return (
<div className="space-y-6">
<div className="text-center py-8 text-red-500">Error loading virtual machines: {error.message}</div>
</div>
)
}
2025-09-28 23:09:31 +02:00
return (
<div className="space-y-6">
{/* VM Overview Cards */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
2025-10-05 12:32:09 +02:00
<CardTitle className="text-sm font-medium text-muted-foreground">Total VMs & LXCs</CardTitle>
2025-09-28 23:09:31 +02:00
<Server className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
2025-10-05 12:56:06 +02:00
<div className="text-2xl font-bold text-foreground">{safeVMData.length}</div>
2025-09-28 23:09:31 +02:00
<div className="vm-badges mt-2">
<Badge variant="outline" className="vm-badge bg-green-500/10 text-green-500 border-green-500/20">
2025-10-05 12:56:06 +02:00
{safeVMData.filter((vm) => vm.status === "running").length} Running
2025-09-28 23:09:31 +02:00
</Badge>
<Badge variant="outline" className="vm-badge bg-red-500/10 text-red-500 border-red-500/20">
2025-10-05 12:56:06 +02:00
{safeVMData.filter((vm) => vm.status === "stopped").length} Stopped
2025-09-28 23:09:31 +02:00
</Badge>
</div>
2025-09-30 00:09:11 +02:00
<p className="text-xs text-muted-foreground mt-2">Virtual machines configured</p>
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
2025-09-30 00:09:11 +02:00
<CardTitle className="text-sm font-medium text-muted-foreground">Total CPU</CardTitle>
2025-09-28 23:09:31 +02:00
<Cpu className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
2025-10-05 12:48:34 +02:00
<div className="text-2xl font-bold text-foreground">
2025-10-05 12:56:06 +02:00
{(safeVMData.reduce((sum, vm) => sum + (vm.cpu || 0), 0) * 100).toFixed(0)}%
2025-10-05 12:48:34 +02:00
</div>
2025-09-30 00:09:11 +02:00
<p className="text-xs text-muted-foreground mt-2">Allocated CPU usage</p>
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
2025-10-05 14:16:21 +02:00
<Card className={`bg-card ${isMemoryOvercommit ? "border-yellow-500/50" : "border-border"}`}>
2025-09-28 23:09:31 +02:00
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Total Memory</CardTitle>
2025-10-05 15:44:19 +02:00
<div className="flex items-center gap-2">
{isMemoryOvercommit && <AlertTriangle className="h-4 w-4 text-yellow-500" />}
<MemoryStick className="h-4 w-4 text-muted-foreground" />
</div>
2025-09-28 23:09:31 +02:00
</CardHeader>
<CardContent>
2025-10-05 14:16:21 +02:00
<div className={`text-2xl font-bold ${isMemoryOvercommit ? "text-yellow-500" : "text-foreground"}`}>
{totalAllocatedMemoryGB} GB
2025-10-05 12:48:34 +02:00
</div>
2025-10-05 15:44:19 +02:00
{isMemoryOvercommit ? (
<p className="text-xs text-yellow-500 mt-2 flex items-center gap-1">
<AlertTriangle className="h-3 w-3" />
Overcommit: Excede memoria física ({physicalMemoryGB} GB)
</p>
) : (
<p className="text-xs text-muted-foreground mt-2">Allocated RAM</p>
2025-10-05 14:16:21 +02:00
)}
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
<Card className="bg-card border-border">
2025-10-05 16:28:12 +02:00
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Server className="h-5 w-5 mr-2" />
Virtual Machines & Containers
</CardTitle>
2025-09-28 23:09:31 +02:00
</CardHeader>
<CardContent>
2025-10-05 16:28:12 +02:00
{safeVMData.length === 0 ? (
<div className="text-center py-8 text-muted-foreground">No virtual machines found</div>
) : (
<div className="space-y-4">
{safeVMData.map((vm) => {
const cpuPercent = (vm.cpu * 100).toFixed(1)
const memPercent = vm.maxmem > 0 ? ((vm.mem / vm.maxmem) * 100).toFixed(1) : "0"
const memGB = (vm.mem / 1024 ** 3).toFixed(1)
const maxMemGB = (vm.maxmem / 1024 ** 3).toFixed(1)
const typeBadge = getTypeBadge(vm.type)
const vmIP = extractIPFromConfig(vm.config)
return (
<div
key={vm.vmid}
className="p-6 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer"
onClick={() => handleVMClick(vm)}
>
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-4">
<div className="flex items-center space-x-4">
<Server className="h-6 w-6 text-muted-foreground flex-shrink-0" />
<div className="min-w-0">
<div className="font-semibold text-foreground text-lg flex items-center flex-wrap gap-2">
<span className="truncate">{vm.name}</span>
<Badge variant="outline" className={`text-xs flex-shrink-0 ${typeBadge.color}`}>
{typeBadge.label}
</Badge>
</div>
<div className="text-sm text-muted-foreground">ID: {vm.vmid}</div>
<div className="text-sm text-muted-foreground">IP: {vmIP}</div>
2025-09-30 00:09:11 +02:00
</div>
</div>
2025-10-05 16:28:12 +02:00
<Badge
variant="outline"
className={`${getStatusColor(vm.status)} flex-shrink-0 self-start sm:self-center`}
>
{getStatusIcon(vm.status)}
{vm.status.toUpperCase()}
</Badge>
2025-09-28 23:09:31 +02:00
</div>
2025-09-30 00:09:11 +02:00
2025-10-05 16:28:12 +02:00
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div>
<div className="text-sm text-muted-foreground mb-2">CPU Usage</div>
<div className="text-lg font-semibold text-foreground mb-1">{cpuPercent}%</div>
<Progress value={Number.parseFloat(cpuPercent)} className="h-2 [&>div]:bg-blue-500" />
2025-10-05 12:03:47 +02:00
</div>
2025-10-05 16:28:12 +02:00
<div>
<div className="text-sm text-muted-foreground mb-2">Memory Usage</div>
<div className="text-lg font-semibold text-foreground mb-1">
{memGB} / {maxMemGB} GB
2025-10-05 12:03:47 +02:00
</div>
2025-10-05 16:28:12 +02:00
<Progress value={Number.parseFloat(memPercent)} className="h-2 [&>div]:bg-blue-500" />
2025-09-30 00:09:11 +02:00
</div>
2025-10-05 16:28:12 +02:00
<div className="hidden md:block">
<div className="text-sm text-muted-foreground mb-2">Disk I/O</div>
<div className="text-sm font-semibold text-foreground">
<div className="flex items-center gap-1">
<HardDrive className="h-3 w-3 text-green-500" />
<span className="text-green-500"> {formatBytes(vm.diskread)}</span>
</div>
<div className="flex items-center gap-1 mt-1">
<HardDrive className="h-3 w-3 text-blue-500" />
<span className="text-blue-500"> {formatBytes(vm.diskwrite)}</span>
</div>
2025-10-05 12:03:47 +02:00
</div>
2025-10-05 16:28:12 +02:00
</div>
<div className="hidden md:block">
<div className="text-sm text-muted-foreground mb-2">Network I/O</div>
<div className="text-sm font-semibold text-foreground">
<div className="flex items-center gap-1">
<Network className="h-3 w-3 text-green-500" />
<span className="text-green-500"> {formatBytes(vm.netin)}</span>
</div>
<div className="flex items-center gap-1 mt-1">
<Network className="h-3 w-3 text-blue-500" />
<span className="text-blue-500"> {formatBytes(vm.netout)}</span>
</div>
2025-10-05 12:03:47 +02:00
</div>
</div>
2025-09-28 23:09:31 +02:00
</div>
2025-10-05 12:03:47 +02:00
2025-10-05 16:28:12 +02:00
<div className="mt-4 pt-4 border-t border-border">
<div className="text-sm text-muted-foreground">Uptime</div>
<div className="text-lg font-semibold text-foreground">{formatUptime(vm.uptime)}</div>
</div>
2025-10-05 12:03:47 +02:00
</div>
2025-10-05 16:28:12 +02:00
)
})}
2025-10-05 14:16:21 +02:00
</div>
2025-10-05 16:28:12 +02:00
)}
</CardContent>
</Card>
{/* VM Details Modal */}
<Dialog
open={!!selectedVM}
onOpenChange={() => {
setSelectedVM(null)
setVMDetails(null)
}}
>
<DialogContent className="max-w-4xl max-h-[95vh] overflow-y-auto">
<DialogHeader className="pb-4 border-b border-border">
<DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3">
<div className="flex items-center gap-2">
<Server className="h-5 w-5 flex-shrink-0" />
<span className="text-lg truncate">{selectedVM?.name}</span>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 16:28:12 +02:00
{selectedVM && (
<div className="flex items-center gap-2 flex-wrap">
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
{getTypeBadge(selectedVM.type).label}
</Badge>
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
{selectedVM.status.toUpperCase()}
</Badge>
</div>
)}
</DialogTitle>
</DialogHeader>
<div className="space-y-6 py-4">
{selectedVM && (
<>
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Basic Information
</h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
<div>
<div className="text-xs text-muted-foreground mb-1">Name</div>
<div className="font-semibold text-foreground">{selectedVM.name}</div>
2025-10-05 13:50:29 +02:00
</div>
2025-10-05 16:28:12 +02:00
<div>
<div className="text-xs text-muted-foreground mb-1">VMID</div>
<div className="font-semibold text-foreground">{selectedVM.vmid}</div>
2025-10-05 12:48:34 +02:00
</div>
2025-10-05 16:28:12 +02:00
<div>
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
<div
className={`font-semibold ${
(selectedVM.cpu * 100) > 80
? "text-red-500"
: selectedVM.cpu * 100 > 60
? "text-yellow-500"
: "text-green-500"
}`}
>
{(selectedVM.cpu * 100).toFixed(1)}%
</div>
2025-10-05 12:48:34 +02:00
</div>
2025-10-05 16:28:12 +02:00
<div>
<div className="text-xs text-muted-foreground mb-1">Memory</div>
<div
className={`font-semibold ${
((selectedVM.mem / selectedVM.maxmem) * 100) > 80
? "text-red-500"
: (selectedVM.mem / selectedVM.maxmem) * 100 > 60
? "text-yellow-500"
: "text-blue-500"
}`}
>
{(selectedVM.mem / 1024 ** 3).toFixed(1)} / {(selectedVM.maxmem / 1024 ** 3).toFixed(1)} GB
2025-10-05 14:16:21 +02:00
</div>
2025-10-05 16:28:12 +02:00
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Disk</div>
<div className="font-semibold text-foreground">
{(selectedVM.disk / 1024 ** 3).toFixed(1)} / {(selectedVM.maxdisk / 1024 ** 3).toFixed(1)} GB
2025-10-05 14:16:21 +02:00
</div>
</div>
2025-10-05 16:28:12 +02:00
<div>
<div className="text-xs text-muted-foreground mb-1">Uptime</div>
<div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
<div className="text-sm font-semibold">
<div className="flex items-center gap-1">
<span className="text-green-500"> {formatBytes(selectedVM.diskread)}</span>
</div>
<div className="flex items-center gap-1">
<span className="text-blue-500"> {formatBytes(selectedVM.diskwrite)}</span>
</div>
2025-10-05 14:16:21 +02:00
</div>
2025-10-05 16:28:12 +02:00
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Network I/O</div>
<div className="text-sm font-semibold">
<div className="flex items-center gap-1">
<span className="text-green-500"> {formatBytes(selectedVM.netin)}</span>
</div>
<div className="flex items-center gap-1">
<span className="text-blue-500"> {formatBytes(selectedVM.netout)}</span>
</div>
2025-10-05 14:16:21 +02:00
</div>
</div>
</div>
2025-10-05 12:32:09 +02:00
</div>
2025-10-05 12:48:34 +02:00
2025-10-05 16:28:12 +02:00
{/* Resources Configuration */}
{detailsLoading ? (
<div className="text-center py-8 text-muted-foreground">Loading configuration...</div>
) : vmDetails?.config ? (
<>
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Resources
</h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
{vmDetails.config.cores && (
<div>
<div className="text-xs text-muted-foreground mb-1">CPU Cores</div>
<div className="font-semibold text-blue-500">{vmDetails.config.cores}</div>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 16:28:12 +02:00
)}
{vmDetails.config.sockets && (
<div>
<div className="text-xs text-muted-foreground mb-1">CPU Sockets</div>
<div className="font-semibold text-foreground">{vmDetails.config.sockets}</div>
</div>
)}
{vmDetails.config.memory && (
<div>
<div className="text-xs text-muted-foreground mb-1">Memory</div>
<div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div>
</div>
)}
{vmDetails.config.swap && (
<div>
<div className="text-xs text-muted-foreground mb-1">Swap</div>
<div className="font-semibold text-foreground">{vmDetails.config.swap} MB</div>
</div>
)}
{vmDetails.config.rootfs && (
<div className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">Root Filesystem</div>
2025-10-05 13:50:29 +02:00
<div className="font-medium text-foreground text-sm break-all font-mono">
2025-10-05 16:28:12 +02:00
{vmDetails.config.rootfs}
2025-10-05 13:50:29 +02:00
</div>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 16:28:12 +02:00
)}
{Object.keys(vmDetails.config)
.filter((key) => key.match(/^(scsi|sata|ide|virtio)\d+$/))
.map((diskKey) => (
<div key={diskKey} className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">
{diskKey.toUpperCase().replace(/(\d+)/, " $1")}
</div>
<div className="font-medium text-foreground text-sm break-all font-mono">
{vmDetails.config[diskKey]}
</div>
</div>
))}
</div>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 16:28:12 +02:00
{/* Network Configuration */}
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Network
</h3>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
{Object.keys(vmDetails.config)
.filter((key) => key.match(/^net\d+$/))
.map((netKey) => (
<div key={netKey} className="col-span-1">
<div className="text-xs text-muted-foreground mb-1">
Network Interface {netKey.replace("net", "")}
</div>
<div className="font-medium text-green-500 text-sm break-all font-mono">
{vmDetails.config[netKey]}
</div>
2025-10-05 15:38:29 +02:00
</div>
2025-10-05 16:28:12 +02:00
))}
{vmDetails.config.nameserver && (
<div>
<div className="text-xs text-muted-foreground mb-1">DNS Nameserver</div>
<div className="font-medium text-foreground font-mono">{vmDetails.config.nameserver}</div>
2025-10-05 16:05:54 +02:00
</div>
2025-10-05 16:28:12 +02:00
)}
{vmDetails.config.searchdomain && (
<div>
<div className="text-xs text-muted-foreground mb-1">Search Domain</div>
<div className="font-medium text-foreground">{vmDetails.config.searchdomain}</div>
</div>
)}
{vmDetails.config.hostname && (
<div>
<div className="text-xs text-muted-foreground mb-1">Hostname</div>
<div className="font-medium text-foreground">{vmDetails.config.hostname}</div>
</div>
)}
</div>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 16:28:12 +02:00
{/* Options */}
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Options
</h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
{vmDetails.config.onboot !== undefined && (
<div>
<div className="text-xs text-muted-foreground mb-1">Start on Boot</div>
<Badge
variant="outline"
className={
vmDetails.config.onboot
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-red-500/10 text-red-500 border-red-500/20"
}
>
{vmDetails.config.onboot ? "Yes" : "No"}
</Badge>
</div>
)}
{vmDetails.config.unprivileged !== undefined && (
<div>
<div className="text-xs text-muted-foreground mb-1">Unprivileged</div>
<Badge
variant="outline"
className={
vmDetails.config.unprivileged
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
}
>
{vmDetails.config.unprivileged ? "Yes" : "No"}
</Badge>
</div>
)}
{vmDetails.config.ostype && (
<div>
<div className="text-xs text-muted-foreground mb-1">OS Type</div>
<div className="font-medium text-foreground">{vmDetails.config.ostype}</div>
</div>
)}
{vmDetails.config.arch && (
<div>
<div className="text-xs text-muted-foreground mb-1">Architecture</div>
<div className="font-medium text-foreground">{vmDetails.config.arch}</div>
</div>
)}
{vmDetails.config.boot && (
<div>
<div className="text-xs text-muted-foreground mb-1">Boot Order</div>
<div className="font-medium text-foreground">{vmDetails.config.boot}</div>
</div>
)}
{vmDetails.config.features && (
<div className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">Features</div>
<div className="font-medium text-foreground text-sm">{vmDetails.config.features}</div>
</div>
)}
</div>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 16:28:12 +02:00
</>
) : null}
{/* Control Actions */}
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Control Actions
</h3>
<div className="grid grid-cols-2 gap-3">
<Button
variant="outline"
className="w-full bg-transparent"
disabled={selectedVM.status === "running" || controlLoading}
onClick={() => handleVMControl(selectedVM.vmid, "start")}
>
<Play className="h-4 w-4 mr-2" />
Start
</Button>
<Button
variant="outline"
className="w-full bg-transparent"
disabled={selectedVM.status !== "running" || controlLoading}
onClick={() => handleVMControl(selectedVM.vmid, "shutdown")}
>
<Power className="h-4 w-4 mr-2" />
Shutdown
</Button>
<Button
variant="outline"
className="w-full bg-transparent"
disabled={selectedVM.status !== "running" || controlLoading}
onClick={() => handleVMControl(selectedVM.vmid, "reboot")}
>
<RotateCcw className="h-4 w-4 mr-2" />
Reboot
</Button>
<Button
variant="outline"
className="w-full bg-transparent"
disabled={selectedVM.status !== "running" || controlLoading}
onClick={() => handleVMControl(selectedVM.vmid, "stop")}
>
<StopCircle className="h-4 w-4 mr-2" />
Force Stop
</Button>
2025-10-05 13:15:44 +02:00
</div>
2025-10-05 12:32:09 +02:00
</div>
2025-10-05 16:28:12 +02:00
</>
)}
</div>
</DialogContent>
</Dialog>
</div>
2025-09-28 23:09:31 +02:00
</div>
)
}