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