[pve-devel] [RFC PATCH 2/4] api: add reboot api call

Dominik Csapak d.csapak at proxmox.com
Wed Aug 14 16:20:28 CEST 2019


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);
+    }});
+
 __PACKAGE__->register_method({
     name => 'vm_suspend',
     path => '{vmid}/status/suspend',
-- 
2.20.1





More information about the pve-devel mailing list