[pve-devel] [PATCH v3 guest-common 02/19] abstractconfig: add load_current_config and load_snapshot_config
Oguz Bektas
o.bektas at proxmox.com
Mon Oct 14 10:28:34 CEST 2019
this code is already used by qemu-server's GET config API call. it is
however better to split this into to methods and decide what to run in
the API call.
this general implementation uses some $class helpers which allow to abstract
away the difference in the child classes. this will be used for
containers once they can do pending changes.
Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
PVE/AbstractConfig.pm | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
index 4dce08a..f1e66a1 100644
--- a/PVE/AbstractConfig.pm
+++ b/PVE/AbstractConfig.pm
@@ -137,6 +137,46 @@ sub cleanup_pending {
return $changes;
}
+sub load_snapshot_config {
+ my ($class, $vmid, $snapname) = @_;
+
+ my $conf = $class->load_config($vmid);
+
+ my $snapshot = $conf->{snapshots}->{$snapname};
+ die "snapshot '$snapname' does not exist\n" if !defined($snapshot);
+
+ $snapshot->{digest} = $conf->{digest};
+
+ return $snapshot;
+
+}
+
+sub load_current_config {
+ my ($class, $vmid, $current) = @_;
+
+ my $conf = $class->load_config($vmid);
+
+ # 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