]>
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 | ||
c9138c03 | 12 | use PVE::APIClient::CLIHandler; |
41d185e8 | 13 | |
c9138c03 | 14 | use base qw(PVE::APIClient::CLIHandler); |
41d185e8 DM |
15 | |
16 | __PACKAGE__->register_method ({ | |
17 | name => 'list', | |
18 | path => 'list', | |
19 | method => 'GET', | |
20 | description => "Dump default configuration.", | |
21 | parameters => { | |
22 | additionalProperties => 0, | |
23 | }, | |
24 | returns => { type => 'null' }, | |
25 | code => sub { | |
26 | ||
27 | my $config = PVE::APIClient::Config->load(); | |
b4007425 | 28 | |
41d185e8 DM |
29 | my $defaults = PVE::APIClient::Config->get_defaults($config); |
30 | ||
b4007425 | 31 | |
41d185e8 | 32 | print Dumper($config); |
b4007425 | 33 | |
41d185e8 DM |
34 | return undef; |
35 | }}); | |
36 | ||
37 | __PACKAGE__->register_method ({ | |
38 | name => 'set', | |
39 | path => 'set', | |
40 | method => 'PUT', | |
41 | description => "Update a remote configuration.", | |
42 | parameters => PVE::APIClient::DefaultsConfig->updateSchema(1), | |
43 | returns => { type => 'null'}, | |
44 | code => sub { | |
45 | my ($param) = @_; | |
46 | ||
41d185e8 DM |
47 | my $digest = extract_param($param, 'digest'); |
48 | my $delete = extract_param($param, 'delete'); | |
49 | ||
b4007425 DM |
50 | my $code = sub { |
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}; | |
41d185e8 | 59 | } |
41d185e8 | 60 | |
b4007425 DM |
61 | if ($delete) { |
62 | my $options = $plugin->private()->{options}->{'defaults'}; | |
63 | foreach my $k (PVE::APIClient::Tools::split_list($delete)) { | |
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 | ||
77 | PVE::APIClient::Config->lock_config(undef, $code); | |
41d185e8 DM |
78 | |
79 | return undef; | |
80 | }}); | |
81 | ||
82 | ||
83 | our $cmddef = { | |
84 | set => [ __PACKAGE__, 'set',], | |
85 | list => [__PACKAGE__, 'list'], | |
86 | }; | |
87 | ||
88 | 1; |