Update modal lxc

This commit is contained in:
MacRimi
2026-02-03 22:53:37 +01:00
parent 303dcb1eb6
commit 91f15b723e
2 changed files with 47 additions and 19 deletions

View File

@@ -224,6 +224,28 @@ const getUsageColor = (percent: number): string => {
return "text-foreground" return "text-foreground"
} }
// Generate consistent color for storage names
const storageColors = [
{ bg: "bg-blue-500/20", text: "text-blue-400", border: "border-blue-500/30" },
{ bg: "bg-emerald-500/20", text: "text-emerald-400", border: "border-emerald-500/30" },
{ bg: "bg-purple-500/20", text: "text-purple-400", border: "border-purple-500/30" },
{ bg: "bg-amber-500/20", text: "text-amber-400", border: "border-amber-500/30" },
{ bg: "bg-pink-500/20", text: "text-pink-400", border: "border-pink-500/30" },
{ bg: "bg-cyan-500/20", text: "text-cyan-400", border: "border-cyan-500/30" },
{ bg: "bg-rose-500/20", text: "text-rose-400", border: "border-rose-500/30" },
{ bg: "bg-indigo-500/20", text: "text-indigo-400", border: "border-indigo-500/30" },
]
const getStorageColor = (storageName: string) => {
// Generate a consistent hash from storage name
let hash = 0
for (let i = 0; i < storageName.length; i++) {
hash = storageName.charCodeAt(i) + ((hash << 5) - hash)
}
const index = Math.abs(hash) % storageColors.length
return storageColors[index]
}
const getIconColor = (percent: number): string => { const getIconColor = (percent: number): string => {
if (percent >= 95) return "text-red-500" if (percent >= 95) return "text-red-500"
if (percent >= 86) return "text-orange-500" if (percent >= 86) return "text-orange-500"
@@ -1423,7 +1445,10 @@ const handleDownloadLogs = async (vmid: number, vmName: string) => {
<div className="w-1.5 h-1.5 rounded-full bg-green-500 flex-shrink-0" /> <div className="w-1.5 h-1.5 rounded-full bg-green-500 flex-shrink-0" />
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" /> <Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="text-sm text-foreground">{backup.date}</span> <span className="text-sm text-foreground">{backup.date}</span>
<Badge variant="outline" className="text-xs bg-muted/50 ml-auto flex-shrink-0"> <Badge
variant="outline"
className={`text-xs ml-auto flex-shrink-0 ${getStorageColor(backup.storage).bg} ${getStorageColor(backup.storage).text} ${getStorageColor(backup.storage).border}`}
>
{backup.storage} {backup.storage}
</Badge> </Badge>
</div> </div>

View File

@@ -5650,11 +5650,9 @@ def api_create_backup(vmid):
notes = notes.replace('{{vmid}}', str(vmid)) notes = notes.replace('{{vmid}}', str(vmid))
notes = notes.replace('{{node}}', node or '') notes = notes.replace('{{node}}', node or '')
# Build pvesh command to create backup via Proxmox API # Build vzdump command directly (more reliable than pvesh for backups)
# This creates a vzdump task through the API which handles clustering properly
cmd = [ cmd = [
'pvesh', 'create', f'/nodes/{node}/vzdump', 'vzdump', str(vmid),
'--vmid', str(vmid),
'--storage', storage, '--storage', storage,
'--mode', mode, '--mode', mode,
'--compress', compress '--compress', compress
@@ -5664,12 +5662,7 @@ def api_create_backup(vmid):
if protected: if protected:
cmd.extend(['--protected', '1']) cmd.extend(['--protected', '1'])
# Add notification mode (mailnotification for older versions, notification-mode for newer) # Add notes if provided (use --description for compatibility)
if notification and notification != 'auto':
# Try notification-mode first (newer Proxmox versions)
cmd.extend(['--notification-mode', notification])
# Add notes if provided
if notes: if notes:
cmd.extend(['--notes-template', notes]) cmd.extend(['--notes-template', notes])
@@ -5677,14 +5670,26 @@ def api_create_backup(vmid):
if pbs_change_detection and pbs_change_detection != 'default' and vm_type == 'lxc': if pbs_change_detection and pbs_change_detection != 'default' and vm_type == 'lxc':
cmd.extend(['--pbs-change-detection-mode', pbs_change_detection]) cmd.extend(['--pbs-change-detection-mode', pbs_change_detection])
# Execute the backup command # Execute vzdump - it will create a Proxmox task automatically
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30) # Using Popen to not block and let vzdump manage the task
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
start_new_session=True # Detach from parent process
)
if result.returncode != 0: # Give it a moment to start and check if it failed immediately
error_msg = result.stderr or result.stdout or 'Unknown error' import time
time.sleep(0.5)
# Check if process failed immediately
poll_result = process.poll()
if poll_result is not None and poll_result != 0:
_, stderr = process.communicate(timeout=5)
return jsonify({ return jsonify({
'success': False, 'success': False,
'error': f'Backup failed: {error_msg}', 'error': f'Backup failed to start: {stderr.decode() if stderr else "Unknown error"}',
'command': ' '.join(cmd) 'command': ' '.join(cmd)
}), 500 }), 500
@@ -5695,9 +5700,7 @@ def api_create_backup(vmid):
'mode': mode, 'mode': mode,
'compress': compress, 'compress': compress,
'protected': protected, 'protected': protected,
'notification': notification, 'notes': notes
'notes': notes,
'task_output': result.stdout
}) })
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired: