]> git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/config.pm
implement config file locking
[pve-client.git] / PVE / APIClient / Commands / config.pm
1 package PVE::APIClient::Commands::config;
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6
7 use PVE::APIClient::Helpers;
8 use PVE::APIClient::JSONSchema qw(get_standard_option);
9 use PVE::APIClient::Tools qw(extract_param);
10 use PVE::APIClient::Config;
11
12 use PVE::APIClient::CLIHandler;
13
14 use base qw(PVE::APIClient::CLIHandler);
15
16 __PACKAGE__->register_method ({
17 name => 'list',
18 path => 'list',
19 method => 'GET',
20 description => "Dump default configuration.",
21 parameters => {
22 additionalProperties => 0,
23 },
24 returns => { type => 'null' },
25 code => sub {
26
27 my $config = PVE::APIClient::Config->load();
28
29 my $defaults = PVE::APIClient::Config->get_defaults($config);
30
31
32 print Dumper($config);
33
34 return undef;
35 }});
36
37 __PACKAGE__->register_method ({
38 name => 'set',
39 path => 'set',
40 method => 'PUT',
41 description => "Update a remote configuration.",
42 parameters => PVE::APIClient::DefaultsConfig->updateSchema(1),
43 returns => { type => 'null'},
44 code => sub {
45 my ($param) = @_;
46
47 my $digest = extract_param($param, 'digest');
48 my $delete = extract_param($param, 'delete');
49
50 my $code = sub {
51 my $config = PVE::APIClient::Config->load();
52 my $defaults = PVE::APIClient::Config->get_defaults($config);
53
54 my $plugin = PVE::APIClient::Config->lookup('defaults');
55 my $opts = $plugin->check_config('defaults', $param, 0, 1);
56
57 foreach my $k (%$opts) {
58 $defaults->{$k} = $opts->{$k};
59 }
60
61 if ($delete) {
62 my $options = $plugin->private()->{options}->{'defaults'};
63 foreach my $k (PVE::APIClient::Tools::split_list($delete)) {
64 my $d = $options->{$k} ||
65 die "no such option '$k'\n";
66 die "unable to delete required option '$k'\n"
67 if !$d->{optional};
68 die "unable to delete fixed option '$k'\n"
69 if $d->{fixed};
70 delete $defaults->{$k};
71 }
72 }
73
74 PVE::APIClient::Config->save($config);
75 };
76
77 PVE::APIClient::Config->lock_config(undef, $code);
78
79 return undef;
80 }});
81
82
83 our $cmddef = {
84 set => [ __PACKAGE__, 'set',],
85 list => [__PACKAGE__, 'list'],
86 };
87
88 1;