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