Commit 4a6712df authored by Dan Hunsaker's avatar Dan Hunsaker Committed by Dietmar Maurer

Add CT suspend/resume support via PVE2 API

Suspend/resume support for VMs has been in the PVE2 API for some time,
but even though vzctl supports suspend/resume (what they call checkpoint/
restore), the API doesn't yet support suspend/resume for CTs.  This patch
adds that support.
Signed-off-by: 's avatarDan Hunsaker <danhunsaker@gmail.com>
parent 995e687e
......@@ -1458,6 +1458,102 @@ __PACKAGE__->register_method({
return $upid;
}});
__PACKAGE__->register_method({
name => 'vm_suspend',
path => '{vmid}/status/suspend',
method => 'POST',
protected => 1,
proxyto => 'node',
description => "Suspend the container.",
permissions => {
check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
},
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid'),
},
},
returns => {
type => 'string',
},
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
my $node = extract_param($param, 'node');
my $vmid = extract_param($param, 'vmid');
die "CT $vmid not running\n" if !PVE::OpenVZ::check_running($vmid);
my $realcmd = sub {
my $upid = shift;
syslog('info', "suspend CT $vmid: $upid\n");
PVE::OpenVZ::vm_suspend($vmid);
return;
};
my $upid = $rpcenv->fork_worker('vzsuspend', $vmid, $authuser, $realcmd);
return $upid;
}});
__PACKAGE__->register_method({
name => 'vm_resume',
path => '{vmid}/status/resume',
method => 'POST',
protected => 1,
proxyto => 'node',
description => "Resume the container.",
permissions => {
check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
},
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid'),
},
},
returns => {
type => 'string',
},
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
my $node = extract_param($param, 'node');
my $vmid = extract_param($param, 'vmid');
die "CT $vmid already running\n" if PVE::OpenVZ::check_running($vmid);
my $realcmd = sub {
my $upid = shift;
syslog('info', "resume CT $vmid: $upid\n");
PVE::OpenVZ::vm_resume($vmid);
return;
};
my $upid = $rpcenv->fork_worker('vzresume', $vmid, $authuser, $realcmd);
return $upid;
}});
__PACKAGE__->register_method({
name => 'migrate_vm',
path => '{vmid}/migrate',
......
......@@ -6,7 +6,7 @@ use File::stat qw();
use POSIX qw (LONG_MAX);
use IO::Dir;
use IO::File;
use PVE::Tools qw(extract_param $IPV6RE $IPV4RE);
use PVE::Tools qw(run_command extract_param $IPV6RE $IPV4RE);
use PVE::ProcFSTools;
use PVE::Cluster qw(cfs_register_file cfs_read_file);
use PVE::SafeSyslog;
......@@ -1220,6 +1220,30 @@ sub lock_container {
return $res;
}
sub vm_suspend {
my ($vmid) = @_;
my $cmd = ['vzctl', 'chkpnt', $vmid];
eval { run_command($cmd); };
if (my $err = $@) {
syslog("err", "CT $vmid suspend failed - $err");
die $err;
}
}
sub vm_resume {
my ($vmid) = @_;
my $cmd = ['vzctl', 'restore', $vmid];
eval { run_command($cmd); };
if (my $err = $@) {
syslog("err", "CT $vmid resume failed - $err");
die $err;
}
}
sub replacepw {
my ($file, $epw) = @_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment