[pve-devel] [PATCH v2 qemu-server] Fix #1924: add snapshot parameter

Rhonda D'Vine rhonda at proxmox.com
Mon Nov 19 12:20:22 CET 2018


The config and showcmd CLI commands offer the config and showcmd
functions. Both of that outputs may vary with respect to a given
snapshot. This adds a switch that shows the corresponding snapshot's
config and command line.

This patch needs the one in pve-guest-common applied first, and have the
versioned dependency in debian/control adjusted.

Signed-off-by: Rhonda D'Vine <rhonda at proxmox.com>
---
 PVE/API2/Qemu.pm  | 19 +++++++++++++++++++
 PVE/CLI/qm.pm     | 12 ++++++++++--
 PVE/QemuServer.pm | 13 ++++++++++++-
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index c82e2fa..d3f4320 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -830,6 +830,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 $vmid = $_[3][0];
+		    PVE::QemuConfig->snapshot_list($vmid);
+		},
+            }),
 	},
     },
     returns => {
@@ -847,6 +855,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}) {
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index eceb9b3..e757be6 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -127,7 +127,15 @@ __PACKAGE__->register_method ({
 		type => 'boolean',
 		optional => 1,
 		default => 0,
-	    }
+	    },
+	    snapshot => get_standard_option('pve-snapshot-name', {
+		description => "Fetch config values from given snapshot.",
+		optional => 1,
+		completion => sub {
+		    my $vmid = $_[3][0];
+		    PVE::QemuConfig->snapshot_list($vmid);
+		}
+	    }),
 	},
     },
     returns => { type => 'null'},
@@ -135,7 +143,7 @@ __PACKAGE__->register_method ({
 	my ($param) = @_;
 
 	my $storecfg = PVE::Storage::config();
-	my $cmdline = PVE::QemuServer::vm_commandline($storecfg, $param->{vmid});
+	my $cmdline = PVE::QemuServer::vm_commandline($storecfg, $param->{vmid}, $param->{snapshot});
 
 	$cmdline =~ s/ -/ \\\n  -/g if $param->{pretty};
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 035d8b7..8956a7d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5337,10 +5337,21 @@ sub vm_human_monitor_command {
 }
 
 sub vm_commandline {
-    my ($storecfg, $vmid) = @_;
+    my ($storecfg, $vmid, $snapname) = @_;
 
     my $conf = PVE::QemuConfig->load_config($vmid);
 
+    if ($snapname) {
+	my $snapshot = $conf->{snapshots}->{$snapname};
+	die "snapshot '$snapname' does not exist\n"
+	    if !defined($snapshot);
+	my $digest = $conf->{digest};
+
+	# we need the digest of the file
+	$snapshot->{digest} = $conf->{digest};
+	$conf = $snapshot;
+    }
+
     my $defaults = load_defaults();
 
     my $cmd = config_to_command($storecfg, $vmid, $conf, $defaults);
-- 
2.11.0





More information about the pve-devel mailing list