]> git.proxmox.com Git - qemu-server.git/commitdiff
fix: #1075: Restore VM template to VM and try to convert to template.
authorChristian Ebner <c.ebner@proxmox.com>
Fri, 19 Apr 2019 10:06:07 +0000 (12:06 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 24 Apr 2019 17:35:32 +0000 (17:35 +0000)
The restore of a backup from a VM template will first restore the VM and then
convert the restored VM back into a template.
This automatically performes the steps of the current behaviour, where the user
has to manually convert the restored VM back to a template.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuServer.pm

index 184f32a6daff7175049721d3a944e719e26d3282..62e654906cfcfccf3f731ae64b13fcc1c71b6f68 100644 (file)
@@ -557,14 +557,21 @@ __PACKAGE__->register_method({
            PVE::QemuConfig->check_protection($conf, $emsg);
 
            die "$emsg vm is running\n" if PVE::QemuServer::check_running($vmid);
-           die "$emsg vm is a template\n" if PVE::QemuConfig->is_template($conf);
 
            my $realcmd = sub {
                PVE::QemuServer::restore_archive($archive, $vmid, $authuser, {
                    storage => $storage,
                    pool => $pool,
                    unique => $unique,
-                   bwlimit => $bwlimit, });
+                   bwlimit => $bwlimit,
+               });
+               my $restored_conf = PVE::QemuConfig->load_config($vmid);
+               # Convert restored VM to template if backup was VM template
+               if (PVE::QemuConfig->is_template($restored_conf)) {
+                   warn "Convert to template.\n";
+                   eval { PVE::QemuServer::template_create($vmid, $restored_conf) };
+                   warn $@ if $@;
+               }
 
                PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
 
index cd86fec94a8d2a8208cf08d56384064693b8a7e3..2ca5f6e9008a44fdfef82c390f5458e606da91aa 100644 (file)
@@ -5904,7 +5904,6 @@ sub restore_update_config_line {
     return if $line =~ m/^lock:/;
     return if $line =~ m/^unused\d+:/;
     return if $line =~ m/^parent:/;
-    return if $line =~ m/^template:/; # restored VM is never a template
 
     my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
     if (($line =~ m/^(vlan(\d+)):\s*(\S+)\s*$/)) {