[pve-devel] [PATCH container 2/9] adapt config GET call for taking pending changes

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Sep 11 09:39:12 CEST 2019


On September 5, 2019 4:11 pm, Oguz Bektas wrote:
> the default behaviour is the same as in Qemu, so without the 'current'
> flag set, current values will be replaced with their respective pending
> counterparts.
> 
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
>  src/PVE/API2/LXC/Config.pm | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm
> index 769fc3b..6e67186 100644
> --- a/src/PVE/API2/LXC/Config.pm
> +++ b/src/PVE/API2/LXC/Config.pm
> @@ -53,6 +53,12 @@ __PACKAGE__->register_method({
>  		items => { type => 'array', items => { type => 'string' }},
>  		optional => 1,
>  	    },
> +	    current => {
> +		description => "Get current values (instead of pending values).",
> +		optional => 1,
> +		default => 0,
> +		type => 'boolean',
> +	    },

did you test this? the new parameter is in the return property instead 
of the parameters property..

>  	    digest => {
>  		type => 'string',
>  		description => 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
> @@ -73,11 +79,28 @@ __PACKAGE__->register_method({
>  	    $conf = $snapshot;
>  	}
>  
> +	# take pending changes in
> +	if (!$param->{current}) {
> +	    foreach my $opt (keys %{$conf->{pending}}) {
> +		next if $opt eq 'delete';
> +		my $value = $conf->{pending}->{$opt};
> +		next if ref($value); # just to be sure
> +		$conf->{$opt} = $value;
> +	    }
> +	    my $pending_delete_hash = PVE::LXC::Config->split_flagged_list($conf->{pending}->{delete});
> +	    foreach my $opt (keys %$pending_delete_hash) {
> +		delete $conf->{$opt} if $conf->{$opt};
> +	    }
> +	}
> +
> +
>  	delete $conf->{snapshots};
> +	delete $conf->{pending};

the whole thing is now identical (modulo comments and line ordering) to 
the same Qemu API path, except that Qemu also masks the 'cipassword' 
option if it is set.

we could instead move the whole 'delete snapshots, conditionally apply 
or delete pending changes' into a new AbstractConfig method 
(e.g., load_current_config($apply_pending)), or add two parameters to 
load_config to get this reduced config instead of the full one.

diff --git a/config_ct b/config_vm
index 04dbfe6..7372ba3 100644
--- a/config_ct
+++ b/config_vm
@@ -1,18 +1,19 @@
     code => sub {
 	my ($param) = @_;
 
-	my $conf = PVE::LXC::Config->load_config($param->{vmid});
+	my $conf = PVE::QemuConfig->load_config($param->{vmid});
 
 	if (my $snapname = $param->{snapshot}) {
 	    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};
+	    $snapshot->{digest} = $conf->{digest}; # keep file digest for API
+
 	    $conf = $snapshot;
 	}
 
-	# take pending changes in
+	delete $conf->{snapshots};
+
 	if (!$param->{current}) {
 	    foreach my $opt (keys %{$conf->{pending}}) {
 		next if $opt eq 'delete';
@@ -20,15 +21,18 @@
 		next if ref($value); # just to be sure
 		$conf->{$opt} = $value;
 	    }
-	    my $pending_delete_hash = PVE::LXC::Config->split_flagged_list($conf->{pending}->{delete});
+	    my $pending_delete_hash = PVE::QemuConfig->split_flagged_list($conf->{pending}->{delete});
 	    foreach my $opt (keys %$pending_delete_hash) {
 		delete $conf->{$opt} if $conf->{$opt};
 	    }
 	}
 
-
-	delete $conf->{snapshots};
 	delete $conf->{pending};
 
+	# hide cloudinit password
+	if ($conf->{cipassword}) {
+	    $conf->{cipassword} = '**********';
+	}
+
 	return $conf;
     }});

>  
>  	return $conf;
>      }});
>  
> +
>  my $vm_config_perm_list = [
>      'VM.Config.Disk',
>      'VM.Config.CPU',
> -- 
> 2.20.1
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 




More information about the pve-devel mailing list