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

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jan 30 15:10:59 CET 2019


On 1/30/19 2:43 PM, Rhonda D'Vine wrote:
> 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.

applied, with removal of an unused variable (see below).

> 
> Signed-off-by: Rhonda D'Vine <rhonda at proxmox.com>
> ---
>  PVE/API2/Qemu.pm  | 19 +++++++++++++++++++
>  PVE/CLI/qm.pm     | 12 ++++++++++--
>  PVE/QemuServer.pm | 13 ++++++++++++-
>  debian/control    |  2 +-
>  4 files changed, 42 insertions(+), 4 deletions(-)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 148ea1a..7f737bf 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -829,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 => {
> @@ -846,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}) {
> diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> index 26d4217..f4bacd6 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 ($cmd, $pname, $cur, $args) = @_;
> +		    PVE::QemuConfig->snapshot_list($args->[0]);
> +		}
> +	    }),
>  	},
>      },
>      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 bc3bb1d..3b64286 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -5372,10 +5372,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};
       ^^^^^^^^^^

removed above...

> +
> +	# we need the digest of the file
> +	$snapshot->{digest} = $conf->{digest};
                             ^^^^^^^^^^^^^^^
.. and just kept this, as in the CT patch.

> +	$conf = $snapshot;
> +    }
> +
>      my $defaults = load_defaults();
>  
>      my $cmd = config_to_command($storecfg, $vmid, $conf, $defaults);
> diff --git a/debian/control b/debian/control
> index 6be81ca..0aec27d 100644
> --- a/debian/control
> +++ b/debian/control
> @@ -6,7 +6,7 @@ Build-Depends: debhelper (>= 7.0.50~),
>                 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,
> 





More information about the pve-devel mailing list