public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Erik Fastermann <e.fastermann@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Erik Fastermann <e.fastermann@proxmox.com>
Subject: [RFC qemu-server 4/4] remote migrate: add precondition check endpoint
Date: Tue, 21 Jul 2026 13:58:27 +0200	[thread overview]
Message-ID: <20260721115827.163442-5-e.fastermann@proxmox.com> (raw)
In-Reply-To: <20260721115827.163442-1-e.fastermann@proxmox.com>

Add a remote_migrate_vm_precondition endpoint that runs the remote
migration precondition checks without starting a migration and returns
them as a list of {severity, code, message} findings, so callers such
as the web UI can surface blockers and warnings before the user commits
to a migration.

It reuses the same validate_remote_migrate_preconditions helper the
migrate endpoint uses, so the precheck cannot drift from what is
actually enforced. The endpoint is POST rather than GET, on its own
path, to keep the remote API token out of request URLs and the access
log.

Suggested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Erik Fastermann <e.fastermann@proxmox.com>
---
 src/PVE/API2/Qemu.pm | 156 ++++++++++++++++++++++++++++++-------------
 1 file changed, 111 insertions(+), 45 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 9b487457..ade1451e 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -1042,6 +1042,53 @@ sub assert_scsi_feature_compatibility {
     }
 }
 
+my $remote_migrate_vm_properties = {
+    additionalProperties => 0,
+    properties => {
+        node => get_standard_option('pve-node'),
+        vmid =>
+            get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
+        'target-vmid' => get_standard_option('pve-vmid', { optional => 1 }),
+        'target-endpoint' => get_standard_option('proxmox-remote', {
+                description => "Remote target endpoint",
+        }),
+        online => {
+            type => 'boolean',
+            description =>
+                "Use online/live migration if VM is running. Ignored if VM is stopped.",
+            optional => 1,
+        },
+        delete => {
+            type => 'boolean',
+            description => "Delete the original VM and related data after successful migration."
+                . " By default the original VM is kept on the source cluster in a stopped state.",
+            optional => 1,
+            default => 0,
+        },
+        'target-storage' => get_standard_option(
+            'pve-targetstorage',
+            {
+                completion => \&PVE::QemuServer::complete_migration_storage,
+                optional => 0,
+            },
+        ),
+        'target-bridge' => {
+            type => 'string',
+            description => "Mapping from source to target bridges. Providing only a single"
+                . " bridge ID maps all source bridges to that bridge. Providing the special"
+                . " value '1' will map each source bridge to itself.",
+            format => 'bridge-pair-list',
+        },
+        bwlimit => {
+            description => "Override I/O bandwidth limit (in KiB/s).",
+            optional => 1,
+            type => 'integer',
+            minimum => '0',
+            default => 'migrate limit from datacenter or storage config',
+        },
+    },
+};
+
 my sub validate_remote_migrate_preconditions {
     my ($param, $findings) = @_;
 
@@ -5837,61 +5884,80 @@ __PACKAGE__->register_method({
 });
 
 __PACKAGE__->register_method({
-    name => 'remote_migrate_vm',
-    path => '{vmid}/remote_migrate',
+    name => 'remote_migrate_vm_precondition',
+    path => '{vmid}/remote_migrate_precondition',
     method => 'POST',
     protected => 1,
     proxyto => 'node',
-    description =>
-        "Migrate virtual machine to a remote cluster. Creates a new migration task. EXPERIMENTAL feature!",
+    description => "Get preconditions for remote migration.",
     permissions => {
         check => ['perm', '/vms/{vmid}', ['VM.Migrate']],
     },
-    parameters => {
-        additionalProperties => 0,
-        properties => {
-            node => get_standard_option('pve-node'),
-            vmid =>
-                get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
-            'target-vmid' => get_standard_option('pve-vmid', { optional => 1 }),
-            'target-endpoint' => get_standard_option('proxmox-remote', {
-                    description => "Remote target endpoint",
-            }),
-            online => {
-                type => 'boolean',
-                description =>
-                    "Use online/live migration if VM is running. Ignored if VM is stopped.",
-                optional => 1,
-            },
-            delete => {
-                type => 'boolean',
-                description =>
-                    "Delete the original VM and related data after successful migration. By default the original VM is kept on the source cluster in a stopped state.",
-                optional => 1,
-                default => 0,
-            },
-            'target-storage' => get_standard_option(
-                'pve-targetstorage',
-                {
-                    completion => \&PVE::QemuServer::complete_migration_storage,
-                    optional => 0,
+    parameters => { $remote_migrate_vm_properties->%* },
+    returns => {
+        type => "array",
+        items => {
+            description => "List of findings.",
+            type => "object",
+            properties => {
+                severity => {
+                    description => "Severity of the finding.",
+                    type => 'string',
+                    enum => [qw(error warning)],
                 },
-            ),
-            'target-bridge' => {
-                type => 'string',
-                description =>
-                    "Mapping from source to target bridges. Providing only a single bridge ID maps all source bridges to that bridge. Providing the special value '1' will map each source bridge to itself.",
-                format => 'bridge-pair-list',
-            },
-            bwlimit => {
-                description => "Override I/O bandwidth limit (in KiB/s).",
-                optional => 1,
-                type => 'integer',
-                minimum => '0',
-                default => 'migrate limit from datacenter or storage config',
+                code => {
+                    description => "Machine readable code of the finding.",
+                    type => 'string',
+                    enum => [qw(
+                        load-vm-config
+                        vm-locked
+                        vm-ha-configured
+                        remote-conn
+                        target-vmid-exists
+                        storage-missing
+                        storage-no-images
+                        vm-replicated
+                        offline-migration-vm-running
+                        online-migration-vm-not-running
+                        custom-cpu-validation
+                        custom-cpu-mismatch
+                        storage-mapping
+                    )],
+                },
+                message => {
+                    description => "Human readable message.",
+                    type => 'string',
+                },
+                storage => get_standard_option(
+                    'pve-storage-id',
+                    {
+                        description => "Optional associated storage.",
+                        optional => 1,
+                    },
+                ),
             },
         },
     },
+    code => sub {
+        my ($param) = @_;
+        my $findings = [];
+        validate_remote_migrate_preconditions($param, $findings);
+        return $findings;
+    },
+});
+
+__PACKAGE__->register_method({
+    name => 'remote_migrate_vm',
+    path => '{vmid}/remote_migrate',
+    method => 'POST',
+    protected => 1,
+    proxyto => 'node',
+    description =>
+        "Migrate virtual machine to a remote cluster. Creates a new migration task. EXPERIMENTAL feature!",
+    permissions => {
+        check => ['perm', '/vms/{vmid}', ['VM.Migrate']],
+    },
+    parameters => { $remote_migrate_vm_properties->%* },
     returns => {
         type => 'string',
         description => "the task ID.",
-- 
2.47.3




      parent reply	other threads:[~2026-07-21 11:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 11:58 [RFC qemu-server 0/4] remote migrate: extract preconditions and add check endpoint Erik Fastermann
2026-07-21 11:58 ` [RFC qemu-server 1/4] remote migrate: drop ineffective fingerprint auto-detection Erik Fastermann
2026-07-21 11:58 ` [RFC qemu-server 2/4] remote migrate: collect preconditions as structured findings Erik Fastermann
2026-07-21 11:58 ` [RFC qemu-server 3/4] qm: remote-migrate: call API endpoint directly Erik Fastermann
2026-07-21 11:58 ` Erik Fastermann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260721115827.163442-5-e.fastermann@proxmox.com \
    --to=e.fastermann@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal