]> git.proxmox.com Git - qemu-server.git/commitdiff
Fix #1924: add snapshot parameter
authorRhonda D'Vine <rhonda@proxmox.com>
Wed, 30 Jan 2019 13:43:38 +0000 (14:43 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 30 Jan 2019 13:56:43 +0000 (14:56 +0100)
The qm CLI command offer the config and showcmd functions. Both of those
outputs may vary with respect to a given snapshot. This adds a switch
that shows the corresponding snapshot's config and command line.

The code needs a newer libpve-guest-common-perl, thus bumping the
dependency.

Signed-off-by: Rhonda D'Vine <rhonda@proxmox.com>
PVE/API2/Qemu.pm
PVE/CLI/qm.pm
PVE/QemuServer.pm
debian/control

index 148ea1ace506865b3e9072b0442c8f5ebf24cda2..7f737bf8eaf3725ebde21290f52a7a10a28866f1 100644 (file)
@@ -829,6 +829,14 @@ __PACKAGE__->register_method({
                default => 0,
                type => 'boolean',
             },
                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 => {
        },
     },
     returns => {
@@ -846,6 +854,17 @@ __PACKAGE__->register_method({
 
        my $conf = PVE::QemuConfig->load_config($param->{vmid});
 
 
        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}) {
        delete $conf->{snapshots};
 
        if (!$param->{current}) {
index 26d4217d07e77fc49399502135f8310a83ba5155..f4bacd696121d94e973130ef67f3b2911906575c 100755 (executable)
@@ -127,7 +127,15 @@ __PACKAGE__->register_method ({
                type => 'boolean',
                optional => 1,
                default => 0,
                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 ($cmd, $pname, $cur, $args) = @_;
+                   PVE::QemuConfig->snapshot_list($args->[0]);
+               }
+           }),
        },
     },
     returns => { type => 'null'},
        },
     },
     returns => { type => 'null'},
@@ -135,7 +143,7 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        my $storecfg = PVE::Storage::config();
        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};
 
 
        $cmdline =~ s/ -/ \\\n  -/g if $param->{pretty};
 
index bc3bb1d34781d91c23bb35337342261042064e89..3b642863fce715d55b66d3393fa48f480e71071b 100644 (file)
@@ -5372,10 +5372,21 @@ sub vm_human_monitor_command {
 }
 
 sub vm_commandline {
 }
 
 sub vm_commandline {
-    my ($storecfg, $vmid) = @_;
+    my ($storecfg, $vmid, $snapname) = @_;
 
     my $conf = PVE::QemuConfig->load_config($vmid);
 
 
     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);
     my $defaults = load_defaults();
 
     my $cmd = config_to_command($storecfg, $vmid, $conf, $defaults);
index 6be81ca1445cab455b35f24254d604b8b470f060..0aec27d23fd6fe38597a84b5636f338bf72273a1 100644 (file)
@@ -6,7 +6,7 @@ Build-Depends: debhelper (>= 7.0.50~),
                libio-multiplex-perl,
                libjson-c-dev,
                libpve-common-perl (>= 5.0-42),
                libio-multiplex-perl,
                libjson-c-dev,
                libpve-common-perl (>= 5.0-42),
-               libpve-guest-common-perl (>= 2.0-18),
+               libpve-guest-common-perl (>= 2.0-19),
                libpve-storage-perl,
                libtest-mockmodule-perl,
                libxml-libxml-perl,
                libpve-storage-perl,
                libtest-mockmodule-perl,
                libxml-libxml-perl,