From 60d7d9c74862cf6278dadffba2bce65bfc2eda51 Mon Sep 17 00:00:00 2001 From: Daniel Kral Date: Thu, 17 Oct 2024 13:51:22 +0200 Subject: [PATCH] importdisk: convert imported volume disks to base images for templates Automatically converts any imported volume disk to a base volume image if the VM is a template and the volume was imported using the "target-disk" option, as "unused" disks are not needed to be converted as they won't be cloned with either linked nor full clones. Signed-off-by: Daniel Kral --- PVE/CLI/qm.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm index fd4688b5..bce87020 100755 --- a/PVE/CLI/qm.pm +++ b/PVE/CLI/qm.pm @@ -624,7 +624,13 @@ __PACKAGE__->register_method ({ }, ); - print "Successfully imported disk as '$drive_id:$volid'\n"; + $vm_conf = PVE::QemuConfig->load_config($vmid); + + # change imported _used_ disk to a base volume in case the VM is a template + PVE::QemuServer::template_create($vmid, $vm_conf, $drive_id) + if is_valid_drivename($drive_id) && PVE::QemuConfig->is_template($vm_conf); + + print "$drive_id: successfully imported disk '$vm_conf->{$drive_id}'\n"; return; }});