public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server 1/4] importdisk: add 'target-disk' option to add imported volume to disk
@ 2024-10-17 11:51 Daniel Kral
  2024-10-17 11:51 ` [pve-devel] [PATCH qemu-server 2/4] importdisk: convert imported volume disks to base images for templates Daniel Kral
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Daniel Kral @ 2024-10-17 11:51 UTC (permalink / raw)
  To: pve-devel

Implements the "target-disk" option for the importdisk command, which
allows a disk to be imported and directly used instead of marking it as
an unused disk (e.g. unused0), which is the default behavior.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 PVE/CLI/qm.pm | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index d3dbf7b4..30282f6f 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -29,7 +29,7 @@ use PVE::Tools qw(extract_param file_get_contents);
 use PVE::API2::Qemu::Agent;
 use PVE::API2::Qemu;
 use PVE::QemuConfig;
-use PVE::QemuServer::Drive;
+use PVE::QemuServer::Drive qw(is_valid_drivename);
 use PVE::QemuServer::Helpers;
 use PVE::QemuServer::Agent qw(agent_available);
 use PVE::QemuServer::ImportDisk;
@@ -579,6 +579,12 @@ __PACKAGE__->register_method ({
 		enum => [ 'raw', 'qcow2', 'vmdk' ],
 		optional => 1,
 	    },
+	    'target-disk' => {
+		type => 'string',
+		description => 'The disk name where the volume will be imported to (e.g. scsi1).',
+		enum => [PVE::QemuServer::Drive::valid_drive_names_with_unused()],
+		optional => 1,
+	    },
 	},
     },
     returns => { type => 'null'},
@@ -589,6 +595,10 @@ __PACKAGE__->register_method ({
 	my $source = extract_param($param, 'source');
 	my $storeid = extract_param($param, 'storage');
 	my $format = extract_param($param, 'format');
+	my $target_disk = extract_param($param, 'target-disk');
+
+	# do_import does not allow invalid drive names (e.g. unused0)
+	$target_disk = undef if !is_valid_drivename($target_disk);
 
 	my $vm_conf = PVE::QemuConfig->load_config($vmid);
 	PVE::QemuConfig->check_lock($vm_conf);
@@ -602,7 +612,16 @@ __PACKAGE__->register_method ({
 	    if !$target_storage_config->{content}->{images};
 
 	print "importing disk '$source' to VM $vmid ...\n";
-	my ($drive_id, $volid) = PVE::QemuServer::ImportDisk::do_import($source, $vmid, $storeid, { format => $format });
+
+	my ($drive_id, $volid) = PVE::QemuServer::ImportDisk::do_import(
+	    $source,
+	    $vmid,
+	    $storeid,
+	    {
+		drive_name => $target_disk,
+		format => $format,
+	    });
+
 	print "Successfully imported disk as '$drive_id:$volid'\n";
 
 	return;
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-17 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-17 11:51 [pve-devel] [PATCH qemu-server 1/4] importdisk: add 'target-disk' option to add imported volume to disk Daniel Kral
2024-10-17 11:51 ` [pve-devel] [PATCH qemu-server 2/4] importdisk: convert imported volume disks to base images for templates Daniel Kral
2024-10-17 11:51 ` [pve-devel] [PATCH qemu-server 3/4] fix #5301: convert added volume disks to base image " Daniel Kral
2024-10-17 11:51 ` [pve-devel] [PATCH qemu-server 4/4] templates: add documentation to template_create Daniel Kral
2024-11-17 18:54 ` [pve-devel] applied-series: [PATCH qemu-server 1/4] importdisk: add 'target-disk' option to add imported volume to disk Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal