]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
pass 'digest', so that GUI can detect changes easily
[qemu-server.git] / PVE / API2 / Qemu.pm
index 9c6d71426c25daf91383f36975a122d1cc1df2e5..5d69ca33f194876ff3c78879084855e552929422 100644 (file)
@@ -1925,14 +1925,14 @@ __PACKAGE__->register_method({
                description => $d->{description} || '',
            };
            $item->{parent} = $d->{parent} if $d->{parent};
+           $item->{snapstate} = $d->{snapstate} if $d->{snapstate};
            push @$res, $item;
        }
 
-       if ($conf->{parent}) {
-           push @$res, { name => '__current', parent => $conf->{parent} };
-       } else {
-           push @$res, { name => '__current' };
-       }
+       my $current = { name => 'current', digest => $conf->{digest} };
+       $current->{parent} = $conf->{parent} if $conf->{parent};
+
+       push @$res, $current;
 
        return $res;
     }});
@@ -1963,6 +1963,11 @@ __PACKAGE__->register_method({
                type => 'boolean',
                description => "Freeze the filesystem",
            },
+           description => {
+               optional => 1,
+               type => 'string',
+               description => "A textual description or comment.",
+           },
        },
     },
     returns => {
@@ -1982,13 +1987,13 @@ __PACKAGE__->register_method({
 
        my $snapname = extract_param($param, 'snapname');
 
-       my $vmstate = extract_param($param, 'vmstate');
-       my $freezefs = extract_param($param, 'freezefs');
+       die "unable to use snapshot name 'current' (reserved name)\n"
+           if $snapname eq 'current';
 
        my $realcmd = sub {
            PVE::Cluster::log_msg('info', $authuser, "snapshot VM $vmid: $snapname");
-           PVE::QemuServer::snapshot_create($vmid, $snapname, $vmstate, $freezefs);
+           PVE::QemuServer::snapshot_create($vmid, $snapname, $param->{vmstate}, 
+                                            $param->{freezefs}, $param->{description});
        };
 
        return $rpcenv->fork_worker('qmsnapshot', $vmid, $authuser, $realcmd);
@@ -2024,10 +2029,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',
@@ -2087,6 +2188,11 @@ __PACKAGE__->register_method({
            node => get_standard_option('pve-node'),
            vmid => get_standard_option('pve-vmid'),
            snapname => get_standard_option('pve-snapshot-name'),
+           force => {
+               optional => 1,
+               type => 'boolean',
+               description => "For removal from config file, even if removing disk snapshots fails.",
+           },
        },
     },
     returns => {
@@ -2108,7 +2214,7 @@ __PACKAGE__->register_method({
 
        my $realcmd = sub {
            PVE::Cluster::log_msg('info', $authuser, "delete snapshot VM $vmid: $snapname");
-           PVE::QemuServer::snapshot_delete($vmid, $snapname);
+           PVE::QemuServer::snapshot_delete($vmid, $snapname, $param->{force});
        };
 
        return $rpcenv->fork_worker('qmdelsnapshot', $vmid, $authuser, $realcmd);