From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH ha-manager v7 30/32] api: resources: migration: support additional migration options
Date: Thu, 12 Nov 2026 12:49:02 +0100 [thread overview]
Message-ID: <20261112115001.107306-31-f.ebner@proxmox.com> (raw)
In-Reply-To: <20261112115001.107306-1-f.ebner@proxmox.com>
Additional migration options can now be passed from the guest API
endpoints to the HA stack. From the HA resource API endpoint, the
options are passed all the way to the resource plugins.
Check that all nodes are recent enough to support the new-style JSON
CRM command, otherwise produce a warning and fall-back to the previous
behavior ignoring the additional migration options.
The migration API endpoints for containers and VMs use different
parameters. For example, the endpoint for containers does not have
the 'with-conntrack-state' option. To keep the schema for the more
abstract endpoint for HA resources clean, separate by type using a
oneOf schema and let the resource plugins declare additional
parameters via a migrate_json_properties() method.
Initially, this will be used to fix #7053 and pass along the
'with-conntrack-state' migration option.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Michael Köppl <m.koeppl@proxmox.com>
Tested-by: Michael Köppl <m.koeppl@proxmox.com>
---
Dependency and build dependency bump for pve-cluster needed!
The pve-manager version in the check must be adapted upon applying!
Changes in v7:
* Bump pve-manager version in check.
src/PVE/API2/HA/Resources.pm | 110 ++++++++++++++++++++++++++++++-----
1 file changed, 96 insertions(+), 14 deletions(-)
diff --git a/src/PVE/API2/HA/Resources.pm b/src/PVE/API2/HA/Resources.pm
index b96572b..70d12ff 100644
--- a/src/PVE/API2/HA/Resources.pm
+++ b/src/PVE/API2/HA/Resources.pm
@@ -3,15 +3,20 @@ package PVE::API2::HA::Resources;
use strict;
use warnings;
+use JSON qw();
+
+use PVE::Exception qw(raise_param_exc);
use PVE::SafeSyslog;
use PVE::Tools qw(extract_param);
use PVE::Cluster;
use PVE::HA::Config;
+use PVE::HA::Env::PVE2; # The resource plugins are registered here.
use PVE::HA::Resources;
use HTTP::Status qw(:constants);
use Storable qw(dclone);
use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment;
+use PVE::RESTEnvironment qw(log_warn);
use PVE::RESTHandler;
@@ -34,6 +39,49 @@ my $api_copy_config = sub {
return $scfg;
};
+my sub migrate_json_properties {
+ my ($type) = @_;
+ my $plugin = PVE::HA::Resources->lookup($type);
+ return $plugin->migrate_json_properties();
+}
+
+my sub json_crm_motion_command_is_supported {
+ PVE::Cluster::cfs_update();
+ my $version_info = PVE::Cluster::get_node_kv('version-info');
+ for my $node (sort keys $version_info->%*) {
+ my $node_info = eval { JSON::decode_json($version_info->{$node}); };
+ if (my $err = $@) {
+ # An updated cluster is the usual situation. An error here should not affect the usual
+ # situation. The unusual situation, where the master is too old and unable to report its
+ # version properly is rare. Submitting a JSON CRM to such a master will lead to warnings
+ # and the command being ignored. Note that migration without extra parameters also still
+ # works.
+ log_warn("failed check for migration options support - cannot parse version info for"
+ . " node '$node' - $err");
+ } elsif (!PVE::Tools::pvecfg_min_version($node_info->{version}, 9, 2, 28)) {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+my sub json_crm_motion_command_is_applicable {
+ my ($sid, $req_node, $param) = @_;
+
+ # FIXME: MAJOR VERSION: use JSON variant even if there are no extra params.
+ if (scalar(keys $param->%*) > 0) {
+ if (json_crm_motion_command_is_supported()) {
+ return 1;
+ } else {
+ log_warn("$sid migration to $req_node: ignoring additional migration options - not"
+ . " supported by CRM on all nodes");
+ }
+ }
+
+ return 0;
+}
+
sub check_service_state {
my ($sid, $req_state) = @_;
@@ -336,20 +384,32 @@ __PACKAGE__->register_method({
check => ['perm', '/', ['Sys.Console']],
},
parameters => {
- additionalProperties => 0,
- properties => {
- sid => get_standard_option(
- 'pve-ha-resource-or-vm-id',
- { completion => \&PVE::HA::Tools::complete_sid },
- ),
- node => get_standard_option(
- 'pve-node',
- {
- completion => \&PVE::Cluster::complete_migration_target,
- description => "Target node.",
- },
- ),
+ 'type-property' => 'resource-type',
+ 'type-property-schema' => {
+ type => 'string',
+ description => 'The resource type. Automatically determined from the service ID.',
+ enum => $resource_type_enum,
},
+ oneOf => [
+ {
+ 'instance-type' => 'ct',
+ additionalProperties => 0,
+ properties => migrate_json_properties('ct'),
+ },
+ {
+ 'instance-type' => 'vm',
+ additionalProperties => 0,
+ properties => migrate_json_properties('vm'),
+ },
+ ],
+ },
+ resolve_type => sub {
+ my ($param) = @_;
+ my $type = (PVE::HA::Config::parse_sid($param->{sid}))[1];
+ if (!($type eq 'ct' || $type eq 'vm')) {
+ die "Unknown service type '$type' for 'migrate' endpoint schema.\n";
+ }
+ return $type;
},
returns => {
type => 'object',
@@ -403,12 +463,34 @@ __PACKAGE__->register_method({
my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
my $req_node = extract_param($param, 'node');
+ my $resource_type = extract_param($param, 'resource-type');
+ if ($resource_type ne $type) {
+ raise_param_exc({
+ 'resource-type' => "value '$resource_type' does not match type of '$sid'" });
+ }
+
+ # The rest of the parameters in $param are migration options passed along to the plugin.
PVE::HA::Config::service_is_ha_managed($sid);
check_service_state($sid);
- PVE::HA::Config::queue_crm_commands("migrate $sid $req_node");
+ my $crm_command;
+ if (json_crm_motion_command_is_applicable($sid, $req_node, $param)) {
+ $crm_command = JSON::to_json(
+ {
+ task => 'migrate',
+ sid => $sid,
+ node => $req_node,
+ options => $param,
+ },
+ { canonical => 1 },
+ );
+ } else {
+ $crm_command = "migrate $sid $req_node";
+ }
+
+ PVE::HA::Config::queue_crm_commands($crm_command);
$result->{sid} = $sid;
$result->{'requested-node'} = $req_node;
--
2.47.3
next prev parent reply other threads:[~2026-11-12 11:54 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 11:48 [PATCH-SERIES many v7 00/32] migration: strict config check for intra-cluster migration Fiona Ebner
2026-11-12 11:48 ` [PATCH guest-common v7 01/32] abstract migrate: add missing imports Fiona Ebner
2026-11-13 12:46 ` Michael Köppl
2026-11-12 11:48 ` [PATCH guest-common v7 02/32] abstract migrate: declare fork_tunnel() as an abstract method Fiona Ebner
2026-11-13 12:46 ` Michael Köppl
2026-11-13 12:51 ` Fiona Ebner
2026-11-12 11:48 ` [PATCH guest-common v7 03/32] abstract migrate: add method for common early checks Fiona Ebner
2026-11-13 12:47 ` Michael Köppl
2026-11-12 11:48 ` [PATCH guest-common v7 04/32] abstract migrate: intra-cluster: check config can be parsed on target Fiona Ebner
2026-11-13 12:47 ` Michael Köppl
2026-11-12 11:48 ` [PATCH qemu-server v7 05/32] helpers: move get_node_pvecfg_version() version helper to pve-cluster Fiona Ebner
2026-11-13 12:47 ` Michael Köppl
2026-11-12 11:48 ` [PATCH qemu-server v7 06/32] api: migrate: allow forwarding certain migration properties to HA Fiona Ebner
2026-11-13 12:47 ` Michael Köppl
2026-11-12 11:48 ` [PATCH qemu-server v7 07/32] fix #7053: api: migrate: pass 'with-conntrack-state' flag to HA migration Fiona Ebner
2026-11-12 11:48 ` [PATCH qemu-server v7 08/32] qm: mtunnel: reply when a command is unknown Fiona Ebner
2026-11-12 11:48 ` [PATCH qemu-server v7 09/32] qm: mtunnel: add 'conf' command to do strict configuration parsing Fiona Ebner
2026-11-12 11:48 ` [PATCH qemu-server v7 10/32] migrate: call prepare_local_cluster_checks() method Fiona Ebner
2026-11-13 12:48 ` Michael Köppl
2026-11-13 13:09 ` Fiona Ebner
2026-11-13 13:22 ` Michael Köppl
2026-11-13 13:32 ` Fiona Ebner
2026-11-12 11:48 ` [PATCH qemu-server v7 11/32] migration: add 'skip-config-check' property and adapt to guest-common Fiona Ebner
2026-11-12 11:48 ` [PATCH qemu-server v7 12/32] api: ha migrate: delete with-conntrack-state for offline migration Fiona Ebner
2026-11-13 12:50 ` Michael Köppl
2026-11-12 11:48 ` [PATCH container v7 13/32] api: migrate: allow forwarding certain migration properties to HA Fiona Ebner
2026-11-13 12:50 ` Michael Köppl
2026-11-12 11:48 ` [PATCH container v7 14/32] pct: introduce mtunnel command Fiona Ebner
2026-11-12 11:48 ` [PATCH container v7 15/32] d/control: bump versioned build dependency for libpve-common-perl to 9.0.12 Fiona Ebner
2026-11-12 11:48 ` [PATCH container v7 16/32] migrate: implement fork_tunnel() method Fiona Ebner
2026-11-13 12:50 ` Michael Köppl
2026-11-12 11:48 ` [PATCH container v7 17/32] migrate: call prepare_local_cluster_checks() method Fiona Ebner
2026-11-13 12:50 ` Michael Köppl
2026-11-12 11:48 ` [PATCH container v7 18/32] migrate: add 'skip-config-check' property Fiona Ebner
2026-11-13 12:51 ` Michael Köppl
2026-11-12 11:48 ` [PATCH ha-manager v7 19/32] manager: add missing PVE::HA::Resources import Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 20/32] update crm commands: align logging with next state started/stopped Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 21/32] manager: factor out helper to check if resource motion is valid Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 22/32] next state {started,stopped}: align logging for motion command Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 23/32] next state {stopped,started}: factor out helper to handle " Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 24/32] lrm: resource migration: support extra migration options Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 25/32] change service state: support hash as a parameter value Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 26/32] next state: handle motion command: support migration options Fiona Ebner
2026-11-12 11:48 ` [PATCH ha-manager v7 27/32] resources: add migrate_json_properties() method Fiona Ebner
2026-11-13 12:51 ` Michael Köppl
2026-11-12 11:49 ` [PATCH ha-manager v7 28/32] queue resource motion: support migration options Fiona Ebner
2026-11-12 11:49 ` [PATCH ha-manager v7 29/32] crm command: support JSON-style migrate command Fiona Ebner
2026-11-12 11:49 ` Fiona Ebner [this message]
2026-11-12 11:49 ` [PATCH ha-manager v7 31/32] test: add test for migration options Fiona Ebner
2026-11-12 11:49 ` [PATCH manager v7 32/32] ui: migrate: add checkbox to allow skipping newly enforced config check Fiona Ebner
2026-11-13 12:51 ` Michael Köppl
2026-11-13 12:51 ` [PATCH-SERIES many v7 00/32] migration: strict config check for intra-cluster migration Michael Köppl
2026-11-18 14:22 ` applied: " Thomas Lamprecht
2026-11-18 14:36 ` Fiona Ebner
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=20261112115001.107306-31-f.ebner@proxmox.com \
--to=f.ebner@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