Am 4/25/19 um 5:14 PM schrieb Christian Ebner: > If a vdisk_create_base fails because the storage backend does not support the > base image creation, it leaves behind the original disk image, this is > correct. This should not create further problems. For such templates, the > user gets a warning stating it is not possible to create a linked clone, only > full clones are possible. > > So the code simply mimics the current behavior, where the user restores to VM > and then manually converts to template. This leads to the same result.
thanks for clarifying, applied! > >> On April 24, 2019 at 7:56 PM Thomas Lamprecht <t.lampre...@proxmox.com> >> wrote: >> >> >> Am 4/19/19 um 12:06 PM schrieb Christian Ebner: >>> 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.eb...@proxmox.com> >>> --- >>> PVE/API2/Qemu.pm | 11 +++++++++-- >>> PVE/QemuServer.pm | 1 - >>> 2 files changed, 9 insertions(+), 3 deletions(-) >>> >>> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm >>> index 651f64f..f61e58e 100644 >>> --- a/PVE/API2/Qemu.pm >>> +++ b/PVE/API2/Qemu.pm >>> @@ -556,14 +556,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) }; >> >> hmm, at the moment we can only restore to all disks to a single target >> storage, or? because the lack of cleanup inside template_create, if one >> vdisk_create_base fails, may then not be a real problem often here, but >> can still happen.. error handling is a bit hard to do arbitrary in this >> case, thus it was probably left out in the first place. >> >> Commit bbd560974af465b2d4d55e6528001e93d4962e06 changed the "die" if a >> storage does not supports templating to just ignore it, as it then needs >> to be full cloned, so yes your quite simple patch seems to do the right >> thing™, need to rethink this a bit, seems almost to easy for the fact that >> we actively didn't do it.. ^^ >> >>> + warn $@ if $@; >>> + } >>> >>> PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool; >>> >>> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm >>> index cd86fec..2ca5f6e 100644 >>> --- a/PVE/QemuServer.pm >>> +++ b/PVE/QemuServer.pm >>> @@ -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*$/)) { >>> >> > > _______________________________________________ > pve-devel mailing list > pve-devel@pve.proxmox.com > https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel > _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel