From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container v3 1/1] api: introduce migration preconditions api endpoint
Date: Fri, 4 Jul 2025 20:21:01 +0200 [thread overview]
Message-ID: <20250704182102.467624-19-d.kral@proxmox.com> (raw)
In-Reply-To: <20250704182102.467624-1-d.kral@proxmox.com>
Add a migration preconditions api endpoint for containers in similar
vein to the one which is already present for virtual machines.
This is needed to inform callees about positive and negative ha resource
affinity rules, which the container is part of. These inform callees
about any comigrated resources or blocking resources that are caused by
the resource affinity rules.
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
src/PVE/API2/LXC.pm | 141 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 141 insertions(+)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 28f7fdd..dd20604 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1395,6 +1395,147 @@ __PACKAGE__->register_method({
},
});
+__PACKAGE__->register_method({
+ name => 'migrate_vm_precondition',
+ path => '{vmid}/migrate',
+ method => 'GET',
+ protected => 1,
+ proxyto => 'node',
+ description => "Get preconditions for 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::LXC::complete_ctid }),
+ target => get_standard_option(
+ 'pve-node',
+ {
+ description => "Target node.",
+ completion => \&PVE::Cluster::complete_migration_target,
+ optional => 1,
+ },
+ ),
+ },
+ },
+ returns => {
+ type => "object",
+ properties => {
+ running => {
+ type => 'boolean',
+ description => "Determines if the container is running.",
+ },
+ 'allowed-nodes' => {
+ type => 'array',
+ items => {
+ type => 'string',
+ description => "An allowed node",
+ },
+ optional => 1,
+ description => "List of nodes allowed for migration.",
+ },
+ 'not-allowed-nodes' => {
+ type => 'object',
+ optional => 1,
+ properties => {
+ 'blocking-ha-resources' => {
+ description => "HA resources, which are blocking the"
+ . " container from being migrated to the node.",
+ type => 'array',
+ optional => 1,
+ items => {
+ description => "A blocking HA resource",
+ type => 'object',
+ properties => {
+ sid => {
+ type => 'string',
+ description => "The blocking HA resource id",
+ },
+ cause => {
+ type => 'string',
+ description => "The reason why the HA"
+ . " resource is blocking the migration.",
+ enum => ['resource-affinity'],
+ },
+ },
+ },
+ },
+ },
+ description => "List of not allowed nodes with additional information.",
+ },
+ 'comigrated-ha-resources' => {
+ description => "HA resources, which will be migrated to the"
+ . " same target node as the container, because these are in"
+ . " positive affinity with the container.",
+ type => 'array',
+ optional => 1,
+ items => {
+ type => 'string',
+ description => "A comigrated HA resource",
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+
+ my $authuser = $rpcenv->get_user();
+
+ PVE::Cluster::check_cfs_quorum();
+
+ my $res = {};
+
+ my $vmid = extract_param($param, 'vmid');
+ my $target = extract_param($param, 'target');
+ my $localnode = PVE::INotify::nodename();
+
+ # test if VM exists
+ my $vmconf = PVE::LXC::Config->load_config($vmid);
+ my $storecfg = PVE::Storage::config();
+
+ # try to detect errors early
+ PVE::LXC::Config->check_lock($vmconf);
+
+ $res->{running} = PVE::LXC::check_running($vmid) ? 1 : 0;
+
+ $res->{'allowed-nodes'} = [];
+ $res->{'not-allowed-nodes'} = {};
+
+ my $comigrated_ha_resources = {};
+ my $blocking_ha_resources_by_node = {};
+
+ if (PVE::HA::Config::vm_is_ha_managed($vmid)) {
+ ($comigrated_ha_resources, $blocking_ha_resources_by_node) =
+ PVE::HA::Config::get_resource_motion_info("ct:$vmid");
+ }
+
+ my $nodelist = PVE::Cluster::get_nodelist();
+ for my $node ($nodelist->@*) {
+ next if $node eq $localnode;
+
+ # extracting blocking resources for current node
+ if (my $blocking_ha_resources = $blocking_ha_resources_by_node->{$node}) {
+ $res->{'not-allowed-nodes'}->{$node}->{'blocking-ha-resources'} =
+ $blocking_ha_resources;
+ }
+
+ # if nothing came up, add it to the allowed nodes
+ if (!defined($res->{'not-allowed-nodes'}->{$node})) {
+ push $res->{'allowed-nodes'}->@*, $node;
+ }
+ }
+
+ $res->{'comigrated-ha-resources'} = $comigrated_ha_resources;
+
+ return $res;
+ },
+});
+
__PACKAGE__->register_method({
name => 'migrate_vm',
path => '{vmid}/migrate',
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-07-04 18:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-04 18:20 [pve-devel] [PATCH container/docs/ha-manager/manager/qemu-server v3 00/19] HA resource affinity rules Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 01/13] rules: introduce plugin-specific canonicalize routines Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 02/13] rules: add haenv node list to the rules' canonicalization stage Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 03/13] rules: introduce resource affinity rule plugin Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 04/13] rules: add global checks between node and resource affinity rules Daniel Kral
2025-07-29 11:44 ` Michael Köppl
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 05/13] usage: add information about a service's assigned nodes Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 06/13] manager: apply resource affinity rules when selecting service nodes Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 07/13] manager: handle resource affinity rules in manual migrations Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 08/13] sim: resources: add option to limit start and migrate tries to node Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 09/13] test: ha tester: add test cases for negative resource affinity rules Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 10/13] test: ha tester: add test cases for positive " Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 11/13] test: ha tester: add test cases for static scheduler resource affinity Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 12/13] test: rules: add test cases for resource affinity rules Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH ha-manager v3 13/13] api: resources: add check for resource affinity in resource migrations Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH docs v3 1/1] ha: add documentation about ha resource affinity rules Daniel Kral
2025-07-08 16:08 ` Shannon Sterz
2025-07-09 6:19 ` Friedrich Weber
2025-07-30 10:05 ` Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH manager v3 1/3] ui: ha: rules: add " Daniel Kral
2025-07-04 18:20 ` [pve-devel] [PATCH manager v3 2/3] ui: migrate: lxc: display precondition messages for ha resource affinity Daniel Kral
2025-07-04 18:21 ` [pve-devel] [PATCH manager v3 3/3] ui: migrate: vm: " Daniel Kral
2025-07-04 18:21 ` Daniel Kral [this message]
2025-07-04 18:21 ` [pve-devel] [PATCH qemu-server v3 1/1] api: migration preconditions: add checks for ha resource affinity rules Daniel Kral
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=20250704182102.467624-19-d.kral@proxmox.com \
--to=d.kral@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