]> git.proxmox.com Git - pve-client.git/blame - PVE/APIClient/Commands/config.pm
use new features from pve-common
[pve-client.git] / PVE / APIClient / Commands / config.pm
CommitLineData
41d185e8
DM
1package PVE::APIClient::Commands::config;
2
3use strict;
4use warnings;
5use Data::Dumper;
6
b4007425 7use PVE::APIClient::Helpers;
c9138c03 8use PVE::APIClient::JSONSchema qw(get_standard_option);
ca3269f4 9use PVE::APIClient::Tools qw(extract_param);
41d185e8
DM
10use PVE::APIClient::Config;
11
59d3653b 12use PVE::APIClient::CLIFormatter;
c9138c03 13use PVE::APIClient::CLIHandler;
41d185e8 14
c9138c03 15use base qw(PVE::APIClient::CLIHandler);
41d185e8 16
e42d9cfe
DM
17my $list_return_props = { %{PVE::APIClient::DefaultsConfig->updateSchema(1)->{properties}} };
18delete $list_return_props->{delete};
19
41d185e8
DM
20__PACKAGE__->register_method ({
21 name => 'list',
22 path => 'list',
23 method => 'GET',
24 description => "Dump default configuration.",
25 parameters => {
26 additionalProperties => 0,
59d3653b 27 properties => {},
41d185e8 28 },
e42d9cfe
DM
29 returns => {
30 type => 'object',
31 properties => $list_return_props,
32 },
41d185e8
DM
33 code => sub {
34
35 my $config = PVE::APIClient::Config->load();
b4007425 36
41d185e8
DM
37 my $defaults = PVE::APIClient::Config->get_defaults($config);
38
e42d9cfe 39 $defaults->{digest} = $config->{digest};
b4007425 40
e42d9cfe 41 return $defaults;
41d185e8
DM
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
41d185e8
DM
54 my $digest = extract_param($param, 'digest');
55 my $delete = extract_param($param, 'delete');
56
b4007425
DM
57 my $code = sub {
58 my $config = PVE::APIClient::Config->load();
633508aa
DM
59
60 PVE::APIClient::Tools::assert_if_modified($config->{digest}, $digest);
61
b4007425
DM
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};
41d185e8 69 }
41d185e8 70
b4007425
DM
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);
41d185e8
DM
88
89 return undef;
90 }});
91
92
93our $cmddef = {
94 set => [ __PACKAGE__, 'set',],
59d3653b
DM
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 ],
41d185e8
DM
102};
103
1041;