]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
fix assertion
[qemu-server.git] / PVE / API2 / Qemu.pm
index 81970706c00d915d357806af424b3e9c853b41fa..7d716703b4da8b9acae9a63cac183a191b79a87d 100644 (file)
@@ -2392,14 +2392,23 @@ __PACKAGE__->register_method({
 
            PVE::QemuServer::check_lock($conf);
 
-           die "you can't convert a template to a template" 
+           die "unable to create template, because VM contains snapshots\n" 
+               if $conf->{snapshots} && scalar(keys %{$conf->{snapshots}});
+
+           die "you can't convert a template to a template\n" 
                if PVE::QemuServer::is_template($conf) && !$disk;
+
+           die "you can't convert a VM to template if VM is running\n" 
+               if check_running($vmid);
+
            my $realcmd = sub {
                PVE::QemuServer::template_create($vmid, $conf, $disk);
            };
-           return $rpcenv->fork_worker('qmtemplate', $vmid, $authuser, $realcmd);
 
+           $conf->{template} = 1;
            PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+
+           return $rpcenv->fork_worker('qmtemplate', $vmid, $authuser, $realcmd);
        };
 
        PVE::QemuServer::lock_config($vmid, $updatefn);