[pve-devel] [RFC PATCH 2/4] api: add reboot api call
Stefan Reiter
s.reiter at proxmox.com
Mon Aug 19 11:10:21 CEST 2019
On 8/14/19 4:20 PM, Dominik Csapak wrote:
> this creates a reboot trigger file (inspired by pve-container)
> and relies on the 'qm cleanup' call by the qmeventd to detect
> and restart the vm afterwards
>
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> PVE/API2/Qemu.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 8be0b7b..d59e23c 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -2339,6 +2339,51 @@ __PACKAGE__->register_method({
> }
> }});
>
> +__PACKAGE__->register_method({
> + name => 'vm_reboot',
> + path => '{vmid}/status/reboot',
> + method => 'POST',
> + protected => 1,
> + proxyto => 'node',
> + description => "Reboot the VM by shutting it down, and starting it again.",
> + permissions => {
> + check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
> + },
> + parameters => {
> + additionalProperties => 0,
> + properties => {
> + node => get_standard_option('pve-node'),
> + vmid => get_standard_option('pve-vmid',
> + { completion => \&PVE::QemuServer::complete_vmid_running }),
> + skiplock => get_standard_option('skiplock'),
> + timeout => {
> + description => "Wait maximal timeout seconds for the shutdown.",
> + type => 'integer',
> + minimum => 0,
> + optional => 1,
> + },
> + forceStop => {
> + description => "Make sure the VM stops.",
> + type => 'boolean',
> + optional => 1,
> + default => 0,
> + },
> + },
> + },
> + returns => {
> + type => 'string',
> + },
> + code => sub {
> + my ($param) = @_;
> +
> + # mark the vm for rebooting, will be caught by qm cleanup
> + my $vmid = $param->{vmid};
> + open(my $fh, '>', "/var/lib/qemu-server/$vmid.reboot")
> + or die "failed to create reboot trigger file: $!\n";
> + close($fh);
> + return PVE::API2::Qemu->vm_shutdown($param);
Testing this, if a backup job (for example) is holding a VM lock, and
you reboot, the <vmid>.reboot file will be created, but the shutdown
fails - next "poweroff" will then be a restart.
In general, if the shutdown fails, the file will be left behind, which
seems like a general issue with the file based approach (in line with
your concerns on the series' cover).
> + }});
> +
> __PACKAGE__->register_method({
> name => 'vm_suspend',
> path => '{vmid}/status/suspend',
>
More information about the pve-devel
mailing list