]> git.proxmox.com Git - qemu-server.git/commitdiff
copy_vm: allow to copy from snapshot
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 30 Apr 2013 07:31:23 +0000 (09:31 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 30 Apr 2013 07:31:23 +0000 (09:31 +0200)
PVE/API2/Qemu.pm

index e92a03e990d9fe299005c3f0b2613d4160698581..fc9b502581fadf9603c4a31bd501602e9d92e3f0 100644 (file)
@@ -1742,7 +1742,6 @@ __PACKAGE__->register_method({
                 optional => 1,
             }),
        },
-
     },
     returns => {
         type => 'boolean'
@@ -1807,6 +1806,10 @@ __PACKAGE__->register_method({
                type => 'string', format => 'pve-poolid',
                description => "Add the new VM to the specified pool.",
            },
+            snapname => get_standard_option('pve-snapshot-name', {
+               requires => 'full',
+               optional => 1,
+            }),
            storage => get_standard_option('pve-storage-id', {
                description => "Target storage for full copy.",
                requires => 'full',
@@ -1844,6 +1847,8 @@ __PACKAGE__->register_method({
            $rpcenv->check_pool_exist($pool);
        }
 
+       my $snapname = extract_param($param, 'snapname');
+
        my $storage = extract_param($param, 'storage');
 
        my $storecfg = PVE::Storage::config();
@@ -1872,9 +1877,12 @@ __PACKAGE__->register_method({
 
            die "unexpected state change\n" if $verify_running != $running;
 
-           &$check_storage_access_copy($rpcenv, $authuser, $storecfg, $conf, $storage);
+           die "snapshot '$snapname' does not exist\n" 
+               if $snapname && !defined( $conf->{snapshots}->{$snapname}); 
 
-           # fixme: snapshots??
+           my $oldconf = $snapname ? $conf->{snapshots}->{$snapname} : $conf; 
+
+           &$check_storage_access_copy($rpcenv, $authuser, $storecfg, $oldconf, $storage);
 
            my $conffile = PVE::QemuServer::config_file($newid);
 
@@ -1893,10 +1901,13 @@ __PACKAGE__->register_method({
                    my $newconf = { lock => 'copy' };
                    my $drives = {};
                    my $vollist = [];
-                   foreach my $opt (keys %$conf) {
-                       my $value = $conf->{$opt};
 
-                       next if $opt eq 'snapshots'; #  do not copy snapshot info
+                   foreach my $opt (keys %$oldconf) {
+                       my $value = $oldconf->{$opt};
+
+                       # do not copy snapshot related info
+                       next if $opt eq 'snapshots' ||  $opt eq 'parent' || $opt eq 'snaptime' ||
+                           $opt eq 'vmstate' || $opt eq 'snapstate';
 
                        # always change MAC! address
                        if ($opt =~ m/^net(\d+)$/) {
@@ -1941,7 +1952,7 @@ __PACKAGE__->register_method({
                                print "copy drive $opt ($drive->{file})\n";
                                $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newid, $fmt, undef, ($size/1024));
 
-                               PVE::QemuServer::qemu_img_convert($drive->{file}, $newvolid, $size);
+                               PVE::QemuServer::qemu_img_convert($drive->{file}, $newvolid, $size, $snapname);
                            }
 
                            my ($size) = PVE::Storage::volume_size_info($storecfg, $newvolid, 3);