[pve-devel] [PATCH ha-manager 2/2] add api getter/setter for node maintenance mode
Thomas Skinner
thomas at atskinner.net
Mon Aug 25 06:11:27 CEST 2025
Signed-off-by: Thomas Skinner <thomas at 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
More information about the pve-devel
mailing list