From d788cea673b0001959b3ce72b69be054ee7274fd Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 11 Sep 2012 09:24:18 +0200 Subject: [PATCH] add API to get/set snapshot configuration. You can currently only modify the 'description'. --- PVE/API2/Qemu.pm | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 2a370da..047b106 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -2026,10 +2026,106 @@ __PACKAGE__->register_method({ my $res = []; push @$res, { cmd => 'rollback' }; + push @$res, { cmd => 'config' }; return $res; }}); +__PACKAGE__->register_method({ + name => 'update_snapshot_config', + path => '{vmid}/snapshot/{snapname}/config', + method => 'PUT', + protected => 1, + proxyto => 'node', + description => "Update snapshot metadata.", + 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-snapshot-name'), + description => { + optional => 1, + type => 'string', + description => "A textual description or comment.", + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + my $rpcenv = PVE::RPCEnvironment::get(); + + my $authuser = $rpcenv->get_user(); + + my $vmid = extract_param($param, 'vmid'); + + my $snapname = extract_param($param, 'snapname'); + + return undef if !defined($param->{description}); + + my $updatefn = sub { + + my $conf = PVE::QemuServer::load_config($vmid); + + PVE::QemuServer::check_lock($conf); + + my $snap = $conf->{snapshots}->{$snapname}; + + die "snapshot '$snapname' does not exist\n" if !defined($snap); + + $snap->{description} = $param->{description} if defined($param->{description}); + + PVE::QemuServer::update_config_nolock($vmid, $conf, 1); + }; + + PVE::QemuServer::lock_config($vmid, $updatefn); + + return undef; + }}); + +__PACKAGE__->register_method({ + name => 'get_snapshot_config', + path => '{vmid}/snapshot/{snapname}/config', + method => 'GET', + proxyto => 'node', + description => "Get snapshot configuration", + 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-snapshot-name'), + }, + }, + returns => { type => "object" }, + code => sub { + my ($param) = @_; + + my $rpcenv = PVE::RPCEnvironment::get(); + + my $authuser = $rpcenv->get_user(); + + my $vmid = extract_param($param, 'vmid'); + + my $snapname = extract_param($param, 'snapname'); + + my $conf = PVE::QemuServer::load_config($vmid); + + my $snap = $conf->{snapshots}->{$snapname}; + + die "snapshot '$snapname' does not exist\n" if !defined($snap); + + return $snap; + }}); + __PACKAGE__->register_method({ name => 'rollback', path => '{vmid}/snapshot/{snapname}/rollback', -- 2.39.2