]> git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/config.pm
b4316d80550ecce889504b0b2ee5bf2a26f11c38
[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::CLIFormatter;
13 use PVE::APIClient::CLIHandler;
14
15 use base qw(PVE::APIClient::CLIHandler);
16
17 my $list_return_props = { %{PVE::APIClient::DefaultsConfig->updateSchema(1)->{properties}} };
18 delete $list_return_props->{delete};
19
20 __PACKAGE__->register_method ({
21 name => 'list',
22 path => 'list',
23 method => 'GET',
24 description => "Dump default configuration.",
25 parameters => {
26 additionalProperties => 0,
27 properties => {},
28 },
29 returns => {
30 type => 'object',
31 properties => $list_return_props,
32 },
33 code => sub {
34
35 my $config = PVE::APIClient::Config->load();
36
37 my $defaults = PVE::APIClient::Config->get_defaults($config);
38
39 $defaults->{digest} = $config->{digest};
40
41 return $defaults;
42 }});
43
44 __PACKAGE__->register_method ({
45 name => 'set',
46 path => 'set',
47 method => 'PUT',
48 description => "Update a remote configuration.",
49 parameters => PVE::APIClient::DefaultsConfig->updateSchema(1),
50 returns => { type => 'null'},
51 code => sub {
52 my ($param) = @_;
53
54 my $digest = extract_param($param, 'digest');
55 my $delete = extract_param($param, 'delete');
56
57 my $code = sub {
58 my $config = PVE::APIClient::Config->load();
59
60 PVE::APIClient::Tools::assert_if_modified($config->{digest}, $digest);
61
62 my $defaults = PVE::APIClient::Config->get_defaults($config);
63
64 my $plugin = PVE::APIClient::Config->lookup('defaults');
65 my $opts = $plugin->check_config('defaults', $param, 0, 1);
66
67 foreach my $k (%$opts) {
68 $defaults->{$k} = $opts->{$k};
69 }
70
71 if ($delete) {
72 my $options = $plugin->private()->{options}->{'defaults'};
73 foreach my $k (PVE::APIClient::Tools::split_list($delete)) {
74 my $d = $options->{$k} ||
75 die "no such option '$k'\n";
76 die "unable to delete required option '$k'\n"
77 if !$d->{optional};
78 die "unable to delete fixed option '$k'\n"
79 if $d->{fixed};
80 delete $defaults->{$k};
81 }
82 }
83
84 PVE::APIClient::Config->save($config);
85 };
86
87 PVE::APIClient::Config->lock_config(undef, $code);
88
89 return undef;
90 }});
91
92
93 our $cmddef = {
94 set => [ __PACKAGE__, 'set',],
95 list => [__PACKAGE__, 'list', undef, undef,
96 sub {
97 my ($data, $schema, $options) = @_;
98
99 PVE::APIClient::CLIFormatter::print_api_result($data, $schema, undef, $options);
100 }
101 ],
102 };
103
104 1;