[pve-devel] [PATCH qemu-server 2/4] importdisk: convert imported volume disks to base images for templates

Daniel Kral d.kral at proxmox.com
Thu Oct 17 13:51:22 CEST 2024


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 <d.kral at proxmox.com>
---

Notes:
    Change to the command line output
    
    There is a small change to the console output at the end, because (a)
    it produces less code than correctly setting the $drive_id and $volid
    again, and (b) it is more consistent with the console prints of
    `create_disks` used when creating new VM disks.

 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 30282f6f..e65684bd 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -622,7 +622,13 @@ __PACKAGE__->register_method ({
 		format => $format,
 	    });
 
-	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;
     }});
-- 
2.39.5





More information about the pve-devel mailing list