]> git.proxmox.com Git - qemu-server.git/commitdiff
cloud-init: clone/move support
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 23 Feb 2018 10:07:19 +0000 (11:07 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Mar 2018 08:11:31 +0000 (09:11 +0100)
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 <w.bumiller@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuServer.pm

index c39fc83c09a911c83c84a541fa0232b9f620dda8..3aec4b75f5e0263c235eda4826b85458515caeaa 100644 (file)
@@ -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);
index 7dfd4a30bed706a637b4f44b662df2b52b99e9e4..bfab406067e1d3ed77ab6b84861de07b76a18586 100644 (file)
@@ -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]);