[pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Jun 20 10:35:48 CEST 2023


On June 16, 2023 1:33 pm, Fiona Ebner wrote:
> Increases flexibility/user-friendliness.
> 
> Suggested-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
> ---
> 
> (Build-)dependency bump for libpve-cluster-perl needed.
> 
> Dependency bump for ha-manager needed (to have the runtime dir exist
> and LRM honor the new param).
> 
>  PVE/API2/Nodes.pm | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
> index 9269694d..1cb83af5 100644
> --- a/PVE/API2/Nodes.pm
> +++ b/PVE/API2/Nodes.pm
> @@ -8,7 +8,7 @@ use Digest::SHA;
>  use Filesys::Df;
>  use HTTP::Status qw(:constants);
>  use JSON;
> -use POSIX qw(LONG_MAX);
> +use POSIX qw(ENOENT LONG_MAX);
>  use Time::Local qw(timegm_nocheck);
>  use Socket;
>  use IO::Socket::SSL;
> @@ -557,12 +557,21 @@ __PACKAGE__->register_method({
>  		type => 'string',
>  		enum => [qw(reboot shutdown)],
>  	    },
> +	    'shutdown-policy' => get_standard_option('pve-ha-shutdown-policy', { optional => 1 }),
>  	},
>      },
>      returns => { type => "null" },
>      code => sub {
>  	my ($param) = @_;
>  
> +	my $sp_override_fn = '/run/pve-ha-lrm/shutdown-policy.local-override';
> +	if ($param->{'shutdown-policy'}) {
> +	    eval { PVE::Tools::file_set_contents($sp_override_fn, $param->{'shutdown-policy'}); };
> +	    die "could not write shutdown policy override to $sp_override_fn - $@" if $@;
> +	} else {
> +	    unlink $sp_override_fn or $! == ENOENT or die "unable to remove $sp_override_fn - $!";
> +	}

should this part (setting or removing the override if one is set)
require `Sys.Modify` (like setting the policy via datacenter.cfg would)
in addition to `Sys.PowerMgmt` that the endpoint itself requires?

> +
>  	if ($param->{command} eq 'reboot') {
>  	    system ("(sleep 2;/sbin/reboot)&");
>  	} elsif ($param->{command} eq 'shutdown') {
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 





More information about the pve-devel mailing list