X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FAPIClient%2FCommands%2Fconfig.pm;h=3b208a0e2311b163ad41e4134a522e9de7643e83;hb=b40074253447b60e2afad198872315e448da18f1;hp=d467b4c7102f6d8eee44cc09ba6daee5a54e02d9;hpb=05d328ef652f3895af2cab77903c578184244992;p=pve-client.git diff --git a/PVE/APIClient/Commands/config.pm b/PVE/APIClient/Commands/config.pm index d467b4c..3b208a0 100644 --- a/PVE/APIClient/Commands/config.pm +++ b/PVE/APIClient/Commands/config.pm @@ -4,6 +4,7 @@ use strict; use warnings; use Data::Dumper; +use PVE::APIClient::Helpers; use PVE::APIClient::JSONSchema qw(get_standard_option); use PVE::APIClient::Tools qw(extract_param); use PVE::APIClient::Config; @@ -24,12 +25,12 @@ __PACKAGE__->register_method ({ code => sub { my $config = PVE::APIClient::Config->load(); - + my $defaults = PVE::APIClient::Config->get_defaults($config); - + print Dumper($config); - + return undef; }}); @@ -43,35 +44,37 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; - # fixme: lock config file - my $digest = extract_param($param, 'digest'); my $delete = extract_param($param, 'delete'); - my $config = PVE::APIClient::Config->load(); - my $defaults = PVE::APIClient::Config->get_defaults($config); - - my $plugin = PVE::APIClient::Config->lookup('defaults'); - my $opts = $plugin->check_config('defaults', $param, 0, 1); - - foreach my $k (%$opts) { - $defaults->{$k} = $opts->{$k}; - } - - if ($delete) { - my $options = $plugin->private()->{options}->{'defaults'}; - foreach my $k (PVE::APIClient::Tools::split_list($delete)) { - my $d = $options->{$k} || - die "no such option '$k'\n"; - die "unable to delete required option '$k'\n" - if !$d->{optional}; - die "unable to delete fixed option '$k'\n" - if $d->{fixed}; - delete $defaults->{$k}; + my $code = sub { + my $config = PVE::APIClient::Config->load(); + my $defaults = PVE::APIClient::Config->get_defaults($config); + + my $plugin = PVE::APIClient::Config->lookup('defaults'); + my $opts = $plugin->check_config('defaults', $param, 0, 1); + + foreach my $k (%$opts) { + $defaults->{$k} = $opts->{$k}; } - } - PVE::APIClient::Config->save($config); + if ($delete) { + my $options = $plugin->private()->{options}->{'defaults'}; + foreach my $k (PVE::APIClient::Tools::split_list($delete)) { + my $d = $options->{$k} || + die "no such option '$k'\n"; + die "unable to delete required option '$k'\n" + if !$d->{optional}; + die "unable to delete fixed option '$k'\n" + if $d->{fixed}; + delete $defaults->{$k}; + } + } + + PVE::APIClient::Config->save($config); + }; + + PVE::APIClient::Config->lock_config(undef, $code); return undef; }});