[pve-devel] [PATCH 2/9] Add snapshot to LXC API2
Wolfgang Link
w.link at proxmox.com
Fri Jul 17 09:26:44 CEST 2015
Signed-off-by: Wolfgang Link <w.link at proxmox.com>
---
src/PVE/API2/LXC.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/PVE/LXC.pm | 8 +++++++
src/pct | 2 ++
3 files changed, 70 insertions(+)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 4a2e329..e63b73b 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -58,6 +58,11 @@ my $check_ct_modify_config_perm = sub {
return 1;
};
+PVE::JSONSchema::register_standard_option('pve-lxc-snapshot-name', {
+ description => "The name of the snapshot.",
+ type => 'string', format => 'pve-configid',
+ maxLength => 40,
+});
__PACKAGE__->register_method({
name => 'vmlist',
@@ -1279,4 +1284,59 @@ __PACKAGE__->register_method({
}
}});
+__PACKAGE__->register_method({
+ name => 'snapshot',
+ path => '{vmid}/snapshot',
+ method => 'POST',
+ protected => 1,
+ proxyto => 'node',
+ description => "Snapshot a container.",
+ permissions => {
+ check => ['perm', '/vms/{vmid}', [ 'VM.Snapshot' ]],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid'),
+ snapname => get_standard_option('pve-lxc-snapshot-name'),
+ vmstate => {
+ optional => 1,
+ type => 'boolean',
+ description => "Save the vmstate",
+ },
+ description => {
+ optional => 1,
+ type => 'string',
+ description => "A textual description or comment.",
+ },
+ },
+ },
+ returns => {
+ type => 'string',
+ description => "the task ID.",
+ },
+ 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');
+
+ my $snapname = extract_param($param, 'snapname');
+
+ die "unable to use snapshot name 'current' (reserved name)\n"
+ if $snapname eq 'current';
+
+ my $realcmd = sub {
+ PVE::Cluster::log_msg('info', $authuser, "snapshot container $vmid: $snapname");
+ PVE::LXC::snapshot_create($vmid, $snapname, $param->{description});
+ };
+
+ return $rpcenv->fork_worker('pctsnapshot', $vmid, $authuser, $realcmd);
+ }});
1;
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index f92b903..3bb69ca 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1425,6 +1425,14 @@ sub update_ipconfig {
&$change_ip_config(4);
&$change_ip_config(6);
+
+}
+
+sub snapshot_create {
+ my ($vmid, $snapname, $comment) = @_;
+
+ print "Not implemented\n";
+
}
1;
diff --git a/src/pct b/src/pct
index 5d5f9fa..06affa0 100755
--- a/src/pct
+++ b/src/pct
@@ -123,6 +123,8 @@ my $cmddef = {
destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
{ node => $nodename }, $upid_exit ],
+ snapshot => [ "PVE::API2::LXC", 'snapshot', ['vmid', 'snapname'],
+ { node => $nodename } , $upid_exit ],
};
my $cmd = shift;
--
2.1.4
More information about the pve-devel
mailing list