}});
__PACKAGE__->register_method({
- name => 'move_vm',
- path => '{vmid}/move',
+ name => 'move_vm_disk',
+ path => '{vmid}/move_disk',
method => 'POST',
protected => 1,
proxyto => 'node',
enum => [ 'raw', 'qcow2', 'vmdk' ],
optional => 1,
},
+ delete => {
+ type => 'boolean',
+ description => "Delete the original disk after successful copy. By default the original disk is kept as unused disk.",
+ optional => 1,
+ default => 0,
+ },
digest => {
type => 'string',
description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
my $drive = PVE::QemuServer::parse_drive($disk, $conf->{$disk});
- my $volid = $drive->{file} || die "disk '$disk' has no associated volume\n";
+ my $old_volid = $drive->{file} || die "disk '$disk' has no associated volume\n";
die "you can't move a cdrom\n" if PVE::QemuServer::drive_is_cdrom($drive);
my $oldfmt;
- my ($oldstoreid, $oldvolname) = PVE::Storage::parse_volume_id($volid);
+ my ($oldstoreid, $oldvolname) = PVE::Storage::parse_volume_id($old_volid);
if ($oldvolname =~ m/\.(raw|qcow2|vmdk)$/){
$oldfmt = $1;
}
$conf->{$disk} = PVE::QemuServer::print_drive($vmid, $newdrive);
- PVE::QemuServer::add_unused_volume($conf, $volid);
-
+ PVE::QemuServer::add_unused_volume($conf, $old_volid) if !$param->{delete};
+
PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
};
if (my $err = $@) {
}
die "storage migration failed: $err";
}
+
+ if ($param->{delete}) {
+ eval { PVE::Storage::vdisk_free($storecfg, $old_volid); };
+ warn $@ if $@;
+ }
};
return $rpcenv->fork_worker('qmmove', $vmid, $authuser, $realcmd);