abstractconfig: add load_current_config and load_snapshot_config

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@proxmox.com>
This commit is contained in:
Oguz Bektas 2019-10-14 10:28:34 +02:00 committed by Thomas Lamprecht
parent 810ee08809
commit 61264e82be

View File

@ -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 {