From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id B99BF1FF0AA for ; Tue, 17 Nov 2026 09:58:36 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D82E7212F3; Tue, 17 Nov 2026 09:58:33 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 17 Nov 2026 09:58:29 +0100 Message-Id: Subject: Re: [PATCH pve-manager v4 1/4] api: nodes: add endpoint to set maintenance mode From: "Dominik Rusovac" To: "Daniel Kral" , X-Mailer: aerc 0.20.0 References: <20261113152620.2662417-1-d.rusovac@proxmox.com> <20261113152620.2662417-2-d.rusovac@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794905909367 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 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) 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: XVEDAHFI3II55UHMOCY3VODT5FNBRU7W X-Message-ID-Hash: XVEDAHFI3II55UHMOCY3VODT5FNBRU7W 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: thx for the review, will send a v5 On Mon Nov 16, 2026 at 12:57 PM CET, Daniel Kral wrote: > 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. > you're right, will prefix it=20 > 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 [snip] >> +__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. = Currently, 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 > thx for the heads up, will reorder=20 >> + parameters =3D> { >> + additionalProperties =3D> 0, >> + properties =3D> { >> + node =3D> get_standard_option('pve-node'), >> + 'maintenance-mode' =3D> { >> + description =3D> "Requests enabling or disabling mainte= nance mode. Currently," >> + . " this only moves HA managed resources away from = the 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." > ack >> + 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 becom= e active for nothing >> + my $node_state =3D $manager_status->{node_status}->{$node}; >> + die "node '$node' is not part of HA - nothing to put into maint= enance\n" >> + if !defined($node_state); >> + >> + my $enable =3D $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 i= s 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. good points, you're right, thx! I will factor out the reasons=20 > > > 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. > I will write a dedicated wrapper that queues a request to enable/disable maintenance=20 >> + >> + return undef; >> + }, >> +}); >> + >> # bash completion helper >> =20 >> sub complete_templet_repo {