]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
Fix #1924: add snapshot parameter
[qemu-server.git] / PVE / API2 / Qemu.pm
index d4085daca734151f56b70c35e5f2296d17b36b63..7f737bf8eaf3725ebde21290f52a7a10a28866f1 100644 (file)
@@ -648,8 +648,7 @@ __PACKAGE__->register_method({
                if (my $err = $@) {
                    eval {
                        my $conffile = PVE::QemuConfig->config_file($vmid);
-                       unlink($conffile)
-                           or die "failed to remove config file: $@\n";
+                       unlink($conffile) or die "failed to remove config file: $!\n";
                    };
                    warn $@ if $@;
                    die $err;
@@ -830,6 +829,14 @@ __PACKAGE__->register_method({
                default => 0,
                type => 'boolean',
             },
+           snapshot => get_standard_option('pve-snapshot-name', {
+               description => "Fetch config values from given snapshot.",
+               optional => 1,
+               completion => sub {
+                   my ($cmd, $pname, $cur, $args) = @_;
+                   PVE::QemuConfig->snapshot_list($args->[0]);
+               },
+           }),
        },
     },
     returns => {
@@ -847,6 +854,17 @@ __PACKAGE__->register_method({
 
        my $conf = PVE::QemuConfig->load_config($param->{vmid});
 
+       my $snapname = $param->{snapshot};
+       if ($snapname) {
+           my $snapshot = $conf->{snapshots}->{$snapname};
+           die "snapshot '$snapname' does not exist\n"
+               if !defined($snapshot);
+
+           # we need the digest of the file
+           $snapshot->{digest} = $conf->{digest};
+           $conf = $snapshot;
+       }
+
        delete $conf->{snapshots};
 
        if (!$param->{current}) {
@@ -1541,7 +1559,7 @@ __PACKAGE__->register_method({
            (undef, $family) = PVE::Cluster::remote_node_ip($node);
            my $sshinfo = PVE::Cluster::get_ssh_info($node);
            # NOTE: kvm VNC traffic is already TLS encrypted or is known unsecure
-           $remcmd = PVE::Cluster::ssh_info_to_command($sshinfo, '-T');
+           $remcmd = PVE::Cluster::ssh_info_to_command($sshinfo, $use_serial ? '-t' : '-T');
        } else {
            $family = PVE::Tools::get_host_address_family($node);
        }