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 BA8871FF0BC for ; Mon, 16 Nov 2026 12:57:58 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CB327216DF; Mon, 16 Nov 2026 12:57:54 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 16 Nov 2026 12:57:48 +0100 Message-Id: From: "Daniel Kral" To: "Dominik Rusovac" , Subject: Re: [PATCH pve-manager v4 1/4] api: nodes: add endpoint to set maintenance mode X-Mailer: aerc 0.22.0-45-gc30c872fde7b-dirty References: <20261113152620.2662417-1-d.rusovac@proxmox.com> <20261113152620.2662417-2-d.rusovac@proxmox.com> In-Reply-To: <20261113152620.2662417-2-d.rusovac@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794830268121 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.421 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: 2IEFQ4JIRMJ3PS2ZW5IC5VRGVH5DYG6M X-Message-ID-Hash: 2IEFQ4JIRMJ3PS2ZW5IC5VRGVH5DYG6M X-MailFrom: d.kral@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: This patch can probably be prefixed with 'fix #6144', because this also allows API users in general to put nodes in maintenance mode rather than requiring users to use the CLI as before. No hard feelings though. On Fri Nov 13, 2026 at 4:26 PM CET, Dominik Rusovac wrote: > 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 =3D> 'hosts' }, > { name =3D> 'journal' }, > { name =3D> 'lxc' }, > + { name =3D> 'maintenance' }, > { name =3D> 'migrateall' }, > { name =3D> 'netstat' }, > { name =3D> 'network' }, > @@ -2901,6 +2902,59 @@ __PACKAGE__->register_method({ > }, > }); > =20 > +__PACKAGE__->register_method({ > + name =3D> 'maintenance_set', > + protected =3D> 1, > + path =3D> 'maintenance', > + method =3D> 'PUT', > + description =3D> "Enable or disable maintenance mode for the node. C= urrently, this only" > + . " requests the HA node maintenance mode.", > + permissions =3D> { > + check =3D> ['perm', '/nodes/{node}', ['Sys.Modify']], > + }, nit: This is not very strict, but usual order for this is: - name - path - method Then usually - description - protected - permissions as it seems > + parameters =3D> { > + additionalProperties =3D> 0, > + properties =3D> { > + node =3D> get_standard_option('pve-node'), > + 'maintenance-mode' =3D> { > + description =3D> "Requests enabling or disabling mainten= ance mode. Currently," > + . " this only moves HA managed resources away from t= he node.", The description here should rather describe what this property does change about how the API method operates, e.g. "Specifies whether the maintenancen mode for the specified node should be enabled or disabled." > + type =3D> 'string', > + enum =3D> ['enable', 'disable'], > + }, > + }, > + }, > + returns =3D> { type =3D> 'null' }, > + code =3D> sub { > + my ($param) =3D @_; > + > + my $node =3D $param->{node}; > + PVE::Cluster::check_node_exists($node); > + > + my $manager_status =3D 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 =3D $manager_status->{node_status}->{$node}; > + die "node '$node' is not part of HA - nothing to put into mainte= nance\n" > + if !defined($node_state); > + > + my $enable =3D $param->{'maintenance-mode'} eq 'enable'; > + > + # the CRM ignores requests to enable maintenance mode while HA i= s 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 =3D $enable ? 'enable-node-maintenance' : 'disable-node-= maintenance'; > + PVE::HA::Config::queue_crm_commands("$cmd $node"); Since we queue the CRM command here, I think it would be a tad nicer to have the validation logic in the 'node-maintenance-set' CLI handler in PVE::CLI::ha_manager. Then, users who still prefer the CLI variant also get feedback there if the maintenance node can be set or not in advance and not just the HA Manager's syslog. Furthermore, there's less dependency on the manager_status structure from external packages (i.e., not pve-ha-manager Perl modules). At last, we could probably factor out the reasons when node maintenance cannot be set from PVE::HA::Manager::update_crm_commands()'s enable-node-maintenance and disable-node-maintenance branches, which would share this logic nicer if any changes are done in the future to this. A PVE::Tools::run_command() would be enough here AFAICT, because if it fails then we just fail here as well and forward the error message. > + > + return undef; > + }, > +}); > + > # bash completion helper > =20 > sub complete_templet_repo {