From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 1C5E11FF0B7 for ; Fri, 13 Nov 2026 16:26:35 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0ED1C216C2; Fri, 13 Nov 2026 16:26:31 +0100 (CET) From: Dominik Rusovac To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager v4 1/4] api: nodes: add endpoint to set maintenance mode Date: Fri, 13 Nov 2026 16:26:17 +0100 Message-ID: <20261113152620.2662417-2-d.rusovac@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113152620.2662417-1-d.rusovac@proxmox.com> References: <20261113152620.2662417-1-d.rusovac@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794583585859 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.121 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: IBMCDUXTIYLGXQE64WUC54GWFEGSQ3U7 X-Message-ID-Hash: IBMCDUXTIYLGXQE64WUC54GWFEGSQ3U7 X-MailFrom: d.rusovac@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Thomas Skinner X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: node maintenance mode can currently only be requested with the HA manager's CLI, which can't be used from the web UI add an endpoint to enable/disable maintenance mode for a node, which lives below the node path rather than the HA API, so that the maintenance concept can be extended to more than HA managed resources later on. for now, it queues the same CRM command as the HA manager's CLI command requests for nodes unknown to the HA manager are rejected. since maintenance is restricted to HA, maintenance mode has no effect on such nodes yet and the queued command would make an idle CRM become active requests to enable maintenance mode are rejected while HA is disarmed or if the respective node is not online from the CRM's point of view. the CRM ignores such requests and logs a message. disabling is still possible in any case as the CRM always processes such requests Originally-by: Thomas Skinner Signed-off-by: Dominik Rusovac --- Notes: changes since v3: * reword commit subject and body * check Sys.Modify on /nodes/{node} instead of /, as suggested in the v2 review * reject requests for nodes unknown to the HA stack * reject enabling maintenance mode while HA is disarmed or if the node is not online from the CRM's point of view, as the CRM ignores such requests PVE/API2/Nodes.pm | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index 1e2a96f1..af4c92f6 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -242,6 +242,7 @@ __PACKAGE__->register_method({ { name => 'hosts' }, { name => 'journal' }, { name => 'lxc' }, + { name => 'maintenance' }, { name => 'migrateall' }, { name => 'netstat' }, { name => 'network' }, @@ -2901,6 +2902,59 @@ __PACKAGE__->register_method({ }, }); +__PACKAGE__->register_method({ + name => 'maintenance_set', + protected => 1, + path => 'maintenance', + method => 'PUT', + description => "Enable or disable maintenance mode for the node. Currently, this only" + . " requests the HA node maintenance mode.", + permissions => { + check => ['perm', '/nodes/{node}', ['Sys.Modify']], + }, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + 'maintenance-mode' => { + description => "Requests enabling or disabling maintenance mode. Currently," + . " this only moves HA managed resources away from the node.", + type => 'string', + enum => ['enable', 'disable'], + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + my $node = $param->{node}; + PVE::Cluster::check_node_exists($node); + + my $manager_status = PVE::HA::Config::read_manager_status(); + + # maintenance mode currently only affects HA managed resources, and queuing the CRM + # command for a node unknown to HA would make an idle CRM become active for nothing + my $node_state = $manager_status->{node_status}->{$node}; + die "node '$node' is not part of HA - nothing to put into maintenance\n" + if !defined($node_state); + + my $enable = $param->{'maintenance-mode'} eq 'enable'; + + # the CRM ignores requests to enable maintenance mode while HA is disarmed or for nodes + # that are not online + die "cannot enable maintenance mode for node '$node' while HA is disarmed\n" + if $enable && $manager_status->{disarm}; + die "cannot enable maintenance mode for node '$node' in HA node state '$node_state'\n" + if $enable && $node_state ne 'online'; + + my $cmd = $enable ? 'enable-node-maintenance' : 'disable-node-maintenance'; + PVE::HA::Config::queue_crm_commands("$cmd $node"); + + return undef; + }, +}); + # bash completion helper sub complete_templet_repo { -- 2.47.3