mirror of
https://git.proxmox.com/git/pve-guest-common
synced 2025-04-28 16:42:06 +00:00
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:
parent
810ee08809
commit
61264e82be
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user