]> git.proxmox.com Git - qemu-server.git/commitdiff
add API to get/set snapshot configuration.
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Sep 2012 07:24:18 +0000 (09:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Sep 2012 07:34:48 +0000 (09:34 +0200)
You can currently only modify the 'description'.

PVE/API2/Qemu.pm

index 2a370dabb2dd6002a52582f6e66f56532d3b9d74..047b1063420a607f97751016e2c1b1cc0b4cb65a 100644 (file)
@@ -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',