[PATCH qemu-server 1/1] fix #5033: api: Add target-filename option to move_disk reassign
Markus Ebner
info at ebner-markus.de
Wed Nov 8 17:52:39 CET 2023
When the move_disk endpoint is used to reassign a disk image from one
vm to another, the target-filename of the image is typically chosen
automatically with the known naming schema.
This patch adds the optional parameter target-filename, allowing
to manually specify a filename for the disk image when doing a vm
to vm reassignment. It's not currently implemented for storage to
storage moving.
Signed-off-by: Markus Ebner <info at ebner-markus.de>
---
PVE/API2/Qemu.pm | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 38bdaab..f4414e9 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -3886,6 +3886,14 @@ __PACKAGE__->register_method({
maxLength => 40,
optional => 1,
},
+ 'target-filename' => {
+ type => 'string',
+ description => "Specify a custom target filename to which the moved disk will be"
+ ." renamed as part of the moving (only supported for reassign at the moment)."
+ ." Caution: Will be normalized",
+ optional => 1,
+ default => "automatically determined with vm-<vmid>-disk-<nr> schema"
+ },
},
},
returns => {
@@ -3907,6 +3915,9 @@ __PACKAGE__->register_method({
my $target_disk = extract_param($param, 'target-disk') // $disk;
my $storeid = extract_param($param, 'storage');
my $format = extract_param($param, 'format');
+ my $target_filename = extract_param($param, 'target-filename');
+ $target_filename = PVE::Storage::normalize_content_filename($target_filename)
+ if $target_filename;
my $storecfg = PVE::Storage::config();
@@ -4148,6 +4159,7 @@ __PACKAGE__->register_method({
$storecfg,
$source_volid,
$target_vmid,
+ $target_filename # undef if no custom filename was requested -> automatically chosen
);
$drive->{file} = $new_volid;
@@ -4226,6 +4238,8 @@ __PACKAGE__->register_method({
$disk_reassignfn
);
} elsif ($storeid) {
+ my $msg = "target-filename option not yet supported when moving to a different storage";
+ raise_param_exc({ 'target-filename' => $msg }) if $target_filename;
$rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
die "cannot move disk '$disk', only configured disks can be moved to another storage\n"
--
2.42.0
More information about the pve-devel
mailing list