]> git.proxmox.com Git - pve-client.git/blame - PVE/APIClient/Commands/config.pm
use packages from PVE::APIClient
[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
c9138c03 7use PVE::APIClient::JSONSchema qw(get_standard_option);
ca3269f4 8use PVE::APIClient::Tools qw(extract_param);
41d185e8
DM
9use PVE::APIClient::Config;
10
c9138c03 11use PVE::APIClient::CLIHandler;
41d185e8 12
c9138c03 13use base qw(PVE::APIClient::CLIHandler);
41d185e8
DM
14
15__PACKAGE__->register_method ({
16 name => 'list',
17 path => 'list',
18 method => 'GET',
19 description => "Dump default configuration.",
20 parameters => {
21 additionalProperties => 0,
22 },
23 returns => { type => 'null' },
24 code => sub {
25
26 my $config = PVE::APIClient::Config->load();
27
28 my $defaults = PVE::APIClient::Config->get_defaults($config);
29
30
31 print Dumper($config);
32
33 return undef;
34 }});
35
36__PACKAGE__->register_method ({
37 name => 'set',
38 path => 'set',
39 method => 'PUT',
40 description => "Update a remote configuration.",
41 parameters => PVE::APIClient::DefaultsConfig->updateSchema(1),
42 returns => { type => 'null'},
43 code => sub {
44 my ($param) = @_;
45
46 # fixme: lock config file
47
48 my $digest = extract_param($param, 'digest');
49 my $delete = extract_param($param, 'delete');
50
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'};
ca3269f4 63 foreach my $k (PVE::APIClient::Tools::split_list($delete)) {
41d185e8
DM
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 return undef;
77 }});
78
79
80our $cmddef = {
81 set => [ __PACKAGE__, 'set',],
82 list => [__PACKAGE__, 'list'],
83};
84
851;