all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Skinner <thomas@atskinner.net>
To: pve-devel@lists.proxmox.com
Cc: Thomas Skinner <thomas@atskinner.net>
Subject: [pve-devel] [PATCH ha-manager 2/2] add api getter/setter for node maintenance mode
Date: Sun, 24 Aug 2025 23:11:27 -0500	[thread overview]
Message-ID: <20250825041128.132814-5-thomas@atskinner.net> (raw)
In-Reply-To: <20250825041128.132814-1-thomas@atskinner.net>

Signed-off-by: Thomas Skinner <thomas@atskinner.net>
---
 debian/pve-ha-manager.install |   1 +
 src/PVE/API2/HA/Makefile      |   2 +-
 src/PVE/API2/HA/Nodes.pm      | 176 ++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+), 1 deletion(-)
 create mode 100644 src/PVE/API2/HA/Nodes.pm

diff --git a/debian/pve-ha-manager.install b/debian/pve-ha-manager.install
index 2e6b7d5..ec85037 100644
--- a/debian/pve-ha-manager.install
+++ b/debian/pve-ha-manager.install
@@ -15,6 +15,7 @@
 /usr/share/man/man8/pve-ha-crm.8.gz
 /usr/share/man/man8/pve-ha-lrm.8.gz
 /usr/share/perl5/PVE/API2/HA/Groups.pm
+/usr/share/perl5/PVE/API2/HA/Nodes.pm
 /usr/share/perl5/PVE/API2/HA/Resources.pm
 /usr/share/perl5/PVE/API2/HA/Rules.pm
 /usr/share/perl5/PVE/API2/HA/Status.pm
diff --git a/src/PVE/API2/HA/Makefile b/src/PVE/API2/HA/Makefile
index 86c1013..45d714b 100644
--- a/src/PVE/API2/HA/Makefile
+++ b/src/PVE/API2/HA/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Resources.pm Groups.pm Rules.pm Status.pm
+SOURCES=Resources.pm Groups.pm Nodes.pm Rules.pm Status.pm
 
 .PHONY: install
 install:
diff --git a/src/PVE/API2/HA/Nodes.pm b/src/PVE/API2/HA/Nodes.pm
new file mode 100644
index 0000000..2afc3a3
--- /dev/null
+++ b/src/PVE/API2/HA/Nodes.pm
@@ -0,0 +1,176 @@
+package PVE::API2::HA::Nodes::Nodeinfo;
+
+use strict;
+use warnings;
+
+use PVE::SafeSyslog;
+use PVE::Tools qw(extract_param);
+use PVE::Cluster qw(cfs_read_file cfs_write_file);
+use PVE::HA::Config;
+use HTTP::Status qw(:constants);
+use Storable qw(dclone);
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RPCEnvironment;
+
+use PVE::RESTHandler;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+    name => 'index',
+    path => '',
+    method => 'GET',
+    permissions => { user => 'all' },
+    description => "Node index.",
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            node => get_standard_option('pve-node'),
+        },
+    },
+    returns => {
+        type => 'array',
+        items => {
+            type => "object",
+            properties => {},
+        },
+        links => [{ rel => 'child', href => "{name}" }],
+    },
+    code => sub {
+        my ($param) = @_;
+
+        my $result = [
+            { name => 'maintenance' },
+        ];
+
+        return $result;
+    },
+});
+
+__PACKAGE__->register_method({
+    name => 'maintenance_state',
+    path => 'maintenance',
+    method => 'GET',
+    permissions => { user => 'all' },
+    description => "Get the node maintenance state.",
+    permissions => {
+ check => ['perm', '/', [ 'Sys.Audit' ]],
+    },
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            node => get_standard_option('pve-node'),
+        },
+    },
+    returns => {
+        type => "object",
+        properties => {},
+    },
+    code => sub {
+        my ($param) = @_;
+
+ my $status = PVE::HA::Config::read_manager_status();
+
+ my $data = {
+            request => $status->{node_request}->{$param->{node}},
+            status => $status->{node_status}->{$param->{node}},
+        };
+
+ return $data;
+    },
+});
+
+__PACKAGE__->register_method ({
+    name => 'maintenance_set',
+    protected => 1,
+    path => 'maintenance',
+    method => 'POST',
+    description => "Change the node-maintenance request state.",
+    permissions => {
+ check => ['perm', '/', [ 'Sys.Console' ]],
+    },
+    parameters => {
+ additionalProperties => 0,
+ properties => {
+     node => get_standard_option('pve-node'),
+     disable => {
+ description => "Requests disabling or enabling maintenance-mode.",
+ type => 'boolean',
+     },
+ },
+    },
+    returns => { type => 'null' },
+    code => sub {
+ my ($param) = @_;
+
+ PVE::Cluster::check_node_exists($param->{node});
+
+ my $cmd = $param->{disable} ? 'disable-node-maintenance' : 'enable-node-maintenance';
+ PVE::HA::Config::queue_crm_commands("$cmd $param->{node}");
+
+ return undef;
+    }
+});
+
+package PVE::API2::HA::Nodes;
+
+use strict;
+use warnings;
+
+use PVE::RESTHandler;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RPCEnvironment;
+use PVE::Cluster;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+    subclass => "PVE::API2::HA::Nodes::Nodeinfo",
+    path => '{node}',
+});
+
+__PACKAGE__->register_method({
+    name => 'index',
+    path => '',
+    method => 'GET',
+    permissions => { user => 'all' },
+    description => "Cluster HA node index.",
+    parameters => {
+        additionalProperties => 0,
+        properties => {},
+    },
+    returns => {
+        type => 'array',
+        items => {
+            type => "object",
+            properties => {
+                node => get_standard_option('pve-node'),
+            },
+        },
+        links => [{ rel => 'child', href => "{node}" }],
+    },
+    code => sub {
+        my ($param) = @_;
+
+        my $rpcenv = PVE::RPCEnvironment::get();
+        my $authuser = $rpcenv->get_user();
+
+        my $clinfo = PVE::Cluster::get_clinfo();
+        my $res = [];
+
+        my $nodelist = PVE::Cluster::get_nodelist();
+        my $members = PVE::Cluster::get_members();
+        my $rrd = PVE::Cluster::rrd_dump();
+
+        foreach my $node (@$nodelist) {
+            my $can_audit = $rpcenv->check($authuser, "/nodes/$node", ['Sys.Audit'], 1);
+            my $entry = { node => $node };
+
+            push @$res, $entry;
+        }
+
+        return $res;
+    },
+});
+
+1;
-- 
2.47.2


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-08-25  4:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-25  4:11 [pve-devel] [PATCH SERIES docs/ha-manager/manager] close #6144: add ui button + api " Thomas Skinner
2025-08-25  4:11 ` [pve-devel] [PATCH ha-manager 1/2] add additional api field for lrm_mode in status check Thomas Skinner
2025-08-25  4:11 ` [pve-devel] [PATCH manager 1/2] add api path map for node HA endpoints Thomas Skinner
2025-08-26  9:38   ` Daniel Kral
2025-08-26 10:26     ` Thomas Lamprecht
2025-08-26 11:34       ` Daniel Kral
2025-08-25  4:11 ` [pve-devel] [PATCH docs 1/1] add docs for maintenance mode buttons in UI Thomas Skinner
2025-08-26  9:44   ` Daniel Kral
2025-08-26 16:05     ` Thomas Skinner
2025-08-27  7:50       ` Daniel Kral
2025-08-25  4:11 ` Thomas Skinner [this message]
2025-08-26  9:38   ` [pve-devel] [PATCH ha-manager 2/2] add api getter/setter for node maintenance mode Daniel Kral
2025-08-26 16:00     ` Thomas Skinner
2025-08-27  7:31       ` Thomas Lamprecht
2025-08-27  8:25       ` Daniel Kral
2025-08-27  9:20         ` Thomas Lamprecht
2025-08-29 20:13         ` Thomas Skinner
2025-09-01  8:52           ` Daniel Kral
2025-08-29 20:17     ` Thomas Skinner
2025-08-25  4:11 ` [pve-devel] [PATCH manager 2/2] add UI for node maintenance enable/disable Thomas Skinner
2025-08-26 10:00   ` Daniel Kral
2025-08-26 17:34     ` Thomas Skinner

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=20250825041128.132814-5-thomas@atskinner.net \
    --to=thomas@atskinner.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal