webgui icon indicating copy to clipboard operation
webgui copied to clipboard

Updates for libvirt image removal and use diretory

Open SimonFair opened this issue 1 year ago β€’ 2 comments

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for migrating VMs between storage paths with automatic synchronization of VM data.
    • Introduced secondary storage location for storing previous versions of VM configurations and metadata.
    • Enhanced VM backup and restore capabilities during service transitions.
  • Documentation

    • Updated help text to clarify VM storage supports both image files and directories.
    • Added documentation for secondary VM storage configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

SimonFair avatar May 08 '24 20:05 SimonFair

Walkthrough

This change implements a VM image file synchronization and backup system for the Unraid libvirt plugin. It adds UI controls to track IMAGE_FILE changes, syncs data between old and new image paths, collects VM metadata during shutdown, and prepares restoration of VM configurations on service restart.

Changes

Cohort / File(s) Summary
UI & Configuration
emhttp/plugins/dynamix.vm.manager/VMSettings.page, emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig, emhttp/languages/en_US/helptext.txt
Added hidden OLD_IMAGE_FILE input to track prior image file path; updated default IMAGE_FILE to directory path; added help text for secondary volume/location storing VM backups; removed pattern restriction on IMAGE_FILE input.
Image File Synchronization
emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init
Added sync block comparing IMAGE_FILE and OLD_IMAGE_FILE; conditionally creates timestamped backups and uses rsync to migrate VM data based on whether old/new paths are .img files or directories.
VM Backup & Restore Operations
etc/rc.d/rc.libvirt, emhttp/plugins/dynamix.vm.manager/scripts/libvirtcopy, emhttp/plugins/dynamix.vm.manager/scripts/libvirtrestore, emhttp/plugins/dynamix.vm.manager/scripts/savehook.php
Added pre-stop hook in rc.libvirt invoking libvirtcopy; new libvirtcopy script queries libvirt domains and writes VM metadata to JSON; new libvirtrestore prepares restoration paths; new savehook.php copies VM XML files to backup location on VM stop.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as VMSettings.page
    participant libvirt_init as libvirt_init (script)
    participant Config as domain.cfg
    participant LibvirtSvc as Libvirt Service
    participant libvirtcopy as libvirtcopy (script)
    participant savehook as savehook.php
    participant Storage as Storage Backend

    User->>UI: Change IMAGE_FILE setting
    UI->>Config: Save IMAGE_FILE + track OLD_IMAGE_FILE
    
    activate libvirt_init
    libvirt_init->>Config: Read IMAGE_FILE & OLD_IMAGE_FILE
    alt Files differ and old path exists
        libvirt_init->>Storage: Create timestamped backup of old image
        libvirt_init->>Storage: Mount old image (if .img)
        libvirt_init->>Storage: rsync contents to new location
        libvirt_init->>Config: Update OLD_IMAGE_FILE to current path
    else Files match or old path missing
        libvirt_init->>Config: Log sync skipped
    end
    deactivate libvirt_init

    User->>LibvirtSvc: Stop libvirt service
    activate LibvirtSvc
    libvirtcopy->>LibvirtSvc: Query all VM domains
    libvirtcopy->>Config: Read VM storage metadata
    libvirtcopy->>Storage: Write vms.json with VM locations
    
    loop For each VM
        savehook->>Config: Read vms.json
        savehook->>Storage: Copy /etc/libvirt/qemu/{vm}.xml to backup path
    end
    LibvirtSvc->>LibvirtSvc: Stop services
    deactivate LibvirtSvc

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 VM images shift and flow,
OLD and NEW paths dance below,
Sync the data, back it up,
When libvirt stops to fill its cup.
Safe migrations, configs savedβ€”
Your virtual machines are braved! πŸ–₯️

πŸš₯ Pre-merge checks | βœ… 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title contains a typo ('diretory' instead of 'directory') and is somewhat vague, but it does relate to the main change: allowing libvirt to use directories instead of image files. Correct the typo 'diretory' to 'directory' and consider a more specific title like 'Support libvirt directory storage and implement image migration logic' to better reflect the comprehensive nature of the changes.
βœ… Passed checks (2 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • [ ] πŸ“ Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Apr 19 '25 17:04 coderabbitai[bot]

πŸ”§ PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.01.07.1413 Build: View Workflow Run

πŸ“₯ Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins β†’ Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-1722/webgui-pr-1722.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates

πŸ“ Modified Files:

Click to expand file list
emhttp/languages/en_US/helptext.txt
emhttp/plugins/dynamix.vm.manager/VMSettings.page
emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init
emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig
emhttp/plugins/dynamix.vm.manager/scripts/libvirtcopy
emhttp/plugins/dynamix.vm.manager/scripts/libvirtrestore
emhttp/plugins/dynamix.vm.manager/scripts/savehook.php

πŸ”„ To Remove:

Navigate to Plugins β†’ Installed Plugins and remove webgui-pr-1722, or run:

plugin remove webgui-pr-1722

πŸ€– This comment is automatically generated and will be updated with each new push to this PR.

github-actions[bot] avatar Oct 24 '25 11:10 github-actions[bot]