mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 03:26:17 +00:00
Update virtual-machines.tsx
This commit is contained in:
@@ -139,7 +139,7 @@ const fetcher = async (url: string) => {
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
signal: AbortSignal.timeout(5000),
|
signal: AbortSignal.timeout(30000),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -267,6 +267,8 @@ export function VirtualMachines() {
|
|||||||
refreshInterval: 23000,
|
refreshInterval: 23000,
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
revalidateOnReconnect: true,
|
revalidateOnReconnect: true,
|
||||||
|
dedupingInterval: 10000,
|
||||||
|
errorRetryCount: 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
const [selectedVM, setSelectedVM] = useState<VMData | null>(null)
|
const [selectedVM, setSelectedVM] = useState<VMData | null>(null)
|
||||||
@@ -274,6 +276,7 @@ export function VirtualMachines() {
|
|||||||
const [controlLoading, setControlLoading] = useState(false)
|
const [controlLoading, setControlLoading] = useState(false)
|
||||||
const [detailsLoading, setDetailsLoading] = useState(false)
|
const [detailsLoading, setDetailsLoading] = useState(false)
|
||||||
const [vmConfigs, setVmConfigs] = useState<Record<number, string>>({})
|
const [vmConfigs, setVmConfigs] = useState<Record<number, string>>({})
|
||||||
|
const [loadingLXCIPs, setLoadingLXCIPs] = useState(false)
|
||||||
const [currentView, setCurrentView] = useState<"main" | "metrics">("main")
|
const [currentView, setCurrentView] = useState<"main" | "metrics">("main")
|
||||||
const [showAdditionalInfo, setShowAdditionalInfo] = useState(false)
|
const [showAdditionalInfo, setShowAdditionalInfo] = useState(false)
|
||||||
const [showNotes, setShowNotes] = useState(false)
|
const [showNotes, setShowNotes] = useState(false)
|
||||||
@@ -287,27 +290,46 @@ export function VirtualMachines() {
|
|||||||
if (!vmData) return
|
if (!vmData) return
|
||||||
|
|
||||||
const lxcs = vmData.filter((vm) => vm.type === "lxc")
|
const lxcs = vmData.filter((vm) => vm.type === "lxc")
|
||||||
|
|
||||||
|
if (lxcs.length === 0) return
|
||||||
|
|
||||||
|
setLoadingLXCIPs(true)
|
||||||
const configs: Record<number, string> = {}
|
const configs: Record<number, string> = {}
|
||||||
|
|
||||||
await Promise.all(
|
const batchSize = 5
|
||||||
lxcs.map(async (lxc) => {
|
for (let i = 0; i < lxcs.length; i += batchSize) {
|
||||||
try {
|
const batch = lxcs.slice(i, i + batchSize)
|
||||||
const response = await fetch(`/api/vms/${lxc.vmid}`)
|
|
||||||
if (response.ok) {
|
|
||||||
const details = await response.json()
|
|
||||||
if (details.lxc_ip_info?.primary_ip) {
|
|
||||||
configs[lxc.vmid] = details.lxc_ip_info.primary_ip
|
|
||||||
} else if (details.config) {
|
|
||||||
configs[lxc.vmid] = extractIPFromConfig(details.config, details.lxc_ip_info)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error fetching config for LXC ${lxc.vmid}:`, error)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
setVmConfigs(configs)
|
await Promise.all(
|
||||||
|
batch.map(async (lxc) => {
|
||||||
|
try {
|
||||||
|
const controller = new AbortController()
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 10000)
|
||||||
|
|
||||||
|
const response = await fetch(`/api/vms/${lxc.vmid}`, {
|
||||||
|
signal: controller.signal,
|
||||||
|
})
|
||||||
|
|
||||||
|
clearTimeout(timeoutId)
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const details = await response.json()
|
||||||
|
if (details.lxc_ip_info?.primary_ip) {
|
||||||
|
configs[lxc.vmid] = details.lxc_ip_info.primary_ip
|
||||||
|
} else if (details.config) {
|
||||||
|
configs[lxc.vmid] = extractIPFromConfig(details.config, details.lxc_ip_info)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`[v0] Could not fetch IP for LXC ${lxc.vmid}`)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
setVmConfigs({ ...configs })
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoadingLXCIPs(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchLXCIPs()
|
fetchLXCIPs()
|
||||||
@@ -478,10 +500,12 @@ export function VirtualMachines() {
|
|||||||
return "text-green-500"
|
return "text-green-500"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading || loadingLXCIPs) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="text-center py-8 text-muted-foreground">Loading virtual machines...</div>
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
{isLoading ? "Loading virtual machines..." : "Loading container IPs..."}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user