From: Wolfgang Bumiller Date: Fri, 23 Feb 2018 10:07:19 +0000 (+0100) Subject: cloud-init: clone/move support X-Git-Url: https://git.proxmox.com/?p=qemu-server.git;a=commitdiff_plain;h=931432bd2d31a3203b309235768aa626bc1f482d cloud-init: clone/move support move: don't error out with "you can't move a cdrom" clone: always full-clone cloud-init images They get completely replaced anyway at the next start, so there's no point in keeping them. Signed-off-by: Wolfgang Bumiller --- diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index c39fc83..3aec4b7 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -2601,10 +2601,10 @@ __PACKAGE__->register_method({ } elsif (PVE::QemuServer::is_valid_drivename($opt)) { my $drive = PVE::QemuServer::parse_drive($opt, $value); die "unable to parse drive options for '$opt'\n" if !$drive; - if (PVE::QemuServer::drive_is_cdrom($drive)) { + if (PVE::QemuServer::drive_is_cdrom($drive, 1)) { $newconf->{$opt} = $value; # simply copy configuration } else { - if ($param->{full}) { + if ($param->{full} || PVE::QemuServer::drive_is_cloudinit($drive)) { die "Full clone feature is not supported for drive '$opt'\n" if !PVE::Storage::volume_has_feature($storecfg, 'copy', $drive->{file}, $snapname, $running); $fullclone->{$opt} = 1; @@ -2812,7 +2812,7 @@ __PACKAGE__->register_method({ 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); + die "you can't move a cdrom\n" if PVE::QemuServer::drive_is_cdrom($drive, 1); my $oldfmt; my ($oldstoreid, $oldvolname) = PVE::Storage::parse_volume_id($old_volid); diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 7dfd4a3..bfab406 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -6395,7 +6395,17 @@ sub clone_disk { my ($size) = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 3); print "create full clone of drive $drivename ($drive->{file})\n"; - $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $dst_format, undef, ($size/1024)); + my $name = undef; + if (drive_is_cloudinit($drive)) { + $name = "vm-$newvmid-cloudinit"; + # cloudinit only supports raw and qcow2 atm: + if ($dst_format eq 'qcow2') { + $name .= '.qcow2'; + } elsif ($dst_format ne 'raw') { + die "clone: unhandled format for cloudinit image\n"; + } + } + $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $dst_format, $name, ($size/1024)); push @$newvollist, $newvolid; PVE::Storage::activate_volumes($storecfg, [$newvolid]);