]>
Commit | Line | Data |
---|---|---|
41d185e8 DM |
1 | package PVE::APIClient::Commands::config; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Data::Dumper; | |
6 | ||
b4007425 | 7 | use PVE::APIClient::Helpers; |
c9138c03 | 8 | use PVE::APIClient::JSONSchema qw(get_standard_option); |
ca3269f4 | 9 | use PVE::APIClient::Tools qw(extract_param); |
41d185e8 DM |
10 | use PVE::APIClient::Config; |
11 | ||
59d3653b | 12 | use PVE::APIClient::CLIFormatter; |
c9138c03 | 13 | use PVE::APIClient::CLIHandler; |
41d185e8 | 14 | |
c9138c03 | 15 | use base qw(PVE::APIClient::CLIHandler); |
41d185e8 | 16 | |
e42d9cfe DM |
17 | my $list_return_props = { %{PVE::APIClient::DefaultsConfig->updateSchema(1)->{properties}} }; |
18 | delete $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 | ||
93 | our $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 | ||
104 | 1; |