]>
Commit | Line | Data |
---|---|---|
41d185e8 DM |
1 | package PVE::APIClient::Commands::config; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Data::Dumper; | |
6 | ||
7 | use PVE::JSONSchema qw(get_standard_option); | |
ca3269f4 | 8 | use PVE::APIClient::Tools qw(extract_param); |
41d185e8 DM |
9 | use PVE::APIClient::Config; |
10 | ||
11 | use PVE::CLIHandler; | |
12 | ||
13 | use base qw(PVE::CLIHandler); | |
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 | ||
80 | our $cmddef = { | |
81 | set => [ __PACKAGE__, 'set',], | |
82 | list => [__PACKAGE__, 'list'], | |
83 | }; | |
84 | ||
85 | 1; |