[pve-devel] [PATCH v2 guest-common 02/18] refactor method used by config GET calls into AbstractConfig

Oguz Bektas o.bektas at proxmox.com
Mon Sep 30 14:44:34 CEST 2019


since this method will be both used by qemu and lxc config GET calls, it
makes sense to move it into AbstractConfig. only difference is that qemu
also hides the cipassword when it's set. this can be handled by having
qemu overwrite the method and add the cipassword code.

Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 PVE/AbstractConfig.pm | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
index 910ca86..6d3f169 100644
--- a/PVE/AbstractConfig.pm
+++ b/PVE/AbstractConfig.pm
@@ -136,6 +136,41 @@ sub cleanup_pending {
     return $changes;
 }
 
+sub load_current_config {
+    my ($class, $vmid, $snapname, $current) = @_;
+
+    my $conf = $class->load_config($vmid);
+
+    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;
+    }
+
+    # take pending changes in
+    if (!$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 = $class->parse_pending_delete($conf->{pending}->{delete});
+	foreach my $opt (keys %$pending_delete_hash) {
+	    delete $conf->{$opt} if $conf->{$opt};
+	}
+    }
+
+    delete $conf->{snapshots};
+    delete $conf->{pending};
+
+    return $conf;
+}
+
+
 # Lock config file using flock, run $code with @param, unlock config file.
 # $timeout is the maximum time to aquire the flock
 sub lock_config_full {
-- 
2.20.1




More information about the pve-devel mailing list